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
This commit is contained in:
Nadia Holmquist Pedersen 2020-11-28 17:12:44 +01:00 committed by GitHub
parent 1ff4a1564f
commit 14be591ab8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -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)