diff --git a/CMakeLists.txt b/CMakeLists.txt index 54a9bd05..dbe4223c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,9 @@ option (SFIZZ_BENCHMARKS "Enable benchmarks build [default: OFF]" OFF) option (SFIZZ_TESTS "Enable tests build [default: OFF]" OFF) option (SFIZZ_SHARED "Enable shared library build [default: ON]" ON) +# Don't use IPO in non Release builds +include (CheckIPO) + # Add Abseil add_subdirectory (external/abseil-cpp EXCLUDE_FROM_ALL) diff --git a/cmake/CheckIPO.cmake b/cmake/CheckIPO.cmake new file mode 100644 index 00000000..73b53d5a --- /dev/null +++ b/cmake/CheckIPO.cmake @@ -0,0 +1,14 @@ +# Added in CMake 3.9 +include (CheckIPOSupported) +check_ipo_supported (RESULT result OUTPUT output) + +if (result AND ENABLE_LTO AND ${CMAKE_BUILD_TYPE} MATCHES Release) + message (STATUS "\nLTO enabled.") +else() + if (${output}) + message (WARNING "\nIPO disabled: ${output}") + else() + message (WARNING "\nIPO was disabled, not in a Release build?") + endif() + set (ENABLE_LTO OFF) +endif()