Skip to content

Commit

Permalink
(#15025) GMP Conan 2.0 compatibilty
Browse files Browse the repository at this point in the history
* GMP Conan 2.0 compatibilty

* Fixed lint warning

* Pull in changes

* Remove blank line to poke CI

Why do merged commits always cause a GitHub merge failure the first time they execute? Is there a race condition somewhere in the implementation?

* Work around Conan 1.x limitations

* Update naming of user.automake:lib-wrapper

* Bump required_conan_version

* Restore ordering of env capture per Spacelm's insights

* Add "m" as system_libs for gmpxx component

* Added blank line to re-run CI build

* libm not on Windows

* Removed blank line to re-run CI build

* Leverage CMake ctest functionality

* Fixed lint issue
  • Loading branch information
System-Arch authored Feb 14, 2023
1 parent 5f9985b commit 03a899d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
38 changes: 18 additions & 20 deletions recipes/gmp/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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([
Expand All @@ -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)

Expand All @@ -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"))
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions recipes/gmp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 5 additions & 7 deletions recipes/gmp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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")

0 comments on commit 03a899d

Please sign in to comment.