Skip to content

Commit 774330f

Browse files
marc-hbstephanosio
authored andcommitted
cmake: provide a useful error msg when native compiler is missing
This avoids a cryptic DTC failure when compiling trying to compile native_posix with a missing gcc or clang. REQUIRED is available since CMake 3.18 Example with clang, cryptic error without this commit: ``` ZEPHYR_TOOLCHAIN_VARIANT=llvm west build \ -p -b native_posix samples/hello_world/ -- Found toolchain: host (clang/ld) <= this is wrong -- Found Dtc: /usr/bin/dtc (found suitable version "1.6.1", minimum ... -- Found BOARD.dts: zephyr/boards/posix/native_posix/native_posix.dts CMake Error at /zephyr/cmake/modules/dts.cmake:191 (message): command failed with return code: No such file or directory Call Stack (most recent call first): zephyr/cmake/modules/zephyr_default.cmake:113 (include) zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include) zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boil... CMakeLists.txt:5 (find_package) ``` Well hidden behind the scenes, dts.cmake fails above because it invokes `CMAKE_C_COMPILER-NOTFOUND` With this commit: ``` ZEPHYR_TOOLCHAIN_VARIANT=llvm west build \ -p -b native_posix samples/hello_world/ -- Found toolchain: host (clang/ld) <= this is still wrong CMake Error at zephyr/cmake/compiler/clang/generic.cmake:7 (find_program): Could not find CMAKE_C_COMPILER using the following names: clang ``` Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent 654fae9 commit 774330f

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

cmake/compiler/clang/generic.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if(DEFINED TOOLCHAIN_HOME)
44
set(find_program_clang_args PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
55
endif()
66

7-
find_program(CMAKE_C_COMPILER clang ${find_program_clang_args})
7+
find_program(CMAKE_C_COMPILER clang ${find_program_clang_args} REQUIRED)
88
find_program(CMAKE_CXX_COMPILER clang++ ${find_program_clang_args})
99
find_program(CMAKE_LLVM_COV llvm-cov ${find_program_clang_args})
1010
set(CMAKE_GCOV "${CMAKE_LLVM_COV} gcov")

cmake/compiler/host-gcc/generic.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
# Configures CMake for using GCC
44

5-
find_program(CMAKE_C_COMPILER gcc)
5+
find_program(CMAKE_C_COMPILER gcc REQUIRED)
66
find_program(CMAKE_GCOV gcov)

0 commit comments

Comments
 (0)