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.

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