Feature request: make CMAKE_CXX_SIMULATE_ID available in genex
When adding a compiler flag to a target, it is common to guard it by a genex check on the compiler ID. For instance, from the documentation:
add_executable(myapp main.cpp foo.c bar.cpp zot.cu) target_compile_definitions(myapp PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:COMPILING_CXX_WITH_CLANG> $<$<COMPILE_LANG_AND_ID:CXX,Intel>:COMPILING_CXX_WITH_INTEL> $<$<COMPILE_LANG_AND_ID:C,Clang>:COMPILING_C_WITH_CLANG> )
However, if we were to add the following to this list:
Then ClangCL would see
COMPILING_CXX_WITH_CLANG, which is probably not what is expected. If that definition is guarding MSVC-specific pragmas, it might fail to build. Also, behaving as though the compiler is vanilla Clang might cause a build to add a flag that ClangCL rejects.
Unfortunately, the mitigations CMake currently has are insufficient. For instance, there is no way to export this logic:
if (MSVC) # covers both MSVC and ClangCL target_compile_definitions(my_interface INTERFACE COMPILING_WITH_MSVC) endif ()
because that if statement exists only at configure time. Similarly, any conditional check on
CMAKE_CXX_SIMULATE_ID will be forgotten.
A genex is needed to query the interface provided by the current compiler.