55from conan .tools .cmake import CMake , CMakeToolchain , cmake_layout
66from conan .tools .files import (
77 apply_conandata_patches , collect_libs , copy , export_conandata_patches , get ,
8- rename , replace_in_file , rmdir , save
8+ rename , replace_in_file , rmdir
99)
1010from conan .tools .scm import Version
1111
1212import os
13- import textwrap
1413
15- required_conan_version = ">=1.53.0 "
14+ required_conan_version = ">=2 "
1615
1716
1817class CryptoPPConan (ConanFile ):
@@ -36,28 +35,24 @@ class CryptoPPConan(ConanFile):
3635 "use_openmp" : False ,
3736 }
3837
38+ implements = ["auto_shared_fpic" ]
39+
3940 def export_sources (self ):
4041 export_conandata_patches (self )
4142
42- def config_options (self ):
43- if self .settings .os == "Windows" :
44- del self .options .fPIC
45-
46- def configure (self ):
47- if self .options .shared :
48- self .options .rm_safe ("fPIC" )
49-
5043 def layout (self ):
5144 cmake_layout (self , src_folder = "src" )
5245
5346 def validate_build (self ):
5447 if is_apple_os (self ) and cross_building (self ) and Version (self .version ) <= "8.6.0" :
5548 # See https://github.com/abdes/cryptopp-cmake/pull/38
5649 raise ConanInvalidConfiguration ("cryptopp 8.6.0 and lower do not support cross-building on Apple platforms" )
57-
50+
5851 def validate (self ):
5952 if self .options .shared and Version (self .version ) >= "8.7.0" :
6053 raise ConanInvalidConfiguration ("cryptopp 8.7.0 and higher do not support shared builds" )
54+ if Version (self .version ) < "8.9.0" and self .settings .os == "Windows" and self .settings .arch == "armv8" :
55+ raise ConanInvalidConfiguration ("Older releases do not support Windows ARM" )
6156
6257 def build_requirements (self ):
6358 if Version (self .version ) >= "8.7.0" :
@@ -82,6 +77,17 @@ def source(self):
8277 # Get cryptopp-cmake sources
8378 get (self , ** self .conan_data ["sources" ][self .version ]["cmake" ],
8479 destination = os .path .join (self .source_folder , "cryptopp-cmake" ), strip_root = True )
80+ self ._patch_sources ()
81+
82+ def _patch_sources (self ):
83+ apply_conandata_patches (self )
84+ # Honor fPIC option
85+ if Version (self .version ) < "8.7.0" :
86+ replace_in_file (self , os .path .join (self .source_folder , "CMakeLists.txt" ),
87+ "SET(CMAKE_POSITION_INDEPENDENT_CODE 1)" , "" )
88+ else :
89+ replace_in_file (self , os .path .join (self .source_folder , "cryptopp-cmake" , "cryptopp" , "CMakeLists.txt" ),
90+ "set(CMAKE_POSITION_INDEPENDENT_CODE 1)" , "" )
8591
8692 def generate (self ):
8793 tc = CMakeToolchain (self )
@@ -108,10 +114,10 @@ def generate(self):
108114 tc .cache_variables ["CRYPTOPP_NATIVE_ARCH" ] = True
109115 tc .cache_variables ["CRYPTOPP_USE_OPENMP" ] = self .options .use_openmp
110116 tc .cache_variables ["CMAKE_DISABLE_FIND_PACKAGE_Git" ] = True
117+ tc .cache_variables ["CMAKE_POLICY_VERSION_MINIMUM" ] = "3.5" # CMake 4 support
111118 tc .generate ()
112119
113- def _patch_sources (self ):
114- apply_conandata_patches (self )
120+ def _ensure_android_cpufeatures (self ):
115121 # Use cpu-features.h from Android NDK
116122 if self .settings .os == "Android" and Version (self .version ) < "8.4.0" :
117123 # Replicate logic from: https://github.com/weidai11/cryptopp/blob/CRYPTOPP_8_2_0/cpu.cpp#L46-L52
@@ -124,16 +130,9 @@ def _patch_sources(self):
124130 src = os .path .join (android_ndk_home , "sources" , "android" , "cpufeatures" ),
125131 dst = self .source_folder ,
126132 )
127- # Honor fPIC option
128- if Version (self .version ) < "8.7.0" :
129- replace_in_file (self , os .path .join (self .source_folder , "CMakeLists.txt" ),
130- "SET(CMAKE_POSITION_INDEPENDENT_CODE 1)" , "" )
131- else :
132- replace_in_file (self , os .path .join (self .source_folder , "cryptopp-cmake" , "cryptopp" , "CMakeLists.txt" ),
133- "set(CMAKE_POSITION_INDEPENDENT_CODE 1)" , "" )
134133
135134 def build (self ):
136- self ._patch_sources ()
135+ self ._ensure_android_cpufeatures ()
137136 cmake = CMake (self )
138137 if Version (self .version ) < "8.7.0" :
139138 cmake .configure ()
@@ -149,29 +148,6 @@ def package(self):
149148 rmdir (self , os .path .join (self .package_folder , "lib" , "cmake" ))
150149 else :
151150 rmdir (self , os .path .join (self .package_folder , "share" ))
152- # TODO: to remove in conan v2 once cmake_find_package* generators removed
153- self ._create_cmake_module_alias_targets (
154- os .path .join (self .package_folder , self ._module_file_rel_path ),
155- {
156- "cryptopp-shared" : "cryptopp::cryptopp-shared" ,
157- "cryptopp-static" : "cryptopp::cryptopp-static"
158- }
159- )
160-
161- def _create_cmake_module_alias_targets (self , module_file , targets ):
162- content = ""
163- for alias , aliased in targets .items ():
164- content += textwrap .dedent (f"""\
165- if(TARGET { aliased } AND NOT TARGET { alias } )
166- add_library({ alias } INTERFACE IMPORTED)
167- set_property(TARGET { alias } PROPERTY INTERFACE_LINK_LIBRARIES { aliased } )
168- endif()
169- """ )
170- save (self , module_file , content )
171-
172- @property
173- def _module_file_rel_path (self ):
174- return os .path .join ("lib" , "cmake" , f"conan-official-{ self .name } -targets.cmake" )
175151
176152 def package_info (self ):
177153 self .cpp_info .set_property ("cmake_file_name" , "cryptopp" )
@@ -195,11 +171,5 @@ def package_info(self):
195171 self .cpp_info .components ["libcryptopp" ].sharedlinkflags = openmp_flag
196172 self .cpp_info .components ["libcryptopp" ].exelinkflags = openmp_flag
197173
198- # TODO: to remove in conan v2 once cmake_find_package* & pkg_config generators removed
199- self .cpp_info .names ["pkg_config" ] = "libcryptopp"
200- self .cpp_info .components ["libcryptopp" ].names ["cmake_find_package" ] = legacy_cmake_target
201- self .cpp_info .components ["libcryptopp" ].names ["cmake_find_package_multi" ] = legacy_cmake_target
202- self .cpp_info .components ["libcryptopp" ].build_modules ["cmake_find_package" ] = [self ._module_file_rel_path ]
203- self .cpp_info .components ["libcryptopp" ].build_modules ["cmake_find_package_multi" ] = [self ._module_file_rel_path ]
204174 self .cpp_info .components ["libcryptopp" ].set_property ("cmake_target_name" , "cryptopp::cryptopp" )
205175 self .cpp_info .components ["libcryptopp" ].set_property ("pkg_config_name" , "libcryptopp" )
0 commit comments