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
3
10
import os
4
11
5
- required_conan_version = ">=1.33.0"
12
+
13
+ required_conan_version = ">=1.54.0"
6
14
7
15
class MpcConan (ConanFile ):
8
16
name = "mpc"
17
+ package_type = "library"
9
18
description = "GNU MPC is a C library for the arithmetic of complex numbers with arbitrarily high precision " \
10
19
"and correct rounding of the result"
11
20
topics = ("conan" , "mpc" , "multiprecision" , "math" , "mathematics" )
@@ -15,66 +24,78 @@ class MpcConan(ConanFile):
15
24
settings = "os" , "arch" , "compiler" , "build_type"
16
25
options = {"shared" : [True , False ], "fPIC" : [True , False ]}
17
26
default_options = {"shared" : False , "fPIC" : True }
18
- exports_sources = "patches/**"
19
- _autotools = None
20
27
21
- @property
22
- def _source_subfolder (self ):
23
- return "source_subfolder"
28
+ def export_sources (self ):
29
+ export_conandata_patches (self )
24
30
25
31
def config_options (self ):
26
32
if self .settings .os == 'Windows' :
27
- del self .options .fPIC
33
+ self .options .rm_safe ( " fPIC" )
28
34
29
35
def configure (self ):
30
36
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" )
34
40
35
41
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 )
37
44
38
45
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." )
42
49
43
50
@property
44
51
def _settings_build (self ):
45
52
return getattr (self , "settings_build" , self .settings )
46
53
47
54
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" )
50
62
51
63
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 )
53
66
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 ()
65
81
66
82
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 ()
70
88
autotools .make ()
71
89
72
90
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 )
75
93
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 )
78
97
79
98
def package_info (self ):
80
99
self .cpp_info .libs = ["mpc" ]
100
+ if self .settings .os in ["Linux" , "FreeBSD" ]:
101
+ self .cpp_info .system_libs = ["m" ]
0 commit comments