forked from Nuand/bladeRF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
351 lines (301 loc) · 11.7 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
cmake_minimum_required(VERSION 3.5)
project(bladeRF-cli C)
################################################################################
# Version information
################################################################################
set(VERSION_INFO_MAJOR 1)
set(VERSION_INFO_MINOR 9)
set(VERSION_INFO_PATCH 0)
if(NOT DEFINED VERSION_INFO_EXTRA)
set(VERSION_INFO_EXTRA "git")
endif()
include(Version)
set(VERSION "${VERSION_INFO}")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
${CMAKE_CURRENT_BINARY_DIR}/src/version.h
@ONLY
)
################################################################################
# Build dependencies
################################################################################
find_package(LibTecla)
find_package(LibEdit)
if(MSVC)
find_package(LibPThreadsWin32 REQUIRED)
else(MSVC)
find_package(Threads REQUIRED)
endif(MSVC)
find_program(PANDOC_EXECUTABLE pandoc)
find_program(BASH_EXECUTABLE bash)
if(PANDOC_EXECUTABLE AND BASH_EXECUTABLE)
set(CAN_BUILD_INTERACTIVE_HELP ON)
else()
set(CAN_BUILD_INTERACTIVE_HELP OFF)
endif()
################################################################################
# Configuration options
################################################################################
option(ENABLE_LIBTECLA
"Enable the use of libtecla, if available.")
option(ENABLE_LIBEDIT
"Enable the use of libtecla, if available.")
option(BUILD_BLADERF_CLI_DOCUMENTATION
"Build bladeRF-cli man page. Requires help2man."
${BUILD_DOCUMENTATION})
option(BUILD_BLADERF_CLI_INTERACTIVE_HELP
"Rebuild bladeRF-cli interactive help. Requires pandoc."
${CAN_BUILD_INTERACTIVE_HELP})
if(NOT ${BUILD_DOCUMENTATION})
set(BUILD_BLADERF_CLI_DOCUMENTATION OFF)
endif()
if((NOT CAN_BUILD_INTERACTIVE_HELP) AND (BUILD_BLADERF_CLI_INTERACTIVE_HELP))
message(FATAL_ERROR "BUILD_BLADERF_CLI_INTERACTIVE_HELP was forced ON, "
"but there are missing prerequisites!")
endif()
if(ENABLE_LIBTECLA)
if((NOT LIBTECLA_INCLUDE_DIR) OR (NOT LIBTECLA_LIBRARIES))
message(FATAL_ERROR "ENABLE_LIBTECLA was forced ON, but libtecla "
"cannot be found!")
endif()
endif()
if(ENABLE_LIBEDIT)
if((NOT LIBEDIT_INCLUDE_DIR) OR (NOT LIBEDIT_LIBRARIES))
message(FATAL_ERROR "ENABLE_LIBEDIT was forced ON, but editline "
"cannot be found!")
endif()
endif()
################################################################################
# Regenerate interactive help
################################################################################
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src/cmd/doc)
if(BUILD_BLADERF_CLI_INTERACTIVE_HELP)
# Do a quick test to make sure we have everything we need...
execute_process(
COMMAND ${BASH_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/src/cmd/doc/generate.bash
--pandoc=${PANDOC_EXECUTABLE}
--test
${CMAKE_CURRENT_SOURCE_DIR}/src/cmd/doc/interactive-help.md
RESULT_VARIABLE INTERACTIVE_HELP_GENERATOR_FAILED
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src/cmd/doc
)
if(INTERACTIVE_HELP_GENERATOR_FAILED)
message(FATAL_ERROR "generate.bash failed! Try disabling "
"BUILD_BLADERF_CLI_INTERACTIVE_HELP, or fix the above error.")
endif()
# Run the generation script during build
message(STATUS "Will regenerate bladeRF-cli interactive help")
add_custom_command(
OUTPUT src/cmd/doc/cmd_help.h src/cmd/doc/cmd_help.man
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/cmd/doc/generate.bash
COMMAND ${BASH_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/src/cmd/doc/generate.bash
--pandoc=${PANDOC_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/src/cmd/doc/interactive-help.md
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src/cmd/doc
)
else()
# Re-use old cmd_help.h and cmd_help.man
message(STATUS "Reusing existing interactive help for bladeRF-cli")
add_custom_command(
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/cmd/doc/cmd_help.h.in
OUTPUT src/cmd/doc/cmd_help.h
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/src/cmd/doc/cmd_help.h.in
${CMAKE_CURRENT_BINARY_DIR}/src/cmd/doc/cmd_help.h
)
add_custom_command(
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/cmd/doc/cmd_help.man.in
OUTPUT src/cmd/doc/cmd_help.man
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/src/cmd/doc/cmd_help.man.in
${CMAKE_CURRENT_BINARY_DIR}/src/cmd/doc/cmd_help.man
)
endif()
################################################################################
# Include paths
################################################################################
set(CLI_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/cmd
${CMAKE_CURRENT_SOURCE_DIR}/src/input
${CMAKE_CURRENT_BINARY_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}/src/cmd
${BLADERF_HOST_COMMON_INCLUDE_DIRS}
${libbladeRF_SOURCE_DIR}/include
${BLADERF_FW_COMMON_INCLUDE_DIR}
)
if(MSVC)
set(CLI_INCLUDE_DIRS ${CLI_INCLUDE_DIRS} ${MSVC_C99_INCLUDES})
endif()
message(STATUS "libtecla ${ENABLE_LIBTECLA} ${LIBTECLA_FOUND}")
message(STATUS "libedit ${ENABLE_LIBEDIT} ${LIBEDIT_FOUND}")
if(ENABLE_LIBTECLA OR (LIBTECLA_FOUND AND NOT ENABLE_LIBEDIT))
message(STATUS "libtecla support enabled")
set(ENABLE_LIBTECLA ON)
set(CLI_INCLUDE_DIRS ${CLI_INCLUDE_DIRS} ${LIBTECLA_INCLUDE_DIR})
elseif(ENABLE_LIBEDIT OR LIBEDIT_FOUND)
message(STATUS "editline support enabled")
set(ENABLE_LIBEDIT ON)
set(CLI_INCLUDE_DIRS ${CLI_INCLUDE_DIRS} ${LIBEDIT_INCLUDE_DIR})
endif()
if(MSVC)
set(CLI_INCLUDE_DIRS ${CLI_INCLUDE_DIRS}
${BLADERF_HOST_COMMON_INCLUDE_DIRS}/windows
${LIBPTHREADSWIN32_INCLUDE_DIRS}
)
endif()
if(APPLE)
set(CLI_INCLUDE_DIRS ${CLI_INCLUDE_DIRS}
${BLADERF_HOST_COMMON_INCLUDE_DIRS}/osx
)
endif()
include_directories(${CLI_INCLUDE_DIRS})
################################################################################
# Configure source files
################################################################################
set(BLADERF_CLI_SOURCE
src/main.c
src/common.c
src/cmd/calibrate.c
src/cmd/cmd.c
src/cmd/doc/cmd_help.h
src/cmd/erase.c
src/cmd/flash_backup.c
src/cmd/flash_image.c
src/cmd/flash_init_cal.c
src/cmd/flash_restore.c
src/cmd/fw_log.c
src/cmd/generate.c
src/cmd/info.c
src/cmd/jump_boot.c
src/cmd/lms_reg_info.c
src/cmd/load.c
src/cmd/mimo.c
src/cmd/open.c
src/cmd/peek.c
src/cmd/peekpoke.c
src/cmd/poke.c
src/cmd/printset.c
src/cmd/printset_hardware.c
src/cmd/printset_impl.c
src/cmd/printset_xb.c
src/cmd/probe.c
src/cmd/recover.c
src/cmd/rx.c
src/cmd/rxtx.c
src/cmd/trigger.c
src/cmd/tx.c
src/cmd/version.c
src/cmd/xb.c
src/cmd/xb100.c
src/cmd/xb200.c
src/cmd/xb300.c
src/input/input.c
src/input/script.c
${BLADERF_HOST_COMMON_SOURCE_DIR}/conversions.c
${BLADERF_HOST_COMMON_SOURCE_DIR}/dc_calibration.c
${BLADERF_HOST_COMMON_SOURCE_DIR}/log.c
${BLADERF_HOST_COMMON_SOURCE_DIR}/str_queue.c
${BLADERF_HOST_COMMON_SOURCE_DIR}/parse.c
)
# Select the input mode (and script handling) backend
if(ENABLE_LIBTECLA)
set(BLADERF_CLI_SOURCE ${BLADERF_CLI_SOURCE} src/input/tecla.c)
elseif(ENABLE_LIBEDIT)
set(BLADERF_CLI_SOURCE ${BLADERF_CLI_SOURCE} src/input/editline.c)
else()
set(BLADERF_CLI_SOURCE ${BLADERF_CLI_SOURCE} src/input/fgets.c)
endif()
if(MSVC)
set(BLADERF_CLI_SOURCE ${BLADERF_CLI_SOURCE}
${BLADERF_HOST_COMMON_SOURCE_DIR}/windows/getopt_long.c
${BLADERF_HOST_COMMON_SOURCE_DIR}/windows/clock_gettime.c
${BLADERF_HOST_COMMON_SOURCE_DIR}/windows/nanosleep.c
${BLADERF_HOST_COMMON_SOURCE_DIR}/windows/setenv.c
)
endif()
if(APPLE)
set(BLADERF_CLI_SOURCE ${BLADERF_CLI_SOURCE}
${BLADERF_HOST_COMMON_SOURCE_DIR}/osx/clock_gettime.c
)
endif()
add_executable(bladeRF-cli ${BLADERF_CLI_SOURCE})
################################################################################
# Build configuration
################################################################################
set(CLI_LINK_LIBRARIES
libbladerf_shared
${CMAKE_THREAD_LIBS_INIT}
)
if(NOT MSVC)
set(CLI_LINK_LIBRARIES ${CLI_LINK_LIBRARIES} m)
endif()
if(ENABLE_LIBTECLA)
set(CLI_LINK_LIBRARIES ${CLI_LINK_LIBRARIES} ${LIBTECLA_LIBRARIES})
# On a few tests Linux distros, libtecla is not build against
# ncurses. However, folks have reported that builds on OSX use it
if(CMAKE_HOST_APPLE)
set(CLI_LINK_LIBRARIES ${CLI_LINK_LIBRARIES} ncurses)
endif(CMAKE_HOST_APPLE)
elseif(ENABLE_LIBEDIT)
set(CLI_LINK_LIBRARIES ${CLI_LINK_LIBRARIES} ${LIBEDIT_LIBRARIES})
endif(ENABLE_LIBTECLA)
if(LIBPTHREADSWIN32_FOUND)
set(CLI_LINK_LIBRARIES ${CLI_LINK_LIBRARIES} ${LIBPTHREADSWIN32_LIBRARIES})
endif()
if(LIBC_VERSION)
# clock_gettime() was moved from librt -> libc in 2.17
if(${LIBC_VERSION} VERSION_LESS "2.17")
set(CLI_LINK_LIBRARIES ${CLI_LINK_LIBRARIES} rt)
endif()
endif()
target_link_libraries(bladeRF-cli ${CLI_LINK_LIBRARIES})
################################################################################
# Man pages
################################################################################
if(BUILD_BLADERF_CLI_DOCUMENTATION)
find_program(HELP2MAN_EXECUTABLE help2man)
if(HELP2MAN_EXECUTABLE)
message(STATUS "Will build man page for bladeRF-cli.")
if(NOT DEFINED MAN_INSTALL_DIR)
set(MAN_INSTALL_DIR share/man)
endif(NOT DEFINED MAN_INSTALL_DIR)
# Build actual man page
add_custom_command(
OUTPUT bladeRF-cli.1
DEPENDS bladeRF-cli src/cmd/doc/cmd_help.man
COMMAND ${HELP2MAN_EXECUTABLE}
--no-info --no-discard-stderr
--opt-include=${CMAKE_CURRENT_SOURCE_DIR}/../doc/include_man/bladeRF-cli.h2m
--opt-include=${CMAKE_CURRENT_BINARY_DIR}/src/cmd/doc/cmd_help.man
--opt-include=${CMAKE_CURRENT_SOURCE_DIR}/../doc/include_man/common.h2m
--output=bladeRF-cli.1
./bladeRF-cli
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
install(
FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/bladeRF-cli.1
DESTINATION ${MAN_INSTALL_DIR}/man1
)
add_custom_target(bladeRF-cli-manpage ALL DEPENDS bladeRF-cli.1)
else(HELP2MAN_EXECUTABLE)
message(FATAL_ERROR "Could not find help2man. bladeRF-cli man page "
"cannot be built.")
endif(HELP2MAN_EXECUTABLE)
else(BUILD_BLADERF_CLI_DOCUMENTATION)
message(STATUS "Not building man page for bladeRF-cli. "
"(BUILD_BLADERF_CLI_DOCUMENTATION is OFF)")
endif(BUILD_BLADERF_CLI_DOCUMENTATION)
################################################################################
# Installation
################################################################################
if(NOT DEFINED BIN_INSTALL_DIR)
set(BIN_INSTALL_DIR bin)
endif()
install(TARGETS bladeRF-cli DESTINATION ${BIN_INSTALL_DIR})
################################################################################
# Informational output
################################################################################
message(STATUS "Configured to build bladeRF-cli version: ${VERSION_INFO}")