On a CI machine I have cmake echoing back some basic compiler variables at the start. After updating clang from 12 to 13, I am seeing both versions here:
-- CMAKE_C_COMPILER: /usr/local/bin/clang
-- CMAKE_C_COMPILER_ID: Clang
-- CMAKE_C_COMPILER_VERSION: 12.0.0
clang version 13.0.0 (/tmp/llvm-project/clang d7b669b3a30345cfcdb2fde2af6f48aa4b94845d)
-- CMAKE_CXX_COMPILER: /usr/local/bin/clang
-- CMAKE_CXX_COMPILER_ID: Clang
-- CMAKE_CXX_COMPILER_VERSION: 12.0.0
clang version 13.0.0 (/tmp/llvm-project/clang d7b669b3a30345cfcdb2fde2af6f48aa4b94845d)
Note that "13.0.0" comes from actually running clang --version
via these cmake functions:
message(STATUS "CMAKE_C_COMPILER: " ${CMAKE_C_COMPILER} )
message(STATUS "CMAKE_C_COMPILER_ID: ${CMAKE_C_COMPILER_ID}")
message(STATUS "CMAKE_C_COMPILER_VERSION: ${CMAKE_C_COMPILER_VERSION}")
execute_process(COMMAND ${CMAKE_C_COMPILER} ${COMPILER_VERSION_ARG} )
Additional info that might be relevant:
-- CMake version: 3.18.1-g262b901
-- Using ccache.
-- Using sanitizer: address
The issue becomes relevant because some later build steps fail as they are checking the compiler version and thus making the wrong decisions. Is there some local caching that could result in such weird behavior? To my understanding this should not be dependent on caching though?
Update: I tossed the CMAKE_C_COMPILER_VERSION check and used check_c_compiler_flag instead, see my answer below.
CodePudding user response:
CMake found /usr/local/bin/clang
, not /tmp/llvm-project/clang
. You might want to explicitly set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER to ensure that CMake finds the Clang you intend it should be used.
CodePudding user response:
Clang 13 introduced two new checks that broke some external libs. Instead of checking the clang version doing a feature check is better anyway:
# clang 13 introduced stricter checks, for now, disable the warning:
include(CheckCCompilerFlag)
check_c_compiler_flag(-Wno-unused-but-set-variable HAS_UNUSED_BUT_SET_VARIABLE)
if (HAS_UNUSED_BUT_SET_VARIABLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-but-set-variable")
endif()
The same can be applied to -Wno-unused-but-set-parameter
, of course. Also use CheckCxxCompilerFlag
/check_cxx_compiler_flag
instead for C .