diff --git a/CMakeLists.txt b/CMakeLists.txt index 1206969025..073d74573a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,20 @@ add_subdirectory(3rdparty) unset(CMAKE_CXX_FLAGS) unset(CMAKE_C_FLAGS) +if (DISABLE_LTO) + if (CMAKE_C_FLAGS) + string(REGEX REPLACE "-flto[^ ]*" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) + endif() + if (CMAKE_CXX_FLAGS) + string(REGEX REPLACE "-flto[^ ]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + endif() +endif() + +string(FIND "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}" "-flto" FOUND_LTO) +if (NOT FOUND_LTO EQUAL -1) + message(FATAL_ERROR "Rpcs3 doesn't support building with LTO, use -DDISABLE_LTO=TRUE to force-disable it") +endif() + if(NOT WIN32) add_compile_options(-pthread) endif()