From b9853319f036b53da3d64a171a32eb733449f10d Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 19 Jul 2023 23:23:29 +0300 Subject: [PATCH] gm2calc: migrate to Conan v2 --- recipes/gm2calc/all/CMakeLists.txt | 11 --- recipes/gm2calc/all/conandata.yml | 1 - recipes/gm2calc/all/conanfile.py | 92 +++++++++++-------- .../gm2calc/all/test_package/CMakeLists.txt | 7 +- recipes/gm2calc/all/test_package/conanfile.py | 21 +++-- .../all/test_v1_package/CMakeLists.txt | 8 ++ .../gm2calc/all/test_v1_package/conanfile.py | 17 ++++ 7 files changed, 95 insertions(+), 62 deletions(-) delete mode 100644 recipes/gm2calc/all/CMakeLists.txt create mode 100644 recipes/gm2calc/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/gm2calc/all/test_v1_package/conanfile.py diff --git a/recipes/gm2calc/all/CMakeLists.txt b/recipes/gm2calc/all/CMakeLists.txt deleted file mode 100644 index 023f135034eeda..00000000000000 --- a/recipes/gm2calc/all/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -cmake_minimum_required(VERSION 3.4) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup() - -if(MSVC AND BUILD_SHARED_LIBS) - set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) -endif() - -add_subdirectory("source_subfolder") diff --git a/recipes/gm2calc/all/conandata.yml b/recipes/gm2calc/all/conandata.yml index 5246438fdf67a1..204ea150e923a6 100644 --- a/recipes/gm2calc/all/conandata.yml +++ b/recipes/gm2calc/all/conandata.yml @@ -11,4 +11,3 @@ sources: patches: "1.7.5": - patch_file: "patches/0001-update-1.7.5-to-FindMathematica-3.6.0.patch" - base_path: "source_subfolder" diff --git a/recipes/gm2calc/all/conanfile.py b/recipes/gm2calc/all/conanfile.py index 5332dc62195c9e..ef9ccce10ba521 100644 --- a/recipes/gm2calc/all/conanfile.py +++ b/recipes/gm2calc/all/conanfile.py @@ -1,35 +1,34 @@ import os -import conan -from conans import ConanFile, CMake, tools -required_conan_version = ">=1.30.0" +from conan import ConanFile +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, replace_in_file + +required_conan_version = ">=1.53.0" class Gm2calcConan(ConanFile): name = "gm2calc" + description = "C++ library to calculate the anomalous magnetic moment of the muon in the MSSM and 2HDM" license = "GPL-3.0" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/GM2Calc/GM2Calc" - description = "C++ library to calculate the anomalous magnetic moment of the muon in the MSSM and 2HDM" topics = ("high-energy", "physics", "hep", "magnetic moment", "muon", "mssm", "2hdm") - settings = "os", "compiler", "build_type", "arch" - options = {"shared": [True, False], "fPIC": [True, False]} - default_options = {"shared": False, "fPIC": True} - exports_sources = ["CMakeLists.txt"] - generators = "cmake", "cmake_find_package" - _cmake = None - - @property - def _source_subfolder(self): - return "source_subfolder" - @property - def _build_subfolder(self): - return "build_subfolder" + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } def export_sources(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - self.copy(patch["patch_file"]) + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": @@ -37,38 +36,51 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self, src_folder="src") def requirements(self): - self.requires("boost/1.75.0") - self.requires("eigen/3.3.9") + self.requires("boost/1.82.0") + self.requires("eigen/3.4.0", transitive_headers=True) + + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, 11) def source(self): - tools.get(**self.conan_data["sources"][self.version]) - conan.tools.files.rename(self, "GM2Calc-{}".format(self.version), self._source_subfolder) + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True + tc.generate() + tc = CMakeDeps(self) + tc.generate() + + def _patch_sources(self): + apply_conandata_patches(self) + replace_in_file(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"), "EIGEN3", "Eigen3") def build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - cmake = self._configure_cmake() + self._patch_sources() + cmake = CMake(self) + cmake.configure() cmake.build() - def _configure_cmake(self): - if self._cmake: - return self._cmake - self._cmake = CMake(self) - self._cmake.configure(build_folder=self._build_subfolder) - return self._cmake - def package(self): - self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder) - cmake = self._configure_cmake() + copy(self, "COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + 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): + self.cpp_info.set_property("cmake_file_name", "GM2Calc") + self.cpp_info.set_property("cmake_target_name", "GM2Calc::GM2Calc") + self.cpp_info.set_property("pkg_config_name", "gm2calc") + self.cpp_info.libs = ["gm2calc"] + + # TODO: to remove in conan v2 once cmake_find_package_* generators removed self.cpp_info.names["cmake_find_package"] = "GM2Calc" self.cpp_info.names["cmake_find_package_multi"] = "GM2Calc" - self.cpp_info.names["pkg_config"] = "gm2calc" - self.cpp_info.libs = ["gm2calc"] - self.cpp_info.requires = ["boost::headers", "eigen::eigen"] diff --git a/recipes/gm2calc/all/test_package/CMakeLists.txt b/recipes/gm2calc/all/test_package/CMakeLists.txt index 126cafe808e380..4cff2f8c273e98 100644 --- a/recipes/gm2calc/all/test_package/CMakeLists.txt +++ b/recipes/gm2calc/all/test_package/CMakeLists.txt @@ -1,11 +1,10 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) project(PackageTest C CXX) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() +find_package(GM2Calc REQUIRED CONFIG) add_executable(test_package test_package.cpp) -target_link_libraries(test_package ${CONAN_LIBS}) +target_link_libraries(test_package PRIVATE GM2Calc::GM2Calc) diff --git a/recipes/gm2calc/all/test_package/conanfile.py b/recipes/gm2calc/all/test_package/conanfile.py index ab40ee8b181e8a..fae501d0afb9e4 100644 --- a/recipes/gm2calc/all/test_package/conanfile.py +++ b/recipes/gm2calc/all/test_package/conanfile.py @@ -1,11 +1,19 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake import os -from conans import ConanFile, CMake, tools +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain" + test_type = "explicit" -class Gm2calcTestConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake" + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) @@ -13,5 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - self.run(os.path.join("bin", "test_package"), run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/gm2calc/all/test_v1_package/CMakeLists.txt b/recipes/gm2calc/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..91630d79f4abb3 --- /dev/null +++ b/recipes/gm2calc/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/gm2calc/all/test_v1_package/conanfile.py b/recipes/gm2calc/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..5ff327440fd867 --- /dev/null +++ b/recipes/gm2calc/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +import os + +from conans import ConanFile, CMake, tools + + +class Gm2calcTestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + self.run(os.path.join("bin", "test_package"), run_environment=True)