1 From d49e5ea2988b2086c7deaa40d3e077531e449844 Mon Sep 17 00:00:00 2001
2 From: Xue Liu <liuxuenetmail@gmail.com>
3 Date: Thu, 21 Feb 2019 00:27:42 +0100
4 Subject: [PATCH 1/3] - add cmake support
6 Signed-off-by: Xue Liu <liuxuenetmail@gmail.com>
8 CMakeLists.txt | 77 +++++++++++++++
9 cmake/loragw-config.cmake | 1 +
10 libloragw/CMakeLists.txt | 150 ++++++++++++++++++++++++++++++
11 libloragw/loragw.pc.in | 10 ++
12 libloragw/loragw_config.h.in | 14 +++
13 util_lbt_test/CMakeLists.txt | 23 +++++
14 util_pkt_logger/CMakeLists.txt | 29 ++++++
15 util_spectral_scan/CMakeLists.txt | 23 +++++
16 util_spi_stress/CMakeLists.txt | 23 +++++
17 util_tx_continuous/CMakeLists.txt | 23 +++++
18 util_tx_test/CMakeLists.txt | 23 +++++
19 11 files changed, 396 insertions(+)
20 create mode 100644 CMakeLists.txt
21 create mode 100644 cmake/loragw-config.cmake
22 create mode 100644 libloragw/CMakeLists.txt
23 create mode 100644 libloragw/loragw.pc.in
24 create mode 100644 libloragw/loragw_config.h.in
25 create mode 100644 util_lbt_test/CMakeLists.txt
26 create mode 100644 util_pkt_logger/CMakeLists.txt
27 create mode 100644 util_spectral_scan/CMakeLists.txt
28 create mode 100644 util_spi_stress/CMakeLists.txt
29 create mode 100644 util_tx_continuous/CMakeLists.txt
30 create mode 100644 util_tx_test/CMakeLists.txt
32 diff --git a/CMakeLists.txt b/CMakeLists.txt
34 index 0000000..b112150
38 +# -- Minimum required version
39 +cmake_minimum_required (VERSION 3.2)
42 +project (lora_gateway)
44 +# -- Various includes
45 +include (CMakePackageConfigHelpers)
46 +include (GNUInstallDirs)
47 +include (CheckFunctionExists)
49 +# -- set c99 standard default
50 +set(CMAKE_C_STANDARD 99)
52 +# -- options for shared lib (defaults off)
53 +option(lora_gateway_build_shared_libs "build as a shared library" OFF)
54 +set(BUILD_SHARED_LIBS ${lora_gateway_build_shared_libs})
56 +# -- Required to build
57 +set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
58 +set(THREADS_PREFER_PTHREAD_FLAG TRUE)
59 +find_package(Threads REQUIRED)
61 +# -- Versioning with git tag
62 +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
64 + COMMAND git describe --tags --always
65 + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
66 + OUTPUT_VARIABLE "lora_gateway_VERSION"
68 + OUTPUT_STRIP_TRAILING_WHITESPACE)
69 + if(lora_gateway_VERSION STREQUAL "")
70 + set(lora_gateway_VERSION 0)
71 + endif(lora_gateway_VERSION STREQUAL "")
72 + message( STATUS "Git full version: ${lora_gateway_VERSION}" )
74 + COMMAND /bin/bash -c "git describe --tags --abbrev=0 | cut --delimiter='v' --fields=2"
75 + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
76 + OUTPUT_VARIABLE "lora_gateway_VERSION_SHORT"
78 + OUTPUT_STRIP_TRAILING_WHITESPACE)
79 + if(lora_gateway_VERSION_SHORT STREQUAL "")
80 + set(lora_gateway_VERSION_SHORT 0)
81 + endif(lora_gateway_VERSION_SHORT STREQUAL "")
82 + message( STATUS "Git version: ${lora_gateway_VERSION_SHORT}" )
83 +else(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
84 + set(lora_gateway_VERSION_SHORT 0)
85 + set(lora_gateway_VERSION 0)
86 +endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
88 +# when building, don't use the install RPATH already
89 +# (but later on when installing)
90 +SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
91 +if (NOT (${CMAKE_INSTALL_PREFIX} STREQUAL "/usr" ) )
92 + SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
95 +# -- add the core library
96 +add_subdirectory(libloragw)
98 +# -- add util_lbt_test
99 +add_subdirectory(util_lbt_test)
101 +# -- add util_pkt_logger
102 +add_subdirectory(util_pkt_logger)
104 +# -- add util_pkt_logger
105 +add_subdirectory(util_spectral_scan)
107 +# -- add util_spi_stress
108 +add_subdirectory(util_spi_stress)
110 +# -- add util_tx_continuous
111 +add_subdirectory(util_tx_continuous)
113 +# -- add util_tx_test
114 +add_subdirectory(util_tx_test)
115 diff --git a/cmake/loragw-config.cmake b/cmake/loragw-config.cmake
117 index 0000000..ee8687b
119 +++ b/cmake/loragw-config.cmake
121 +include("${CMAKE_CURRENT_LIST_DIR}/loragw-targets.cmake")
122 diff --git a/libloragw/CMakeLists.txt b/libloragw/CMakeLists.txt
124 index 0000000..b2102ae
126 +++ b/libloragw/CMakeLists.txt
130 +add_library(${TARGET} "")
132 +# -- add additional debug options
133 +# Set the DEBUG_* to 1 to activate debug mode in individual modules.
134 +# Warning: that makes the module *very verbose*, do not use for production
135 +option(DEBUG_AUX "Active debug mode in AUX module" OFF)
136 +option(DEBUG_SPI "Active debug mode in SPI module" OFF)
137 +option(DEBUG_REG "Active debug mode in REG module" OFF)
138 +option(DEBUG_HAL "Active debug mode in HAL module" OFF)
139 +option(DEBUG_GPIO "Active debug mode in GPIO module" OFF)
140 +option(DEBUG_LBT "Active debug mode in LBT module" OFF)
141 +option(DEBUG_GPS "Active debug mode in GPS module" OFF)
143 +message("-- Build with debug AUX: ${DEBUG_AUX}")
144 +message("-- Build with debug SPI: ${DEBUG_SPI}")
145 +message("-- Build with debug REG: ${DEBUG_REG}")
146 +message("-- Build with debug HAL: ${DEBUG_HAL}")
147 +message("-- Build with debug GPIO: ${DEBUG_GPIO}")
148 +message("-- Build with debug LBT: ${DEBUG_LBT}")
149 +message("-- Build with debug GPS: ${DEBUG_GPS}")
151 +# -- add the compile options
152 +target_compile_options(
160 +target_sources(${TARGET}
162 + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_aux.c
163 + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_fpga.c
164 + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_gps.c
165 + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_hal.c
166 + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_lbt.c
167 + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_radio.c
168 + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_reg.c
169 + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_spi.native.c
172 +# -- add the public headers
173 +set (${TARGET}_PUBLIC_HEADERS
174 + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_aux.h
175 + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_fpga.h
176 + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_gps.h
177 + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_hal.h
178 + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_lbt.h
179 + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_radio.h
180 + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_reg.h
183 +target_include_directories(${TARGET}
185 + ${CMAKE_CURRENT_LIST_DIR}
186 + ${CMAKE_CURRENT_LIST_DIR}/inc
188 + $<INSTALL_INTERFACE:include>
189 + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
190 + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
193 +configure_file(${CMAKE_CURRENT_LIST_DIR}/${TARGET}_config.h.in "${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY)
195 +target_link_libraries(${TARGET}
201 +set_target_properties(${TARGET} PROPERTIES VERSION ${lora_gateway_VERSION_SHORT})
202 +set_target_properties(${TARGET} PROPERTIES SOVERSION ${lora_gateway_VERSION_SHORT})
203 +set_target_properties(${TARGET} PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_BINARY_DIR}/config.h;${${TARGET}_PUBLIC_HEADERS}")
205 +# -- add the install targets
206 +install (TARGETS ${TARGET}
207 + EXPORT ${TARGET}_targets
208 + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
209 + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
210 + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${TARGET}
211 + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${TARGET}
214 +# -- add pkg config file
215 +configure_file ("${CMAKE_CURRENT_LIST_DIR}/${TARGET}.pc.in" "${PROJECT_BINARY_DIR}/${TARGET}.pc" @ONLY)
216 +install (FILES ${PROJECT_BINARY_DIR}/${TARGET}.pc DESTINATION lib/pkgconfig)
218 +# -- write cmake package config file
219 +write_basic_package_version_file(
220 + "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/${TARGET}-config-version.cmake"
221 + VERSION ${lora_gateway_VERSION}
222 + COMPATIBILITY AnyNewerVersion
225 +export(EXPORT ${TARGET}_targets
226 + FILE "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/${TARGET}-targets.cmake"
227 + NAMESPACE Semtech::
230 +configure_file(${PROJECT_SOURCE_DIR}/cmake/${TARGET}-config.cmake
231 + "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/${TARGET}-config.cmake"
235 +set(ConfigPackageLocation lib/cmake/${TARGET})
237 +install(EXPORT ${TARGET}_targets
238 + FILE ${TARGET}-targets.cmake
239 + NAMESPACE Semtech::
240 + DESTINATION ${ConfigPackageLocation}
244 + FILES ${PROJECT_SOURCE_DIR}/cmake/${TARGET}-config.cmake "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/${TARGET}-config-version.cmake"
245 + DESTINATION ${ConfigPackageLocation}
249 +# -- add test programs
250 +foreach(TEST test_loragw_spi test_loragw_gps test_loragw_reg test_loragw_hal test_loragw_cal)
251 + add_executable(${TEST} "")
253 + target_sources(${TEST}
255 + ${CMAKE_CURRENT_LIST_DIR}/tst/${TEST}.c
258 + target_include_directories(${TEST}
260 + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
261 + $<INSTALL_INTERFACE:include>
262 + ${CMAKE_CURRENT_LIST_DIR}/inc
263 + ${CMAKE_CURRENT_BINARY_DIR}
266 + target_link_libraries(${TEST}
273 + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
278 diff --git a/libloragw/loragw.pc.in b/libloragw/loragw.pc.in
280 index 0000000..01bb3cf
282 +++ b/libloragw/loragw.pc.in
284 +prefix=@CMAKE_INSTALL_PREFIX@
285 +exec_prefix=${prefix}/bin
286 +includedir=${prefix}/include/libloragw
287 +libdir=${prefix}/lib
290 +Description: BLANK_TEXT
291 +Version: @lora_gateway_VERSION@
292 +Cflags: -I${includedir}
293 +Libs: -L${libdir} -lloragw
294 diff --git a/libloragw/loragw_config.h.in b/libloragw/loragw_config.h.in
296 index 0000000..76ad35a
298 +++ b/libloragw/loragw_config.h.in
300 +#ifndef _LORAGW_CONFIGURATION_H
301 +#define _LORAGW_CONFIGURATION_H
303 +#define LIBLORAGW_VERSION "@lora_gateway_VERSION_SHORT@"
305 +#cmakedefine01 DEBUG_AUX
306 +#cmakedefine01 DEBUG_SPI
307 +#cmakedefine01 DEBUG_REG
308 +#cmakedefine01 DEBUG_HAL
309 +#cmakedefine01 DEBUG_GPS
310 +#cmakedefine01 DEBUG_GPIO
311 +#cmakedefine01 DEBUG_LBT
314 diff --git a/util_lbt_test/CMakeLists.txt b/util_lbt_test/CMakeLists.txt
316 index 0000000..f184b82
318 +++ b/util_lbt_test/CMakeLists.txt
321 +add_executable(util_lbt_test "")
322 +target_sources(util_lbt_test
324 + ${CMAKE_CURRENT_LIST_DIR}/src/util_lbt_test.c
327 +target_link_libraries(util_lbt_test
332 +set_target_properties(util_lbt_test PROPERTIES
333 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
336 +# add the install targets
338 + TARGETS util_lbt_test
339 + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
340 + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
341 + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
343 diff --git a/util_pkt_logger/CMakeLists.txt b/util_pkt_logger/CMakeLists.txt
345 index 0000000..82cfc86
347 +++ b/util_pkt_logger/CMakeLists.txt
350 +add_executable(util_pkt_logger "")
351 +target_sources(util_pkt_logger
353 + ${CMAKE_CURRENT_LIST_DIR}/src/util_pkt_logger.c
354 + ${CMAKE_CURRENT_LIST_DIR}/src/parson.c
357 +target_include_directories(util_pkt_logger
359 + ${CMAKE_CURRENT_LIST_DIR}/inc
362 +target_link_libraries(util_pkt_logger
367 +set_target_properties(util_pkt_logger PROPERTIES
368 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
371 +# add the install targets
373 + TARGETS util_pkt_logger
374 + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
375 + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
376 + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
378 diff --git a/util_spectral_scan/CMakeLists.txt b/util_spectral_scan/CMakeLists.txt
380 index 0000000..3cec2a9
382 +++ b/util_spectral_scan/CMakeLists.txt
385 +add_executable(util_spectral_scan "")
386 +target_sources(util_spectral_scan
388 + ${CMAKE_CURRENT_LIST_DIR}/src/util_spectral_scan.c
391 +target_link_libraries(util_spectral_scan
396 +set_target_properties(util_spectral_scan PROPERTIES
397 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
400 +# add the install targets
402 + TARGETS util_spectral_scan
403 + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
404 + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
405 + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
407 diff --git a/util_spi_stress/CMakeLists.txt b/util_spi_stress/CMakeLists.txt
409 index 0000000..d5f0eea
411 +++ b/util_spi_stress/CMakeLists.txt
414 +add_executable(util_spi_stress "")
415 +target_sources(util_spi_stress
417 + ${CMAKE_CURRENT_LIST_DIR}/src/util_spi_stress.c
420 +target_link_libraries(util_spi_stress
425 +set_target_properties(util_spi_stress PROPERTIES
426 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
429 +# add the install targets
431 + TARGETS util_spi_stress
432 + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
433 + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
434 + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
436 diff --git a/util_tx_continuous/CMakeLists.txt b/util_tx_continuous/CMakeLists.txt
438 index 0000000..97c70e5
440 +++ b/util_tx_continuous/CMakeLists.txt
443 +add_executable(util_tx_continuous "")
444 +target_sources(util_tx_continuous
446 + ${CMAKE_CURRENT_LIST_DIR}/src/util_tx_continuous.c
449 +target_link_libraries(util_tx_continuous
454 +set_target_properties(util_tx_continuous PROPERTIES
455 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
458 +# add the install targets
460 + TARGETS util_tx_continuous
461 + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
462 + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
463 + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
465 diff --git a/util_tx_test/CMakeLists.txt b/util_tx_test/CMakeLists.txt
467 index 0000000..6cc0e04
469 +++ b/util_tx_test/CMakeLists.txt
472 +add_executable(util_tx_test "")
473 +target_sources(util_tx_test
475 + ${CMAKE_CURRENT_LIST_DIR}/src/util_tx_test.c
478 +target_link_libraries(util_tx_test
483 +set_target_properties(util_tx_test PROPERTIES
484 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
487 +# add the install targets
489 + TARGETS util_tx_test
490 + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
491 + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
492 + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}