We're using -nodefaultlibs to avoid the dependency on C++ library when using check_cxx_compiler_flag, and as such we cannot use check_cxx_compiler_flag to check the availability of -nodefaultlibs itself, because check_cxx_compile_flags adds the flag to COMPILE_DEFINITIONS when calling try_compile and this variable is only considered for compilation but not for linking where -nodefaultlibs actually makes a difference.
Diff Detail
- Repository
- rL LLVM
Event Timeline
Why not? The executable should still link and run without requiring the C++ standard library, just as it links and runs without requiring the C standard library.
The problem is that check_cxx_compile_flags adds the flag to COMPILE_DEFINITIONSwhen calling try_compile and that variable is only considered for compilation but not for linking where -nodefaultlibs actually makes a difference (I should probably add this into the description).
Is there any CMake documentation which documents this particular behavior?
Otherwise LGTM.
https://cmake.org/cmake/help/latest/module/CheckCXXCompilerFlag.html says that "This internally calls the check_cxx_source_compiles macro and sets CMAKE_REQUIRED_DEFINITIONS to <flag>" and https://github.com/Kitware/CMake/blob/master/Modules/CheckCXXSourceCompiles.cmake#L67 shows that this is being passed to try_compile as COMPILE_DEFINITIONS, this is the best I could find.