1# SPDX-License-Identifier: Apache-2.0
2
3# Purpose of this CMake file is to install a ZephyrUnittestConfig package reference in:
4# Unix/Linux/MacOS: ~/.cmake/packages/ZephyrUnittest
5# Windows         : HKEY_CURRENT_USER
6#
7# Having ZephyrUnittestConfig package allows for find_package(ZephyrUnittest) 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\\ZephyrUnittest\;${MD5_SUM}" "${CMAKE_CURRENT_LIST_DIR}"
24)
25else()
26  file(WRITE $ENV{HOME}/.cmake/packages/ZephyrUnittest/${MD5_SUM} ${CMAKE_CURRENT_LIST_DIR})
27endif()
28
29message("ZephyrUnittest (${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\\ZephyrUnittest\n")
33else()
34  message("~/.cmake/packages/ZephyrUnittest\n")
35endif()
36
37file(REMOVE ${CMAKE_CURRENT_LIST_DIR}/${MD5_INFILE})
38