1 From 5da1f631bc753655ac94b08a6233eecd0d451327 Mon Sep 17 00:00:00 2001
2 From: "Arnout Vandecappelle (Essensium/Mind)" <arnout@mind.be>
3 Date: Fri, 26 Aug 2016 21:55:06 +0200
4 Subject: [PATCH] Fix LTO support for cross-compilation.
6 When cross-compiling, the ar and ranlib to be used for LTO are prefixed
7 by the cross-tuple. gcc-ar and gcc-ranlib may not exist. Cfr.
8 http://autobuild.buildroot.net/results/f3c/f3c48da3a9706cd366c0e0a96c3cd0ff959f2a78/
10 Therefore, search for an appropriate lto-ar and lto-ranlib before
13 Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
15 Submitted upstream: https://github.com/tomba/kmsxx/pull/14
17 CMakeLists.txt | 12 +++++++++---
18 1 file changed, 9 insertions(+), 3 deletions(-)
20 diff --git a/CMakeLists.txt b/CMakeLists.txt
21 index e5b5ea5..c61c81d 100644
24 @@ -39,9 +39,15 @@ if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
25 CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
28 - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
29 - set(CMAKE_AR gcc-ar)
30 - set(CMAKE_RANLIB gcc-ranlib)
31 + find_program(LTO_AR NAMES "${CMAKE_C_COMPILER}-ar" gcc-ar)
32 + find_program(LTO_RANLIB NAMES "${CMAKE_C_COMPILER}-ranlib" gcc-ranlib)
33 + if (LTO_AR AND LTO_RANLIB)
34 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
35 + set(CMAKE_AR "${LTO_AR}")
36 + set(CMAKE_RANLIB "${LTO_RANLIB}")
38 + message(STATUS "gcc-ar or gcc-ranlib not found, disabling LTO")