Get build command or all compiler flags that will

2020-06-08 13:58发布

问题:

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()?

回答1:

Build flags are, actually, associated with source files, because you can have differrent flags for different files. On the other hand, for the most cases these flags are equivalent.

Anyways, to get all build flags for a source file you can use COMPILE_FLAGS property:

get_source_file_property(RESULT file.cpp COMPILE_FLAGS)


标签: cmake