Skip to content

Commit

Permalink
Improved logic for enabling LTO
Browse files Browse the repository at this point in the history
CMake 3.9 added proper support for enabling LTO on all platforms, so we no
longer need to rely on our previous MSVC specific code.
  • Loading branch information
athre0z committed May 1, 2022
1 parent c58d7fb commit b01063b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if (TARGET Zycore)
return()
endif ()

cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)

project(Zycore VERSION 1.1.0.0 LANGUAGES C CXX)

Expand Down Expand Up @@ -127,7 +127,7 @@ target_include_directories("Zycore"
PRIVATE "src")
target_compile_definitions("Zycore" PRIVATE "_CRT_SECURE_NO_WARNINGS")
zyan_set_common_flags("Zycore")
zyan_maybe_enable_wpo_for_lib("Zycore")
zyan_maybe_enable_wpo("Zycore")

if (ZYAN_NO_LIBC)
target_compile_definitions("Zycore" PUBLIC "ZYAN_NO_LIBC")
Expand Down
12 changes: 4 additions & 8 deletions cmake/zyan-functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,12 @@ function (zyan_set_source_group target)
endfunction ()

function (zyan_maybe_enable_wpo target)
if (ZYAN_WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
set_target_properties("${target}" PROPERTIES COMPILE_FLAGS "/GL")
set_target_properties("${target}" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
if (ZYAN_WHOLE_PROGRAM_OPTIMIZATION)
set_property(TARGET "${target}" PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif ()
endfunction ()

# deprecated alias for `zyan_maybe_enable_wpo`, for backward compatibility.
function (zyan_maybe_enable_wpo_for_lib target)
if (ZYAN_WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
set_target_properties("${target}" PROPERTIES COMPILE_FLAGS "/GL")
set_target_properties("${target}" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
set_target_properties("${target}" PROPERTIES STATIC_LIBRARY_FLAGS_RELEASE "/LTCG")
endif ()
zyan_maybe_enable_wpo("${target}")
endfunction ()

0 comments on commit b01063b

Please sign in to comment.