Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get build command or all compiler flags that will be used to build a target

Tags:

cmake

Is there a sensible way to get a CMake variable containing the build command or all the compiler flags that CMake will associate with a target?

It doesn't seem practical to try to gather and maintain a list of all properties that could add flags. Besides, CMake must have this info somewhere, since it has to eventually generate a build system.

From the CMake docs it looks like this feature once existed and was provided by calling build_command() but this was replaced:

Note In CMake versions prior to 3.0 this command returned a command line that directly invokes the native build tool for the current generator.

Is there a new command that gives the old behavior of build_command()?

like image 283
Praxeolitic Avatar asked Dec 10 '25 00:12

Praxeolitic


1 Answers

If you want the final output of how the source files will actually be compiled you will want to look at the generated files. I don't really know a better way currently:

Example:

Here is an example output from Ninja Multi

build\CMakeFiles\impl-Release.ninja

This file will list all of the compile definitions, compiler flags, include directories, object directory, etc.