diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index d4600943fb..8bd8668130 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -261,7 +261,11 @@ if(CV_GCC OR CV_CLANG) endif() if(ENABLE_LTO) - add_extra_compiler_option(-flto) + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12) + add_extra_compiler_option(-flto=auto) + else() + add_extra_compiler_option(-flto) + endif() endif() if(ENABLE_THIN_LTO) add_extra_compiler_option(-flto=thin)