2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-07-07 20:45:51 +00:00

Use lld with clang, gold with gcc, LTO only on release builds

This commit is contained in:
Luke Street 2019-11-30 23:01:38 -05:00
parent 697a100bca
commit 9c8960cf5f

View File

@ -156,20 +156,56 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
link_directories(/usr/local/lib) link_directories(/usr/local/lib)
endif() endif()
if(("${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
option(USE_LD_GOLD "Link with GNU Gold and enable LTO" ON) option(USE_LD_LLD "Link with LLD" ON)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
option(USE_LD_GOLD "Link with GNU Gold" ON)
endif()
include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_SUPPORTED)
if(LTO_SUPPORTED AND ("${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo"))
option(USE_LTO "Enable LTO" ON)
else()
option(USE_LTO "Enable LTO" OFF)
endif()
else() else()
option(USE_LD_GOLD "Link with GNU Gold and enable LTO" OFF) option(USE_LD_LLD "Link with LLD" OFF)
option(USE_LD_GOLD "Link with GNU Gold" OFF)
option(USE_LTO "Enable LTO" OFF)
endif() endif()
if(USE_LD_GOLD AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")) if(USE_LD_LLD)
execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=lld -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
if("${LD_VERSION}" MATCHES "LLD")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
if(USE_LTO)
add_compile_options(-flto=thin)
add_link_options(-flto=thin)
message(STATUS "LLD linker enabled with LTO.")
else()
message(STATUS "LLD linker enabled.")
endif()
set(USE_LD_GOLD OFF)
else()
message(WARNING "LLD linker isn't available, using the default system linker.")
set(USE_LD_LLD OFF)
endif()
endif()
if(USE_LD_GOLD)
execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
if("${LD_VERSION}" MATCHES "GNU gold") if("${LD_VERSION}" MATCHES "GNU gold")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold -Wl,--disable-new-dtags") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold -Wl,--disable-new-dtags")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold -Wl,--disable-new-dtags") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold -Wl,--disable-new-dtags")
if(USE_LTO)
add_compile_options(-flto=thin) add_compile_options(-flto=thin)
add_link_options(-flto=thin) add_link_options(-flto=thin)
message(STATUS "GNU gold linker enabled with LTO.")
else()
message(STATUS "GNU gold linker enabled.") message(STATUS "GNU gold linker enabled.")
endif()
set(USE_LD_LLD OFF)
else() else()
message(WARNING "GNU gold linker isn't available, using the default system linker.") message(WARNING "GNU gold linker isn't available, using the default system linker.")
set(USE_LD_GOLD OFF) set(USE_LD_GOLD OFF)