Skip to content

Commit

Permalink
Merge pull request #92 from cpp-best-practices/lto
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Mar 7, 2022
2 parents fe896ba + cc84b78 commit 592ba69
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Index.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ macro(project_options)
set(ProjectOptions_ENABLE_INTERPROCEDURAL_OPTIMIZATION ${ProjectOptions_ENABLE_IPO})
endif()
if(${ProjectOptions_ENABLE_INTERPROCEDURAL_OPTIMIZATION})
enable_interprocedural_optimization()
enable_interprocedural_optimization(project_options)
endif()

if(${ProjectOptions_ENABLE_NATIVE_OPTIMIZATION})
Expand Down
11 changes: 9 additions & 2 deletions src/Optimization.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
macro(enable_interprocedural_optimization)
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)
if(result)
# 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(SEND_ERROR "IPO is not supported: ${output}")
message(WARNING "Interprocedural Optimization is not supported. Not using it. Here is the error log: ${output}")
endif()
endif()
endmacro()
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ project_options(
# ENABLE_PCH
# PCH_HEADERS <Eigen/Dense> <fmt/core.h> <vector> <utility> <string> <string_view>
ENABLE_DOXYGEN
# ENABLE_INTERPROCEDURAL_OPTIMIZATION
ENABLE_INTERPROCEDURAL_OPTIMIZATION
ENABLE_NATIVE_OPTIMIZATION
# ENABLE_USER_LINKER
# ENABLE_BUILD_WITH_TIME_TRACE
Expand Down
2 changes: 1 addition & 1 deletion test_install/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ project_options(
# ENABLE_PCH
# PCH_HEADERS <Eigen/Dense> <fmt/core.h> <vector> <utility> <string> <string_view>
# ENABLE_DOXYGEN
# ENABLE_INTERPROCEDURAL_OPTIMIZATION
ENABLE_INTERPROCEDURAL_OPTIMIZATION
# ENABLE_USER_LINKER
# ENABLE_BUILD_WITH_TIME_TRACE
# ENABLE_UNITY
Expand Down

0 comments on commit 592ba69

Please sign in to comment.