use CMake LTO module, enable LTO for MSVC build

This commit is contained in:
Roman Fomin 2023-04-28 23:09:37 +07:00
parent ca54e65886
commit 8a34e13dcc
3 changed files with 8 additions and 9 deletions

View File

@ -53,7 +53,7 @@ jobs:
- name: Configure
run: |
cmake -B build -G Ninja `
-DCMAKE_BUILD_TYPE=Release -DENABLE_WERROR=ON `
-DCMAKE_BUILD_TYPE=Release -DENABLE_WERROR=ON -DENABLE_LTO=ON`
-DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" `
-DVCPKG_TARGET_TRIPLET="${{ matrix.arch }}-windows-static-release" `
-DVCPKG_OVERLAY_TRIPLETS="cmake/triplets"

View File

@ -12,7 +12,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(X_VCPKG_APPLOCAL_DEPS_INSTALL ON)
cmake_minimum_required(VERSION 3.6)
cmake_minimum_required(VERSION 3.9)
project("Woof"
VERSION 10.5.1

View File

@ -99,13 +99,11 @@ if(ENABLE_HARDENING)
_checked_add_link_option(-Wl,-z,relro)
endif()
option(ENABLE_LTO "Enable link time optimization" OFF)
if(ENABLE_LTO)
_checked_add_compile_option(-flto=auto)
_checked_add_compile_option(-ffat-lto-objects)
_checked_add_link_option(-flto=auto)
_checked_add_link_option(-ffat-lto-objects)
endif()
include(CheckIPOSupported)
check_ipo_supported(RESULT HAVE_LTO)
include(CMakeDependentOption)
cmake_dependent_option(ENABLE_LTO "Enable link time optimization" OFF "HAVE_LTO" OFF)
if(${FORCE_COLORED_OUTPUT})
_checked_add_compile_option(-fdiagnostics-color=always F_DIAG_COLOR)
@ -118,5 +116,6 @@ function(target_woof_settings)
foreach(target ${ARGN})
target_compile_options(${target} PRIVATE ${COMMON_COMPILE_OPTIONS})
target_link_options(${target} PRIVATE ${COMMON_LINK_OPTIONS})
set_target_properties(${target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABLE_LTO})
endforeach()
endfunction()