zephyr/share/zephyr-package/cmake/zephyr_export.cmake
Christopher Friedt 3650537a9d cmake: calculate the md5 sum using the built-in string command
Assuming that all supported releases require at least CMake
version 3.0, we should be able to calculate the md5sum in a
much simpler way using string().
https://cmake.org/cmake/help/v3.0/command/string.html

This avoids writing a temporary file into the source directory
and therefore mitigates the possibility of the following
warning.

share/zephyr-package/cmake/zephyr_export.cmake:19 (string):
  string sub-command SUBSTRING requires four arguments.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-12-12 10:56:06 +01:00

30 lines
1 KiB
CMake

# SPDX-License-Identifier: Apache-2.0
# Purpose of this CMake file is to install a ZephyrConfig package reference in:
# Unix/Linux/MacOS: ~/.cmake/packages/Zephyr
# Windows : HKEY_CURRENT_USER
#
# Having ZephyrConfig package allows for find_package(Zephyr) to work when ZEPHYR_BASE is not defined.
#
# Create the reference by running `cmake -P zephyr_export.cmake` in this directory.
string(MD5 MD5_SUM ${CMAKE_CURRENT_LIST_DIR})
if(WIN32)
execute_process(COMMAND ${CMAKE_COMMAND}
-E write_regv
"HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Packages\\Zephyr\;${MD5_SUM}" "${CMAKE_CURRENT_LIST_DIR}"
)
else()
file(WRITE $ENV{HOME}/.cmake/packages/Zephyr/${MD5_SUM} ${CMAKE_CURRENT_LIST_DIR})
endif()
message("Zephyr (${CMAKE_CURRENT_LIST_DIR})")
message("has been added to the user package registry in:")
if(WIN32)
message("HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Packages\\Zephyr\n")
else()
message("~/.cmake/packages/Zephyr\n")
endif()
file(REMOVE ${CMAKE_CURRENT_LIST_DIR}/${MD5_INFILE})