Hakaishin
Hakaishin

Reputation: 2932

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?

Upvotes: 24

Views: 42393

Answers (4)

videvelop
videvelop

Reputation: 11

Add the following in CMakeLists.txt to see the compiler cmake is using.

message (${CMAKE_C_COMPILER})
message (${CMAKE_CXX_COMPILER})
message (${CMAKE_CXX_COMPILER_AR})
message (${CMAKE_CXX_COMPILER_RANLIB})

This works in cmake version 3.27.20230928-g92adbb5.

Upvotes: 1

Bretwalda
Bretwalda

Reputation: 81

You can check which compiler is being used by CMake by looking at the

CMakeCache.txt

CMake generates a cache file (usually named CMakeCache.txt) in the build directory. This file stores various configuration settings, including the compiler being used. To check the compiler you can search for the term CMAKE_C_COMPILER or CMAKE_CXX_COMPILER it includes the path to the current compiler, you are configuring your project with.

Upvotes: 3

Sergio Losilla
Sergio Losilla

Reputation: 850

I am not quite sure if I understood your question precisely, but if you just want to know which compiler is being used, enable a verbose build with the CMAKE_VERBOSE_MAKEFILE option:

cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON

and then run make as usual. This will show which commands are used for building your code.

Upvotes: 6

Florian
Florian

Reputation: 42842

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.

Upvotes: 27

Related Questions