获取构建命令或将用于构建目标的所有编译器标志 [英] Get build command or all compiler flags that will be used to build a target

查看:65
本文介绍了获取构建命令或将用于构建目标的所有编译器标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种明智的方法来获取包含构建命令或CMake与目标相关联的所有编译器标志的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?

尝试收集和维护可能添加标志的所有属性的列表。此外,CMake必须在某处具有此信息,因为它必须最终生成构建系统。

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.

来自 CMake文档,它似乎曾经存在并且通过调用 build_command(),但已将其替换:

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


注意在3.0之前的CMake版本中,此命令返回了直接调用的命令

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.

是否有一个新命令给出了<$ c的旧行为? $ c> build_command()

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

推荐答案

Build标志实际上与源文件相关联,因为您可以为不同的文件使用不同的标志。另一方面,在大多数情况下,这些标志是等效的。

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.

无论如何,要获取源文件的所有构建标志,可以使用 COMPILE_FLAGS 属性:

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)

这篇关于获取构建命令或将用于构建目标的所有编译器标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆