I _think_ this is a decent compromise for LTO vs non-LTO builds

pull/654/head
Rick V 5 years ago
parent 0b1e3ce959
commit 302fa232d7
No known key found for this signature in database
GPG Key ID: C0EDC8723FDC3465

@ -154,20 +154,30 @@ set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
# not supported on Solaris - system libraries are not available as archives
# LTO is supported only for native builds
if(STATIC_LINK_RUNTIME)
if (NOT SOLARIS)
add_compile_options(-static -flto)
if(NOT CMAKE_CROSSCOMPILING)
add_compile_options(-static -flto)
else()
add_compile_options(-static)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
link_libraries( -static -static-libstdc++ -pthread -flto )
else()
# this is messing with release builds
add_compile_options(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0)
set(CMAKE_AR "gcc-ar")
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "true")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_FINISH "true")
link_libraries( -flto -static-libstdc++ -static-libgcc -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive )
if(NOT CMAKE_CROSSCOMPILING)
# this is messing with release builds
add_compile_options(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0)
set(CMAKE_AR "gcc-ar")
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "true")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_FINISH "true")
link_libraries( -flto -static-libstdc++ -static-libgcc -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive )
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive" )
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
endif()
endif()
else()
link_libraries( -static-libstdc++ -static-libgcc )

Loading…
Cancel
Save