Search code examples
c++cmake

How to check what compiler cmake is using?


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?


Solution

  • 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.