summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt17
1 files changed, 16 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 190119f..9214bfd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,12 +35,27 @@ set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
# static link libc
# set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
-if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
+if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG AND NOT DEFINED HAS_LTO_FLAG)
CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
if (HAS_LTO_FLAG)
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)
+ EXECUTE_PROCESS(COMMAND "${LTO_AR}" --version RESULT_VARIABLE ret OUTPUT_QUIET ERROR_QUIET)
+ if (ret)
+ unset(LTO_AR CACHE)
+ endif()
+ endif()
+
+ if (LTO_RANLIB)
+ EXECUTE_PROCESS(COMMAND "${LTO_RANLIB}" --version RESULT_VARIABLE ret OUTPUT_QUIET ERROR_QUIET)
+ if (ret)
+ unset(LTO_RANLIB CACHE)
+ endif()
+ endif()
+
if (LTO_AR AND LTO_RANLIB)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
set(CMAKE_AR "${LTO_AR}")