c++ - 如何指示 CMake 不要合并编译器参数?

标签 c++ cmake

我的 CMakeLists.txt 中有以下说明:

target_compile_options(sometarget PRIVATE
    $<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:-mllvm --inline-threshold=8192>
    $<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:-mllvm -polly>
)

cmake 主动将这些命令行选项转换为

-mllvm --inline-threshold=8192 -polly

在将其传递给编译器之前(通过 make 文件)。当然,编译器会提示它不知道 -polly

如何限制 CMake 的聪明才智并强制它按照我的意思传递给编译器:

-mllvm --inline-threshold=8192 -mllvm -polly

最佳答案

来自cmake add_compile_options :

The final set of compile or link options used for a target is constructed by accumulating options from the current target and the usage requirements of its dependencies. The set of options is de-duplicated to avoid repetition. While beneficial for individual options, the de-duplication step can break up option groups. For example, -D A -D B becomes -D A B. One may specify a group of options using shell-like quoting along with a SHELL: prefix. The SHELL: prefix is dropped, and the rest of the option string is parsed using the separate_arguments() UNIX_COMMAND mode. For example, "SHELL:-D A" "SHELL:-D B" becomes -D A -D B.

尝试:

"SHELL:$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:-mllvm --inline-threshold=8192>"
"SHELL:$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:-mllvm -polly>"

关于c++ - 如何指示 CMake 不要合并编译器参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63889460/

相关文章:

cmake - 如何从命令行设置列表类型的 CMake 变量

android - 如何传递特定参数(例如 : opencv_dir) to CMake through gradle externaNativeTool?

CMake 从 Autoconf 生成 config.h

opencv - 将 OpenCV 构建为 deb 包 : CPackDeb: file utility is not available

c++ - 战舰游戏 - 跟踪船只

c++ - 询问基本的 C++ 语法细节;使用 & 内部初始化与外部初始化

c++ - 无法访问模板基类中的变量

ubuntu - 交叉编译ROS Melodic on RaspberryPi 3B+问题

c++ - 为什么不能推导嵌套在模板类中的枚举的模板参数?

c++ - 如何在 C++ 中启用 Unicode?