diff --git a/src/Index.cmake b/src/Index.cmake index ec4ddf8f..5ed2831b 100644 --- a/src/Index.cmake +++ b/src/Index.cmake @@ -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}) diff --git a/src/Optimization.cmake b/src/Optimization.cmake index 2e9063dd..0e58ffa2 100644 --- a/src/Optimization.cmake +++ b/src/Optimization.cmake @@ -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() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 686bedbd..aa70b1b1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -31,7 +31,7 @@ project_options( # ENABLE_PCH # PCH_HEADERS ENABLE_DOXYGEN - # ENABLE_INTERPROCEDURAL_OPTIMIZATION + ENABLE_INTERPROCEDURAL_OPTIMIZATION ENABLE_NATIVE_OPTIMIZATION # ENABLE_USER_LINKER # ENABLE_BUILD_WITH_TIME_TRACE diff --git a/test_install/CMakeLists.txt b/test_install/CMakeLists.txt index c18df9d0..39fda38c 100644 --- a/test_install/CMakeLists.txt +++ b/test_install/CMakeLists.txt @@ -22,7 +22,7 @@ project_options( # ENABLE_PCH # PCH_HEADERS # ENABLE_DOXYGEN - # ENABLE_INTERPROCEDURAL_OPTIMIZATION + ENABLE_INTERPROCEDURAL_OPTIMIZATION # ENABLE_USER_LINKER # ENABLE_BUILD_WITH_TIME_TRACE # ENABLE_UNITY