define gets ignored by target_compile_definitions

跟風遠走 提交于 2021-02-11 13:51:03

问题


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.

The two defines are:

  • -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.


回答1:


CMake has known limitations on what compile definitions could be.

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)

This header file could be included with -include compiler option (gcc) or /FI option (Visual Studio).



来源:https://stackoverflow.com/questions/61632105/define-gets-ignored-by-target-compile-definitions

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