GetCompilerInfos.cmake 4.92 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
###########################################################################
# Inastemp - Berenger Bramas MPCDF - 2016
# Under MIT Licence, please you must read the LICENCE file.
###########################################################################
# Doc for intel :
# https://software.intel.com/en-us/articles/performance-tools-for-software-developers-intel-compiler-options-for-sse-generation-and-processor-specific-optimizations
# 
# Doc for gcc :
# https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
###########################################################################
macro (GetCompilerInfosCore TYPE)    
string(TOUPPER ${TYPE} UTYPE)

# The original CPP file
set(checkTypeFile "${PROJECT_SOURCE_DIR}/CMakeModules/${UTYPE}/compileTest${UTYPE}.cpp")

# Fatal error if the file does not exist
if(NOT EXISTS ${checkTypeFile})
	message(FATAL_ERROR "The GetCompilerInfosFile does not exist (${checkTypeFile})")
endif()


try_compile(COMPILE_RESULT  ${CMAKE_CURRENT_BINARY_DIR}
      ${checkTypeFile}
      COMPILE_DEFINITIONS "-Wno-error ${${UTYPE}_FLAGS}"
      OUTPUT_VARIABLE COMPILE_OUTPUT)

if(${COMPILE_RESULT})
    set(COMPILER_INFO_${UTYPE} ON)

    if($ENV{VERBOSE})
        message(STATUS "GetCompilerInfos -- The compiler can compile ${TYPE}")
    endif()
else()
    set(COMPILER_INFO_${UTYPE} OFF)

    if($ENV{VERBOSE})
        message(STATUS "GetCompilerInfos -- The compiler cannot compile ${TYPE} : ${COMPILE_OUTPUT}")
    endif()
endif()

endmacro(GetCompilerInfosCore)
###########################################################################################
###########################################################################################
macro(GetCompilerInfos)

SET( ARCH_NATIVE_FLAG "-march=native" CACHE STRING "Additional flag for the compiler capacities detection"  )

# (ADD-NEW-HERE for each compilers)

if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
    if(APPLE) # INTEL APPLE
        set(SSE3_FLAGS  "-msse3 ${ARCH_NATIVE_FLAG}")
        set(SSSE3_FLAGS  "-mssse3 ${ARCH_NATIVE_FLAG}")
        set(SSE41_FLAGS  "-msse4 -msse4.1 ${ARCH_NATIVE_FLAG}")
        set(SSE42_FLAGS  "-msse4 -msse4.2 ${ARCH_NATIVE_FLAG}")
        set(AVX_FLAGS  "-mAVX ${ARCH_NATIVE_FLAG}")
        set(AVX2_FLAGS "-march=core-avx2 ${ARCH_NATIVE_FLAG}")
59
        set(AVX512COMMON_FLAGS "-xCOMMON-AVX512 ${ARCH_NATIVE_FLAG}")
60
        set(AVX512KNL_FLAGS "-xCOMMON-AVX512 -xMIC-AVX512 ${ARCH_NATIVE_FLAG}")
61
        set(AVX512SKL_FLAGS "-xCOMMON-AVX512 -xCORE-AVX512 ${ARCH_NATIVE_FLAG}")
62 63 64 65 66
    else() # INTEL LINUX
        set(SSE3_FLAGS  "-msse3 ${ARCH_NATIVE_FLAG}")
        set(SSSE3_FLAGS "-mssse3 ${ARCH_NATIVE_FLAG}")
        set(SSE41_FLAGS  "-msse4 -msse4.1 ${ARCH_NATIVE_FLAG}")
        set(SSE42_FLAGS  "-msse4 -msse4.2 ${ARCH_NATIVE_FLAG}")
67
        set(AVX_FLAGS  "-march=core-avx-i ${ARCH_NATIVE_FLAG}")
68
        set(AVX2_FLAGS "-march=core-avx2 ${ARCH_NATIVE_FLAG}")
69
        set(AVX512COMMON_FLAGS "-xCOMMON-AVX512 ${ARCH_NATIVE_FLAG}")
70
        set(AVX512KNL_FLAGS "-xCOMMON-AVX512 -xMIC-AVX512 ${ARCH_NATIVE_FLAG}")
71
        set(AVX512SKL_FLAGS "-xCOMMON-AVX512 -xCORE-AVX512 ${ARCH_NATIVE_FLAG}")
72 73 74 75 76 77 78 79 80
    endif()
else()
    if(APPLE) # GCC APPLE
        set(SSE3_FLAGS  "-msse3 ${ARCH_NATIVE_FLAG}")
        set(SSSE3_FLAGS  "-mssse3 ${ARCH_NATIVE_FLAG}")
        set(SSE41_FLAGS  "-msse4 -msse4.1 ${ARCH_NATIVE_FLAG}")
        set(SSE42_FLAGS  "-msse4 -msse4.2 ${ARCH_NATIVE_FLAG}")
        set(AVX_FLAGS  "-mavx ${ARCH_NATIVE_FLAG}")
        set(AVX2_FLAGS "-mavx2 ${ARCH_NATIVE_FLAG}")
81
        set(AVX512COMMON_FLAGS "-mavx512f -mavx512er -mavx512cd ${ARCH_NATIVE_FLAG}")
82
        set(AVX512KNL_FLAGS "-mavx512f -mavx512pf -mavx512er -mavx512cd ${ARCH_NATIVE_FLAG}")
83
        set(AVX512SKL_FLAGS "-mavx512f -mavx512er -mavx512cd -mavx512vl -mavx512bw -mavx512dq ${ARCH_NATIVE_FLAG}")
84 85 86 87 88 89 90
    else() # GCC LINUX
        set(SSE3_FLAGS  "-msse3 ${ARCH_NATIVE_FLAG}")
        set(SSSE3_FLAGS  "-mssse3 ${ARCH_NATIVE_FLAG}")
        set(SSE41_FLAGS  "-msse4 -msse4.1 ${ARCH_NATIVE_FLAG}")
        set(SSE42_FLAGS  "-msse4 -msse4.2 ${ARCH_NATIVE_FLAG}")
        set(AVX_FLAGS  "-mavx ${ARCH_NATIVE_FLAG}")
        set(AVX2_FLAGS "-mavx2 ${ARCH_NATIVE_FLAG}")
91
        set(AVX512COMMON_FLAGS "-mavx512f -mavx512er -mavx512cd ${ARCH_NATIVE_FLAG}")
92
        set(AVX512KNL_FLAGS "-mavx512f -mavx512pf -mavx512er -mavx512cd ${ARCH_NATIVE_FLAG}")
93
        set(AVX512SKL_FLAGS "-mavx512f -mavx512er -mavx512cd -mavx512vl -mavx512bw -mavx512dq ${ARCH_NATIVE_FLAG}")
94 95 96 97
    endif(APPLE)
endif()

# (ADD-NEW-HERE)
98
set(ALL_TYPES "SSE3;SSSE3;SSE41;SSE42;AVX;AVX2;AVX512COMMON;AVX512KNL;AVX512SKL")
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

if($ENV{VERBOSE})
    foreach(TYPE ${ALL_TYPES})
        message(STATUS "GetCompilerInfos -- ${TYPE}_FLAGS = ${${TYPE}_FLAGS}")
    endforeach()
endif()

foreach(TYPE ${ALL_TYPES})
    GetCompilerInfosCore(${TYPE})
endforeach()

if($ENV{VERBOSE})    
    foreach(TYPE ${ALL_TYPES})
        message(STATUS "GetCompilerInfos -- COMPILER_INFO_${TYPE} = ${COMPILER_INFO_${TYPE}}")
    endforeach()
endif()

endmacro(GetCompilerInfos)