Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Intel ICC 18 detection/support to CMakeLists.txt #1841

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
message(FATAL_ERROR "g++ version must be at least 5.1!")
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
include_directories(BEFORE "/opt/intel/include")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not hard code any path's. It could be that the compiler is installed somewhere else even if this path is the default path.

add_definitions(-D__PURE_INTEL_C99_HEADERS__)
link_directories(BEFORE "/opt/intel/lib")
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 17) AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19))
# locate best gcc version to pass to icc-18 (gcc-8 doesn't work, for example)
# Use -DICC_GCCVER=6 for example to force 'gcc-6' and 'g++-6'
# Otherwise, the newest available and compatible pair will be selected
find_program(ICC_GXX NAMES "g++-${ICC_GCCVER}" "g++-7" "g++-6" "g++")
get_filename_component(ICC_GXX ${ICC_GXX} NAME)
find_program(ICC_GCC NAMES "gcc-${ICC_GCCVER}" "gcc-7" "gcc-6" "gcc")
get_filename_component(ICC_GCC ${ICC_GCC} NAME)
set(ICC_COMPILERS "-gxx-name=${ICC_GXX} -gcc-name=${ICC_GCC}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the correct way, because if I install icc I select already an gcc version. This looks like a workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What, where? I run the installer, remove everything but the C++, it never asks it only seeks whatever /usr/bin/gcc points to... system default

I also use this to generate test binaries made with every permutation of ICC+GCC regardless what was configured or what the system defaults are. So yes, it is a workaround, for having to use the ICC environment at all (I don't use their shell scripts or whatever). I also don't have ICC in the system path.

unset(ICC_GXX)
unset(ICC_GCC)
endif()
message(STATUS "Intel ICC-18 subcompiler flags: ${ICC_COMPILERS}")
set(CMAKE_CXX_FLAGS "-O3 -no-prec-div -fp-model fast=2 -std=gnu++11 ${ICC_COMPILERS}")
set(CMAKE_C_FLAGS "-O3 -no-prec-div -fp-model fast=2 -std=gnu99 ${ICC_COMPILERS}")
endif()

set(BUILD_TYPE "Release;Debug")
Expand All @@ -39,7 +58,11 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${BUILD_TYPE}")
set(XMR-STAK_COMPILE "native" CACHE STRING "select CPU compute architecture")
set_property(CACHE XMR-STAK_COMPILE PROPERTY STRINGS "native;generic")
if(XMR-STAK_COMPILE STREQUAL "native")
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
# activate Intel Compiler options: optimize for current host CPU
set(CMAKE_CXX_FLAGS "-xHOST ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-xHOST ${CMAKE_C_FLAGS}")
elseif(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_CXX_FLAGS "-march=native -mtune=native ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-march=native -mtune=native ${CMAKE_C_FLAGS}")
endif()
Expand Down Expand Up @@ -429,7 +452,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
# disable min define to allow usage of std::min
add_definitions(-DNOMINMAX)
else()
elseif(NOT CMAKE_CXX_COMPILER_ID MATCHES "Intel")
# activate sse2 and aes-ni
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -maes")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -maes")
Expand All @@ -450,6 +473,8 @@ if(CMAKE_LINK_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
set(LIBS "-static-libgcc -static-libstdc++ ${LIBS}")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set(LIBS "-static-libgcc -static-libstdc++ -static-intel ${LIBS}")
endif()
endif()

Expand Down