1
- from conans import ConanFile , CMake , tools
2
- from conans .errors import ConanInvalidConfiguration
1
+ from conan import ConanFile
2
+ from conan .errors import ConanInvalidConfiguration
3
+ from conan .tools .files import apply_conandata_patches , export_conandata_patches , get , copy , replace_in_file , rm
4
+ from conan .tools .cmake import CMake , CMakeDeps , CMakeToolchain , cmake_layout
5
+ from conan .tools .build import check_min_cppstd
3
6
import os
4
7
5
- required_conan_version = ">=1.33.0"
6
-
8
+ required_conan_version = ">=1.53.0"
7
9
8
10
class CassandraCppDriverConan (ConanFile ):
9
11
name = "cassandra-cpp-driver"
12
+ description = "DataStax C/C++ Driver for Apache Cassandra and DataStax Products"
10
13
license = "Apache-2.0"
11
14
url = "https://github.com/conan-io/conan-center-index"
12
15
homepage = "https://docs.datastax.com/en/developer/cpp-driver/"
13
- description = "DataStax C/C++ Driver for Apache Cassandra and DataStax Products"
14
- topics = ("cassandra" , "cpp-driver" , "database" , "conan-recipe" )
15
-
16
- settings = "os" , "compiler" , "build_type" , "arch"
16
+ topics = ("cassandra" , "cpp-driver" , "database" ,)
17
+ settings = "os" , "arch" , "compiler" , "build_type"
17
18
options = {
18
19
"shared" : [True , False ],
19
20
"fPIC" : [True , False ],
@@ -34,19 +35,14 @@ class CassandraCppDriverConan(ConanFile):
34
35
"with_kerberos" : False ,
35
36
"use_timerfd" : True ,
36
37
}
37
-
38
38
short_paths = True
39
- generators = "cmake"
40
- exports_sources = [
41
- "CMakeLists.txt" ,
42
- "patches/*"
43
- ]
44
-
45
- _cmake = None
46
39
47
40
@property
48
- def _source_subfolder (self ):
49
- return "source_subfolder"
41
+ def _min_cppstd (self ):
42
+ return 11
43
+
44
+ def export_sources (self ):
45
+ export_conandata_patches (self )
50
46
51
47
def config_options (self ):
52
48
if self .settings .os == "Windows" :
@@ -55,24 +51,30 @@ def config_options(self):
55
51
56
52
def configure (self ):
57
53
if self .options .shared :
58
- del self .options .fPIC
54
+ self .options .rm_safe ("fPIC" )
55
+
56
+ def layout (self ):
57
+ cmake_layout (self , src_folder = "src" )
59
58
60
59
def requirements (self ):
61
- self .requires ("libuv/1.44.1 " )
60
+ self .requires ("libuv/1.46.0 " )
62
61
self .requires ("http_parser/2.9.4" )
63
- self .requires ("rapidjson/cci.20211112 " )
62
+ self .requires ("rapidjson/cci.20220822 " )
64
63
65
64
if self .options .with_openssl :
66
- self .requires ("openssl/1.1.1q " )
65
+ self .requires ("openssl/[>= 1.1 <4] " )
67
66
68
67
if self .options .with_zlib :
69
- self .requires ("minizip/1.2.12 " )
70
- self .requires ("zlib/1.2.12 " )
68
+ self .requires ("minizip/1.2.13 " )
69
+ self .requires ("zlib/1.2.13 " )
71
70
72
71
if self .options .use_atomic == "boost" :
73
- self .requires ("boost/1.79 .0" )
72
+ self .requires ("boost/1.82 .0" )
74
73
75
74
def validate (self ):
75
+ if self .info .settings .compiler .cppstd :
76
+ check_min_cppstd (self , self ._min_cppstd )
77
+
76
78
if self .options .use_atomic == "boost" :
77
79
# Compilation error on Linux
78
80
if self .settings .os == "Linux" :
@@ -84,69 +86,69 @@ def validate(self):
84
86
"Kerberos is not supported at the moment" )
85
87
86
88
def source (self ):
87
- tools .get (** self .conan_data ["sources" ][self .version ],
88
- destination = self ._source_subfolder , strip_root = True )
89
-
90
- def _patch_sources (self ):
91
- for patch in self .conan_data .get ("patches" , {}).get (self .version , []):
92
- tools .patch (** patch )
93
- tools .replace_in_file (os .path .join (self ._source_subfolder , "CMakeLists.txt" ),
94
- "\" ${CMAKE_CXX_COMPILER_ID}\" STREQUAL \" Clang\" " ,
95
- "\" ${CMAKE_CXX_COMPILER_ID}\" STREQUAL \" Clang\" OR \" ${CMAKE_CXX_COMPILER_ID}\" STREQUAL \" AppleClang\" " )
96
-
97
- def _configure_cmake (self ):
98
- if self ._cmake :
99
- return self ._cmake
100
-
101
- self ._cmake = CMake (self )
102
- self ._cmake .definitions ["VERSION" ] = self .version
103
- self ._cmake .definitions ["CASS_BUILD_EXAMPLES" ] = False
104
- self ._cmake .definitions ["CASS_BUILD_INTEGRATION_TESTS" ] = False
105
- self ._cmake .definitions ["CASS_BUILD_SHARED" ] = self .options .shared
106
- self ._cmake .definitions ["CASS_BUILD_STATIC" ] = not self .options .shared
107
- self ._cmake .definitions ["CASS_BUILD_TESTS" ] = False
108
- self ._cmake .definitions ["CASS_BUILD_UNIT_TESTS" ] = False
109
- self ._cmake .definitions ["CASS_DEBUG_CUSTOM_ALLOC" ] = False
110
- self ._cmake .definitions ["CASS_INSTALL_HEADER_IN_SUBDIR" ] = self .options .install_header_in_subdir
111
- self ._cmake .definitions ["CASS_INSTALL_PKG_CONFIG" ] = False
89
+ get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
90
+
91
+ def generate (self ):
92
+ tc = CMakeToolchain (self )
93
+ tc .variables ["VERSION" ] = self .version
94
+ tc .variables ["CASS_BUILD_EXAMPLES" ] = False
95
+ tc .variables ["CASS_BUILD_INTEGRATION_TESTS" ] = False
96
+ tc .variables ["CASS_BUILD_SHARED" ] = self .options .shared
97
+ tc .variables ["CASS_BUILD_STATIC" ] = not self .options .shared
98
+ tc .variables ["CASS_BUILD_TESTS" ] = False
99
+ tc .variables ["CASS_BUILD_UNIT_TESTS" ] = False
100
+ tc .variables ["CASS_DEBUG_CUSTOM_ALLOC" ] = False
101
+ tc .variables ["CASS_INSTALL_HEADER_IN_SUBDIR" ] = self .options .install_header_in_subdir
102
+ tc .variables ["CASS_INSTALL_PKG_CONFIG" ] = False
112
103
113
104
if self .options .use_atomic == "boost" :
114
- self . _cmake . definitions ["CASS_USE_BOOST_ATOMIC" ] = True
115
- self . _cmake . definitions ["CASS_USE_STD_ATOMIC" ] = False
105
+ tc . variables ["CASS_USE_BOOST_ATOMIC" ] = True
106
+ tc . variables ["CASS_USE_STD_ATOMIC" ] = False
116
107
117
108
elif self .options .use_atomic == "std" :
118
- self . _cmake . definitions ["CASS_USE_BOOST_ATOMIC" ] = False
119
- self . _cmake . definitions ["CASS_USE_STD_ATOMIC" ] = True
109
+ tc . variables ["CASS_USE_BOOST_ATOMIC" ] = False
110
+ tc . variables ["CASS_USE_STD_ATOMIC" ] = True
120
111
else :
121
- self . _cmake . definitions ["CASS_USE_BOOST_ATOMIC" ] = False
122
- self . _cmake . definitions ["CASS_USE_STD_ATOMIC" ] = False
112
+ tc . variables ["CASS_USE_BOOST_ATOMIC" ] = False
113
+ tc . variables ["CASS_USE_STD_ATOMIC" ] = False
123
114
124
- self . _cmake . definitions ["CASS_USE_OPENSSL" ] = self .options .with_openssl
125
- self . _cmake . definitions ["CASS_USE_STATIC_LIBS" ] = False
126
- self . _cmake . definitions ["CASS_USE_ZLIB" ] = self .options .with_zlib
127
- self . _cmake . definitions ["CASS_USE_LIBSSH2" ] = False
115
+ tc . variables ["CASS_USE_OPENSSL" ] = self .options .with_openssl
116
+ tc . variables ["CASS_USE_STATIC_LIBS" ] = False
117
+ tc . variables ["CASS_USE_ZLIB" ] = self .options .with_zlib
118
+ tc . variables ["CASS_USE_LIBSSH2" ] = False
128
119
129
120
# FIXME: To use kerberos, its conan package is needed. Uncomment this when kerberos conan package is ready.
130
- # self._cmake.definitions ["CASS_USE_KERBEROS"] = self.options.with_kerberos
121
+ # tc.variables ["CASS_USE_KERBEROS"] = self.options.with_kerberos
131
122
132
123
if self .settings .os == "Linux" :
133
- self ._cmake .definitions ["CASS_USE_TIMERFD" ] = self .options .use_timerfd
124
+ tc .variables ["CASS_USE_TIMERFD" ] = self .options .use_timerfd
125
+ tc .generate ()
134
126
135
- self ._cmake .configure ()
136
- return self ._cmake
127
+ deps = CMakeDeps (self )
128
+ deps .generate ()
129
+
130
+ def _patch_sources (self ):
131
+ apply_conandata_patches (self )
132
+ replace_in_file (self , os .path .join (self .source_folder , "CMakeLists.txt" ),
133
+ "\" ${CMAKE_CXX_COMPILER_ID}\" STREQUAL \" Clang\" " ,
134
+ "\" ${CMAKE_CXX_COMPILER_ID}\" STREQUAL \" Clang\" OR \" ${CMAKE_CXX_COMPILER_ID}\" STREQUAL \" AppleClang\" " )
135
+ rm (self , "Findlibssh2.cmake" , os .path .join (self .source_folder , "cmake" ))
136
+ rm (self , "Findlibuv.cmake" , os .path .join (self .source_folder , "cmake" ))
137
+ rm (self , "FindOpenSSL.cmake" , os .path .join (self .source_folder , "cmake" ))
137
138
138
139
def build (self ):
139
140
self ._patch_sources ()
140
- cmake = self ._configure_cmake ()
141
+ cmake = CMake (self )
142
+ cmake .configure ()
141
143
cmake .build ()
142
144
143
145
def package (self ):
144
- self . copy (pattern = "LICENSE.txt" , dst = "licenses" , src = self ._source_subfolder )
145
- cmake = self . _configure_cmake ( )
146
+ copy (self , pattern = "LICENSE.txt" , dst = os . path . join ( self . package_folder , "licenses" ) , src = self .source_folder )
147
+ cmake = CMake ( self )
146
148
cmake .install ()
147
149
148
150
def package_info (self ):
149
- self .cpp_info .libs = tools . collect_libs ( self )
151
+ self .cpp_info .libs = [ "cassandra" if self . options . shared else "cassandra_static" ]
150
152
151
153
if self .settings .os == "Windows" :
152
154
self .cpp_info .system_libs .extend (["iphlpapi" , "psapi" , "wsock32" ,
0 commit comments