How to properly specify idiosyncratic ICC compiler options in CMake?

Viewed 128

The Intel C/C++ has a bunch of custom flags, some of which mix compilation and linking, (such as -qopenmp), and others are just idiosyncratic alternative forms (such as -ipp for linking with Intel's ipp libraries).

I can add such flags "manually" to the compiler flags, and ignore the fact they may have linking implications; or add them both to the compilation and linking flags. But both of these alternatives seem "off". How do I properly work with the various ICC-specific flags in CMake?

1 Answers

First looking at: https://cmake.org/cmake/help/latest/release/3.20.html#compilers

The Intel oneAPI NextGen LLVM compilers are now supported with compiler id IntelLLVM:
The icx/icpx C/C++ compilers on Linux, and the icx C/C++ compiler on Windows, are fully supported as of oneAPI 2021.1.
The ifx Fortran compiler on Linux is supported as of oneAPI 2021.1.
The ifx Fortran compiler on Windows is not yet supported.
The Intel oneAPI Classic compilers (icc, icpc, and ifort) continue to be supported with compiler id Intel.

So If i were you I would use the compiler id Intel to pass icc scpecific flags.
ref: 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()

ref:

Related