summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-03-31 14:37:56 (GMT)
committerKitware Robot <kwrobot@kitware.com>2017-03-31 14:38:08 (GMT)
commit8772fc81c4ab745eb5abbae58c6a69706f610429 (patch)
treecf974aec17ed5a474680b488d1effbf137a7db5e /Modules
parent60dde287e71efbad71b107902991098a6c77556d (diff)
parentdfa8263f4be4f1413b73c81649fdc4567a71e56a (diff)
downloadCMake-8772fc81c4ab745eb5abbae58c6a69706f610429.zip
CMake-8772fc81c4ab745eb5abbae58c6a69706f610429.tar.gz
CMake-8772fc81c4ab745eb5abbae58c6a69706f610429.tar.bz2
Merge topic 'ipo-policy-CMP0069'
dfa8263f Implement interprocedural optimization for GNU compilers 1588a577 Add policy CMP0069 to enforce INTERPROCEDURAL_OPTIMIZATION a7575700 Refactoring: s,GetFeatureAsBool,IsIPOEnabled, e05835c3 CheckIPOSupported: Visual Studio and Xcode generators do not support IPO Acked-by: Kitware Robot <kwrobot@kitware.com> Reviewed-by: Brad King <brad.king@kitware.com> Reviewed-by: Nils Gladitz <nilsgladitz@gmail.com> Merge-request: !568
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CheckIPOSupported.cmake22
-rw-r--r--Modules/CheckIPOSupported/CMakeLists-C.txt.in2
-rw-r--r--Modules/CheckIPOSupported/CMakeLists-CXX.txt.in2
-rw-r--r--Modules/Compiler/Clang.cmake8
-rw-r--r--Modules/Compiler/GNU.cmake39
-rw-r--r--Modules/Compiler/QCC.cmake8
-rw-r--r--Modules/Platform/Linux-Intel.cmake1
7 files changed, 78 insertions, 4 deletions
diff --git a/Modules/CheckIPOSupported.cmake b/Modules/CheckIPOSupported.cmake
index 6f7bc82..31c1bd3 100644
--- a/Modules/CheckIPOSupported.cmake
+++ b/Modules/CheckIPOSupported.cmake
@@ -28,6 +28,9 @@ property.
Specify languages whose compilers to check.
Languages ``C`` and ``CXX`` are supported.
+It makes no sense to use this module when :policy:`CMP0069` is set to ``OLD`` so
+module will return error in this case. See policy :policy:`CMP0069` for details.
+
Examples
^^^^^^^^
@@ -125,7 +128,17 @@ macro(_ipo_run_language_check language)
endmacro()
function(check_ipo_supported)
- # TODO: IPO policy
+ cmake_policy(GET CMP0069 x)
+
+ string(COMPARE EQUAL "${x}" "" not_set)
+ if(not_set)
+ message(FATAL_ERROR "Policy CMP0069 is not set")
+ endif()
+
+ string(COMPARE EQUAL "${x}" "OLD" is_old)
+ if(is_old)
+ message(FATAL_ERROR "Policy CMP0069 set to OLD")
+ endif()
set(optional)
set(one RESULT OUTPUT)
@@ -203,7 +216,12 @@ function(check_ipo_supported)
endif()
if(NOT _CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER)
- _ipo_not_supported("compiler doesn't support IPO")
+ _ipo_not_supported("Compiler doesn't support IPO")
+ return()
+ endif()
+
+ if(CMAKE_GENERATOR MATCHES "^(Visual Studio |Xcode$)")
+ _ipo_not_supported("CMake doesn't support IPO for current generator")
return()
endif()
diff --git a/Modules/CheckIPOSupported/CMakeLists-C.txt.in b/Modules/CheckIPOSupported/CMakeLists-C.txt.in
index d20f31f..5a3b8ee 100644
--- a/Modules/CheckIPOSupported/CMakeLists-C.txt.in
+++ b/Modules/CheckIPOSupported/CMakeLists-C.txt.in
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION "@CMAKE_VERSION@")
project("@TRY_COMPILE_PROJECT_NAME@" LANGUAGES C)
-# TODO: IPO policy
+cmake_policy(SET CMP0069 NEW)
add_library(foo foo.c)
add_executable(boo main.c)
diff --git a/Modules/CheckIPOSupported/CMakeLists-CXX.txt.in b/Modules/CheckIPOSupported/CMakeLists-CXX.txt.in
index 4b55c70..30993fa 100644
--- a/Modules/CheckIPOSupported/CMakeLists-CXX.txt.in
+++ b/Modules/CheckIPOSupported/CMakeLists-CXX.txt.in
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION "@CMAKE_VERSION@")
project("@TRY_COMPILE_PROJECT_NAME@" LANGUAGES CXX)
-# TODO: IPO policy
+cmake_policy(SET CMP0069 NEW)
add_library(foo foo.cpp)
add_executable(boo main.cpp)
diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake
index 96263fc..6b99a08 100644
--- a/Modules/Compiler/Clang.cmake
+++ b/Modules/Compiler/Clang.cmake
@@ -27,5 +27,13 @@ else()
set(CMAKE_${lang}_COMPILE_OPTIONS_TARGET "--target=")
set(CMAKE_${lang}_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN "--gcc-toolchain=")
endif()
+
+ set(_CMAKE_IPO_SUPPORTED_BY_CMAKE NO)
+ set(_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
+
+ unset(CMAKE_${lang}_COMPILE_OPTIONS_IPO)
+ unset(CMAKE_${lang}_ARCHIVE_CREATE_IPO)
+ unset(CMAKE_${lang}_ARCHIVE_APPEND_IPO)
+ unset(CMAKE_${lang}_ARCHIVE_FINISH_IPO)
endmacro()
endif()
diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake
index b67002c..4b1c598 100644
--- a/Modules/Compiler/GNU.cmake
+++ b/Modules/Compiler/GNU.cmake
@@ -45,4 +45,43 @@ macro(__compiler_gnu lang)
if(NOT APPLE OR NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4) # work around #4462
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
endif()
+
+ set(_CMAKE_IPO_SUPPORTED_BY_CMAKE YES)
+ set(_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
+
+ # '-flto' introduced since GCC 4.5:
+ # * https://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Option-Summary.html (no)
+ # * https://gcc.gnu.org/onlinedocs/gcc-4.5.4/gcc/Option-Summary.html (yes)
+ if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.5)
+ set(_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
+ set(__lto_flags -flto)
+
+ if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.7)
+ # '-ffat-lto-objects' introduced since GCC 4.7:
+ # * https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Option-Summary.html (no)
+ # * https://gcc.gnu.org/onlinedocs/gcc-4.7.4/gcc/Option-Summary.html (yes)
+ list(APPEND __lto_flags -fno-fat-lto-objects)
+ endif()
+
+ set(CMAKE_${lang}_COMPILE_OPTIONS_IPO ${__lto_flags})
+
+ # Need to use version of 'ar'/'ranlib' with plugin support.
+ # Quote from [documentation][1]:
+ #
+ # To create static libraries suitable for LTO,
+ # use gcc-ar and gcc-ranlib instead of ar and ranlib
+ #
+ # [1]: https://gcc.gnu.org/onlinedocs/gcc-4.9.4/gcc/Optimize-Options.html
+ set(CMAKE_${lang}_ARCHIVE_CREATE_IPO
+ "${CMAKE_GCC_AR} cr <TARGET> <LINK_FLAGS> <OBJECTS>"
+ )
+
+ set(CMAKE_${lang}_ARCHIVE_APPEND_IPO
+ "${CMAKE_GCC_AR} r <TARGET> <LINK_FLAGS> <OBJECTS>"
+ )
+
+ set(CMAKE_${lang}_ARCHIVE_FINISH_IPO
+ "${CMAKE_GCC_RANLIB} <TARGET>"
+ )
+ endif()
endmacro()
diff --git a/Modules/Compiler/QCC.cmake b/Modules/Compiler/QCC.cmake
index 2d7e881..695a138 100644
--- a/Modules/Compiler/QCC.cmake
+++ b/Modules/Compiler/QCC.cmake
@@ -12,4 +12,12 @@ macro(__compiler_qcc lang)
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-Wp,-isystem,")
set(CMAKE_DEPFILE_FLAGS_${lang} "-Wc,-MD,<DEPFILE>,-MT,<OBJECT>,-MF,<DEPFILE>")
+
+ set(_CMAKE_IPO_SUPPORTED_BY_CMAKE NO)
+ set(_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
+
+ unset(CMAKE_${lang}_COMPILE_OPTIONS_IPO)
+ unset(CMAKE_${lang}_ARCHIVE_CREATE_IPO)
+ unset(CMAKE_${lang}_ARCHIVE_APPEND_IPO)
+ unset(CMAKE_${lang}_ARCHIVE_FINISH_IPO)
endmacro()
diff --git a/Modules/Platform/Linux-Intel.cmake b/Modules/Platform/Linux-Intel.cmake
index 45dc36f..6e2978a 100644
--- a/Modules/Platform/Linux-Intel.cmake
+++ b/Modules/Platform/Linux-Intel.cmake
@@ -39,6 +39,7 @@ macro(__linux_compiler_intel lang)
"${XIAR} cr <TARGET> <LINK_FLAGS> <OBJECTS> "
"${XIAR} -s <TARGET> ")
set(_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
+ set(_CMAKE_IPO_LEGACY_BEHAVIOR YES)
else()
set(_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
endif()