1# SPDX-License-Identifier: Apache-2.0
2
3# Purpose of this CMake file is to install a ZephyrConfig package reference in:
4# Unix/Linux/MacOS: ~/.cmake/packages/Zephyr
5# Windows         : HKEY_CURRENT_USER
6#
7# Having ZephyrConfig package allows for find_package(Zephyr) to work when ZEPHYR_BASE is not defined.
8#
9# Create the reference by running `cmake -P zephyr_export.cmake` in this directory.
10
11set(MD5_INFILE "current_path.txt")
12
13# We write CMAKE_CURRENT_LIST_DIR into MD5_INFILE, as the content of that file will be used for MD5 calculation.
14# This means we effectively get the MD5 of CMAKE_CURRENT_LIST_DIR which must be used for CMake user package registry.
15file(WRITE ${CMAKE_CURRENT_LIST_DIR}/${MD5_INFILE} ${CMAKE_CURRENT_LIST_DIR})
16execute_process(COMMAND ${CMAKE_COMMAND} -E md5sum ${CMAKE_CURRENT_LIST_DIR}/${MD5_INFILE}
17                OUTPUT_VARIABLE MD5_SUM
18)
19string(SUBSTRING ${MD5_SUM} 0 32 MD5_SUM)
20if(WIN32)
21  execute_process(COMMAND ${CMAKE_COMMAND}
22                  -E  write_regv
23                 "HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Packages\\Zephyr\;${MD5_SUM}" "${CMAKE_CURRENT_LIST_DIR}"
24)
25else()
26  file(WRITE $ENV{HOME}/.cmake/packages/Zephyr/${MD5_SUM} ${CMAKE_CURRENT_LIST_DIR})
27endif()
28
29message("Zephyr (${CMAKE_CURRENT_LIST_DIR})")
30message("has been added to the user package registry in:")
31if(WIN32)
32  message("HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Packages\\Zephyr\n")
33else()
34  message("~/.cmake/packages/Zephyr\n")
35endif()
36
37file(REMOVE ${CMAKE_CURRENT_LIST_DIR}/${MD5_INFILE})
38