cmake: Relocating Zephyr Unittest CMake package.

Fixes: #23872

Relocating Zephyr Unittest CMake package to ensure that
HINTS ${ZEPHYR_BASE} in
find_package(ZephyrUnittest HINTS ${ZEPHYR_BASE}) works correctly when
the package has not been exported to CMake user package registry.

This ensure that the new package functionality is fully backwards
compatible on systems where the package is not exported and ZEPHYR_BASE
is set.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2020-03-27 21:31:36 +01:00 committed by Anas Nashif
commit 3074a7a498
10 changed files with 81 additions and 16 deletions

View file

@ -408,6 +408,7 @@
/scripts/zephyr_module.py @tejlmand
/scripts/valgrind.supp @aescolar @daor-oti
/share/zephyr-package/ @tejlmand
/share/zephyrunittest-package/ @tejlmand
/subsys/bluetooth/ @joerchan @jhedberg @Vudentz
/subsys/bluetooth/controller/ @carlescufi @cvinayak @thoh-ot
/subsys/bluetooth/mesh/ @jhedberg @trond-snekvik @joerchan @Vudentz

View file

@ -47,7 +47,7 @@ class ZephyrExport(WestCommand):
lines = run_cmake(cmake_args, capture_output=True)
# Let's clean up, as Zephyr has now been exported, and we no longer
# need the generated files.
# need the generated files.
cmake_args = ['--build', f'{zephyr_config_package_path}',
'--target', 'pristine']
run_cmake(cmake_args, capture_output=True)
@ -56,3 +56,21 @@ class ZephyrExport(WestCommand):
# the important information.
msg = [line for line in lines if not line.startswith('-- ')]
print('\n'.join(msg))
zephyr_unittest_config_package_path = PurePath(__file__).parents[2] \
/ 'share' / 'zephyrunittest-package' / 'cmake'
cmake_args = ['-S', f'{zephyr_unittest_config_package_path}',
'-B', f'{zephyr_unittest_config_package_path}']
lines = run_cmake(cmake_args, capture_output=True)
# Let's clean up, as Zephyr has now been exported, and we no longer
# need the generated files.
cmake_args = ['--build', f'{zephyr_unittest_config_package_path}',
'--target', 'pristine']
run_cmake(cmake_args, capture_output=True)
# Let's ignore the normal CMake printing and instead only print
# the important information.
msg = [line for line in lines if not line.startswith('-- ')]
print('\n'.join(msg))

View file

@ -15,14 +15,12 @@ if(NOT (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_LIST_DIR))
message(WARNING "\$\{CMAKE_BINARY_DIR\} is different from \$\{CMAKE_CURRENT_LIST_DIR\}, Zephyr config package may not work as expected.")
endif()
message("Zephyr and ZephyrUnitTest (${CMAKE_CURRENT_LIST_DIR})")
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")
message("HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Packages\\ZephyrUnitTest")
message("HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Packages\\Zephyr\n")
else()
message("~/.cmake/packages/Zephyr")
message("~/.cmake/packages/ZephyrUnitTest")
message("~/.cmake/packages/Zephyr\n")
endif()
add_custom_target(pristine
@ -30,4 +28,3 @@ add_custom_target(pristine
)
export(PACKAGE Zephyr)
export(PACKAGE ZephyrUnittest)

View file

@ -1,4 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
set(ZEPHYR_UNITTEST TRUE)
include(${CMAKE_CURRENT_LIST_DIR}/ZephyrConfig.cmake)

View file

@ -1,3 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
include(${CMAKE_CURRENT_LIST_DIR}/ZephyrConfigVersion.cmake)

View file

@ -15,9 +15,7 @@ list(REMOVE_ITEM GENERATED_FILES
"${CMAKE_CURRENT_LIST_DIR}/pristine.cmake"
"${CMAKE_CURRENT_LIST_DIR}/zephyr_package_search.cmake"
"${CMAKE_CURRENT_LIST_DIR}/ZephyrConfigVersion.cmake"
"${CMAKE_CURRENT_LIST_DIR}/ZephyrUnittestConfigVersion.cmake"
"${CMAKE_CURRENT_LIST_DIR}/ZephyrConfig.cmake"
"${CMAKE_CURRENT_LIST_DIR}/ZephyrUnittestConfig.cmake"
)
# Delete everything else, as those files are created by CMake.

View file

@ -0,0 +1,30 @@
# SPDX-License-Identifier: Apache-2.0
# Purpose of this CMake file is to install a ZephyrUnittestConfig package reference in:
# Unix/Linux/MacOS: ~/.cmake/packages/ZephyrUnittest
# Windows : HKEY_CURRENT_USER
#
# Having ZephyrUnittestConfig package allows for find_package(ZephyrUnittest) to work when ZEPHYR_BASE is not defined.
#
# Create the reference by running `cmake .` in this directory.
cmake_minimum_required(VERSION 3.13.1)
project(ZephyrUnittestPackageConfig NONE)
if(NOT (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_LIST_DIR))
message(WARNING "\$\{CMAKE_BINARY_DIR\} is different from \$\{CMAKE_CURRENT_LIST_DIR\}, ZephyrUnittest config package may not work as expected.")
endif()
message("ZephyrUnittest (${CMAKE_CURRENT_LIST_DIR})")
message("has been added to the user package registry in:")
if(WIN32)
message("HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Packages\\ZephyrUnittest\n")
else()
message("~/.cmake/packages/ZephyrUnittest\n")
endif()
add_custom_target(pristine
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_LIST_DIR}/pristine.cmake
)
export(PACKAGE ZephyrUnittest)

View file

@ -0,0 +1,4 @@
# SPDX-License-Identifier: Apache-2.0
set(ZEPHYR_UNITTEST TRUE)
include(${CMAKE_CURRENT_LIST_DIR}/../../zephyr-package/cmake/ZephyrConfig.cmake)

View file

@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
include(${CMAKE_CURRENT_LIST_DIR}/../../zephyr-package/cmake/ZephyrConfigVersion.cmake)

View file

@ -0,0 +1,21 @@
# SPDX-License-Identifier: Apache-2.0
# Purpose of this CMake file is to clean all CMake files generated by CMake when
# exporting Zephry to CMake user package registry.
# Get a list of all files.
file(GLOB_RECURSE GENERATED_FILES
LIST_DIRECTORIES true
${CMAKE_CURRENT_LIST_DIR}/*
)
# Remove the files that is used be Zephyr from the list.
list(REMOVE_ITEM GENERATED_FILES
"${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt"
"${CMAKE_CURRENT_LIST_DIR}/pristine.cmake"
"${CMAKE_CURRENT_LIST_DIR}/ZephyrUnittestConfigVersion.cmake"
"${CMAKE_CURRENT_LIST_DIR}/ZephyrUnittestConfig.cmake"
)
# Delete everything else, as those files are created by CMake.
file(REMOVE_RECURSE ${GENERATED_FILES})