From 14be591ab8e769457678d5cac8536b2abfb3a94f Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Sat, 28 Nov 2020 17:12:44 +0100 Subject: Override CMAKE_AR/CMAKE_RANLIB, fixes flatpak builds, also use lld with clang if found (#828) * Override CMAKE_AR/CMAKE_RANLIB, fixes flatpak builds, also use lld with clang if found * Ensure we build with -fPIC/-pie for LTO builds --- CMakeLists.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f34367f..04ad2a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,8 +74,20 @@ if (CMAKE_BUILD_TYPE STREQUAL Release) endif() if (ENABLE_LTO) - add_compile_options(-flto) - add_link_options(-flto -fuse-linker-plugin) + add_compile_options(-flto -fPIC) + add_link_options(-flto -fuse-linker-plugin -pie) +endif() + +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_AR "gcc-ar") + set(CMAKE_RANLIB "gcc-ranlib") +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + find_program(LLD NAMES ld.lld ld64.lld lld-link) + if (NOT LLD STREQUAL "LLD-NOTFOUND") + add_link_options(-fuse-ld=lld) + endif() + set(CMAKE_AR "llvm-ar") + set(CMAKE_RANLIB "llvm-ranlib") endif() option(BUILD_QT_SDL "Build Qt/SDL frontend" ON) -- cgit v1.2.3