我可以在工具链文件中调用add_compile_definitions吗?
Cmake提供了诸如cmake_< lang> _flags_init
之类的变量,以允许您在工具链文件中设置编译器标志,但我不知道设置预处理程序定义的等效性。实际上,Cmake似乎并没有真正区分编译器标志的预处理器标志。
在工具链文件中设置预处理器宏定义的“正确”或“支持”的方法是什么?调用add_compile_definitions()
是否可以接受,我应该将它们包含在cmake_c_flags_init
中,还是违反某些CMAKE哲学以使其甚至在工具链文件中设置它们?
CMake provides variables such as CMAKE_<LANG>_FLAGS_INIT
to allow you to set compiler flags in a toolchain file, but I don't know of an equivalent for setting preprocessor definitions. In fact, CMake doesn't really seem to distinguish between preprocessor flags an compiler flags.
What is the "correct", or "supported" way to set preprocessor macro definitions in a toolchain file? Is it acceptable to call add_compile_definitions()
, should I include them in CMAKE_C_FLAGS_INIT
, or does it go against some CMake philosophy to even set them in the toolchain file at all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,它等效于
string(Append cmake_c_flags
。最好从工具链文件设置
*_ INIT
变量,还将其中的任何定义放在其中。在文档中https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS_INIT. html :
在实践中由工具链文件设置,使用:
cmake的示例:
请参阅上面的
bruce-c.cmake
上面的示例。Sure, it's equivalent to
string(APPEND CMAKE_C_FLAGS
.It's best to set
*_INIT
variables from toolchain file, and also put there any definitions that you want. It's in the dochttps://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS_INIT.html :
In practice, use:
Examples from cmake:
See the
Bruce-C.cmake
example above.工具链文件通常设置环境和特定目标所需的标志。因此,添加此类目标所需的编译定义是可以接受的。
The toolchain files usually set up the environment and the flags needed for a specific target. So it is acceptable to add compile definitions required for such targets.