I'm surprised I couldn't find this googling. I only found this, but I want to known how to find what compiler is cmake using in general? I also found this but I assume there is some variable in cmake that just holds the compiler name, right?
You can see what variables are available in your CMake's binary output directory CMakeFiles/[your CMake's version]/CMakeCXXCompiler.cmake
.
If you just want to print it, your are looking for CMAKE_CXX_COMPILER_ID
and CMAKE_CXX_COMPILER_VERSION
. Those are available cross-platform.
Here are two examples of what CMake detects and generates from my projects:
set(CMAKE_CXX_COMPILER_ID "GNU")
set(CMAKE_CXX_COMPILER_VERSION "4.6.3")
Or
set(CMAKE_CXX_COMPILER_ID "MSVC")
set(CMAKE_CXX_COMPILER_VERSION "19.0.24215.1")
Other kind of variables are there to check for platforms/toolchains like CMAKE_COMPILER_IS_GNUCXX
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With