diff --git a/cmake/compiler/clang/generic.cmake b/cmake/compiler/clang/generic.cmake index 869a788e244..99402676ede 100644 --- a/cmake/compiler/clang/generic.cmake +++ b/cmake/compiler/clang/generic.cmake @@ -5,6 +5,7 @@ if(DEFINED TOOLCHAIN_HOME) endif() find_program(CMAKE_C_COMPILER clang ${find_program_clang_args}) +find_program(CMAKE_CXX_COMPILER clang++ ${find_program_clang_args}) find_program(CMAKE_LLVM_COV llvm-cov ${find_program_clang_args}) set(CMAKE_GCOV "${CMAKE_LLVM_COV} gcov") diff --git a/cmake/linker/lld/linker_flags.cmake b/cmake/linker/lld/linker_flags.cmake new file mode 100644 index 00000000000..43b96baeba5 --- /dev/null +++ b/cmake/linker/lld/linker_flags.cmake @@ -0,0 +1,5 @@ +# Copyright (c) 2022 Google LLC +# SPDX-License-Identifier: Apache-2.0 + +# Since lld is a drop in replacement for ld, we can just use ld's flags +include(${ZEPHYR_BASE}/cmake/linker/ld/${COMPILER}/linker_flags.cmake OPTIONAL) diff --git a/cmake/modules/FindDeprecated.cmake b/cmake/modules/FindDeprecated.cmake index d593846afc7..35d69875149 100644 --- a/cmake/modules/FindDeprecated.cmake +++ b/cmake/modules/FindDeprecated.cmake @@ -84,10 +84,12 @@ if(NOT "${Deprecated_FIND_COMPONENTS}" STREQUAL "") endif() if("SOURCES" IN_LIST Deprecated_FIND_COMPONENTS) - message(DEPRECATION - "Setting SOURCES prior to calling find_package() for unit tests is deprecated." - "To add sources after find_package() use:\n" - " target_sources(testbinary PRIVATE )") + if(SOURCES) + message(DEPRECATION + "Setting SOURCES prior to calling find_package() for unit tests is deprecated." + " To add sources after find_package() use:\n" + " target_sources(testbinary PRIVATE )") + endif() endif() set(Deprecated_FOUND True) diff --git a/cmake/modules/FindHostTools.cmake b/cmake/modules/FindHostTools.cmake index 87aba695823..c8f28f21285 100644 --- a/cmake/modules/FindHostTools.cmake +++ b/cmake/modules/FindHostTools.cmake @@ -66,7 +66,7 @@ find_program(BOSSAC bossac) find_program(IMGTOOL imgtool) # Pick host system's toolchain if we are targeting posix -if("${ARCH}" STREQUAL "posix") +if("${ARCH}" STREQUAL "posix" OR "${ARCH}" STREQUAL "unit_testing") if(NOT "${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "llvm") set(ZEPHYR_TOOLCHAIN_VARIANT "host") endif() diff --git a/cmake/modules/unittest.cmake b/cmake/modules/unittest.cmake index 7bb61b14ae1..5bc6765338d 100644 --- a/cmake/modules/unittest.cmake +++ b/cmake/modules/unittest.cmake @@ -2,14 +2,18 @@ cmake_minimum_required(VERSION 3.20.0) -enable_language(C CXX ASM) - include(root) include(boards) include(arch) include(configuration_files) include(kconfig) +find_package(TargetTools) + +enable_language(C CXX ASM) + +include(${ZEPHYR_BASE}/cmake/target_toolchain_flags.cmake) + # Parameters: # SOURCES: list of source files, default main.c # INCLUDE: list of additional include paths relative to ZEPHYR_BASE @@ -33,12 +37,13 @@ if((NOT DEFINED ZEPHYR_BASE) AND (DEFINED ENV_ZEPHYR_BASE)) set(ZEPHYR_BASE ${ENV_ZEPHYR_BASE} CACHE PATH "Zephyr base") endif() +find_package(Deprecated COMPONENTS SOURCES) + if(NOT SOURCES AND EXISTS main.c) set(SOURCES main.c) endif() add_executable(testbinary ${SOURCES}) -find_package(Deprecated COMPONENTS SOURCES) add_library(test_interface INTERFACE) target_link_libraries(testbinary PRIVATE test_interface) @@ -89,16 +94,9 @@ target_link_libraries(testbinary PRIVATE ) if(COVERAGE) - target_compile_options(test_interface INTERFACE - -fno-default-inline - -fno-inline - -fprofile-arcs - -ftest-coverage - ) + target_compile_options(test_interface INTERFACE $) - target_link_libraries(testbinary PRIVATE - -lgcov - ) + target_link_libraries(testbinary PRIVATE $) endif() if(LIBS) diff --git a/tests/unit/crc/CMakeLists.txt b/tests/unit/crc/CMakeLists.txt index cbbe675da6c..48726fcf170 100644 --- a/tests/unit/crc/CMakeLists.txt +++ b/tests/unit/crc/CMakeLists.txt @@ -2,6 +2,6 @@ cmake_minimum_required(VERSION 3.20.0) -project(crc) find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(crc) target_sources(testbinary PRIVATE main.c)