pico_sdk_init.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Pre-initialize the Raspberry Pi Pico SDK, setting up the platform and toolchain and some CMake utility functions
  2. # This file must be included prior to the project() call
  3. # Note: this file is perhaps named badly, as it provides a method pico_sdk_init which
  4. # the enclosing project calls LATER to actually "initialize" the SDK (by including the CMakeLists.txt from this
  5. # same directory)
  6. if (NOT TARGET _pico_sdk_pre_init_marker)
  7. add_library(_pico_sdk_pre_init_marker INTERFACE)
  8. function(pico_is_top_level_project VAR)
  9. string(TOLOWER ${CMAKE_CURRENT_LIST_DIR} __list_dir)
  10. string(TOLOWER ${CMAKE_SOURCE_DIR} __source_dir)
  11. if (__source_dir STREQUAL __list_dir)
  12. set(${VAR} 1 PARENT_SCOPE)
  13. else()
  14. set(${VAR} 0 PARENT_SCOPE)
  15. endif()
  16. endfunction()
  17. function(pico_message_debug MESSAGE)
  18. # The log-level system was added in CMake 3.15.
  19. if(${CMAKE_VERSION} VERSION_LESS "3.15.0")
  20. message(${MESSAGE})
  21. else()
  22. message(DEBUG ${MESSAGE})
  23. endif()
  24. endfunction()
  25. if (NOT PICO_SDK_PATH)
  26. set(PICO_SDK_PATH ${CMAKE_CURRENT_LIST_DIR})
  27. endif ()
  28. get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
  29. set(PICO_SDK_PATH ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
  30. list(APPEND CMAKE_MODULE_PATH ${PICO_SDK_PATH}/cmake)
  31. include(${CMAKE_CURRENT_LIST_DIR}/pico_sdk_version.cmake)
  32. include(pico_utils)
  33. message("PICO_SDK_PATH is ${CMAKE_CURRENT_LIST_DIR}")
  34. include(pico_pre_load_platform)
  35. # We want to configure correct toolchain prior to project load
  36. # todo perhaps this should be included by the platform instead?
  37. include(pico_pre_load_toolchain)
  38. macro(pico_sdk_init)
  39. if (NOT CMAKE_PROJECT_NAME)
  40. message(WARNING "pico_sdk_init() should be called after the project is created (and languages added)")
  41. endif()
  42. add_subdirectory(${PICO_SDK_PATH} pico-sdk)
  43. endmacro()
  44. macro(add_sub_list_dirs var)
  45. foreach(LIST_DIR IN LISTS ${var})
  46. get_filename_component(SHORT_NAME "${LIST_DIR}" NAME)
  47. pico_message_debug("Including custom CMakeLists.txt ${SHORT_NAME}")
  48. add_subdirectory(${LIST_DIR} ${SHORT_NAME})
  49. endforeach()
  50. endmacro()
  51. macro(add_sub_list_files var)
  52. foreach(LIST_FILE IN LISTS ${var})
  53. pico_message_debug("Including custom CMake file ${LIST_FILE}")
  54. include(${LIST_FILE})
  55. endforeach()
  56. endmacro()
  57. macro(pico_register_common_scope_var NAME)
  58. if (NOT ${NAME} IN_LIST PICO_PROMOTE_COMMON_SCOPE_VARS)
  59. list(APPEND PICO_PROMOTE_COMMON_SCOPE_VARS ${NAME})
  60. endif()
  61. endmacro()
  62. set(PICO_PROMOTE_COMMON_SCOPE_VARS
  63. PICO_INCLUDE_DIRS
  64. PICO_SDK_POST_LIST_DIRS
  65. PICO_SDK_POST_LIST_FILES
  66. PICO_CONFIG_HEADER_FILES
  67. PICO_RP2040_CONFIG_HEADER_FILES
  68. )
  69. macro(pico_promote_common_scope_vars)
  70. set(PICO_PROMOTE_COMMON_SCOPE_VARS ${PICO_PROMOTE_COMMON_SCOPE_VARS} PARENT_SCOPE)
  71. foreach(VAR IN LISTS PICO_PROMOTE_COMMON_SCOPE_VARS)
  72. SET(${VAR} ${${VAR}} PARENT_SCOPE)
  73. endforeach()
  74. endmacro()
  75. endif()