如何在 CMake 中正确指定特殊的 ICC 编译器选项?

ein*_*ica 5 idioms intel cmake icc buildconfiguration

英特尔 C/C++ 有一堆自定义标志,其中一些混合了编译和链接(例如-qopenmp),而另一些只是特殊的替代形式(例如-ipp用于与英特尔的 ipp 库链接)。

我可以“手动”将此类标志添加到编译器标志中,并忽略它们可能具有链接含义的事实;或者将它们添加到编译和链接标志中。但这两种选择似乎都“不可行”。如何在 CMake 中正确使用各种 ICC 特定标志?

Miz*_*zux 0

首先查看:https ://cmake.org/cmake/help/latest/release/3.20.html#compilers

编译器 id 现在支持英特尔 oneAPI NextGen LLVM 编译器IntelLLVM:自 oneAPI 2021.1 起,完全支持 Linux 上的 /C/C++ 编译器和 Windows 上的 icx C/C++ 编译
icx。自 oneAPI 2021.1 起支持 Linux 上的 Fortran 编译器 。尚不支持 Windows 上的 Fortran 编译器 。编译器 ID 继续支持 英特尔 oneAPI 经典编译器(、、和) 。icpx
ifx
ifx
iccicpcifortIntel

所以如果我是你,我会使用编译器 idIntel来传递 icc scpecific 标志。
参考:https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html

if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
  add_compile_definitions(...) # CMake 3.12
  add_compile_options(...)
  add_link_options(...) # CMake 3.13
endif()
Run Code Online (Sandbox Code Playgroud)

参考: