CMake 3.28, 3.29 Clang scandep workaround
CMake 3.28.0 .. 3.29.2 have a bug with Clang > 17 if CMAKE_CXX_STANDARD
is set to 20
or higher before project()
or enable_language(CXX)
.
Specifically, if
CMake policy CMP0155
is set to NEW
by cmake_minimum_required(VERSION)
or otherwise, then CMake 3.28.0 .. 3.29.2 will scan for C++ modules during initial C++ compiler checks, which is not expected or desired.
To trivially workaround this issue without otherwise impacting the project or newer CMake versions, do like:
set(CMAKE_CXX_STANDARD 20)
# assuming default settings near top of CMakeLists.txt for readability
# <snip>
if(${PROJECT_NAME}_cxx) # arbitrary user option
set(CMAKE_CXX_SCAN_FOR_MODULES OFF) # workaround CMake 3.28.0 .. 3.29.2 with Clang
enable_language(CXX)
set(CMAKE_CXX_SCAN_FOR_MODULES ON) # optional, if project actually uses C++ modules
endif()
Related: CMake C++ standard with fallback
This issue was fixed in CMake 3.29.3.