diff options
author | William R. Dieter <william.r.dieter@intel.com> | 2022-05-27 21:29:18 (GMT) |
---|---|---|
committer | William R. Dieter <william.r.dieter@intel.com> | 2022-08-01 23:34:49 (GMT) |
commit | 6823db0c5ae8c22e1b9655860a7b614ae8a96f12 (patch) | |
tree | 4704bd05fef5a2fd76bdd612dd171d7e7998dbf0 /Modules | |
parent | adbffd204dc48566be9287a30a8e1d99878e5d23 (diff) | |
download | CMake-6823db0c5ae8c22e1b9655860a7b614ae8a96f12.zip CMake-6823db0c5ae8c22e1b9655860a7b614ae8a96f12.tar.gz CMake-6823db0c5ae8c22e1b9655860a7b614ae8a96f12.tar.bz2 |
Enable IPO for IntelLLVM compilers on Linux and Windows
Replicate and adapt Linux IPO options for Intel for IntelLLVM compilers
on Linux and Windows.
Signed-off-by: William R. Dieter <william.r.dieter@intel.com>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/Compiler/IntelLLVM-FindBinUtils.cmake | 45 | ||||
-rw-r--r-- | Modules/Compiler/IntelLLVM.cmake | 21 | ||||
-rw-r--r-- | Modules/Platform/Linux-IntelLLVM.cmake | 26 |
3 files changed, 60 insertions, 32 deletions
diff --git a/Modules/Compiler/IntelLLVM-FindBinUtils.cmake b/Modules/Compiler/IntelLLVM-FindBinUtils.cmake new file mode 100644 index 0000000..c5b1ee6 --- /dev/null +++ b/Modules/Compiler/IntelLLVM-FindBinUtils.cmake @@ -0,0 +1,45 @@ +if(NOT DEFINED _CMAKE_PROCESSING_LANGUAGE OR _CMAKE_PROCESSING_LANGUAGE STREQUAL "") + message(FATAL_ERROR "Internal error: _CMAKE_PROCESSING_LANGUAGE is not set") +endif() + +# Ubuntu: +# * /usr/bin/llvm-ar-9 +# * /usr/bin/llvm-ranlib-9 +string(REGEX MATCH "^([0-9]+)" __version_x + "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_VERSION}") + +# Debian: +# * /usr/bin/llvm-ar-4.0 +# * /usr/bin/llvm-ranlib-4.0 +string(REGEX MATCH "^([0-9]+\\.[0-9]+)" __version_x_y + "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_VERSION}") + +# Try to find tools in the IntelLLVM Clang tools directory +get_filename_component(__intel_llvm_hint_1 "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER}" DIRECTORY) +get_filename_component(__intel_llvm_hint_1 "${__intel_llvm_hint_1}/../bin-llvm" REALPATH) + +get_filename_component(__intel_llvm_hint_2 "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER}" DIRECTORY) + +set(__intel_llvm_hints ${__intel_llvm_hint_1} ${__intel_llvm_hint_2}) + +# http://manpages.ubuntu.com/manpages/precise/en/man1/llvm-ar.1.html +find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR NAMES + "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ar-${__version_x_y}" + "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ar-${__version_x}" + "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ar" + HINTS ${__intel_llvm_hints} + NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH + DOC "LLVM archiver" +) +mark_as_advanced(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR) + +# http://manpages.ubuntu.com/manpages/precise/en/man1/llvm-ranlib.1.html +find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_RANLIB NAMES + "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ranlib-${__version_x_y}" + "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ranlib-${__version_x}" + "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ranlib" + HINTS ${__intel_llvm_hints} + NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH + DOC "Generate index for LLVM archive" +) +mark_as_advanced(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_RANLIB) diff --git a/Modules/Compiler/IntelLLVM.cmake b/Modules/Compiler/IntelLLVM.cmake index c344f32..3f22efd 100644 --- a/Modules/Compiler/IntelLLVM.cmake +++ b/Modules/Compiler/IntelLLVM.cmake @@ -15,6 +15,15 @@ set(__pch_header_CXX "c++-header") set(__pch_header_OBJC "objective-c-header") set(__pch_header_OBJCXX "objective-c++-header") +# Variables that are common across front-end variants +macro(__compiler_intel_llvm_common lang) + set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES) + set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES) + set(CMAKE_${lang}_ARCHIVE_CREATE_IPO "\"${CMAKE_${lang}_COMPILER_AR}\" cr <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_${lang}_ARCHIVE_APPEND_IPO "\"${CMAKE_${lang}_COMPILER_AR}\" r <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_${lang}_ARCHIVE_FINISH_IPO "\"${CMAKE_${lang}_COMPILER_RANLIB}\" <TARGET>") +endmacro() + if(CMAKE_HOST_WIN32) # MSVC-like macro(__compiler_intel_llvm lang) @@ -22,6 +31,9 @@ if(CMAKE_HOST_WIN32) set(CMAKE_${lang}_COMPILE_OPTIONS_INVALID_PCH -Winvalid-pch) set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-WX") endif() + __compiler_intel_llvm_common(${lang}) + set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-Qipo") + set(CMAKE_${lang}_LINK_OPTIONS_IPO "-Qipo") endmacro() else() # GNU-like @@ -60,12 +72,9 @@ else() set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Xlinker" " ") set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP) - set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES) - set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES) - set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-flto=thin") - set(CMAKE_${lang}_ARCHIVE_CREATE_IPO "\"${CMAKE_${lang}_COMPILER_AR}\" cr <TARGET> <LINK_FLAGS> <OBJECTS>") - set(CMAKE_${lang}_ARCHIVE_APPEND_IPO "\"${CMAKE_${lang}_COMPILER_AR}\" r <TARGET> <LINK_FLAGS> <OBJECTS>") - set(CMAKE_${lang}_ARCHIVE_FINISH_IPO "\"${CMAKE_${lang}_COMPILER_RANLIB}\" <TARGET>") + __compiler_intel_llvm_common(${lang}) + set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-ipo") + set(CMAKE_${lang}_LINK_OPTIONS_IPO "-ipo") set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>") set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>") diff --git a/Modules/Platform/Linux-IntelLLVM.cmake b/Modules/Platform/Linux-IntelLLVM.cmake index 1363b44..992f80e 100644 --- a/Modules/Platform/Linux-IntelLLVM.cmake +++ b/Modules/Platform/Linux-IntelLLVM.cmake @@ -8,18 +8,6 @@ if(__LINUX_COMPILER_INTEL_LLVM) endif() set(__LINUX_COMPILER_INTEL_LLVM 1) -if(NOT XIAR) - set(_intel_xiar_hints) - foreach(lang C CXX Fortran) - if(IS_ABSOLUTE "${CMAKE_${lang}_COMPILER}") - get_filename_component(_hint "${CMAKE_${lang}_COMPILER}" PATH) - list(APPEND _intel_xiar_hints ${_hint}) - endif() - endforeach() - find_program(XIAR NAMES xiar HINTS ${_intel_xiar_hints}) - mark_as_advanced(XIAR) -endif() - macro(__linux_compiler_intel_llvm lang) set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC") set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE") @@ -37,19 +25,5 @@ macro(__linux_compiler_intel_llvm lang) set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,") set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",") - set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES) - - if(XIAR) - # INTERPROCEDURAL_OPTIMIZATION - set(CMAKE_${lang}_COMPILE_OPTIONS_IPO -ipo) - set(CMAKE_${lang}_CREATE_STATIC_LIBRARY_IPO - "${XIAR} cr <TARGET> <LINK_FLAGS> <OBJECTS> " - "${XIAR} -s <TARGET> ") - set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES) - set(_CMAKE_${lang}_IPO_LEGACY_BEHAVIOR YES) - else() - set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO) - endif() - set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=") endmacro() |