且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以强制cmake将头文件包含在特定目标中吗?

更新时间:2023-09-19 23:20:04

CMake具有基于属性的机制。您可以分配给目标,源文件和其他部分的属性。使用目标是通常的默认操作,因此提供了一系列的 target _ * 命令来设置目标的属性。如果要为特定目标中的所有源添加编译选项,请使用 target_compile_options 。请勿使用 COMPILE_DEFINITIONS 属性,用于定义除预处理程序符号以外的其他选项。这样您就可以使用

CMake has a properties-based mechanism. You can assign to properties on targets, source files, and other parts. Working with targets is the usual and default action, so a whole family of target_* commands are provided for setting properties on targets. If you want to add a compile option for all sources in a specific target then use target_compile_options. Do not use the COMPILE_DEFINITIONS property for other options than defining pre-processor symbols. So you be able to get what you want with

target_compile_options(<my-test-target> "-include ../include/failing-malloc-test.h")