Skip to content

Commit aa5bf41

Browse files
System-ArchStellaSmithSpaceIm
committed
(conan-io#14770) MPC Conan 2.0 Compatibility
* MPC Conan 2.0 Compatibility * Fixed lint errors * Fixed license copying code * Tweaked how win_bash is set * Added new metadata for patch * Try adding VirtrualBuildEnv for v1.x * Bump required_conan_version * Define CL-related flag macro values. * Import is_msvc * Add automake as a tool_requires * Fixed typo * Recognize that recipe lacks Visual Studio support * Formatting tweak * Added blank line to trigger CI build * Use autotools.autoreconf() per review suggestion * Add "m" as system_libs * Add call to fix_apple_shared_install_name Co-authored-by: Stella Smith <[email protected]> * Removed setting of shared/static options per code review * Incorporate @spacelm's review feedback Co-authored-by: SpaceIm <[email protected]> * Per review feedback --------- Co-authored-by: Stella Smith <[email protected]> Co-authored-by: SpaceIm <[email protected]>
1 parent aac5c3a commit aa5bf41

File tree

6 files changed

+100
-46
lines changed

6 files changed

+100
-46
lines changed

recipes/mpc/all/conandata.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ sources:
88
patches:
99
"1.2.0":
1010
- patch_file: "patches/1.2.0-0001-asin-missing-limits.patch"
11-
base_path: "source_subfolder"
11+
patch_description: "asin.c needs limits.h"
12+
patch_type: "portability"

recipes/mpc/all/conanfile.py

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
from conans import ConanFile, AutoToolsBuildEnvironment, tools
2-
from conans.errors import ConanInvalidConfiguration
1+
from conan import ConanFile
2+
from conan.tools.build import cross_building
3+
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
4+
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir
5+
from conan.tools.layout import basic_layout
6+
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps
7+
from conan.tools.microsoft import is_msvc, unix_path
8+
from conan.tools.apple import fix_apple_shared_install_name
9+
from conan.errors import ConanInvalidConfiguration
310
import os
411

5-
required_conan_version = ">=1.33.0"
12+
13+
required_conan_version = ">=1.54.0"
614

715
class MpcConan(ConanFile):
816
name = "mpc"
17+
package_type = "library"
918
description = "GNU MPC is a C library for the arithmetic of complex numbers with arbitrarily high precision " \
1019
"and correct rounding of the result"
1120
topics = ("conan", "mpc", "multiprecision", "math", "mathematics")
@@ -15,66 +24,78 @@ class MpcConan(ConanFile):
1524
settings = "os", "arch", "compiler", "build_type"
1625
options = {"shared": [True, False], "fPIC": [True, False]}
1726
default_options = {"shared": False, "fPIC": True}
18-
exports_sources = "patches/**"
19-
_autotools = None
2027

21-
@property
22-
def _source_subfolder(self):
23-
return "source_subfolder"
28+
def export_sources(self):
29+
export_conandata_patches(self)
2430

2531
def config_options(self):
2632
if self.settings.os == 'Windows':
27-
del self.options.fPIC
33+
self.options.rm_safe("fPIC")
2834

2935
def configure(self):
3036
if self.options.shared:
31-
del self.options.fPIC
32-
del self.settings.compiler.libcxx
33-
del self.settings.compiler.cppstd
37+
self.options.rm_safe("fPIC")
38+
self.settings.rm_safe("compiler.libcxx")
39+
self.settings.rm_safe("compiler.cppstd")
3440

3541
def requirements(self):
36-
self.requires("mpfr/4.1.0")
42+
self.requires("gmp/6.2.1", transitive_headers=True)
43+
self.requires("mpfr/4.1.0", transitive_headers=True)
3744

3845
def validate(self):
39-
# FIXME: add Visual Studio support, upstream has a makefile.vc
40-
if self.settings.compiler == "Visual Studio":
41-
raise ConanInvalidConfiguration("mpc can be built with Visual Studio, but it's not supported yet in this recipe.")
46+
# FIXME: add msvc support, upstream has a makefile.vc
47+
if is_msvc(self):
48+
raise ConanInvalidConfiguration("mpc can be built with msvc, but it's not supported yet in this recipe.")
4249

4350
@property
4451
def _settings_build(self):
4552
return getattr(self, "settings_build", self.settings)
4653

4754
def build_requirements(self):
48-
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
49-
self.build_requires("msys2/cci.latest")
55+
if self._settings_build.os == "Windows":
56+
self.win_bash = True
57+
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
58+
self.tool_requires("msys2/cci.latest")
59+
60+
def layout(self):
61+
basic_layout(self, src_folder="src")
5062

5163
def source(self):
52-
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
64+
get(self, **self.conan_data["sources"][self.version],
65+
destination=self.source_folder, strip_root=True)
5366

54-
def _configure_autotools(self):
55-
if self._autotools:
56-
return self._autotools
57-
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
58-
args = []
59-
if self.options.shared:
60-
args.extend(["--disable-static", "--enable-shared"])
61-
else:
62-
args.extend(["--disable-shared", "--enable-static"])
63-
self._autotools.configure(args=args, configure_dir=self._source_subfolder)
64-
return self._autotools
67+
def generate(self):
68+
env = VirtualBuildEnv(self)
69+
env.generate()
70+
if not cross_building(self):
71+
env = VirtualRunEnv(self)
72+
env.generate(scope="build")
73+
74+
tc = AutotoolsToolchain(self)
75+
tc.configure_args.append(f'--with-gmp={unix_path(self, self.dependencies["gmp"].package_folder)}')
76+
tc.configure_args.append(f'--with-mpfr={unix_path(self, self.dependencies["mpfr"].package_folder)}')
77+
tc.generate()
78+
79+
tc = AutotoolsDeps(self)
80+
tc.generate()
6581

6682
def build(self):
67-
for patch in self.conan_data.get("patches", {}).get(self.version, []):
68-
tools.patch(**patch)
69-
autotools = self._configure_autotools()
83+
apply_conandata_patches(self)
84+
autotools = Autotools(self)
85+
if not os.path.exists(os.path.join(self.source_folder, "configure")):
86+
autotools.autoreconf(["-i"])
87+
autotools.configure()
7088
autotools.make()
7189

7290
def package(self):
73-
self.copy(pattern="COPYING.LESSER", dst="licenses", src=self._source_subfolder)
74-
autotools = self._configure_autotools()
91+
copy(self, "COPYING.LESSER", self.source_folder, os.path.join(self.package_folder, "licenses"), keep_path=False)
92+
autotools = Autotools(self)
7593
autotools.install()
76-
tools.rmdir(os.path.join(self.package_folder, "share"))
77-
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
94+
fix_apple_shared_install_name(self)
95+
rmdir(self, os.path.join(self.package_folder, "share"))
96+
rm(self, "*.la", os.path.join(self.package_folder, "lib"), recursive=True)
7897

7998
def package_info(self):
8099
self.cpp_info.libs = ["mpc"]
100+
if self.settings.os in ["Linux", "FreeBSD"]:
101+
self.cpp_info.system_libs = ["m"]
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
cmake_minimum_required(VERSION 3.1)
22
project(test_package C)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup()
4+
find_package(mpc REQUIRED CONFIG)
65

76
add_executable(${PROJECT_NAME} test_package.c)
8-
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
7+
target_link_libraries(${PROJECT_NAME} PRIVATE mpc::mpc)
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
from conans import ConanFile, CMake, tools
1+
from conan import ConanFile
2+
from conan.tools.cmake import CMake, cmake_layout
3+
from conan.tools.build import cross_building
24
import os
35

46

57
class TestPackageConan(ConanFile):
68
settings = "os", "compiler", "build_type", "arch"
7-
generators = "cmake"
9+
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
10+
11+
def layout(self):
12+
cmake_layout(self)
13+
14+
def requirements(self):
15+
self.requires(self.tested_reference_str)
816

917
def build(self):
1018
cmake = CMake(self)
1119
cmake.configure()
1220
cmake.build()
1321

1422
def test(self):
15-
if not tools.cross_building(self.settings):
16-
bin_path = os.path.join("bin", "test_package")
17-
self.run(bin_path, run_environment=True)
23+
if not cross_building(self):
24+
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
25+
self.run(bin_path, env="conanrun")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
8+
${CMAKE_CURRENT_BINARY_DIR}/test_package)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from conans import ConanFile, CMake, tools
2+
import os
3+
4+
5+
class TestPackageConan(ConanFile):
6+
settings = "os", "compiler", "build_type", "arch"
7+
generators = "cmake", "cmake_find_package_multi"
8+
9+
def build(self):
10+
cmake = CMake(self)
11+
cmake.configure()
12+
cmake.build()
13+
14+
def test(self):
15+
if not tools.cross_building(self.settings):
16+
bin_path = os.path.join("bin", "test_package")
17+
self.run(bin_path, run_environment=True)

0 commit comments

Comments
 (0)