e41e2ddcd5d46340bc4576f2ded67a66378b177b
[feed/packages.git] / net / lora-gateway-hal / patches / 0001-add-cmake-support.patch
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
5
6 Signed-off-by: Xue Liu <liuxuenetmail@gmail.com>
7 ---
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
31
32 diff --git a/CMakeLists.txt b/CMakeLists.txt
33 new file mode 100644
34 index 0000000..b112150
35 --- /dev/null
36 +++ b/CMakeLists.txt
37 @@ -0,0 +1,77 @@
38 +# -- Minimum required version
39 +cmake_minimum_required (VERSION 3.2)
40 +
41 +# -- Project name
42 +project (lora_gateway)
43 +
44 +# -- Various includes
45 +include (CMakePackageConfigHelpers)
46 +include (GNUInstallDirs)
47 +include (CheckFunctionExists)
48 +
49 +# -- set c99 standard default
50 +set(CMAKE_C_STANDARD 99)
51 +
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})
55 +
56 +# -- Required to build
57 +set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
58 +set(THREADS_PREFER_PTHREAD_FLAG TRUE)
59 +find_package(Threads REQUIRED)
60 +
61 +# -- Versioning with git tag
62 +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
63 + execute_process(
64 + COMMAND git describe --tags --always
65 + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
66 + OUTPUT_VARIABLE "lora_gateway_VERSION"
67 + ERROR_QUIET
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}" )
73 + execute_process(
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"
77 + ERROR_QUIET
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)
87 +
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}")
93 +endif()
94 +
95 +# -- add the core library
96 +add_subdirectory(libloragw)
97 +
98 +# -- add util_lbt_test
99 +add_subdirectory(util_lbt_test)
100 +
101 +# -- add util_pkt_logger
102 +add_subdirectory(util_pkt_logger)
103 +
104 +# -- add util_pkt_logger
105 +add_subdirectory(util_spectral_scan)
106 +
107 +# -- add util_spi_stress
108 +add_subdirectory(util_spi_stress)
109 +
110 +# -- add util_tx_continuous
111 +add_subdirectory(util_tx_continuous)
112 +
113 +# -- add util_tx_test
114 +add_subdirectory(util_tx_test)
115 diff --git a/cmake/loragw-config.cmake b/cmake/loragw-config.cmake
116 new file mode 100644
117 index 0000000..ee8687b
118 --- /dev/null
119 +++ b/cmake/loragw-config.cmake
120 @@ -0,0 +1 @@
121 +include("${CMAKE_CURRENT_LIST_DIR}/loragw-targets.cmake")
122 diff --git a/libloragw/CMakeLists.txt b/libloragw/CMakeLists.txt
123 new file mode 100644
124 index 0000000..b2102ae
125 --- /dev/null
126 +++ b/libloragw/CMakeLists.txt
127 @@ -0,0 +1,150 @@
128 +set(TARGET loragw)
129 +
130 +add_library(${TARGET} "")
131 +
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)
142 +
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}")
150 +
151 +# -- add the compile options
152 +target_compile_options(
153 + ${TARGET}
154 + PRIVATE
155 + -Werror
156 + -Wall
157 + -Wextra
158 +)
159 +
160 +target_sources(${TARGET}
161 + PRIVATE
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
170 +)
171 +
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
181 +)
182 +
183 +target_include_directories(${TARGET}
184 + PRIVATE
185 + ${CMAKE_CURRENT_LIST_DIR}
186 + ${CMAKE_CURRENT_LIST_DIR}/inc
187 + PUBLIC
188 + $<INSTALL_INTERFACE:include>
189 + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
190 + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
191 +)
192 +
193 +configure_file(${CMAKE_CURRENT_LIST_DIR}/${TARGET}_config.h.in "${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY)
194 +
195 +target_link_libraries(${TARGET}
196 + PUBLIC
197 + Threads::Threads
198 + m
199 +)
200 +
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}")
204 +
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}
212 +)
213 +
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)
217 +
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
223 +)
224 +
225 +export(EXPORT ${TARGET}_targets
226 + FILE "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/${TARGET}-targets.cmake"
227 + NAMESPACE Semtech::
228 +)
229 +
230 +configure_file(${PROJECT_SOURCE_DIR}/cmake/${TARGET}-config.cmake
231 + "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/${TARGET}-config.cmake"
232 + COPYONLY
233 +)
234 +
235 +set(ConfigPackageLocation lib/cmake/${TARGET})
236 +
237 +install(EXPORT ${TARGET}_targets
238 + FILE ${TARGET}-targets.cmake
239 + NAMESPACE Semtech::
240 + DESTINATION ${ConfigPackageLocation}
241 +)
242 +
243 +install(
244 + FILES ${PROJECT_SOURCE_DIR}/cmake/${TARGET}-config.cmake "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/${TARGET}-config-version.cmake"
245 + DESTINATION ${ConfigPackageLocation}
246 + COMPONENT Devel
247 +)
248 +
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} "")
252 +
253 + target_sources(${TEST}
254 + PRIVATE
255 + ${CMAKE_CURRENT_LIST_DIR}/tst/${TEST}.c
256 + )
257 +
258 + target_include_directories(${TEST}
259 + PRIVATE
260 + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
261 + $<INSTALL_INTERFACE:include>
262 + ${CMAKE_CURRENT_LIST_DIR}/inc
263 + ${CMAKE_CURRENT_BINARY_DIR}
264 + )
265 +
266 + target_link_libraries(${TEST}
267 + PRIVATE
268 + loragw
269 + )
270 +
271 + install (
272 + TARGETS ${TEST}
273 + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
274 + )
275 +
276 +endforeach()
277 +
278 diff --git a/libloragw/loragw.pc.in b/libloragw/loragw.pc.in
279 new file mode 100644
280 index 0000000..01bb3cf
281 --- /dev/null
282 +++ b/libloragw/loragw.pc.in
283 @@ -0,0 +1,10 @@
284 +prefix=@CMAKE_INSTALL_PREFIX@
285 +exec_prefix=${prefix}/bin
286 +includedir=${prefix}/include/libloragw
287 +libdir=${prefix}/lib
288 +
289 +Name: LIBLORAGW
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
295 new file mode 100644
296 index 0000000..76ad35a
297 --- /dev/null
298 +++ b/libloragw/loragw_config.h.in
299 @@ -0,0 +1,14 @@
300 +#ifndef _LORAGW_CONFIGURATION_H
301 +#define _LORAGW_CONFIGURATION_H
302 +
303 +#define LIBLORAGW_VERSION "@lora_gateway_VERSION_SHORT@"
304 +
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
312 +
313 +#endif
314 diff --git a/util_lbt_test/CMakeLists.txt b/util_lbt_test/CMakeLists.txt
315 new file mode 100644
316 index 0000000..f184b82
317 --- /dev/null
318 +++ b/util_lbt_test/CMakeLists.txt
319 @@ -0,0 +1,23 @@
320 +
321 +add_executable(util_lbt_test "")
322 +target_sources(util_lbt_test
323 + PRIVATE
324 + ${CMAKE_CURRENT_LIST_DIR}/src/util_lbt_test.c
325 +)
326 +
327 +target_link_libraries(util_lbt_test
328 + PUBLIC
329 + loragw
330 +)
331 +
332 +set_target_properties(util_lbt_test PROPERTIES
333 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
334 +)
335 +
336 +# add the install targets
337 +install (
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}
342 +)
343 diff --git a/util_pkt_logger/CMakeLists.txt b/util_pkt_logger/CMakeLists.txt
344 new file mode 100644
345 index 0000000..82cfc86
346 --- /dev/null
347 +++ b/util_pkt_logger/CMakeLists.txt
348 @@ -0,0 +1,29 @@
349 +
350 +add_executable(util_pkt_logger "")
351 +target_sources(util_pkt_logger
352 + PRIVATE
353 + ${CMAKE_CURRENT_LIST_DIR}/src/util_pkt_logger.c
354 + ${CMAKE_CURRENT_LIST_DIR}/src/parson.c
355 +)
356 +
357 +target_include_directories(util_pkt_logger
358 + PRIVATE
359 + ${CMAKE_CURRENT_LIST_DIR}/inc
360 +)
361 +
362 +target_link_libraries(util_pkt_logger
363 + PUBLIC
364 + loragw
365 +)
366 +
367 +set_target_properties(util_pkt_logger PROPERTIES
368 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
369 +)
370 +
371 +# add the install targets
372 +install (
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}
377 +)
378 diff --git a/util_spectral_scan/CMakeLists.txt b/util_spectral_scan/CMakeLists.txt
379 new file mode 100644
380 index 0000000..3cec2a9
381 --- /dev/null
382 +++ b/util_spectral_scan/CMakeLists.txt
383 @@ -0,0 +1,23 @@
384 +
385 +add_executable(util_spectral_scan "")
386 +target_sources(util_spectral_scan
387 + PRIVATE
388 + ${CMAKE_CURRENT_LIST_DIR}/src/util_spectral_scan.c
389 +)
390 +
391 +target_link_libraries(util_spectral_scan
392 + PUBLIC
393 + loragw
394 +)
395 +
396 +set_target_properties(util_spectral_scan PROPERTIES
397 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
398 +)
399 +
400 +# add the install targets
401 +install (
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}
406 +)
407 diff --git a/util_spi_stress/CMakeLists.txt b/util_spi_stress/CMakeLists.txt
408 new file mode 100644
409 index 0000000..d5f0eea
410 --- /dev/null
411 +++ b/util_spi_stress/CMakeLists.txt
412 @@ -0,0 +1,23 @@
413 +
414 +add_executable(util_spi_stress "")
415 +target_sources(util_spi_stress
416 + PRIVATE
417 + ${CMAKE_CURRENT_LIST_DIR}/src/util_spi_stress.c
418 +)
419 +
420 +target_link_libraries(util_spi_stress
421 + PUBLIC
422 + loragw
423 +)
424 +
425 +set_target_properties(util_spi_stress PROPERTIES
426 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
427 +)
428 +
429 +# add the install targets
430 +install (
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}
435 +)
436 diff --git a/util_tx_continuous/CMakeLists.txt b/util_tx_continuous/CMakeLists.txt
437 new file mode 100644
438 index 0000000..97c70e5
439 --- /dev/null
440 +++ b/util_tx_continuous/CMakeLists.txt
441 @@ -0,0 +1,23 @@
442 +
443 +add_executable(util_tx_continuous "")
444 +target_sources(util_tx_continuous
445 + PRIVATE
446 + ${CMAKE_CURRENT_LIST_DIR}/src/util_tx_continuous.c
447 +)
448 +
449 +target_link_libraries(util_tx_continuous
450 + PUBLIC
451 + loragw
452 +)
453 +
454 +set_target_properties(util_tx_continuous PROPERTIES
455 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
456 +)
457 +
458 +# add the install targets
459 +install (
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}
464 +)
465 diff --git a/util_tx_test/CMakeLists.txt b/util_tx_test/CMakeLists.txt
466 new file mode 100644
467 index 0000000..6cc0e04
468 --- /dev/null
469 +++ b/util_tx_test/CMakeLists.txt
470 @@ -0,0 +1,23 @@
471 +
472 +add_executable(util_tx_test "")
473 +target_sources(util_tx_test
474 + PRIVATE
475 + ${CMAKE_CURRENT_LIST_DIR}/src/util_tx_test.c
476 +)
477 +
478 +target_link_libraries(util_tx_test
479 + PUBLIC
480 + loragw
481 +)
482 +
483 +set_target_properties(util_tx_test PROPERTIES
484 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
485 +)
486 +
487 +# add the install targets
488 +install (
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}
493 +)
494 --
495 2.20.1
496