Skip to content

Commit bf00a2a

Browse files
stephanosionashif
authored andcommitted
cmake: Add CMake package registration script
This commit adds a universal CMake script that automates the registration of the `Zephyr-sdk` CMake package in the user package registry. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 92dfbc0 commit bf00a2a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

cmake/zephyr_sdk_export.cmake

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
# The purpose of this CMake file is to register the Zephyr-sdk package in:
4+
#
5+
# Linux/macOS: ~/.cmake/packages/Zephyr-sdk
6+
# Windows: HKEY_CURRENT_USER
7+
#
8+
# By registering the Zephyr-sdk package, the Zephyr build system can locate the
9+
# required version of Zephyr SDK through `find_package(Zephyr-sdk)` even when
10+
# ZEPHYR_SDK_INSTALL_DIR is not explicitly set.
11+
#
12+
# Register the Zephyr-sdk package by running `cmake -P zephyr_sdk_export.cmake`
13+
# in this directory.
14+
15+
set(MD5_INFILE "current_path.txt")
16+
17+
# We write CMAKE_CURRENT_LIST_DIR into MD5_INFILE, as the content of that file
18+
# will be used for MD5 calculation. This means we effectively get the MD5 of
19+
# CMAKE_CURRENT_LIST_DIR which must be used for CMake user package registry.
20+
file(WRITE ${CMAKE_CURRENT_LIST_DIR}/${MD5_INFILE} ${CMAKE_CURRENT_LIST_DIR})
21+
execute_process(COMMAND ${CMAKE_COMMAND} -E md5sum ${CMAKE_CURRENT_LIST_DIR}/${MD5_INFILE}
22+
OUTPUT_VARIABLE MD5_SUM
23+
)
24+
string(SUBSTRING ${MD5_SUM} 0 32 MD5_SUM)
25+
if(WIN32)
26+
execute_process(COMMAND ${CMAKE_COMMAND}
27+
-E write_regv
28+
"HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Packages\\Zephyr-sdk\;${MD5_SUM}"
29+
"${CMAKE_CURRENT_LIST_DIR}"
30+
)
31+
else()
32+
file(WRITE $ENV{HOME}/.cmake/packages/Zephyr-sdk/${MD5_SUM} ${CMAKE_CURRENT_LIST_DIR})
33+
endif()
34+
35+
message("Zephyr-sdk (${CMAKE_CURRENT_LIST_DIR})")
36+
message("has been added to the user package registry in:")
37+
if(WIN32)
38+
message("HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Packages\\Zephyr-sdk\n")
39+
else()
40+
message("~/.cmake/packages/Zephyr-sdk\n")
41+
endif()
42+
43+
file(REMOVE ${CMAKE_CURRENT_LIST_DIR}/${MD5_INFILE})

0 commit comments

Comments
 (0)