-
Notifications
You must be signed in to change notification settings - Fork 16
/
CMakeLists.txt
244 lines (217 loc) · 9.76 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
########################################################################
# Setup project
########################################################################
cmake_minimum_required(VERSION 3.0)
project(libsigmf VERSION 1.0.2 LANGUAGES CXX)
# c++17 used for supporting flatbuffers optional scalar fields via std::optional<T>
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
list(APPEND CMAKE_MODULE_PATH cmake)
option(ENABLE_EXAMPLES "Enable building of examples" ON)
option(USE_SYSTEM_JSON "Attempt to use the system installed nlohmann JSON library" OFF)
option(USE_SYSTEM_FLATBUFFERS "Attempt to use the system installed flatbuffers library and flatc" OFF)
include(GNUInstallDirs)
set(LIBSIGMF_TARGET_NAME ${PROJECT_NAME})
set(LIBSIGMF_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
set(LIBSIGMF_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(LIBSIGMF_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(LIBSIGMF_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
set(LIBSIGMF_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(LIBSIGMF_CMAKE_PROJECT_CONFIG_FILE "${LIBSIGMF_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")
set(LIBSIGMF_CMAKE_VERSION_CONFIG_FILE "${LIBSIGMF_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(LIBSIGMF_CMAKE_PROJECT_TARGETS_FILE "${LIBSIGMF_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
########################################################################
# Dependency management
#
# Prefer system-installed versions, but revert to using submodules
########################################################################
set(libsigmf_deps "")
# flatbuffers
if (${USE_SYSTEM_FLATBUFFERS})
find_package(Flatbuffers REQUIRED)
endif (${USE_SYSTEM_FLATBUFFERS})
if (NOT ${USE_SYSTEM_FLATBUFFERS})
message(STATUS "Flatbuffers was not found. Submodule will be used. This will require building flatc")
set(FLATBUFFERS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/flatbuffers/include")
# Initialize Flatbuffers submodule if unititialized
set(FLATBUFFERS_INCLUDE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/external/flatbuffers/include
CACHE PATH "flatbuffers include directory")
if (NOT IS_DIRECTORY ${FLATBUFFERS_INCLUDE_DIR})
message("Flatbuffers submodule not found! Downloading...")
execute_process(COMMAND git submodule update --init -- external/flatbuffers
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif(NOT IS_DIRECTORY ${FLATBUFFERS_INCLUDE_DIR})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/flatbuffers
${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-build
EXCLUDE_FROM_ALL)
endif (NOT ${USE_SYSTEM_FLATBUFFERS})
# nlohmann_json
if (${USE_SYSTEM_JSON})
find_package(nlohmann_json REQUIRED)
endif (${USE_SYSTEM_JSON})
if (NOT ${USE_SYSTEM_JSON})
message(STATUS "Nlohmann JSON was not found. Submodule will be used.")
# Initialize Json submodule if unititialized
set(JSON_INCLUDE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/external/json/include
CACHE PATH "json include directory")
if (NOT IS_DIRECTORY ${JSON_INCLUDE_DIR})
message("Json submodule not found! Downloading...")
execute_process(COMMAND git submodule update --init -- external/json
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif(NOT IS_DIRECTORY ${JSON_INCLUDE_DIR})
endif(NOT ${USE_SYSTEM_JSON})
########################################################################
# Use flatbuffers to generate SigMF headers
########################################################################
function(generate_sigmf_header generate_sigmf_target FBS_FILE OUTPUT_LOCATION)
get_filename_component(generated_output_name ${FBS_FILE} NAME_WE)
message(STATUS "Flatbuffers generated ${generated_output_name}")
if( ${ARGC} GREATER 3)
set(FLATC_EXTRA_ARGS ${ARGN})
string(REPLACE " " ";" FLATC_EXTRA_ARGS ${FLATC_EXTRA_ARGS})
else()
set(FLATC_EXTRA_ARGS "")
endif()
add_custom_command(OUTPUT ${OUTPUT_LOCATION}/${generated_output_name}_generated.h
COMMAND flatc ${FLATC_EXTRA_ARGS} -c --cpp-ptr-type std::shared_ptr --reflect-types --reflect-names --gen-object-api -o "${OUTPUT_LOCATION}/" "${FBS_FILE}"
COMMENT "Building C++ header for flatbuffers definition ${FBS_FILE} ${ARGC} ${ARGN}"
WORKING_DIRECTORY .
DEPENDS "${FBS_FILE}"
)
add_custom_target(generate_sigmf_target_${generate_sigmf_target}
DEPENDS ${OUTPUT_LOCATION}/${generated_output_name}_generated.h
)
add_library(${generate_sigmf_target} INTERFACE)
add_dependencies(${generate_sigmf_target} generate_sigmf_target_${generate_sigmf_target} flatc)
target_include_directories(${generate_sigmf_target} INTERFACE "${OUTPUT_LOCATION}/")
endfunction(generate_sigmf_header)
########################################################################
# Create targets for generating default namespace definitions
########################################################################
generate_sigmf_header(generated_core_ns
"${CMAKE_CURRENT_SOURCE_DIR}/sigmf_protocols/sigmf_core.fbs"
"${CMAKE_CURRENT_BINARY_DIR}/include"
)
generate_sigmf_header(generated_adsb_ns
"${CMAKE_CURRENT_SOURCE_DIR}/sigmf_protocols/sigmf_adsb.fbs"
"${CMAKE_CURRENT_BINARY_DIR}/include"
)
generate_sigmf_header(generated_antenna_ns
"${CMAKE_CURRENT_SOURCE_DIR}/sigmf_protocols/sigmf_antenna.fbs"
"${CMAKE_CURRENT_BINARY_DIR}/include"
)
generate_sigmf_header(generated_capture_details_ns
"${CMAKE_CURRENT_SOURCE_DIR}/sigmf_protocols/sigmf_capture_details.fbs"
"${CMAKE_CURRENT_BINARY_DIR}/include"
)
generate_sigmf_header(generated_signal_ns
"${CMAKE_CURRENT_SOURCE_DIR}/sigmf_protocols/sigmf_signal.fbs"
"${CMAKE_CURRENT_BINARY_DIR}/include"
)
generate_sigmf_header(generated_spatial_ns
"${CMAKE_CURRENT_SOURCE_DIR}/sigmf_protocols/sigmf_spatial.fbs"
"${CMAKE_CURRENT_BINARY_DIR}/include"
)
generate_sigmf_header(generated_wifi_ns
"${CMAKE_CURRENT_SOURCE_DIR}/sigmf_protocols/sigmf_wifi.fbs"
"${CMAKE_CURRENT_BINARY_DIR}/include"
)
generate_sigmf_header(generated_testing_ns
"${CMAKE_CURRENT_SOURCE_DIR}/sigmf_protocols/testing_protocols.fbs"
"${CMAKE_CURRENT_BINARY_DIR}/include"
)
# We also carry around pre-generated headers so downstream doesn't need to build flatc
set(LIBSIGMF_PREGEN_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/sigmf_protocols")
########################################################################
# Our interface target that downstream have to use
########################################################################
add_library(libsigmf INTERFACE)
target_include_directories(libsigmf INTERFACE
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include/sigmf/fbs>
$<BUILD_INTERFACE:${LIBSIGMF_PREGEN_HEADERS}>
)
if (${Flatbuffers_FOUND})
# System flatbuffers can import this target
else()
target_include_directories(libsigmf INTERFACE
$<BUILD_INTERFACE:${FLATBUFFERS_INCLUDE_DIR}>
)
endif(${Flatbuffers_FOUND})
if (${nlohmann_json_FOUND})
# TODO: add target_link_libraries interface to nlohmann json
# when we use the system version
else()
target_include_directories(libsigmf INTERFACE
$<BUILD_INTERFACE:${JSON_INCLUDE_DIR}>
)
endif(${nlohmann_json_FOUND})
########################################################################
# Ensure that our protocol headers are generated before libsigmf dep
########################################################################
add_dependencies(libsigmf libsigmf_genheaders)
add_custom_target(libsigmf_genheaders DEPENDS
generate_sigmf_target_generated_core_ns
# extension namespaces:
generate_sigmf_target_generated_adsb_ns
generate_sigmf_target_generated_antenna_ns
generate_sigmf_target_generated_capture_details_ns
generate_sigmf_target_generated_spatial_ns
generate_sigmf_target_generated_signal_ns
generate_sigmf_target_generated_wifi_ns
generate_sigmf_target_generated_testing_ns
)
if (ENABLE_EXAMPLES)
add_subdirectory(examples)
endif (ENABLE_EXAMPLES)
add_custom_target(makedocs
COMMAND mkdocs build
COMMENT "Building documentation website"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${LIBSIGMF_CMAKE_VERSION_CONFIG_FILE} COMPATIBILITY SameMajorVersion
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/${LIBSIGMF_CMAKE_CONFIG_TEMPLATE}
${LIBSIGMF_CMAKE_PROJECT_CONFIG_FILE}
@ONLY
)
########################################################################
# Install SigMF headers
########################################################################
install( # install flatbuf proto defs
DIRECTORY ${LIBSIGMF_PREGEN_HEADERS}/
DESTINATION include/sigmf/fbs
FILES_MATCHING PATTERN "*.fbs")
install( # install pregenerated headers
DIRECTORY ${LIBSIGMF_PREGEN_HEADERS}/
DESTINATION include/sigmf
FILES_MATCHING PATTERN "*.h")
install( # if headers were built, replace pregenerated headers with those
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
DESTINATION include/sigmf
FILES_MATCHING PATTERN "*.h")
install( # install original headers
DIRECTORY ${CMAKE_SOURCE_DIR}/src/
DESTINATION include/sigmf
FILES_MATCHING PATTERN "*.h")
########################################################################
# Install cmake configuration foo
########################################################################
install(
FILES ${LIBSIGMF_CMAKE_PROJECT_CONFIG_FILE}
${LIBSIGMF_CMAKE_VERSION_CONFIG_FILE}
DESTINATION ${LIBSIGMF_CONFIG_INSTALL_DIR}
)
install(TARGETS libsigmf
EXPORT ${LIBSIGMF_TARGETS_EXPORT_NAME}
)
install(EXPORT ${LIBSIGMF_TARGETS_EXPORT_NAME}
FILE ${LIBSIGMF_TARGETS_EXPORT_NAME}.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${LIBSIGMF_CONFIG_INSTALL_DIR}
)