11import os
22
3- from conan import ConanFile , conan_version
3+ from conan import ConanFile
44from conan .errors import ConanInvalidConfiguration
55from conan .tools .build import check_min_cppstd
66from conan .tools .cmake import CMake , CMakeDeps , CMakeToolchain , cmake_layout
77from conan .tools .env import VirtualBuildEnv
88from conan .tools .files import get , copy , rmdir , rm , save , replace_in_file , export_conandata_patches , apply_conandata_patches
99from conan .tools .scm import Version
1010
11- required_conan_version = ">=1.60.0 <2.0 || >= 2.0.6"
11+ required_conan_version = ">=2.0.6"
1212
1313class OusterSdkConan (ConanFile ):
1414 name = "ouster_sdk"
1515 description = "Ouster SDK - tools for working with Ouster Lidars"
16- license = "BSD 3-Clause"
16+ license = "BSD- 3-Clause"
1717 url = "https://github.com/conan-io/conan-center-index"
1818 homepage = "https://github.com/ouster-lidar/ouster-sdk"
1919 topics = ("ouster" , "lidar" , "driver" , "hardware" , "point cloud" , "3d" , "robotics" , "automotive" )
@@ -43,30 +43,12 @@ class OusterSdkConan(ConanFile):
4343 "eigen_max_align_bytes" : "Force maximum alignment of Eigen data to 32 bytes." ,
4444 }
4545
46- @property
47- def _min_cppstd (self ):
48- return 17
49-
50- @property
51- def _compilers_minimum_version (self ):
52- return {
53- "gcc" : "7" ,
54- "clang" : "5" ,
55- "apple-clang" : "10" ,
56- "msvc" : "191" ,
57- "Visual Studio" : "15" ,
58- }
59-
6046 def export_sources (self ):
6147 export_conandata_patches (self )
6248
6349 def config_options (self ):
6450 if self .settings .os == "Windows" :
6551 del self .options .fPIC
66- if conan_version .major == 1 :
67- # Turning off by default due to perpetually missing libtins binaries on CCI
68- self .options .build_pcap = False
69- self .options .build_osf = False
7052
7153 def configure (self ):
7254 if self .options .shared :
@@ -78,37 +60,37 @@ def layout(self):
7860 def requirements (self ):
7961 # Used in ouster/types.h
8062 self .requires ("eigen/3.4.0" , transitive_headers = True )
81- # Used in ouster/sensor_http.h
82- self .requires ("jsoncpp/1.9.5" , transitive_headers = True , transitive_libs = True )
83- self .requires ("spdlog/1.13.0" )
84- self .requires ("fmt/10.2.1" )
8563 self .requires ("libcurl/[>=7.78 <9]" )
8664 # Replaces vendored optional-lite
8765 self .requires ("optional-lite/3.6.0" , transitive_headers = True )
66+ if Version (self .version ) < "0.14.0" :
67+ # Used in ouster/sensor_http.h
68+ # 0.14.0+ replaced jsoncpp by vendorized jsoncons
69+ self .requires ("jsoncpp/1.9.5" , transitive_headers = True , transitive_libs = True )
70+ # 0.14.0+ vendorized spdlog instead of external dependency
71+ self .requires ("spdlog/[>=1.12.0 <1.15]" )
8872
8973 if self .options .build_pcap :
9074 self .requires ("libtins/4.5" )
75+ if Version (self .version ) >= "0.14.0" :
76+ self .requires ("libpcap/1.10.5" )
9177
9278 if self .options .build_osf :
9379 # Used in fb_generated/*.h
9480 self .requires ("flatbuffers/24.3.7" , transitive_headers = True )
95- self .requires ("libpng/[>=1.6 <2]" )
81+ # 0.12.0+ shared_library uses private libpng in ouster_osf and result in missing symbols
82+ # 0.11.0 and earlier used private libpng in ouster_osf
83+ self .requires ("libpng/[>=1.6 <2]" , transitive_libs = True )
9684 self .requires ("zlib/[>=1.2.11 <2]" , transitive_libs = True )
9785
9886 if self .options .build_viz :
99- self .requires ("glad/0.1.36" )
87+ if Version (self .version ) < "0.14.0" :
88+ # 0.14.0+ vendorized glad
89+ self .requires ("glad/0.1.36" )
10090 self .requires ("glfw/3.4" )
10191
10292 def validate (self ):
103- if conan_version .major < 2 and self .settings .os == "Windows" :
104- raise ConanInvalidConfiguration ("Windows builds require Conan >= 2.0" )
105- if self .settings .compiler .cppstd :
106- check_min_cppstd (self , self ._min_cppstd )
107- minimum_version = self ._compilers_minimum_version .get (str (self .settings .compiler ))
108- if minimum_version and Version (self .settings .compiler .version ) < minimum_version :
109- raise ConanInvalidConfiguration (
110- f"{ self .ref } requires C++{ self ._min_cppstd } , which your compiler does not support."
111- )
93+ check_min_cppstd (self , 14 )
11294
11395 if self .options .build_osf and not self .options .build_pcap :
11496 raise ConanInvalidConfiguration ("build_osf=True requires build_pcap=True" )
@@ -122,16 +104,19 @@ def build_requirements(self):
122104
123105 def source (self ):
124106 get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
107+ self ._patch_sources ()
125108
126109 def generate (self ):
127110 env = VirtualBuildEnv (self )
128111 env .generate ()
129112 tc = CMakeToolchain (self )
130- tc .variables ["BUILD_VIZ" ] = self .options .build_viz
131- tc .variables ["BUILD_PCAP" ] = self .options .build_pcap
132- tc .variables ["BUILD_OSF" ] = self .options .build_osf
133- tc .variables ["OUSTER_USE_EIGEN_MAX_ALIGN_BYTES_32" ] = self .options .eigen_max_align_bytes
113+ tc .cache_variables ["BUILD_VIZ" ] = self .options .build_viz
114+ tc .cache_variables ["BUILD_PCAP" ] = self .options .build_pcap
115+ tc .cache_variables ["BUILD_OSF" ] = self .options .build_osf
116+ tc .cache_variables ["OUSTER_USE_EIGEN_MAX_ALIGN_BYTES_32" ] = self .options .eigen_max_align_bytes
134117 tc .cache_variables ["CMAKE_POLICY_DEFAULT_CMP0077" ] = "NEW"
118+ if Version (self .version ) >= "0.14.0" :
119+ tc .cache_variables ["BUILD_SHARED_LIBRARY" ] = self .options .shared
135120 tc .generate ()
136121 deps = CMakeDeps (self )
137122 deps .set_property ("flatbuffers" , "cmake_target_name" , "flatbuffers::flatbuffers" )
@@ -149,42 +134,55 @@ def _patch_sources(self):
149134 "target_link_libraries(ouster_client PUBLIC nonstd::optional-lite)\n " ,
150135 append = True )
151136
152- # Allow non-static ouster_osf for consistency with other components
153- replace_in_file (self , os .path .join (self .source_folder , "ouster_osf" , "CMakeLists.txt" ),
154- "add_library(ouster_osf STATIC" , "add_library(ouster_osf" )
137+ if Version (self .version ) < "0.14.0" :
138+ # Allow non-static ouster_osf for consistency with other components
139+ # FIXME: This was applied previously in the recipe, but does not follow the upstream
140+ # in 0.14.0, it breaks because shared_library.dylib expects static ouster_osf
141+ replace_in_file (self , os .path .join (self .source_folder , "ouster_osf" , "CMakeLists.txt" ),
142+ "add_library(ouster_osf STATIC" , "add_library(ouster_osf" )
143+
155144
156145 def build (self ):
157- self ._patch_sources ()
158146 cmake = CMake (self )
159147 cmake .configure ()
160148 cmake .build ()
161149
162150 def package (self ):
163- copy (self , pattern = "LICENSE" , dst = os .path .join (self .package_folder , "licenses" ), src = self .source_folder )
151+ copy (self , pattern = "LICENSE* " , dst = os .path .join (self .package_folder , "licenses" ), src = self .source_folder )
164152 cmake = CMake (self )
165153 cmake .install ()
166154 rmdir (self , os .path .join (self .package_folder , "lib" , "cmake" ))
167155 rmdir (self , os .path .join (self .package_folder , "share" ))
168156 rm (self , "*.pdb" , self .package_folder , recursive = True )
157+ if Version (self .version ) >= "0.14.0" and self .options .shared :
158+ # INFO: Version 0.14.0+ produces both shared and static libraries when shared=True
159+ rm (self , "*.a" , os .path .join (self .package_folder , "lib" ))
169160
170161 def package_info (self ):
171162 self .cpp_info .set_property ("cmake_file_name" , "OusterSDK" )
172163 self .cpp_info .set_property ("cmake_target_name" , "OusterSDK::OusterSDK" )
164+ produce_library = Version (self .version ) < "0.14.0" or not self .options .shared
173165
174166 self .cpp_info .components ["ouster_client" ].set_property ("cmake_target_name" , "OusterSDK::ouster_client" )
175- self .cpp_info .components ["ouster_client" ].libs = ["ouster_client" ]
167+ self .cpp_info .components ["ouster_client" ].libs = ["ouster_client" ] if produce_library else []
176168 self .cpp_info .components ["ouster_client" ].requires = [
177169 "eigen::eigen" ,
178- "jsoncpp::jsoncpp" ,
179- "spdlog::spdlog" ,
180- "fmt::fmt" ,
181170 "libcurl::libcurl" ,
182171 "optional-lite::optional-lite" ,
183172 ]
173+ if self .settings .os == "Windows" :
174+ self .cpp_info .components ["ouster_client" ].system_libs = ["ws2_32" ]
175+ if Version (self .version ) >= "0.14.0" :
176+ if self .settings .os in ["Linux" , "FreeBSD" ]:
177+ self .cpp_info .components ["ouster_client" ].system_libs = ["pthread" ]
178+ else :
179+ self .cpp_info .components ["ouster_client" ].requires .extend (["jsoncpp::jsoncpp" , "spdlog::spdlog" ,])
180+ if self .options .eigen_max_align_bytes :
181+ self .cpp_info .components ["ouster_client" ].defines = ["EIGEN_MAX_ALIGN_BYTES=32" ]
184182
185183 if self .options .build_osf :
186184 self .cpp_info .components ["ouster_osf" ].set_property ("cmake_target_name" , "OusterSDK::ouster_osf" )
187- self .cpp_info .components ["ouster_osf" ].libs = ["ouster_osf" ]
185+ self .cpp_info .components ["ouster_osf" ].libs = ["ouster_osf" ] if produce_library else []
188186 self .cpp_info .components ["ouster_osf" ].includedirs .append (os .path .join ("include" , "fb_generated" ))
189187 self .cpp_info .components ["ouster_osf" ].requires = [
190188 "ouster_client" ,
@@ -196,24 +194,35 @@ def package_info(self):
196194
197195 if self .options .build_pcap :
198196 self .cpp_info .components ["ouster_pcap" ].set_property ("cmake_target_name" , "OusterSDK::ouster_pcap" )
199- self .cpp_info .components ["ouster_pcap" ].libs = ["ouster_pcap" ]
197+ self .cpp_info .components ["ouster_pcap" ].libs = ["ouster_pcap" ] if produce_library else []
200198 self .cpp_info .components ["ouster_pcap" ].requires = [
201199 "ouster_client" ,
202200 "libtins::libtins" ,
203201 ]
202+ if Version (self .version ) >= "0.14.0" :
203+ self .cpp_info .components ["ouster_pcap" ].requires .append ("libpcap::libpcap" )
204+ if self .settings .os == "Windows" :
205+ self .cpp_info .components ["ouster_pcap" ].system_libs = ["ws2_32" ]
204206
205207 if self .options .build_viz :
206208 self .cpp_info .components ["ouster_viz" ].set_property ("cmake_target_name" , "OusterSDK::ouster_viz" )
207- self .cpp_info .components ["ouster_viz" ].libs = ["ouster_viz" ]
209+ self .cpp_info .components ["ouster_viz" ].libs = ["ouster_viz" ] if produce_library else []
208210 self .cpp_info .components ["ouster_viz" ].requires = [
209211 "ouster_client" ,
210- "glad::glad" ,
211212 "glfw::glfw" ,
212213 ]
213-
214- # TODO: to remove in conan v2 once cmake_find_package_* generators removed
215- self .cpp_info .filenames ["cmake_find_package" ] = "OusterSDK"
216- self .cpp_info .filenames ["cmake_find_package_multi" ] = "OusterSDK"
217- self .cpp_info .names ["cmake_find_package" ] = "OusterSDK"
218- self .cpp_info .names ["cmake_find_package_multi" ] = "OusterSDK"
219-
214+ if Version (self .version ) >= "0.14.0" :
215+ self .cpp_info .components ["ouster_viz" ].libs .append ("glad" )
216+ else :
217+ self .cpp_info .components ["ouster_viz" ].requires .append ("glad::glad" )
218+
219+ if Version (self .version ) >= "0.14.0" and self .options .shared :
220+ self .cpp_info .components ["shared_library" ].set_property ("cmake_target_name" , "OusterSDK::shared_library" )
221+ self .cpp_info .components ["shared_library" ].libs = ["shared_library" ]
222+ self .cpp_info .components ["shared_library" ].requires = ["ouster_client" ]
223+ if self .options .build_osf :
224+ self .cpp_info .components ["shared_library" ].requires .append ("ouster_osf" )
225+ if self .options .build_pcap :
226+ self .cpp_info .components ["shared_library" ].requires .append ("ouster_pcap" )
227+ if self .options .build_viz :
228+ self .cpp_info .components ["shared_library" ].requires .append ("ouster_viz" )
0 commit comments