From d8add861fed6b45ef4f4b897910e938f57b1f3d4 Mon Sep 17 00:00:00 2001 From: Lukas Werling Date: Mon, 24 Sep 2018 17:43:27 +0200 Subject: [PATCH] Fix LTO ar wrappers for versioned gcc executables Debian packages older/newer gcc versions with executables named like gcc-5, gcc-ar-5. The previous implementation did not handle this correctly, breaking LTO-enabled linking. --- CMakeLists.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 02a7e117e..7cb677dfa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,9 +101,11 @@ if(USE_GCC_STYLE_LTCG) # Use GCC's ar and ranlib wrappers if necessary, because the plain ones # don't understand lto objects without an explicit plugin parameter - if(CMAKE_C_COMPILER MATCHES "gcc$") + # Note that versioned gcc executables need splitting: gcc-5 -> gcc-ar-5 + if(CMAKE_C_COMPILER MATCHES "^(.*gcc)(-[0-9.])?$") set(LTCG_NEEDS_AR_WRAPPER 1) - set(LTCG_AR_WRAPPER_PREFIX "${CMAKE_C_COMPILER}") + set(LTCG_AR_WRAPPER_PREFIX "${CMAKE_MATCH_1}") + set(LTCG_AR_WRAPPER_SUFFIX "${CMAKE_MATCH_2}") elseif(CMAKE_C_COMPILER MATCHES "cc$") set(LTCG_NEEDS_AR_WRAPPER 1) set(LTCG_AR_WRAPPER_PREFIX "gcc") @@ -112,12 +114,12 @@ if(USE_GCC_STYLE_LTCG) endif() if(LTCG_NEEDS_AR_WRAPPER) - find_program(AR_WRAPPER "${LTCG_AR_WRAPPER_PREFIX}-ar") + find_program(AR_WRAPPER "${LTCG_AR_WRAPPER_PREFIX}-ar${LTCG_AR_WRAPPER_SUFFIX}") if (AR_WRAPPER) message("Using ${AR_WRAPPER} instead of ${CMAKE_AR} to support lto objects.") set(CMAKE_AR "${AR_WRAPPER}" CACHE FILEPATH "Path to an ar that supports lto objects." FORCE) endif() - find_program(RANLIB_WRAPPER "${LTCG_AR_WRAPPER_PREFIX}-ranlib") + find_program(RANLIB_WRAPPER "${LTCG_AR_WRAPPER_PREFIX}-ranlib${LTCG_AR_WRAPPER_SUFFIX}") if (RANLIB_WRAPPER) message("Using ${RANLIB_WRAPPER} instead of ${CMAKE_RANLIB} to support lto objects.") set(CMAKE_RANLIB "${RANLIB_WRAPPER}" CACHE FILEPATH "Path to a ranlib that supports lto objects." FORCE)