diff options
author | Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be> | 2016-08-26 21:55:06 +0200 |
---|---|---|
committer | Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be> | 2016-08-27 12:29:44 +0200 |
commit | 21113e024402057d878b4650ffba61b922552b86 (patch) | |
tree | 40d9208c76b7bb8f76bf742db944dcb440a28580 | |
parent | 86f3c44f768d6e49ad8cb2133e0ac3f6ed11baea (diff) |
Fix LTO support for cross-compilation.
When cross-compiling, the ar and ranlib to be used for LTO are prefixed
by the cross-tuple. gcc-ar and gcc-ranlib may not exist. Cfr.
http://autobuild.buildroot.net/results/f3c/f3c48da3a9706cd366c0e0a96c3cd0ff959f2a78/
Therefore, search for an appropriate lto-ar and lto-ranlib before
enabling LTO.
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
-rw-r--r-- | CMakeLists.txt | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e5b5ea5..190119f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,9 +39,15 @@ if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG) CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG) if (HAS_LTO_FLAG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto") - set(CMAKE_AR gcc-ar) - set(CMAKE_RANLIB gcc-ranlib) + find_program(LTO_AR NAMES "${CMAKE_C_COMPILER}-ar" gcc-ar) + find_program(LTO_RANLIB NAMES "${CMAKE_C_COMPILER}-ranlib" gcc-ranlib) + if (LTO_AR AND LTO_RANLIB) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto") + set(CMAKE_AR "${LTO_AR}") + set(CMAKE_RANLIB "${LTO_RANLIB}") + else() + message(STATUS "gcc-ar or gcc-ranlib not found, disabling LTO") + endif() endif() endif() |