Skip to content

Commit

Permalink
Fix setting of release only LTO
Browse files Browse the repository at this point in the history
  • Loading branch information
FeignClaims committed May 19, 2024
1 parent 925c23b commit fa01d39
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/Optimization.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ include_guard()

# Enable Interprocedural Optimization (Link Time Optimization, LTO) in the release build
macro(enable_interprocedural_optimization _project_name)
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
is_mingw(_is_mingw)
if(result AND NOT ${_is_mingw})
# If a static library of this project is used in another project that does not have `CMAKE_INTERPROCEDURAL_OPTIMIZATION` enabled, a linker error might happen.
# TODO set this option in `package_project` function.
message(
STATUS
"Interprocedural optimization is enabled. In other projects, linking with the compiled libraries of this project might require `set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)`"
)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
set_target_properties(${_project_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)
else()
message(
WARNING
"Interprocedural Optimization is not supported. Not using it. Here is the error log: ${output}"
)
endif()
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
is_mingw(_is_mingw)
if(result AND NOT ${_is_mingw})
# If a static library of this project is used in another project that does not have `CMAKE_INTERPROCEDURAL_OPTIMIZATION` enabled, a linker error might happen.
# TODO set this option in `package_project` function.
message(
STATUS
"Interprocedural optimization is enabled. In other projects, linking with the compiled libraries of this project might require `set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)`"
)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON)
set_target_properties(${_project_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
set_target_properties(${_project_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON)
else()
message(
WARNING
"Interprocedural Optimization is not supported. Not using it. Here is the error log: ${output}"
)
endif()
endmacro()

Expand Down

0 comments on commit fa01d39

Please sign in to comment.