You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

496 lines
14 KiB

  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. Signed-off-by: Xue Liu <liuxuenetmail@gmail.com>
  6. ---
  7. CMakeLists.txt | 77 +++++++++++++++
  8. cmake/loragw-config.cmake | 1 +
  9. libloragw/CMakeLists.txt | 150 ++++++++++++++++++++++++++++++
  10. libloragw/loragw.pc.in | 10 ++
  11. libloragw/loragw_config.h.in | 14 +++
  12. util_lbt_test/CMakeLists.txt | 23 +++++
  13. util_pkt_logger/CMakeLists.txt | 29 ++++++
  14. util_spectral_scan/CMakeLists.txt | 23 +++++
  15. util_spi_stress/CMakeLists.txt | 23 +++++
  16. util_tx_continuous/CMakeLists.txt | 23 +++++
  17. util_tx_test/CMakeLists.txt | 23 +++++
  18. 11 files changed, 396 insertions(+)
  19. create mode 100644 CMakeLists.txt
  20. create mode 100644 cmake/loragw-config.cmake
  21. create mode 100644 libloragw/CMakeLists.txt
  22. create mode 100644 libloragw/loragw.pc.in
  23. create mode 100644 libloragw/loragw_config.h.in
  24. create mode 100644 util_lbt_test/CMakeLists.txt
  25. create mode 100644 util_pkt_logger/CMakeLists.txt
  26. create mode 100644 util_spectral_scan/CMakeLists.txt
  27. create mode 100644 util_spi_stress/CMakeLists.txt
  28. create mode 100644 util_tx_continuous/CMakeLists.txt
  29. create mode 100644 util_tx_test/CMakeLists.txt
  30. diff --git a/CMakeLists.txt b/CMakeLists.txt
  31. new file mode 100644
  32. index 0000000..b112150
  33. --- /dev/null
  34. +++ b/CMakeLists.txt
  35. @@ -0,0 +1,77 @@
  36. +# -- Minimum required version
  37. +cmake_minimum_required (VERSION 3.2)
  38. +
  39. +# -- Project name
  40. +project (lora_gateway)
  41. +
  42. +# -- Various includes
  43. +include (CMakePackageConfigHelpers)
  44. +include (GNUInstallDirs)
  45. +include (CheckFunctionExists)
  46. +
  47. +# -- set c99 standard default
  48. +set(CMAKE_C_STANDARD 99)
  49. +
  50. +# -- options for shared lib (defaults off)
  51. +option(lora_gateway_build_shared_libs "build as a shared library" OFF)
  52. +set(BUILD_SHARED_LIBS ${lora_gateway_build_shared_libs})
  53. +
  54. +# -- Required to build
  55. +set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
  56. +set(THREADS_PREFER_PTHREAD_FLAG TRUE)
  57. +find_package(Threads REQUIRED)
  58. +
  59. +# -- Versioning with git tag
  60. +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
  61. + execute_process(
  62. + COMMAND git describe --tags --always
  63. + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  64. + OUTPUT_VARIABLE "lora_gateway_VERSION"
  65. + ERROR_QUIET
  66. + OUTPUT_STRIP_TRAILING_WHITESPACE)
  67. + if(lora_gateway_VERSION STREQUAL "")
  68. + set(lora_gateway_VERSION 0)
  69. + endif(lora_gateway_VERSION STREQUAL "")
  70. + message( STATUS "Git full version: ${lora_gateway_VERSION}" )
  71. + execute_process(
  72. + COMMAND /bin/bash -c "git describe --tags --abbrev=0 | cut --delimiter='v' --fields=2"
  73. + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  74. + OUTPUT_VARIABLE "lora_gateway_VERSION_SHORT"
  75. + ERROR_QUIET
  76. + OUTPUT_STRIP_TRAILING_WHITESPACE)
  77. + if(lora_gateway_VERSION_SHORT STREQUAL "")
  78. + set(lora_gateway_VERSION_SHORT 0)
  79. + endif(lora_gateway_VERSION_SHORT STREQUAL "")
  80. + message( STATUS "Git version: ${lora_gateway_VERSION_SHORT}" )
  81. +else(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
  82. + set(lora_gateway_VERSION_SHORT 0)
  83. + set(lora_gateway_VERSION 0)
  84. +endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
  85. +
  86. +# when building, don't use the install RPATH already
  87. +# (but later on when installing)
  88. +SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  89. +if (NOT (${CMAKE_INSTALL_PREFIX} STREQUAL "/usr" ) )
  90. + SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
  91. +endif()
  92. +
  93. +# -- add the core library
  94. +add_subdirectory(libloragw)
  95. +
  96. +# -- add util_lbt_test
  97. +add_subdirectory(util_lbt_test)
  98. +
  99. +# -- add util_pkt_logger
  100. +add_subdirectory(util_pkt_logger)
  101. +
  102. +# -- add util_pkt_logger
  103. +add_subdirectory(util_spectral_scan)
  104. +
  105. +# -- add util_spi_stress
  106. +add_subdirectory(util_spi_stress)
  107. +
  108. +# -- add util_tx_continuous
  109. +add_subdirectory(util_tx_continuous)
  110. +
  111. +# -- add util_tx_test
  112. +add_subdirectory(util_tx_test)
  113. diff --git a/cmake/loragw-config.cmake b/cmake/loragw-config.cmake
  114. new file mode 100644
  115. index 0000000..ee8687b
  116. --- /dev/null
  117. +++ b/cmake/loragw-config.cmake
  118. @@ -0,0 +1 @@
  119. +include("${CMAKE_CURRENT_LIST_DIR}/loragw-targets.cmake")
  120. diff --git a/libloragw/CMakeLists.txt b/libloragw/CMakeLists.txt
  121. new file mode 100644
  122. index 0000000..b2102ae
  123. --- /dev/null
  124. +++ b/libloragw/CMakeLists.txt
  125. @@ -0,0 +1,150 @@
  126. +set(TARGET loragw)
  127. +
  128. +add_library(${TARGET} "")
  129. +
  130. +# -- add additional debug options
  131. +# Set the DEBUG_* to 1 to activate debug mode in individual modules.
  132. +# Warning: that makes the module *very verbose*, do not use for production
  133. +option(DEBUG_AUX "Active debug mode in AUX module" OFF)
  134. +option(DEBUG_SPI "Active debug mode in SPI module" OFF)
  135. +option(DEBUG_REG "Active debug mode in REG module" OFF)
  136. +option(DEBUG_HAL "Active debug mode in HAL module" OFF)
  137. +option(DEBUG_GPIO "Active debug mode in GPIO module" OFF)
  138. +option(DEBUG_LBT "Active debug mode in LBT module" OFF)
  139. +option(DEBUG_GPS "Active debug mode in GPS module" OFF)
  140. +
  141. +message("-- Build with debug AUX: ${DEBUG_AUX}")
  142. +message("-- Build with debug SPI: ${DEBUG_SPI}")
  143. +message("-- Build with debug REG: ${DEBUG_REG}")
  144. +message("-- Build with debug HAL: ${DEBUG_HAL}")
  145. +message("-- Build with debug GPIO: ${DEBUG_GPIO}")
  146. +message("-- Build with debug LBT: ${DEBUG_LBT}")
  147. +message("-- Build with debug GPS: ${DEBUG_GPS}")
  148. +
  149. +# -- add the compile options
  150. +target_compile_options(
  151. + ${TARGET}
  152. + PRIVATE
  153. + -Werror
  154. + -Wall
  155. + -Wextra
  156. +)
  157. +
  158. +target_sources(${TARGET}
  159. + PRIVATE
  160. + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_aux.c
  161. + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_fpga.c
  162. + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_gps.c
  163. + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_hal.c
  164. + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_lbt.c
  165. + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_radio.c
  166. + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_reg.c
  167. + ${CMAKE_CURRENT_LIST_DIR}/src/loragw_spi.native.c
  168. +)
  169. +
  170. +# -- add the public headers
  171. +set (${TARGET}_PUBLIC_HEADERS
  172. + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_aux.h
  173. + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_fpga.h
  174. + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_gps.h
  175. + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_hal.h
  176. + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_lbt.h
  177. + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_radio.h
  178. + ${CMAKE_CURRENT_LIST_DIR}/inc/loragw_reg.h
  179. +)
  180. +
  181. +target_include_directories(${TARGET}
  182. + PRIVATE
  183. + ${CMAKE_CURRENT_LIST_DIR}
  184. + ${CMAKE_CURRENT_LIST_DIR}/inc
  185. + PUBLIC
  186. + $<INSTALL_INTERFACE:include>
  187. + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
  188. + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
  189. +)
  190. +
  191. +configure_file(${CMAKE_CURRENT_LIST_DIR}/${TARGET}_config.h.in "${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY)
  192. +
  193. +target_link_libraries(${TARGET}
  194. + PUBLIC
  195. + Threads::Threads
  196. + m
  197. +)
  198. +
  199. +set_target_properties(${TARGET} PROPERTIES VERSION ${lora_gateway_VERSION_SHORT})
  200. +set_target_properties(${TARGET} PROPERTIES SOVERSION ${lora_gateway_VERSION_SHORT})
  201. +set_target_properties(${TARGET} PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_BINARY_DIR}/config.h;${${TARGET}_PUBLIC_HEADERS}")
  202. +
  203. +# -- add the install targets
  204. +install (TARGETS ${TARGET}
  205. + EXPORT ${TARGET}_targets
  206. + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
  207. + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  208. + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${TARGET}
  209. + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${TARGET}
  210. +)
  211. +
  212. +# -- add pkg config file
  213. +configure_file ("${CMAKE_CURRENT_LIST_DIR}/${TARGET}.pc.in" "${PROJECT_BINARY_DIR}/${TARGET}.pc" @ONLY)
  214. +install (FILES ${PROJECT_BINARY_DIR}/${TARGET}.pc DESTINATION lib/pkgconfig)
  215. +
  216. +# -- write cmake package config file
  217. +write_basic_package_version_file(
  218. + "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/${TARGET}-config-version.cmake"
  219. + VERSION ${lora_gateway_VERSION}
  220. + COMPATIBILITY AnyNewerVersion
  221. +)
  222. +
  223. +export(EXPORT ${TARGET}_targets
  224. + FILE "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/${TARGET}-targets.cmake"
  225. + NAMESPACE Semtech::
  226. +)
  227. +
  228. +configure_file(${PROJECT_SOURCE_DIR}/cmake/${TARGET}-config.cmake
  229. + "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/${TARGET}-config.cmake"
  230. + COPYONLY
  231. +)
  232. +
  233. +set(ConfigPackageLocation lib/cmake/${TARGET})
  234. +
  235. +install(EXPORT ${TARGET}_targets
  236. + FILE ${TARGET}-targets.cmake
  237. + NAMESPACE Semtech::
  238. + DESTINATION ${ConfigPackageLocation}
  239. +)
  240. +
  241. +install(
  242. + FILES ${PROJECT_SOURCE_DIR}/cmake/${TARGET}-config.cmake "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/${TARGET}-config-version.cmake"
  243. + DESTINATION ${ConfigPackageLocation}
  244. + COMPONENT Devel
  245. +)
  246. +
  247. +# -- add test programs
  248. +foreach(TEST test_loragw_spi test_loragw_gps test_loragw_reg test_loragw_hal test_loragw_cal)
  249. + add_executable(${TEST} "")
  250. +
  251. + target_sources(${TEST}
  252. + PRIVATE
  253. + ${CMAKE_CURRENT_LIST_DIR}/tst/${TEST}.c
  254. + )
  255. +
  256. + target_include_directories(${TEST}
  257. + PRIVATE
  258. + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  259. + $<INSTALL_INTERFACE:include>
  260. + ${CMAKE_CURRENT_LIST_DIR}/inc
  261. + ${CMAKE_CURRENT_BINARY_DIR}
  262. + )
  263. +
  264. + target_link_libraries(${TEST}
  265. + PRIVATE
  266. + loragw
  267. + )
  268. +
  269. + install (
  270. + TARGETS ${TEST}
  271. + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  272. + )
  273. +
  274. +endforeach()
  275. +
  276. diff --git a/libloragw/loragw.pc.in b/libloragw/loragw.pc.in
  277. new file mode 100644
  278. index 0000000..01bb3cf
  279. --- /dev/null
  280. +++ b/libloragw/loragw.pc.in
  281. @@ -0,0 +1,10 @@
  282. +prefix=@CMAKE_INSTALL_PREFIX@
  283. +exec_prefix=${prefix}/bin
  284. +includedir=${prefix}/include/libloragw
  285. +libdir=${prefix}/lib
  286. +
  287. +Name: LIBLORAGW
  288. +Description: BLANK_TEXT
  289. +Version: @lora_gateway_VERSION@
  290. +Cflags: -I${includedir}
  291. +Libs: -L${libdir} -lloragw
  292. diff --git a/libloragw/loragw_config.h.in b/libloragw/loragw_config.h.in
  293. new file mode 100644
  294. index 0000000..76ad35a
  295. --- /dev/null
  296. +++ b/libloragw/loragw_config.h.in
  297. @@ -0,0 +1,14 @@
  298. +#ifndef _LORAGW_CONFIGURATION_H
  299. +#define _LORAGW_CONFIGURATION_H
  300. +
  301. +#define LIBLORAGW_VERSION "@lora_gateway_VERSION_SHORT@"
  302. +
  303. +#cmakedefine01 DEBUG_AUX
  304. +#cmakedefine01 DEBUG_SPI
  305. +#cmakedefine01 DEBUG_REG
  306. +#cmakedefine01 DEBUG_HAL
  307. +#cmakedefine01 DEBUG_GPS
  308. +#cmakedefine01 DEBUG_GPIO
  309. +#cmakedefine01 DEBUG_LBT
  310. +
  311. +#endif
  312. diff --git a/util_lbt_test/CMakeLists.txt b/util_lbt_test/CMakeLists.txt
  313. new file mode 100644
  314. index 0000000..f184b82
  315. --- /dev/null
  316. +++ b/util_lbt_test/CMakeLists.txt
  317. @@ -0,0 +1,23 @@
  318. +
  319. +add_executable(util_lbt_test "")
  320. +target_sources(util_lbt_test
  321. + PRIVATE
  322. + ${CMAKE_CURRENT_LIST_DIR}/src/util_lbt_test.c
  323. +)
  324. +
  325. +target_link_libraries(util_lbt_test
  326. + PUBLIC
  327. + loragw
  328. +)
  329. +
  330. +set_target_properties(util_lbt_test PROPERTIES
  331. + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
  332. +)
  333. +
  334. +# add the install targets
  335. +install (
  336. + TARGETS util_lbt_test
  337. + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
  338. + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  339. + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  340. +)
  341. diff --git a/util_pkt_logger/CMakeLists.txt b/util_pkt_logger/CMakeLists.txt
  342. new file mode 100644
  343. index 0000000..82cfc86
  344. --- /dev/null
  345. +++ b/util_pkt_logger/CMakeLists.txt
  346. @@ -0,0 +1,29 @@
  347. +
  348. +add_executable(util_pkt_logger "")
  349. +target_sources(util_pkt_logger
  350. + PRIVATE
  351. + ${CMAKE_CURRENT_LIST_DIR}/src/util_pkt_logger.c
  352. + ${CMAKE_CURRENT_LIST_DIR}/src/parson.c
  353. +)
  354. +
  355. +target_include_directories(util_pkt_logger
  356. + PRIVATE
  357. + ${CMAKE_CURRENT_LIST_DIR}/inc
  358. +)
  359. +
  360. +target_link_libraries(util_pkt_logger
  361. + PUBLIC
  362. + loragw
  363. +)
  364. +
  365. +set_target_properties(util_pkt_logger PROPERTIES
  366. + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
  367. +)
  368. +
  369. +# add the install targets
  370. +install (
  371. + TARGETS util_pkt_logger
  372. + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
  373. + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  374. + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  375. +)
  376. diff --git a/util_spectral_scan/CMakeLists.txt b/util_spectral_scan/CMakeLists.txt
  377. new file mode 100644
  378. index 0000000..3cec2a9
  379. --- /dev/null
  380. +++ b/util_spectral_scan/CMakeLists.txt
  381. @@ -0,0 +1,23 @@
  382. +
  383. +add_executable(util_spectral_scan "")
  384. +target_sources(util_spectral_scan
  385. + PRIVATE
  386. + ${CMAKE_CURRENT_LIST_DIR}/src/util_spectral_scan.c
  387. +)
  388. +
  389. +target_link_libraries(util_spectral_scan
  390. + PUBLIC
  391. + loragw
  392. +)
  393. +
  394. +set_target_properties(util_spectral_scan PROPERTIES
  395. + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
  396. +)
  397. +
  398. +# add the install targets
  399. +install (
  400. + TARGETS util_spectral_scan
  401. + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
  402. + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  403. + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  404. +)
  405. diff --git a/util_spi_stress/CMakeLists.txt b/util_spi_stress/CMakeLists.txt
  406. new file mode 100644
  407. index 0000000..d5f0eea
  408. --- /dev/null
  409. +++ b/util_spi_stress/CMakeLists.txt
  410. @@ -0,0 +1,23 @@
  411. +
  412. +add_executable(util_spi_stress "")
  413. +target_sources(util_spi_stress
  414. + PRIVATE
  415. + ${CMAKE_CURRENT_LIST_DIR}/src/util_spi_stress.c
  416. +)
  417. +
  418. +target_link_libraries(util_spi_stress
  419. + PUBLIC
  420. + loragw
  421. +)
  422. +
  423. +set_target_properties(util_spi_stress PROPERTIES
  424. + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
  425. +)
  426. +
  427. +# add the install targets
  428. +install (
  429. + TARGETS util_spi_stress
  430. + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
  431. + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  432. + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  433. +)
  434. diff --git a/util_tx_continuous/CMakeLists.txt b/util_tx_continuous/CMakeLists.txt
  435. new file mode 100644
  436. index 0000000..97c70e5
  437. --- /dev/null
  438. +++ b/util_tx_continuous/CMakeLists.txt
  439. @@ -0,0 +1,23 @@
  440. +
  441. +add_executable(util_tx_continuous "")
  442. +target_sources(util_tx_continuous
  443. + PRIVATE
  444. + ${CMAKE_CURRENT_LIST_DIR}/src/util_tx_continuous.c
  445. +)
  446. +
  447. +target_link_libraries(util_tx_continuous
  448. + PUBLIC
  449. + loragw
  450. +)
  451. +
  452. +set_target_properties(util_tx_continuous PROPERTIES
  453. + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
  454. +)
  455. +
  456. +# add the install targets
  457. +install (
  458. + TARGETS util_tx_continuous
  459. + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
  460. + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  461. + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  462. +)
  463. diff --git a/util_tx_test/CMakeLists.txt b/util_tx_test/CMakeLists.txt
  464. new file mode 100644
  465. index 0000000..6cc0e04
  466. --- /dev/null
  467. +++ b/util_tx_test/CMakeLists.txt
  468. @@ -0,0 +1,23 @@
  469. +
  470. +add_executable(util_tx_test "")
  471. +target_sources(util_tx_test
  472. + PRIVATE
  473. + ${CMAKE_CURRENT_LIST_DIR}/src/util_tx_test.c
  474. +)
  475. +
  476. +target_link_libraries(util_tx_test
  477. + PUBLIC
  478. + loragw
  479. +)
  480. +
  481. +set_target_properties(util_tx_test PROPERTIES
  482. + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
  483. +)
  484. +
  485. +# add the install targets
  486. +install (
  487. + TARGETS util_tx_test
  488. + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
  489. + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  490. + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  491. +)
  492. --
  493. 2.20.1