COMPILE_DEFINITIONS¶
Preprocessor definitions for compiling a target's sources.
The COMPILE_DEFINITIONS property may be set to a semicolon-separated
list of preprocessor definitions using the syntax VAR or VAR=value.
Function-style definitions are not supported. CMake will
automatically escape the value correctly for the native build system
(note that CMake language syntax may require escapes to specify some
values).
CMake will automatically drop some definitions that are not supported by the native build tool.
在 3.26 版被加入: Any leading -D on an item will be removed.
免責聲明:大多數原生建置工具對跳脫某些值的支援很差。CMake 對許多情況有因應措施,但某些值可能無法正確傳遞。如果某個值似乎沒有被正確跳脫,請不要嘗試透過在值中新增跳脫序列來解決問題。您的因應措施可能會在未來版本中具有改進跳脫支援的 CMake 中失效。請考慮在(配置過的)標頭檔中定義巨集,然後回報此限制。已知的限制包括:
#幾乎在所有地方都無法運作。
;在 VS IDE 7.0 和 Borland Makefiles 中無法運作。
,在 VS IDE 中無法運作。
%在某些情況下的 NMake 中無法運作。
& |在某些情況下的 MinGW 中無法運作。
^ < > \ "在 Windows 上的大多數 Make 工具中無法運作。
CMake 不會直接拒絕這些值,因為它們在某些情況下確實有效。請謹慎使用。
Contents of COMPILE_DEFINITIONS may use "generator expressions" with the
syntax $<...>. See the cmake-generator-expressions(7) manual
for available expressions. See the cmake-buildsystem(7) manual
for more on defining buildsystem properties.
The corresponding COMPILE_DEFINITIONS_<CONFIG> property may
be set to specify per-configuration definitions. Generator expressions
should be preferred instead of setting the alternative property.