使用CMAKE编译具有不同标志的相同文件 [英] Compile same file with different flags using CMAKE
问题描述
我想编译同样的.cpp源文件到两个不同的目标可执行文件,我使用cmake。一个有一些仪器代码,另一个不会。这样我可以比较仪器的开销。
I want to compile the same .cpp source file into two different target executables and I am using cmake. One will have some instrumentation code and the other won't. That way I can compare the overhead of instrumentation.
我有仪器代码用#ifdefs分隔,所以我想使用-D标志定义一个值。我看到这是可能的
I have the instrumentation code separated with #ifdefs so I want to define a value using the -D flag. I see that is possible with
add_definitions(-DINSTRUMENT)
但是它看起来像这样适用于在该目录中创建的所有可执行文件。
But it looks like this then applies to all the executables created in that directory. I'm wondering if there is a good way to set the definition only for a specific executable target.
推荐答案
您可以设置一个特定的可执行目标。目标之一的 COMPILE_DEFINITIONS 属性具有目标 - 具体定义:
You can set the COMPILE_DEFINITIONS property of one of the targets to have target-specific definitions:
set_target_properties (instrumented_target PROPERTIES COMPILE_DEFINITIONS "INSTRUMENT")
更新:
从CMake 2.8.11开始, a href =http://www.cmake.org/cmake/help/v3.0/command/target_compile_definitions.html =nofollow> target_compile_definitions
为同一目的。
Starting from CMake 2.8.11 you can also use target_compile_definitions
for the same purpose.
这篇关于使用CMAKE编译具有不同标志的相同文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!