cmake: remove the use of SOURCES in tests

Setting SOURCES before calling find_package() was deprecated in #51049.

Cleanup usage of SOURCES and instead use the proper target_sources()
CMake function.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2024-08-01 12:18:08 +02:00 committed by Carles Cufí
commit e8e5169f95
11 changed files with 40 additions and 56 deletions

View file

@ -4,8 +4,6 @@
cmake_minimum_required(VERSION 3.20.0)
include(ExternalProject)
# Add the sources and set up the build for either unit testing or native_sim
list(APPEND SOURCES src/main.cpp)
if(BOARD STREQUAL unit_testing)
find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})
set(target testbinary)
@ -22,7 +20,7 @@ endif()
# Create the project and set the sources for the target
project(fail)
target_sources(${target} PRIVATE ${SOURCES})
target_sources(${target} PRIVATE src/main.cpp)
# Find which CONFIG_ZTEST_FAIL_TEST_* choice was set so we can pass it to the external project
# Once we find the config, we'll need to prepend a '-D' and append '=y' so we can pass it to the

View file

@ -6,34 +6,35 @@ cmake_minimum_required(VERSION 3.20.0)
set(KCONFIG_ROOT ${CMAKE_CURRENT_LIST_DIR}/../Kconfig)
# Add the sources
list(APPEND SOURCES src/main.cpp)
list(APPEND test_sources src/main.cpp)
if(CONFIG_ZTEST_FAIL_TEST_ASSERT_AFTER)
list(APPEND SOURCES src/assert_after.cpp)
list(APPEND test_sources src/assert_after.cpp)
elseif(CONFIG_ZTEST_FAIL_TEST_ASSERT_TEARDOWN)
list(APPEND SOURCES src/assert_teardown.cpp)
list(APPEND test_sources src/assert_teardown.cpp)
elseif(CONFIG_ZTEST_FAIL_TEST_ASSUME_AFTER)
list(APPEND SOURCES src/assume_after.cpp)
list(APPEND test_sources src/assume_after.cpp)
elseif(CONFIG_ZTEST_FAIL_TEST_ASSUME_TEARDOWN)
list(APPEND SOURCES src/assume_teardown.cpp)
list(APPEND test_sources src/assume_teardown.cpp)
elseif(CONFIG_ZTEST_FAIL_TEST_PASS_AFTER)
list(APPEND SOURCES src/pass_after.cpp)
list(APPEND test_sources src/pass_after.cpp)
elseif(CONFIG_ZTEST_FAIL_TEST_PASS_TEARDOWN)
list(APPEND SOURCES src/pass_teardown.cpp)
list(APPEND test_sources src/pass_teardown.cpp)
elseif(CONFIG_ZTEST_FAIL_TEST_UNEXPECTED_ASSUME)
list(APPEND SOURCES src/unexpected_assume.cpp)
list(APPEND test_sources src/unexpected_assume.cpp)
endif()
if(BOARD STREQUAL unit_testing)
find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(base)
target_sources(testbinary PRIVATE ${test_sources})
target_include_directories(testbinary PRIVATE include)
install(TARGETS testbinary)
else()
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(base)
target_sources(app PRIVATE ${SOURCES})
target_sources(app PRIVATE ${test_sources})
target_include_directories(app PRIVATE include)
install(FILES ${APPLICATION_BINARY_DIR}/zephyr/${KERNEL_EXE_NAME}
DESTINATION bin/