diff options
author | Be <be@mixxx.org> | 2021-02-25 09:39:01 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-25 09:39:01 -0800 |
commit | b0103a4948ca775f908fdb1ca528eb973e91d406 (patch) | |
tree | b573aa35b78f90902f0f917006d88d82ef671ba7 /CMakeLists.txt | |
parent | 771d650b815dbefee62c22bea91920d5329a00c7 (diff) | |
parent | 1c49c0dd4f217e267ad573642eba81072f4bcea6 (diff) |
Merge pull request #3589 from daschuer/ipo_on
Disable IPO on all targets
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 104 |
1 files changed, 65 insertions, 39 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 966081763e..ddb80f7e2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,10 @@ if(POLICY CMP0042) cmake_policy(SET CMP0042 NEW) endif() +if(POLICY CMP0069) + cmake_policy(SET CMP0069 NEW) +endif() + ####################################################################### # Compilers and toolchains @@ -77,9 +81,25 @@ endif() # # Optimizations # -set(OPTIMIZE "portable" CACHE STRING "Optimization and Tuning (set to off, portable, native, legacy, fastbuild)") + +set(OPTIMIZE "portable" CACHE STRING "Optimization and Tuning (set to off, portable, native, legacy)") +string(TOLOWER "${OPTIMIZE}" OPTIMIZE) message(STATUS "Optimization level: ${OPTIMIZE}") +# CMAKE_INTERPROCEDURAL_OPTIMIZATION can be defined to override the default behaviour. +# We keep CMAKE_INTERPROCEDURAL_OPTIMIZATION unset (IPO disabled) to save +# build time at the cost of a bigger memory footprint at run-time. +# See https://github.com/mixxxdj/mixxx/pull/3589 for some test results +# Note: IPO has caused issues on Fedora https://bugzilla.rpmfusion.org/show_bug.cgi?id=5829 +# Uncomment the following code to enable IPO for Release builds +#if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT OPTIMIZE STREQUAL "off") +# include(CheckIPOSupported) +# check_ipo_supported(RESULT HAVE_IPO) +# if(HAVE_IPO) +# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) +# endif() +#endif() + if(MSVC) # Microsoft Visual Studio Compiler if(CMAKE_SIZEOF_VOID_P EQUAL 8) @@ -100,37 +120,25 @@ if(MSVC) # http://msdn.microsoft.com/en-us/library/xsa71f43.aspx # http://msdn.microsoft.com/en-us/library/bxwfs976.aspx add_compile_options(/Gy) - add_link_options(/OPT:REF /OPT:ICF) - - # http://msdn.microsoft.com/en-us/library/59a3b321.aspx - # In general, you should pick /O2 over /Ox - add_compile_options($<$<NOT:$<CONFIG:Debug>>:/O2>) - - # Remove /RTC1 flag (conflicts with /O2) - string(REGEX REPLACE "/RTC[^ ]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - - # Re-add /RTC1 for Debug builds - add_compile_options($<$<CONFIG:Debug>:/RTC1>) - - if(OPTIMIZE STREQUAL "fastbuild") - # /GL : http://msdn.microsoft.com/en-us/library/0zza0de8.aspx - # !!! /GL is incompatible with /ZI, which is set by mscvdebug - add_compile_options(/GL-) - - # Do link-time code generation (and don't show a progress indicator - # -- this relies on ANSI control characters and tends to overwhelm - # Jenkins logs) Should we turn on PGO ? - # http://msdn.microsoft.com/en-us/library/xbf3tbeh.aspx - add_link_options(/LTCG:OFF) - elseif(CMAKE_BUILD_TYPE STREQUAL "Debug") - add_compile_options(/GL-) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + #optimize Debug Builds as well, to have "normal" behaviour of mixxx during development + string(REPLACE "/Od" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + string(REPLACE "/Od" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS}") + string(REPLACE "/Ob0" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + string(REPLACE "/Ob0" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS}") + + add_compile_options(/O2) # this implies /Od2 + # Remove /RTC1 flag set by CMAKE by default (conflicts with /O2) + string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + string(REPLACE "/RTC1" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") else() - add_compile_options(/GL) - add_link_options(/LTCG:NOSTATUS) + # Squeeze binary in Release builds + add_link_options(/OPT:REF /OPT:ICF) + # Note: CMAKE_INTERPROCEDURAL_OPTIMIZATION sets the /GL and /LTCG flags for us endif() - if(OPTIMIZE STREQUAL "portable" OR OPTIMIZE STREQUAL "fastbuild") + if(OPTIMIZE STREQUAL "portable") if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) # Target architecture is x86 with SSE and SSE2 message(STATUS "x86 Enabling SS2 CPU optimizations (>= Pentium 4)") @@ -147,20 +155,39 @@ if(MSVC) # Define gcc/clang style defines for SSE and SSE2 for compatibility add_compile_definitions("__SSE__" "__SSE2__") endif() - # Define the target processor instruction and other compiler optimization flags here: - # https://docs.microsoft.com/en-us/cpp/build/reference/arch-x64?view=msvc-160 - # add_compile_options(/arch:AVX512) - message(FATAL_ERROR "User need to set the MSVC compiler flags for the native processor here!") + # Define the target processor instruction and other compiler optimization flags here: + # https://docs.microsoft.com/en-us/cpp/build/reference/arch-x64?view=msvc-160 + # add_compile_options(/arch:AVX512) + message(FATAL_ERROR "User need to set the MSVC compiler flags for the native processor here!") add_compile_options("/favor:${CMAKE_SYSTEM_PROCESSOR}") elseif(OPTIMIZE STREQUAL "legacy") - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - message("Enabling pure x64 instruction set (without AVX etc.)") - else() - message("Enabling pure i386 instruction set (without SSE/SSE2 etc.)") - endif() + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + message("Enabling pure x64 instruction set (without AVX etc.)") + else() + message("Enabling pure i386 instruction set (without SSE/SSE2 etc.)") + endif() else() message(FATAL_ERROR "Invalid value passed to OPTIMIZE option: ${OPTIMIZE}") endif() + else() + # OPTIMIZE=off + if(CMAKE_BUILD_TYPE STREQUAL "Release") + #Remove optimize flags set by cmake defaults + string(REPLACE "/O2" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "/O2" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + string(REPLACE "/Ob2" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "/Ob2" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + add_compile_options(/Od) # this implies /Ob0 + add_compile_options(/RTC1) + elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + #Remove optimize flags set by cmake defaults + string(REPLACE "/O2" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") + string(REPLACE "/O2" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}") + string(REPLACE "/Ob2" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") + string(REPLACE "/Ob2" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}") + add_compile_options(/Od) # this implies /Ob0 + add_compile_options(/RTC1) + endif() endif() elseif(GNU_GCC OR LLVM_CLANG) if(NOT OPTIMIZE STREQUAL "off") @@ -175,7 +202,6 @@ elseif(GNU_GCC OR LLVM_CLANG) -ffast-math -funroll-loops ) - # set -fomit-frame-pointer when we don't profile and are not using # Clang sanitizers. # Note: It is only included in -O on machines where it does not @@ -184,7 +210,7 @@ elseif(GNU_GCC OR LLVM_CLANG) add_compile_options(-fomit-frame-pointer) endif() - if(OPTIMIZE STREQUAL "portable" OR OPTIMIZE STREQUAL "fastbuild") + if(OPTIMIZE STREQUAL "portable") # portable: sse2 CPU (>= Pentium 4) if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i[3456]86|x86|x64|x86_64|AMD64)$") message(STATUS "Enabling SS2 CPU optimizations (>= Pentium 4)") |