Skip to content

Commit

Permalink
Add find_package compatible install
Browse files Browse the repository at this point in the history
  • Loading branch information
will-v-pi committed Aug 22, 2024
1 parent eba6adb commit 6d08e41
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,31 @@ if (NOT TARGET _pico_sdk_inclusion_marker)
if (NOT PICO_SDK_TOP_LEVEL_PROJECT)
pico_promote_common_scope_vars()
endif()

if (PICO_SDK_TOP_LEVEL_PROJECT)
# Create a ConfigVersion.cmake file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_BINARY_DIR}/pico-sdk-config-version.cmake
VERSION ${PICO_SDK_VERSION_STRING}
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)

# Temporarily copy that file into source tree
install(CODE "file(COPY ${CMAKE_BINARY_DIR}/pico-sdk-config-version.cmake DESTINATION ${CMAKE_CURRENT_LIST_DIR}/cmake/)")

# Install entire pico-sdk directory
get_filename_component(binDir ${CMAKE_BINARY_DIR} NAME)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
TYPE LIB
PATTERN "${binDir}*" EXCLUDE
PATTERN "*.git*" EXCLUDE
PATTERN "*.github*" EXCLUDE
PATTERN "*.vscode*" EXCLUDE
PATTERN "test*" EXCLUDE)

# Delete temp file
install(CODE "file(REMOVE ${CMAKE_CURRENT_LIST_DIR}/cmake/pico-sdk-config-version.cmake)")
endif()
endif()
6 changes: 6 additions & 0 deletions cmake/pico-sdk-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

if (DEFINED PICO_SDK_PATH)
pico_sdk_init()
else()
message(FATAL_ERROR "Must use the toolchain file at ${CMAKE_CURRENT_LIST_DIR}/pico_toolchain_file.cmake, else pico-sdk project will not build")
endif()
17 changes: 17 additions & 0 deletions cmake/pico_toolchain_file.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set(CMAKE_SYSTEM_NAME PICO)

if (NOT DEFINED PICO_PREVIOUS_CMAKE_TOOLCHAIN_FILE)
unset(CMAKE_TOOLCHAIN_FILE CACHE)
else()
set(CMAKE_TOOLCHAIN_FILE ${PICO_PREVIOUS_CMAKE_TOOLCHAIN_FILE})
endif()

if (${PROJECT_NAME} MATCHES "CMAKE_TRY_COMPILE")
# Don't log toolchain searches when testing compiler
set(CMAKE_MESSAGE_LOG_LEVEL ERROR)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/../pico_sdk_init.cmake)

message("Toolchain file now ${CMAKE_TOOLCHAIN_FILE}")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" CACHE FILEPATH "")
include(${CMAKE_TOOLCHAIN_FILE})

0 comments on commit 6d08e41

Please sign in to comment.