定义被target_compile_definitions忽略 [英] define gets ignored by target_compile_definitions
问题描述
我正在寻找一个库,我需要向该构建传递两个定义,但是cmake的 target_compile_definitions()对它们进行了打乱,使其无法使用.
I am looking to build a library and I need to pass two defines to that build, but cmake's target_compile_definitions() scrambles them in a manner that renders them unusable.
两个定义是:
-
-D'_LIB_EXCEPTION_ABI = __ attribute __((visibility("default")))'
-
-D'_LIB_FALLTHROUGH()=((void)0)'
不幸的是,第一个被翻译为(在命令构建行中):
Unfortunately, the first one gets translated to (in the command build line):
-
-D'_LIB_EXCEPTION_ABI ="\ __ attribute __((visibility(\" default \)))'"
第二个命令行完全丢失了.
While the second one is missing altogether from the command line.
推荐答案
CMake具有关于可能的编译定义的已知限制.
在这些限制中,有函数样式定义( _LIB_FALLTHROUGH()
)和包含双引号的定义("
).
Among these limitations are function-style definitions (_LIB_FALLTHROUGH()
) and ones containing double quotes ("
).
建议不要使用这些编译定义来创建单独的头文件,而不是尝试克服这些限制:
Instead of attempting to overcome these limitations, it is recommended to create a separate header file with these compile definitions:
#define _LIB_EXCEPTION_ABI __attribute__((visibility("default")))
#define _LIB_FALLTHROUGH() ((void)0)
此头文件可能包含在 -include
编译器选项(gcc)或/FI
选项(Visual Studio)中.
This header file could be included with -include
compiler option (gcc) or /FI
option (Visual Studio).
这篇关于定义被target_compile_definitions忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!