CMake and Meson compiler option family
On Windows, compiler option syntax is generally MSVC-like or GCC-like. On Windows, the compiler option families are:
- MSVC-like: Intel oneAPI (IntelLLVM), Clang-CL, Visual Studio
- GCC-like: GCC, Clang, non-Windows OS.
Meson and CMake can each detect compiler option family. In general, the “else” branch would have further nested “if” to handle compiler options with distinct syntax.
CMake uses the MSVC variable to detect compiler option family. More specific compiler option selection is often handled with an if-else tree for each compiler ID and / or check_compiler_flag().
project(Hello LANGUAGES C)
if(MSVC)
message(STATUS "${CMAKE_C_COMPILER_ID} is MSVC-like")
else()
message(STATUS "${CMAKE_C_COMPILER_ID} is GCC-like")
endif()
Meson uses the .get_argument_syntax() property to detect compiler option family. Getting more specific compiler options can be done with an if-else tree for each compiler ID and / or the .has_argument() method.
project('hello', 'c')
cc = meson.get_compiler('c')
if cc.get_argument_syntax() == 'msvc'
message(cc.get_id() + ' is MSVC-like')
else
message(cc.get_id() + ' is GCC-like')
endif