diff --git a/tools/pybind11Tools.cmake b/tools/pybind11Tools.cmake index 49876eb9f6..11ea0dc580 100644 --- a/tools/pybind11Tools.cmake +++ b/tools/pybind11Tools.cmake @@ -183,7 +183,12 @@ function(pybind11_add_module target_name) if(CMAKE_VERSION VERSION_LESS 3.9 OR PYBIND11_CLASSIC_LTO) _pybind11_add_lto_flags(${target_name} ${ARG_THIN_LTO}) - else() + elseif(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION) + cmake_policy(GET CMP0069 IPO_POL) + if(CMP0069 STREQUAL "NEW") + cmake_policy(SET CMP0069 NEW) + endif() + include(CheckIPOSupported) check_ipo_supported(RESULT supported OUTPUT error) if(supported)