diff --git a/recipes/gmp/all/conanfile.py b/recipes/gmp/all/conanfile.py index 6d9215c94d74d..44f661282ff5d 100644 --- a/recipes/gmp/all/conanfile.py +++ b/recipes/gmp/all/conanfile.py @@ -10,8 +10,7 @@ import os import stat -required_conan_version = ">=1.54.0" - +required_conan_version = ">=1.56.0" class GmpConan(ConanFile): name = "gmp" @@ -46,10 +45,6 @@ class GmpConan(ConanFile): def _settings_build(self): return getattr(self, "settings_build", self.settings) - @property - def _user_info_build(self): - return getattr(self, "user_info_build", self.deps_user_info) - def export_sources(self): export_conandata_patches(self) @@ -87,11 +82,12 @@ def build_requirements(self): if not self.conf.get("tools.microsoft.bash:path", check_type=str): self.tool_requires("msys2/cci.latest") if is_msvc(self): - self.tool_requires("yasm/1.3.0") - self.tool_requires("automake/1.16.5") + self.tool_requires("yasm/1.3.0") # Needed for determining 32-bit word size + self.tool_requires("automake/1.16.5") # Needed for lib-wrapper def source(self): - get(self, **self.conan_data["sources"][self.version], strip_root=True, verify=False) + get(self, **self.conan_data["sources"][self.version], + destination=self.source_folder, strip_root=True) def generate(self): env = VirtualBuildEnv(self) @@ -100,11 +96,11 @@ def generate(self): tc = AutotoolsToolchain(self) yes_no = lambda v: "yes" if v else "no" tc.configure_args.extend([ - "--with-pic={}".format(yes_no(self.options.get_safe("fPIC", True))), - "--enable-assembly={}".format(yes_no(not self.options.get_safe("disable_assembly", False))), - "--enable-fat={}".format(yes_no(self.options.get_safe("enable_fat", False))), - "--enable-cxx={}".format(yes_no(self.options.enable_cxx)), - "--srcdir={}".format(self.source_folder.replace("\\", "/")), + f'--with-pic={yes_no(self.options.get_safe("fPIC", True))}', + f'--enable-assembly={yes_no(not self.options.get_safe("disable_assembly", False))}', + f'--enable-fat={yes_no(self.options.get_safe("enable_fat", False))}', + f'--enable-cxx={yes_no(self.options.enable_cxx)}', + f'--srcdir={"../src"}', # Use relative path to avoid issues with #include "$srcdir/gmp-h.in" on Windows ]) if is_msvc(self): tc.configure_args.extend([ @@ -113,24 +109,24 @@ def generate(self): "lt_cv_sys_global_symbol_pipe=cat", # added to get further in shared MSVC build, but it gets stuck later ]) tc.extra_cxxflags.append("-EHsc") - if (str(self.settings.compiler) == "Visual Studio" and Version(self.settings.compiler.version) >= "12") or \ - (str(self.settings.compiler) == "msvc" and Version(self.settings.compiler.version) >= "180"): + if (self.settings.compiler == "msvc" and Version(self.settings.compiler.version) >= "180") or \ + (self.settings.compiler == "Visual Studio" and Version(self.settings.compiler.version) >= "12"): tc.extra_cflags.append("-FS") tc.extra_cxxflags.append("-FS") - env = tc.environment() + env = tc.environment() # Environment must be captured *after* setting extra_cflags, etc. to pick up changes if is_msvc(self): yasm_wrapper = unix_path(self, os.path.join(self.source_folder, "yasm_wrapper.sh")) yasm_machine = { "x86": "x86", "x86_64": "amd64", }[str(self.settings.arch)] - ar_wrapper = unix_path(self, self._user_info_build["automake"].ar_lib) + ar_wrapper = unix_path(self, self.conf.get("user.automake:lib-wrapper")) dumpbin_nm = unix_path(self, os.path.join(self.source_folder, "dumpbin_nm.py")) env.define("CC", "cl -nologo") env.define("CCAS", f"{yasm_wrapper} -a x86 -m {yasm_machine} -p gas -r raw -f win32 -g null -X gnu") env.define("CXX", "cl -nologo") env.define("LD", "link -nologo") - env.define("AR", f"{ar_wrapper} \"lib -nologo\"") + env.define("AR", f'{ar_wrapper} "lib -nologo"') env.define("NM", f"python {dumpbin_nm}") tc.generate(env) @@ -149,7 +145,7 @@ def build(self): autotools.make() # INFO: According to the gmp readme file, make check should not be omitted, but it causes timeouts on the CI server. if self.options.run_checks: - autotools.make(args=["check"]) + autotools.make(target="check") def package(self): copy(self, "COPYINGv2", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) @@ -171,6 +167,8 @@ def package_info(self): self.cpp_info.components["gmpxx"].set_property("pkg_config_name", "gmpxx") self.cpp_info.components["gmpxx"].libs = ["gmpxx"] self.cpp_info.components["gmpxx"].requires = ["libgmp"] + if self.settings.os != "Windows": + self.cpp_info.components["gmpxx"].system_libs = ["m"] # TODO: to remove in conan v2 once cmake_find_package_* generators removed # GMP doesn't have any official CMake Find nor config file, do not port these names to CMakeDeps diff --git a/recipes/gmp/all/test_package/CMakeLists.txt b/recipes/gmp/all/test_package/CMakeLists.txt index 382515baaeb92..ba2fbfaf5b1f9 100644 --- a/recipes/gmp/all/test_package/CMakeLists.txt +++ b/recipes/gmp/all/test_package/CMakeLists.txt @@ -1,18 +1,24 @@ cmake_minimum_required(VERSION 3.1) project(test_package LANGUAGES C) +enable_testing() + find_package(gmp REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.c) target_link_libraries(${PROJECT_NAME} PRIVATE gmp::libgmp) +add_test(NAME ${PROJECT_NAME}_test COMMAND ${PROJECT_NAME}) if(TEST_PIC) - add_library(${PROJECT_NAME}_shared SHARED test_package.c) - target_link_libraries(${PROJECT_NAME}_shared PRIVATE gmp::libgmp) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + add_executable(${PROJECT_NAME}_pic test_package.c) + target_link_libraries(${PROJECT_NAME}_pic PRIVATE gmp::libgmp) + add_test(NAME ${PROJECT_NAME}_pic_test COMMAND ${PROJECT_NAME}_pic) endif() if(ENABLE_CXX) enable_language(CXX) add_executable(${PROJECT_NAME}_cpp test_package.cpp) target_link_libraries(${PROJECT_NAME}_cpp PRIVATE gmp::gmpxx) + add_test(NAME ${PROJECT_NAME}_cpp_test COMMAND ${PROJECT_NAME}_cpp) endif() diff --git a/recipes/gmp/all/test_package/conanfile.py b/recipes/gmp/all/test_package/conanfile.py index 472d139ec19ee..408e5ddb1389c 100644 --- a/recipes/gmp/all/test_package/conanfile.py +++ b/recipes/gmp/all/test_package/conanfile.py @@ -1,7 +1,7 @@ from conan import ConanFile from conan.tools.build import can_run from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout -import os +from conan.tools.files import chdir class TestPackageConan(ConanFile): @@ -27,9 +27,7 @@ def build(self): cmake.build() def test(self): - if can_run(self): - bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") - self.run(bin_path, env="conanrun") - if self.options["gmp"].enable_cxx: - bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package_cpp") - self.run(bin_path, env="conanrun") + if not can_run(self): + return + with chdir(self, self.folders.build_folder): + self.run(f"ctest --output-on-failure -C {self.settings.build_type}", env="conanrun")