Skip to content
Snippets Groups Projects
Commit abbc28fc authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Use native cmake LTO support

parent aff44f56
No related branches found
No related tags found
No related merge requests found
......@@ -55,6 +55,10 @@ endif()
# Warnings
option(DISABLE_FATAL_WARNINGS "Disable warnings as errors" ON)
if(USE_LTO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${USE_LTO})
endif()
# Platform-specific compilation flags.
if (WINDOWS)
# Don't build DLLs.
......@@ -139,31 +143,10 @@ if (WINDOWS)
endif()
if (USE_LTO)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
if(INCREMENTAL_LINK)
add_link_options(/LTCG:incremental)
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /LTCG")
else()
add_link_options(/LTCG)
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /LTCG")
endif()
add_link_options(
$<$<CONFIG:Release>:/OPT:REF>
$<$<CONFIG:Release>:/OPT:ICF>
$<$<CONFIG:Release>:/INCREMENTAL:NO>
)
add_compile_options(/GL /Gy /Gw)
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if(INCREMENTAL_LINK)
add_compile_options(-flto=thin -fwhole-program-vtables /clang:-fforce-emit-vtables)
else()
add_compile_options(-flto=full -fwhole-program-vtables /clang:-fforce-emit-vtables)
endif()
add_link_options(
$<$<CONFIG:Release>:/OPT:REF>
$<$<CONFIG:Release>:/OPT:ICF>
)
endif()
add_link_options(
$<$<CONFIG:Release>:/OPT:REF>
$<$<CONFIG:Release>:/OPT:ICF>
)
elseif (INCREMENTAL_LINK)
add_link_options($<$<CONFIG:Release>:/INCREMENTAL>)
else ()
......@@ -233,14 +216,6 @@ if (LINUX)
add_compile_options(-mfpmath=sse -msse -msse2 -msse3 -mssse3 -msse4 -msse4.1)
endif ()
if (USE_LTO)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-flto=thin -fwhole-program-vtables -fforce-emit-vtables)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-flto=auto -fno-fat-lto-objects)
endif ()
endif ()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if (USE_ASAN)
add_compile_options(-fsanitize=address -fsanitize-recover=address)
......@@ -262,10 +237,6 @@ if (LINUX)
add_compile_options(-O3 -ffast-math)
endif ()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND USE_LTO)
add_link_options(-fuse-ld=lld)
endif()
# Enable these flags so we have a read only GOT and some linking opts
add_link_options("LINKER:-z,relro" "LINKER:-z,now" "LINKER:--as-needed")
endif ()
......
......@@ -172,9 +172,6 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_XCODE_ATTRIBUTE_GCC_FAST_MATH NO)
set(CMAKE_XCODE_ATTRIBUTE_GCC_STRICT_ALIASING NO)
set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES)
if(USE_LTO)
set(CMAKE_XCODE_ATTRIBUTE_LLVM_LTO YES_THIN)
endif()
set(CMAKE_XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS YES)
if(FULL_DEBUG_SYMS OR USE_SENTRY)
......
project(deps)
include(00-Common)
include(FetchContent)
set(CMAKE_FOLDER "Third Party")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(deps_SOURCE_FILES
CMakeLists.txt
......@@ -18,17 +20,6 @@ add_library(deps
${deps_SOURCE_FILES}
)
if(${CMAKE_VERSION} VERSION_LESS 3.14)
macro(FetchContent_MakeAvailable NAME)
FetchContent_GetProperties(${NAME})
if(NOT ${NAME}_POPULATED)
FetchContent_Populate(${NAME})
add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR})
endif()
endmacro()
endif()
FetchContent_Declare(
meshoptimizer
GIT_REPOSITORY https://git.alchemyviewer.org/alchemy/mirrors/meshoptimizer.git
......@@ -79,8 +70,7 @@ if(USE_TRACY)
set(TRACY_ON_DEMAND ON)
set(TRACY_ONLY_LOCALHOST ON)
set(TRACY_FIBERS ON)
FetchContent_MakeAvailable (tracy)
FetchContent_MakeAvailable(tracy)
endif()
unset(CMAKE_FOLDER)
unset(CMAKE_POSITION_INDEPENDENT_CODE)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment