Compile same file with different flags using CMAKE

匆匆过客 提交于 2019-12-21 03:19:14

问题


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.

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.


回答1:


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")

Update:

Starting from CMake 2.8.11 you can also use target_compile_definitions for the same purpose.



来源:https://stackoverflow.com/questions/7843926/compile-same-file-with-different-flags-using-cmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!