CMakeLists.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. cmake_minimum_required(VERSION 3.13)
  2. if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.12)
  3. cmake_policy(SET CMP0074 NEW)
  4. endif()
  5. set(ROTOR_LIGHT_VERSION "0.01")
  6. project (rotor_light LANGUAGES CXX VERSION ${ROTOR_LIGHT_VERSION})
  7. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
  8. if (NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET AND
  9. NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN)
  10. set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  11. set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
  12. endif ()
  13. set(ROTOR_LIGHT_DOC OFF CACHE BOOL "generate docs using doxygen")
  14. set(ROTOR_LIGHT_ACTOR "uint64_t" CACHE STRING "ActorId type [default: uint64_t]")
  15. set(ROTOR_LIGHT_TIMEPOINT "int64_t" CACHE STRING "TimePoint type [default: int64_t]")
  16. set(ROTOR_LIGHT_DURATION "std::int_fast32_t" CACHE STRING "Duration type [default: std::int_fast32_t]")
  17. set(ROTOR_LIGHT_MESSAGE "std::uint_fast16_t" CACHE STRING "Message id type [default: std::uint_fast16_t]")
  18. set(ROTOR_LIGHT_EVENT "std::uint16_t" CACHE STRING "Event id type [default: std::uint16_t]")
  19. set(ROTOR_LIGHT_INDEX "std::uint_fast8_t" CACHE STRING "Queue indexing type [default: std::uint_fast8_t]")
  20. set(ROTOR_LIGHT_FW_QUEUE "0" CACHE STRING "Default queue/priority for rotor light framework messages [default: 0]")
  21. if(DEFINED ROTOR_LIGHT_QUEUE_SZ)
  22. set(ROTOR_LIGHT_QUEUE_SZ OFF CACHE BOOL "Allow measurement queues filling [default: off, on for 'Debug' build]")
  23. else()
  24. if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  25. set(RLQS ON)
  26. else()
  27. set(RLQS OFF)
  28. endif()
  29. set(ROTOR_LIGHT_QUEUE_SZ ${RLQS} CACHE BOOL "Allow measurement queues filling [default: off, on for debug builds]")
  30. endif()
  31. include(CMakePrintHelpers)
  32. include(GenerateExportHeader)
  33. if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AVR")
  34. set(ROTOR_LIGHT_BSP_DIR "avr")
  35. elseif ("${TOOLCHAIN_PREFIX}" MATCHES "^arm-.*")
  36. set(ROTOR_LIGHT_BSP_DIR "arm")
  37. elseif ("${TOOLCHAIN_PREFIX}" STREQUAL "mb-")
  38. set(ROTOR_LIGHT_BSP_DIR "mb")
  39. elseif ("${TOOLCHAIN_PREFIX}" STREQUAL "")
  40. set(ROTOR_LIGHT_BSP_DIR "host")
  41. endif()
  42. set(ROTOR_LIGHT_BSP_PATH "include/rotor-light/bsp/${ROTOR_LIGHT_BSP_DIR}")
  43. add_library(rotor_light_bsp INTERFACE)
  44. target_include_directories(rotor_light_bsp INTERFACE
  45. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${ROTOR_LIGHT_BSP_PATH}>
  46. $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${ROTOR_LIGHT_BSP_PATH}>
  47. $<INSTALL_INTERFACE:include/${ROTOR_LIGHT_BSP_PATH}>
  48. )
  49. add_library(rotor_light
  50. src/rotor-light/actor.cpp
  51. src/rotor-light/misc.cpp
  52. src/rotor-light/queue.cpp
  53. src/rotor-light/planner.cpp
  54. src/rotor-light/supervisor.cpp
  55. )
  56. target_include_directories(rotor_light PUBLIC
  57. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  58. $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
  59. $<INSTALL_INTERFACE:include>
  60. )
  61. target_compile_features(rotor_light PUBLIC cxx_std_17)
  62. set_target_properties(rotor_light PROPERTIES
  63. CXX_STANDARD 17
  64. CXX_STANDARD_REQUIRED YES
  65. CXX_EXTENSIONS NO
  66. )
  67. set(RLTCD
  68. "ROTOR_LIGHT_ACTOR=${ROTOR_LIGHT_ACTOR}"
  69. "ROTOR_LIGHT_TIMEPOINT=${ROTOR_LIGHT_TIMEPOINT}"
  70. "ROTOR_LIGHT_DURATION=${ROTOR_LIGHT_DURATION}"
  71. "ROTOR_LIGHT_MESSAGE=${ROTOR_LIGHT_MESSAGE}"
  72. "ROTOR_LIGHT_EVENT=${ROTOR_LIGHT_EVENT}"
  73. "ROTOR_LIGHT_INDEX=${ROTOR_LIGHT_INDEX}"
  74. "ROTOR_LIGHT_FW_QUEUE=${ROTOR_LIGHT_FW_QUEUE}"
  75. )
  76. if (${RLQS})
  77. list(APPEND RLTCD "ROTOR_LIGHT_QUEUE_SZ=1")
  78. endif()
  79. target_compile_definitions(rotor_light PUBLIC ${RLTCD})
  80. target_link_libraries(rotor_light rotor_light_bsp)
  81. if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
  82. add_subdirectory("examples")
  83. if ("${TOOLCHAIN_PREFIX}" STREQUAL "")
  84. include(CTest)
  85. if (BUILD_TESTING)
  86. add_subdirectory("tests")
  87. endif()
  88. endif()
  89. find_package(Doxygen)
  90. if (DOXYGEN_FOUND AND ${ROTOR_LIGHT_DOC})
  91. set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
  92. set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
  93. configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
  94. add_custom_target( doc_doxygen ALL
  95. COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
  96. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  97. COMMENT "Generating API documentation with Doxygen"
  98. VERBATIM)
  99. file(GLOB DOC_IMAGES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/docs/*.png)
  100. file(COPY ${DOC_IMAGES} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/doxygen)
  101. message("Doxygen need to be installed to generate the doxygen documentation")
  102. endif()
  103. endif()