summaryrefslogtreecommitdiffstats
path: root/Modules/Compiler/Clang.cmake
diff options
context:
space:
mode:
authorRuslan Baratov <ruslan_baratov@yahoo.com>2017-04-28 14:13:56 (GMT)
committerRuslan Baratov <ruslan_baratov@yahoo.com>2017-04-28 14:13:56 (GMT)
commit7d057b2738e229192ae5afe71d50354681813235 (patch)
treebebcaf0fcca709a89a4d6e9dde390ef7003cef38 /Modules/Compiler/Clang.cmake
parentd828d0eb084cf094119d2b47dae0053267aba138 (diff)
downloadCMake-7d057b2738e229192ae5afe71d50354681813235.zip
CMake-7d057b2738e229192ae5afe71d50354681813235.tar.gz
CMake-7d057b2738e229192ae5afe71d50354681813235.tar.bz2
Clang IPO (LTO) support
Diffstat (limited to 'Modules/Compiler/Clang.cmake')
-rw-r--r--Modules/Compiler/Clang.cmake54
1 files changed, 48 insertions, 6 deletions
diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake
index 6b99a08..8c2f87d 100644
--- a/Modules/Compiler/Clang.cmake
+++ b/Modules/Compiler/Clang.cmake
@@ -28,12 +28,54 @@ else()
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)
+ set(_CMAKE_IPO_SUPPORTED_BY_CMAKE YES)
+ set(_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
- unset(CMAKE_${lang}_COMPILE_OPTIONS_IPO)
- unset(CMAKE_${lang}_ARCHIVE_CREATE_IPO)
- unset(CMAKE_${lang}_ARCHIVE_APPEND_IPO)
- unset(CMAKE_${lang}_ARCHIVE_FINISH_IPO)
+ string(COMPARE EQUAL "${CMAKE_${lang}_COMPILER_ID}" "AppleClang" __is_apple_clang)
+
+ # '-flto=thin' available since Clang 3.9 and Xcode 8
+ # * http://clang.llvm.org/docs/ThinLTO.html#clang-llvm
+ # * https://trac.macports.org/wiki/XcodeVersionInfo
+ set(_CMAKE_LTO_THIN TRUE)
+ if(__is_apple_clang)
+ if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 8.0)
+ set(_CMAKE_LTO_THIN FALSE)
+ endif()
+ else()
+ if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.9)
+ set(_CMAKE_LTO_THIN FALSE)
+ endif()
+ endif()
+
+ if(_CMAKE_LTO_THIN)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-flto=thin")
+ else()
+ set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-flto")
+ endif()
+
+ if(ANDROID)
+ # https://github.com/android-ndk/ndk/issues/242
+ set(CMAKE_${lang}_LINK_OPTIONS_IPO "-fuse-ld=gold")
+ endif()
+
+ if(ANDROID OR __is_apple_clang)
+ set(__ar "${CMAKE_AR}")
+ set(__ranlib "${CMAKE_RANLIB}")
+ else()
+ set(__ar "${CMAKE_${lang}_COMPILER_AR}")
+ set(__ranlib "${CMAKE_${lang}_COMPILER_RANLIB}")
+ endif()
+
+ set(CMAKE_${lang}_ARCHIVE_CREATE_IPO
+ "${__ar} cr <TARGET> <LINK_FLAGS> <OBJECTS>"
+ )
+
+ set(CMAKE_${lang}_ARCHIVE_APPEND_IPO
+ "${__ar} r <TARGET> <LINK_FLAGS> <OBJECTS>"
+ )
+
+ set(CMAKE_${lang}_ARCHIVE_FINISH_IPO
+ "${__ranlib} <TARGET>"
+ )
endmacro()
endif()