Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cppcheck: add version 2.9.0, support conan v2 #14277

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions recipes/cppcheck/all/CMakeLists.txt

This file was deleted.

22 changes: 14 additions & 8 deletions recipes/cppcheck/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
sources:
"2.9.0":
url: "https://github.com/danmar/cppcheck/archive/refs/tags/2.9.tar.gz"
sha256: "56aee8b5bdf936ab7adc9ab43903ba2052f088695c80f047682024a1ed0ef3f3"
"2.7.5":
url: "https://github.com/danmar/cppcheck/archive/2.7.5.tar.gz"
sha256: "6c7ac29e57fa8b3ac7be224510200e579d5a90217e2152591ef46ffc947d8f78"
"2.7.4":
url: "https://github.com/danmar/cppcheck/archive/2.7.4.tar.gz"
sha256: "f0558c497b7807763325f3a821f1c72b743e5d888b037b8d32157dd07d6c26e1"
patches:
"2.9.0":
- patch_file: "patches/2.9.0-0001-fix-cmake.patch"
patch_description: "support 'NOT USE_BUNDLED_TINYXML2'"
patch_type: "conan"
- patch_file: "patches/0002-htmlreport-python3.patch"
"2.7.5":
- patch_file: "patches/0001-cmake-source-dir-2.5.patch"
base_path: "source_subfolder"
- patch_file: "patches/2.7.4-0001-fix-cmake.patch"
patch_description: "fix variable names for conan recipes, support 'NOT USE_BUNDLED_TINYXML2'"
patch_type: "conan"
- patch_file: "patches/0002-htmlreport-python3.patch"
base_path: "source_subfolder"
- patch_file: "patches/0003-handle-exename-on-macos.patch"
base_path: "source_subfolder"
"2.7.4":
- patch_file: "patches/0001-cmake-source-dir-2.5.patch"
base_path: "source_subfolder"
- patch_file: "patches/2.7.4-0001-fix-cmake.patch"
patch_description: "fix variable names for conan recipes, support 'NOT USE_BUNDLED_TINYXML2'"
patch_type: "conan"
- patch_file: "patches/0002-htmlreport-python3.patch"
base_path: "source_subfolder"
- patch_file: "patches/0003-handle-exename-on-macos.patch"
base_path: "source_subfolder"
118 changes: 77 additions & 41 deletions recipes/cppcheck/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,110 @@
from conans import ConanFile, CMake, tools
import functools
import os
from conan import ConanFile
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir, replace_in_file
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout

required_conan_version = ">=1.33.0"
import os

required_conan_version = ">=1.53.0"

class CppcheckConan(ConanFile):
name = "cppcheck"
description = "Cppcheck is an analysis tool for C/C++ code."
license = "GPL-3.0-or-later"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/danmar/cppcheck"
topics = ("Cpp Check", "static analyzer")
description = "Cppcheck is an analysis tool for C/C++ code."
license = "GPL-3.0-or-later"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
options = {"with_z3": [True, False], "have_rules": [True, False]}
default_options = {"with_z3": True, "have_rules": True}
exports_sources = ["CMakeLists.txt", "patches/**"]
options = {
"with_z3": [True, False],
"have_rules": [True, False],
"with_threads": [True, False],
"with_boost": [True, False],
}
default_options = {
"with_z3": True,
"have_rules": True,
"with_threads": False,
"with_boost": False,
}

@property
def _source_subfolder(self):
return "source_subfolder"
def _min_cppstd(self):
return 11

@property
def _build_subfolder(self):
return "build_subfolder"
def config_options(self):
if Version(self.version) < "2.8":
del self.options.with_threads
del self.options.with_boost
else:
del self.options.with_z3

def _patch_sources(self):
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)
tools.replace_in_file(os.path.join(self._source_subfolder, "cli", "CMakeLists.txt"),
"RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}",
"DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}")
def export_sources(self):
export_conandata_patches(self)

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if self.options.with_z3:
self.requires("z3/4.8.8")
if self.options.get_safe("with_z3"):
self.requires("z3/4.10.2")
if self.options.have_rules:
self.requires("pcre/8.45")
self.requires("tinyxml2/9.0.0")
if self.options.get_safe("with_boost"):
self.requires("boost/1.80.0")

def validate(self):
if self.info.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["USE_Z3"] = self.options.with_z3
cmake.definitions["HAVE_RULES"] = self.options.have_rules
cmake.definitions["USE_MATCHCOMPILER"] = "Auto"
cmake.definitions["ENABLE_OSS_FUZZ"] = False
cmake.configure(build_folder=self._build_subfolder)
return cmake
def generate(self):
tc = CMakeToolchain(self)
if "with_z3" in self.options:
tc.variables["USE_Z3"] = self.options.with_z3
tc.variables["HAVE_RULES"] = self.options.have_rules
# TODO: force disable until cpython requires latest zlib (which conflicts other dependencies)
tc.variables["USE_MATCHCOMPILER"] = "Off"
tc.variables["ENABLE_OSS_FUZZ"] = False
tc.variables["USE_BUNDLED_TINYXML2"] = False
if "with_threads" in self.options:
tc.variables["USE_THREADS"] = self.options.with_threads
if "with_boost" in self.options:
tc.variables["USE_BOOST"] = self.options.with_boost
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)
replace_in_file(self, os.path.join(self.source_folder, "cli", "CMakeLists.txt"),
"RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}",
"DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}")

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
self.copy("*", dst=os.path.join("bin","cfg"), src=os.path.join(self._source_subfolder,"cfg"))
self.copy("cppcheck-htmlreport", dst=os.path.join("bin"), src=os.path.join(self._source_subfolder,"htmlreport"))
cmake = self._configure_cmake()
copy(self, pattern="COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)

copy(self, "*", dst=os.path.join(self.package_folder, "bin", "cfg"), src=os.path.join(self.source_folder,"cfg"))
copy(self, "cppcheck-htmlreport", dst=os.path.join(self.package_folder, "bin"), src=os.path.join(self.source_folder,"htmlreport"))

cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
bin_folder = os.path.join(self.package_folder, "bin")
self.output.info("Append %s to environment variable PATH" % bin_folder)
self.output.info(f"Append {bin_folder} to environment variable PATH")
self.env_info.PATH.append(bin_folder)
# This is required to run the python script on windows, as we cannot simply add it to the PATH
self.env_info.CPPCHECK_HTMLREPORT = os.path.join(bin_folder, "cppcheck-htmlreport")
36 changes: 0 additions & 36 deletions recipes/cppcheck/all/patches/0001-cmake-source-dir-2.5.patch

This file was deleted.

35 changes: 0 additions & 35 deletions recipes/cppcheck/all/patches/0001-cmake-source-dir.patch

This file was deleted.

49 changes: 49 additions & 0 deletions recipes/cppcheck/all/patches/2.7.4-0001-fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt
index 6293540..bb40aba 100644
--- a/cli/CMakeLists.txt
+++ b/cli/CMakeLists.txt
@@ -7,6 +7,8 @@ add_library(cli_objs OBJECT ${hdrs} ${srcs})
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
if(USE_BUNDLED_TINYXML2)
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
+else()
+ target_include_directories(cli_objs PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)

@@ -27,6 +29,10 @@ endif()
if (USE_Z3)
target_link_libraries(cppcheck ${Z3_LIBRARIES})
endif()
+if(NOT USE_BUNDLED_TINYXML2)
+ target_link_libraries(cppcheck ${tinyxml2_LIBRARIES})
+endif()
+
if (WIN32 AND NOT BORLAND)
if(NOT MINGW)
target_link_libraries(cppcheck Shlwapi.lib)
diff --git a/cmake/findDependencies.cmake b/cmake/findDependencies.cmake
index b8c1817..206a4ae 100644
--- a/cmake/findDependencies.cmake
+++ b/cmake/findDependencies.cmake
@@ -34,6 +34,7 @@ if (USE_Z3)
message(FATAL_ERROR "z3++.h has not been found")
endif()
endif()
+ set(Z3_CXX_INCLUDE_DIRS "${Z3_INCLUDE_DIRS}")
endif()

set(CMAKE_INCLUDE_CURRENT_DIR ON)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 48c70ec..e79df4a 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -36,6 +36,8 @@ add_library(lib_objs OBJECT ${srcs_lib} ${hdrs})
target_include_directories(lib_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/)
if(USE_BUNDLED_TINYXML2)
target_include_directories(lib_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
+else()
+ target_include_directories(lib_objs PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_include_directories(lib_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/picojson/)
target_include_directories(lib_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
36 changes: 36 additions & 0 deletions recipes/cppcheck/all/patches/2.9.0-0001-fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt
index aee67e6..bb5ade2 100644
--- a/cli/CMakeLists.txt
+++ b/cli/CMakeLists.txt
@@ -7,6 +7,8 @@ add_library(cli_objs OBJECT ${hdrs} ${srcs})
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
if(USE_BUNDLED_TINYXML2)
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
+else()
+ target_include_directories(cli_objs PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)

@@ -29,6 +31,9 @@ target_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/simp
if (HAVE_RULES)
target_link_libraries(cppcheck ${PCRE_LIBRARY})
endif()
+if(NOT USE_BUNDLED_TINYXML2)
+ target_link_libraries(cppcheck ${tinyxml2_LIBRARIES})
+endif()
if (WIN32 AND NOT BORLAND)
if(NOT MINGW)
target_link_libraries(cppcheck Shlwapi.lib)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 44af140..bb4ce5e 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -36,6 +36,8 @@ add_library(lib_objs OBJECT ${srcs_lib} ${hdrs})
target_include_directories(lib_objs SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/externals/)
if(USE_BUNDLED_TINYXML2)
target_include_directories(lib_objs SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
+else()
+ target_include_directories(lib_objs SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_include_directories(lib_objs SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/externals/picojson/)
target_include_directories(lib_objs SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
Loading