ChibiOS.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. IF(NOT ChibiOS_FIND_COMPONENTS)
  2. SET(ChibiOS_FIND_COMPONENTS nil hal)
  3. MESSAGE(STATUS "No ChibiOS components specified, using default: ${ChibiOS_FIND_COMPONENTS}")
  4. ENDIF()
  5. SET (CHIBIOS_COMPONENTS nil rt hal)
  6. LIST(FIND ChibiOS_FIND_COMPONENTS nil ChibiOS_FIND_COMPONENTS_nil)
  7. LIST(FIND ChibiOS_FIND_COMPONENTS rt ChibiOS_FIND_COMPONENTS_rt)
  8. LIST(FIND ChibiOS_FIND_COMPONENTS hal ChibiOS_FIND_COMPONENTS_hal)
  9. IF((${ChibiOS_FIND_COMPONENTS_nil} LESS 0) AND (${ChibiOS_FIND_COMPONENTS_rt} LESS 0))
  10. MESSAGE(STATUS "No kernel component selected, using Nil kernel")
  11. LIST(APPEND ChibiOS_FIND_COMPONENTS nil)
  12. SET(CHIBIOS_KERNEL nil)
  13. ELSE()
  14. IF((NOT (${ChibiOS_FIND_COMPONENTS_nil} LESS 0)) AND (NOT (${ChibiOS_FIND_COMPONENTS_rt} LESS 0)))
  15. MESSAGE(FATAL_ERROR "Cannot use RT and Nil kernel at the same time")
  16. ENDIF()
  17. IF(NOT (${ChibiOS_FIND_COMPONENTS_nil} LESS 0))
  18. SET(CHIBIOS_KERNEL nil)
  19. ELSE()
  20. SET(CHIBIOS_KERNEL rt)
  21. ENDIF()
  22. ENDIF()
  23. IF(${ChibiOS_FIND_COMPONENTS_hal} LESS 0)
  24. LIST(APPEND ChibiOS_FIND_COMPONENTS hal)
  25. ENDIF()
  26. IF(NOT CHIBIOS_HALCONF_FILE)
  27. MESSAGE(STATUS "No ChibiOS halconf.h specified, trying to find it...")
  28. FILE(GLOB CHIBIOS_HALCONF_FILE "halconf.h")
  29. IF (CHIBIOS_HALCONF_FILE STREQUAL "")
  30. MESSAGE(FATAL_ERROR "Cannot find halconf.h, please specify it using CHIBIOS_HALCONF_FILE variable")
  31. ELSE()
  32. MESSAGE(STATUS "Found halconf.h: ${CHIBIOS_HALCONF_FILE}")
  33. ENDIF()
  34. ENDIF()
  35. IF(NOT CHIBIOS_CHCONF_FILE)
  36. MESSAGE(STATUS "No ChibiOS chconf.h specified, trying to find it...")
  37. FILE(GLOB CHIBIOS_CHCONF_FILE "chconf.h")
  38. IF (CHIBIOS_CHCONF_FILE STREQUAL "")
  39. MESSAGE(FATAL_ERROR "Cannot find chconf.h, please specify it using CHIBIOS_CHCONF_FILE variable")
  40. ELSE()
  41. MESSAGE(STATUS "Found chconf.h: ${CHIBIOS_CHCONF_FILE}")
  42. ENDIF()
  43. ENDIF()
  44. FILE(STRINGS ${CHIBIOS_CHCONF_FILE} CHCONF_LINES REGEX "#define CH_CFG_USE_([a-zA-Z_0-9]+) +TRUE")
  45. FOREACH(LINE ${CHCONF_LINES})
  46. STRING(REGEX REPLACE "#define CH_CFG_USE_([a-zA-Z_0-9]+) +TRUE" "\\1" COMP ${LINE})
  47. LIST(APPEND CHIBIOS_RTOS_COMPONENTS ${COMP})
  48. ENDFOREACH()
  49. MESSAGE(STATUS "Detected ChibiOS RTOS components:")
  50. FOREACH(COMP ${CHIBIOS_RTOS_COMPONENTS})
  51. MESSAGE(STATUS "\t${COMP}")
  52. ENDFOREACH()
  53. FILE(STRINGS ${CHIBIOS_HALCONF_FILE} HALCONF_LINES REGEX "#define HAL_USE_([a-zA-Z_0-9]+) +TRUE")
  54. FOREACH(LINE ${HALCONF_LINES})
  55. STRING(REGEX REPLACE "#define HAL_USE_([a-zA-Z_0-9]+) +TRUE" "\\1" COMP ${LINE})
  56. LIST(APPEND CHIBIOS_HAL_COMPONENTS ${COMP})
  57. ENDFOREACH()
  58. MESSAGE(STATUS "Detected ChibiOS HAL components:")
  59. FOREACH(COMP ${CHIBIOS_HAL_COMPONENTS})
  60. MESSAGE(STATUS "\t${COMP}")
  61. ENDFOREACH()
  62. INCLUDE(ChibiOS/18.2/ChibiOS_LD)
  63. INCLUDE(ChibiOS/18.2/ChibiOS_RTOS)
  64. INCLUDE(ChibiOS/18.2/ChibiOS_HAL)
  65. MESSAGE(STATUS "RTOS sources: ")
  66. FOREACH(SOURCE ${CHIBIOS_SOURCES_${CHIBIOS_KERNEL}})
  67. MESSAGE(STATUS "\t${SOURCE}")
  68. ENDFOREACH()
  69. MESSAGE(STATUS "HAL sources: ")
  70. FOREACH(SOURCE ${CHIBIOS_SOURCES_hal})
  71. MESSAGE(STATUS "\t${SOURCE}")
  72. ENDFOREACH()
  73. IF(NOT ChibiOS_LINKER_SCRIPT)
  74. MESSAGE(STATUS "ChibiOS doesn't have linker script for your chip, please specify it directly using ChibiOS_LINKER_SCRIPT variable.")
  75. ENDIF()
  76. FOREACH(comp ${ChibiOS_FIND_COMPONENTS})
  77. LIST(FIND CHIBIOS_COMPONENTS ${comp} INDEX)
  78. IF(INDEX EQUAL -1)
  79. MESSAGE(FATAL_ERROR "Unknown ChibiOS component: ${comp}\nSupported ChibiOS components: ${CHIBIOS_COMPONENTS}")
  80. ENDIF()
  81. FOREACH(source ${CHIBIOS_SOURCES_${comp}})
  82. FIND_FILE(CHIBIOS_${comp}_${source} NAMES ${source} PATHS ${CHIBIOS_ROOT} NO_DEFAULT_PATH CMAKE_FIND_ROOT_PATH_BOTH)
  83. LIST(APPEND ChibiOS_SOURCES ${CHIBIOS_${comp}_${source}})
  84. ENDFOREACH()
  85. FOREACH(incl ${CHIBIOS_INCLUDES_${comp}})
  86. LIST(APPEND ChibiOS_INCLUDE_DIRS ${CHIBIOS_ROOT}/${incl})
  87. ENDFOREACH()
  88. ENDFOREACH()