Fix LTO detection
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Mon, 19 Sep 2016 11:38:16 +0000 (14:38 +0300)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Wed, 28 Sep 2016 07:14:07 +0000 (10:14 +0300)
Catch gcc-ar and gcc-ranlib versions compiled without plugin support and
disable LTO in that case.

Also do the LTO check only once by checking if HAS_LTO_FLAG has been set.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
CMakeLists.txt

index 190119f93646a65e4ebb1f5d211b0107defe67ef..9214bfdf12e243ba2c616b7436f6ecb5a22113cf 100644 (file)
@@ -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}")