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

gm2calc: migrate to Conan v2 #18689

Merged
merged 5 commits into from
Nov 10, 2023
Merged
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
11 changes: 0 additions & 11 deletions recipes/gm2calc/all/CMakeLists.txt

This file was deleted.

4 changes: 3 additions & 1 deletion recipes/gm2calc/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"2.1.0":
url: "https://github.com/GM2Calc/GM2Calc/archive/v2.1.0.tar.gz"
sha256: "33fd0d6da089e25ae0a6ac81b70e9bc9152952e7be4383f4c0baa862af7921bb"
"2.2.0":
url: "https://github.com/GM2Calc/GM2Calc/archive/v2.2.0.tar.gz"
sha256: "02c36a3d1d58d66cd1bce8affcd64152d965596075730d51147dc5ac78323106"
patches:
"1.7.5":
- patch_file: "patches/0001-update-1.7.5-to-FindMathematica-3.6.0.patch"

Check warning on line 16 in recipes/gm2calc/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/0001-upd ... ^ (line: 16)
base_path: "source_subfolder"
100 changes: 60 additions & 40 deletions recipes/gm2calc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,94 @@
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, save
from conan.tools.scm import Version

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":
del self.options.fPIC

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.83.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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
tc.variables["ENABLE_TESTS"] = True

Since 2.2 you can actually disable tests:
https://github.com/GM2Calc/GM2Calc/blob/v2.2.0/CMakeLists.txt#L9

tc.generate()
tc = CMakeDeps(self)
tc.generate()

def _patch_sources(self):
apply_conandata_patches(self)
if Version(self.version) < "2.2.0":
replace_in_file(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"), "EIGEN3", "Eigen3")
# Fix src/slhaea.h:25:10: fatal error: boost/algorithm/string/classification.hpp: No such file or directory
save(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"),
"\ninclude_directories(${Boost_INCLUDE_DIRS})", append=True)
# Disable examples, test and doc
for subdir in ["examples", "test", "doc"]:
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), f"add_subdirectory({subdir})", "")

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"]
7 changes: 3 additions & 4 deletions recipes/gm2calc/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 15 additions & 6 deletions recipes/gm2calc/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
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", "VirtualRunEnv"
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)
cmake.configure()
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")
8 changes: 8 additions & 0 deletions recipes/gm2calc/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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/)
17 changes: 17 additions & 0 deletions recipes/gm2calc/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions recipes/gm2calc/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ versions:
folder: all
"2.1.0":
folder: all
"2.2.0":
folder: all