2019-04-06 15:08:09 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2021-08-10 14:44:56 +02:00
|
|
|
cmake_minimum_required(VERSION 3.20.0)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2024-03-05 11:39:57 +01:00
|
|
|
include(extensions)
|
|
|
|
include(west)
|
2022-08-05 11:09:26 +02:00
|
|
|
include(root)
|
2024-03-05 11:39:57 +01:00
|
|
|
include(zephyr_module)
|
2022-08-05 11:09:26 +02:00
|
|
|
include(boards)
|
2024-03-05 11:39:57 +01:00
|
|
|
include(hwm_v2)
|
2022-08-05 11:09:26 +02:00
|
|
|
include(configuration_files)
|
2023-10-25 23:53:02 +02:00
|
|
|
|
2022-08-05 11:09:26 +02:00
|
|
|
include(kconfig)
|
2024-03-05 11:39:57 +01:00
|
|
|
include(arch_v2)
|
|
|
|
include(soc_v2)
|
2022-08-05 11:09:26 +02:00
|
|
|
|
2022-11-07 06:43:14 +01:00
|
|
|
find_package(TargetTools)
|
|
|
|
|
|
|
|
enable_language(C CXX ASM)
|
|
|
|
|
|
|
|
include(${ZEPHYR_BASE}/cmake/target_toolchain_flags.cmake)
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
# Parameters:
|
|
|
|
# SOURCES: list of source files, default main.c
|
|
|
|
# INCLUDE: list of additional include paths relative to ZEPHYR_BASE
|
|
|
|
|
2022-03-14 12:56:40 +01:00
|
|
|
foreach(extra_flags EXTRA_CPPFLAGS EXTRA_LDFLAGS EXTRA_CFLAGS EXTRA_CXXFLAGS EXTRA_AFLAGS)
|
|
|
|
list(LENGTH ${extra_flags} flags_length)
|
|
|
|
if(flags_length LESS_EQUAL 1)
|
|
|
|
# A length of zero means no argument.
|
|
|
|
# A length of one means a single argument or a space separated list was provided.
|
|
|
|
# In both cases, it is safe to do a separate_arguments on the argument.
|
|
|
|
separate_arguments(${extra_flags}_AS_LIST UNIX_COMMAND ${${extra_flags}})
|
|
|
|
else()
|
|
|
|
# Already a proper list, no conversion needed.
|
|
|
|
set(${extra_flags}_AS_LIST "${${extra_flags}}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2017-11-10 13:27:53 +01:00
|
|
|
|
2020-02-12 15:42:09 +01:00
|
|
|
set(ENV_ZEPHYR_BASE $ENV{ZEPHYR_BASE})
|
|
|
|
# This add support for old style boilerplate include.
|
|
|
|
if((NOT DEFINED ZEPHYR_BASE) AND (DEFINED ENV_ZEPHYR_BASE))
|
|
|
|
set(ZEPHYR_BASE ${ENV_ZEPHYR_BASE} CACHE PATH "Zephyr base")
|
|
|
|
endif()
|
|
|
|
|
2022-11-07 06:43:14 +01:00
|
|
|
find_package(Deprecated COMPONENTS SOURCES)
|
|
|
|
|
2022-10-06 18:31:18 +02:00
|
|
|
if(NOT SOURCES AND EXISTS main.c)
|
2017-10-27 15:43:34 +02:00
|
|
|
set(SOURCES main.c)
|
|
|
|
endif()
|
|
|
|
|
2018-04-05 22:59:33 +02:00
|
|
|
add_executable(testbinary ${SOURCES})
|
2022-09-01 10:11:36 +02:00
|
|
|
add_library(test_interface INTERFACE)
|
|
|
|
target_link_libraries(testbinary PRIVATE test_interface)
|
2018-04-05 22:59:33 +02:00
|
|
|
|
2019-01-14 16:39:33 +01:00
|
|
|
set(KOBJ_TYPES_H_TARGET kobj_types_h_target)
|
2020-02-12 15:42:09 +01:00
|
|
|
include(${ZEPHYR_BASE}/cmake/kobj.cmake)
|
2022-09-01 10:11:36 +02:00
|
|
|
add_dependencies(test_interface ${KOBJ_TYPES_H_TARGET})
|
2018-04-05 22:59:33 +02:00
|
|
|
gen_kobj(KOBJ_GEN_DIR)
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
list(APPEND INCLUDE
|
2022-05-06 15:27:18 +02:00
|
|
|
subsys/testsuite/ztest/include/zephyr
|
2022-04-19 19:54:42 +02:00
|
|
|
subsys/testsuite/include/zephyr
|
2019-02-19 21:45:18 +01:00
|
|
|
subsys/testsuite/ztest/include
|
|
|
|
subsys/testsuite/include
|
2022-03-29 21:52:59 +02:00
|
|
|
include/zephyr
|
2022-04-01 05:05:42 +02:00
|
|
|
include
|
2017-10-27 15:43:34 +02:00
|
|
|
.
|
2018-04-05 22:59:33 +02:00
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2019-09-25 11:40:11 +02:00
|
|
|
if(CMAKE_HOST_APPLE)
|
|
|
|
else()
|
2019-10-14 16:23:18 +02:00
|
|
|
|
|
|
|
if(M64_MODE)
|
|
|
|
set (CMAKE_C_FLAGS "-m64")
|
2020-08-31 12:48:34 +02:00
|
|
|
set (CMAKE_CXX_FLAGS "-m64")
|
2019-10-14 16:23:18 +02:00
|
|
|
else()
|
2019-09-25 11:40:11 +02:00
|
|
|
set (CMAKE_C_FLAGS "-m32") #deprecated on macOS
|
2020-08-31 12:48:34 +02:00
|
|
|
set (CMAKE_CXX_FLAGS "-m32") #deprecated on macOS
|
2019-10-14 16:23:18 +02:00
|
|
|
endif(M64_MODE)
|
|
|
|
|
2019-09-25 11:40:11 +02:00
|
|
|
endif()
|
2018-11-21 14:50:41 +01:00
|
|
|
|
2022-09-01 10:11:36 +02:00
|
|
|
target_compile_options(test_interface INTERFACE
|
2022-08-05 11:09:26 +02:00
|
|
|
-imacros ${AUTOCONF_H}
|
2017-11-10 13:27:53 +01:00
|
|
|
-Wall
|
2018-04-05 22:59:33 +02:00
|
|
|
-I ${KOBJ_GEN_DIR}
|
2017-11-10 13:27:53 +01:00
|
|
|
${EXTRA_CPPFLAGS_AS_LIST}
|
|
|
|
${EXTRA_CFLAGS_AS_LIST}
|
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:${EXTRA_CXXFLAGS_AS_LIST}>
|
|
|
|
$<$<COMPILE_LANGUAGE:ASM>:${EXTRA_AFLAGS_AS_LIST}>
|
|
|
|
)
|
|
|
|
|
2021-07-23 19:47:52 +02:00
|
|
|
target_link_options(testbinary PRIVATE
|
2022-04-19 19:54:42 +02:00
|
|
|
-T "${ZEPHYR_BASE}/subsys/testsuite/include/zephyr/ztest_unittest.ld"
|
2021-07-23 19:47:52 +02:00
|
|
|
)
|
|
|
|
|
2017-11-10 13:27:53 +01:00
|
|
|
target_link_libraries(testbinary PRIVATE
|
|
|
|
${EXTRA_LDFLAGS_AS_LIST}
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2022-11-28 19:33:11 +01:00
|
|
|
if(CONFIG_COVERAGE)
|
2022-11-07 06:43:14 +01:00
|
|
|
target_compile_options(test_interface INTERFACE $<TARGET_PROPERTY:compiler,coverage>)
|
|
|
|
|
|
|
|
target_link_libraries(testbinary PRIVATE $<TARGET_PROPERTY:linker,coverage>)
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(LIBS)
|
|
|
|
message(FATAL_ERROR "This variable is not supported, see SOURCES instead")
|
|
|
|
endif()
|
|
|
|
|
2023-10-10 02:06:05 +02:00
|
|
|
target_sources(testbinary PRIVATE
|
|
|
|
${ZEPHYR_BASE}/subsys/testsuite/ztest/src/ztest.c
|
|
|
|
${ZEPHYR_BASE}/subsys/testsuite/ztest/src/ztest_mock.c
|
|
|
|
${ZEPHYR_BASE}/subsys/testsuite/ztest/src/ztest_rules.c
|
|
|
|
${ZEPHYR_BASE}/subsys/testsuite/ztest/src/ztest_defaults.c
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2022-09-01 10:11:36 +02:00
|
|
|
target_compile_definitions(test_interface INTERFACE ZTEST_UNITTEST)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
foreach(inc ${INCLUDE})
|
2022-09-01 10:11:36 +02:00
|
|
|
target_include_directories(test_interface INTERFACE ${ZEPHYR_BASE}/${inc})
|
2017-10-27 15:43:34 +02:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
find_program(VALGRIND_PROGRAM valgrind)
|
|
|
|
if(VALGRIND_PROGRAM)
|
|
|
|
set(VALGRIND ${VALGRIND_PROGRAM})
|
|
|
|
set(VALGRIND_FLAGS
|
|
|
|
--leak-check=full
|
|
|
|
--error-exitcode=1
|
2022-08-05 11:09:26 +02:00
|
|
|
--log-file=valgrind.log
|
2017-10-27 15:43:34 +02:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_target(run-test
|
|
|
|
COMMAND
|
|
|
|
${VALGRIND} ${VALGRIND_FLAGS}
|
|
|
|
$<TARGET_FILE:testbinary>
|
|
|
|
DEPENDS testbinary
|
|
|
|
WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}
|
|
|
|
)
|
|
|
|
# TODO: Redirect output to unit.log
|