Setting CMP0025 is not taken into account soon enough
Some context first: I use the latest version of CMake on Mac OS, and I need for my project Clang features that are not present in AppleClang (libFuzzer). So, I have two new versions of Clang on my computer, one compiled from source, and the other from Homebrew.
Also, my project's CMake uses the target_compile_feature
command to get the correct compiler flags and propagate them across dependencies. Unfortunately, it appears that CMake cannot use this command on Mac OS with a non-Apple Clang. Indeed, when I run cmake
after having set CC
and CXX
to the newer compiler, CMake does not properly populate the CMakeFiles/*/CMakeCXXCompiler.cmake
file: the CMAKE_CXX*_COMPILE_FEATURES
variables remain empty.
I traced my cmake
call and went through CMake's code to try to understand the problem. It appears that, in the Modules/Compilers/Clang-CXX.cmake
file nothing is done on Mac OS if the CMP0025
policy is set to NEW
, cf. these lines (8-11) in the file:
cmake_policy(GET CMP0025 appleClangPolicy)
if(APPLE AND NOT appleClangPolicy STREQUAL NEW)
return()
endif()
I thought that setting CMP0025 to OLD
would solve the problem, but this is not the case as Modules/Compilers/Clang-CXX.cmake
's code is called before my project's CMakeLists.txt
(I verified that through tracing). Also, using -DCMAKE_POLICY_DEFAULT_CMP0025=OLD
is not a solution as, according to the documentation, it only silences the corresponding warning (also, I tried it, just in case, and it did not work).
In the end, it seems that, on Mac OS, no other Clang than AppleClang can be used correctly.
Unfortunately, I do not see a good way to solve this issue: setting CMP0025
to OLD
by default is obviously not a solution; having an additional cmake
flag would be good, but would require to manage the possible conflicts between the flag and CMP0025
; letting things how they are today is definitely an issue for people who want to play with different compilers.
Note that a similar problem with Clang-C.cmake
is very likely, although I did not try to reproduce the issue for this file.