Commit 3074a7a4 authored by Torsten Rasmussen's avatar Torsten Rasmussen Committed by Anas Nashif
Browse files

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: default avatarTorsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
parent 8b589258
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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
+19 −1
Original line number Diff line number Diff line
@@ -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))
+3 −6
Original line number Diff line number Diff line
@@ -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)
+0 −2
Original line number Diff line number Diff line
@@ -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.
+30 −0
Original line number Diff line number Diff line
# 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)
Loading