forked from ouster-lidar/ouster-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
159 lines (137 loc) · 5.6 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# ==== Debug params ============
# == NOTE(pb): Left intentionally
# set(CMAKE_VERBOSE_MAKEFILE OFF)
# set(CMAKE_FIND_DEBUG_MODE OFF)
option(OUSTER_OSF_NO_MMAP "Don't use mmap(), useful for WASM targets" OFF)
option(OUSTER_OSF_NO_THREADING "Don't use threads, useful for WASM targets" OFF)
# ==== Requirements ====
find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(jsoncpp REQUIRED)
find_package(spdlog REQUIRED)
include(Coverage)
# TODO: Extract to a separate FindFlatbuffers cmake file
# Flatbuffers flatc resolution and different search name 'flatbuffers` with Conan
# NOTE2[pb]: 200221007: We changed Conan cmake package to look to `flatbuffers`
# because it started failing out of blue :idk:scream: will see.
if(NOT CONAN_EXPORTED)
find_package(Flatbuffers REQUIRED)
if(NOT DEFINED FLATBUFFERS_FLATC_EXECUTABLE)
set(FLATBUFFERS_FLATC_EXECUTABLE flatbuffers::flatc)
endif()
message(STATUS "Flatbuffers found: ${Flatbuffers_DIR}" )
else()
find_package(flatbuffers REQUIRED)
if(WIN32)
set(FLATBUFFERS_FLATC_EXECUTABLE flatc.exe)
else()
set(FLATBUFFERS_FLATC_EXECUTABLE flatc)
endif()
message(STATUS "flatbuffers found: ${Flatbuffers_DIR}" )
endif()
# TODO[pb]: Move to flatbuffers 2.0 and check do we still need this???
# Using this link lib search method so to get shared .so library and not
# static in Debian systems. But it correctly find static lib in vcpkg/manylinux
# builds.
# STORY: We need to make it static (but with -fPIC) for Python bindings.
# However in Debian packages we can only use shared libs because static
# are not compiled with PIC. Though in vcpkg it uses static lib,
# which we've confirmed to be the case and what we need for manylinux.
# find_library(flatbuffers_lib NAMES flatbuffers REQUIRED)
# set(flatbuffers_lib flatbuffers::flatbuffers)
# === Flatbuffer builder functions ====
include(cmake/osf_fb_utils.cmake)
set(OSF_FB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/fb)
set(FB_SOURCE_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/fb_source_generated)
set(FB_BINARY_SCHEMA_DIR ${CMAKE_CURRENT_BINARY_DIR}/fb_binary_schemas)
set(FB_MODULES_TO_BUILD os_sensor streaming ml)
# ======= Typescript Flatbuffer Generators =====
set(FB_TS_GENERATED_DIR ${FB_SOURCE_GEN_DIR}/ts)
build_ts_fb_modules(
TARGET ts_gen
FB_DIR "${OSF_FB_DIR}"
FB_MODULES "${FB_MODULES_TO_BUILD}"
SOURCE_GEN_DIR "${FB_TS_GENERATED_DIR}"
)
# ======= Python Flatbuffer Generators =====
set(FB_PYTHON_GENERATED_DIR ${FB_SOURCE_GEN_DIR}/python)
build_py_fb_modules(
TARGET py_gen
FB_DIR "${OSF_FB_DIR}"
SOURCE_GEN_DIR "${FB_PYTHON_GENERATED_DIR}"
)
# ======= C++ Flatbuffer Generators =====
set(FB_CPP_GENERATED_DIR ${FB_SOURCE_GEN_DIR}/cpp)
build_cpp_fb_modules(
TARGET cpp_gen
FB_DIR "${OSF_FB_DIR}"
FB_MODULES "${FB_MODULES_TO_BUILD}"
SOURCE_GEN_DIR "${FB_CPP_GENERATED_DIR}"
BINARY_SCHEMA_DIR "${FB_BINARY_SCHEMA_DIR}"
)
# === Always generate C++ stubs ==============
# and skip Typescript and Python code from FB specs generation
# since they not needed during a regular OSF lib builds
add_custom_target(all_fb_gen ALL DEPENDS cpp_gen) # ts_gen py_gen
add_library(ouster_osf STATIC src/compat_ops.cpp
src/png_tools.cpp
src/basics.cpp
src/crc32.cpp
src/metadata.cpp
src/meta_lidar_sensor.cpp
src/meta_extrinsics.cpp
src/meta_streaming_info.cpp
src/stream_lidar_scan.cpp
src/layout_streaming.cpp
src/file.cpp
src/reader.cpp
src/operations.cpp
src/json_utils.cpp
src/fb_utils.cpp
src/writer.cpp
)
CodeCoverageFunctionality(ouster_osf)
if (OUSTER_OSF_NO_MMAP)
target_compile_definitions(ouster_osf PRIVATE OUSTER_OSF_NO_MMAP)
endif()
if (OUSTER_OSF_NO_THREADING)
target_compile_definitions(ouster_osf PRIVATE OUSTER_OSF_NO_THREADING)
endif()
# Include Flatbuffers generated C++ headers
target_include_directories(ouster_osf PUBLIC
$<BUILD_INTERFACE:${FB_CPP_GENERATED_DIR}>
$<INSTALL_INTERFACE:include/fb_generated>
)
target_link_libraries(ouster_osf
PUBLIC
OusterSDK::ouster_client OusterSDK::ouster_pcap PNG::PNG
flatbuffers::flatbuffers ZLIB::ZLIB jsoncpp_lib
)
target_include_directories(ouster_osf PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${EIGEN3_INCLUDE_DIR}
)
add_dependencies(ouster_osf cpp_gen)
add_library(OusterSDK::ouster_osf ALIAS ouster_osf)
# Check if ouster_client compiled with -mavx2 option and add those to ouster_osf
# If we are not matching -mavx2 compile flag Eigen lib functions might crash with
# SegFault and double free/memory corruption errors...
get_target_property(CLIENT_OPTIONS OusterSDK::ouster_client COMPILE_OPTIONS)
if(CLIENT_OPTIONS MATCHES ".*-mavx2.*")
target_compile_options(ouster_osf PUBLIC -mavx2)
endif()
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
# ==== Install =========================================================
install(TARGETS ouster_osf
EXPORT ouster-sdk-targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include)
install(DIRECTORY include/ouster DESTINATION include)
install(DIRECTORY ${FB_CPP_GENERATED_DIR}/ DESTINATION include/fb_generated)