diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index 499408026c..5ad7bcdebd 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -37,11 +37,43 @@ if(MSVC) endif() endforeach() + if(wxBUILD_OPTIMISE) + set(MSVC_LINKER_RELEASE_FLAGS " /LTCG /OPT:REF /OPT:ICF") + wx_string_append(CMAKE_EXE_LINKER_FLAGS_RELEASE "${MSVC_LINKER_RELEASE_FLAGS}") + wx_string_append(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${MSVC_LINKER_RELEASE_FLAGS}") + wx_string_append(CMAKE_STATIC_LINKER_FLAGS_RELEASE " /LTCG") + set(MSVC_COMPILER_RELEASE_FLAGS " /Ox /Oi /Ot /Oy /GS- /Gy /GL /Gw") + wx_string_append(CMAKE_CXX_FLAGS_RELEASE "${MSVC_COMPILER_RELEASE_FLAGS}") + wx_string_append(CMAKE_C_FLAGS_RELEASE "${MSVC_COMPILER_RELEASE_FLAGS}") + endif() + + if(NOT wxBUILD_STRIPPED_RELEASE) + set(MSVC_PDB_FLAG " /DEBUG") + endif() + wx_string_append(CMAKE_EXE_LINKER_FLAGS_RELEASE "${MSVC_PDB_FLAG}") + wx_string_append(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${MSVC_PDB_FLAG}") + if(wxBUILD_MSVC_MULTIPROC) wx_string_append(CMAKE_C_FLAGS " /MP") wx_string_append(CMAKE_CXX_FLAGS " /MP") endif() elseif(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")) + if(wxBUILD_OPTIMISE) + set(GCC_PREFERRED_RELEASE_FLAGS " -O2 -fomit-frame-pointer") + wx_string_append(CMAKE_CXX_FLAGS_RELEASE "${GCC_PREFERRED_RELEASE_FLAGS}") + wx_string_append(CMAKE_C_FLAGS_RELEASE "${GCC_PREFERRED_RELEASE_FLAGS}") + endif() + + if(wxBUILD_STRIPPED_RELEASE) + set(LD_STRIPPING_FLAG " -s") + wx_string_append(CMAKE_EXE_LINKER_FLAGS_RELEASE "${LD_STRIPPING_FLAG}") + wx_string_append(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${LD_STRIPPING_FLAG}") + else() + set(COMPILER_DBGSYM_FLAG " -g") + wx_string_append(CMAKE_CXX_FLAGS_RELEASE "${COMPILER_DBGSYM_FLAG}") + wx_string_append(CMAKE_C_FLAGS_RELEASE "${COMPILER_DBGSYM_FLAG}") + endif() + if(wxBUILD_USE_STATIC_RUNTIME) if(MINGW) set(STATIC_LINKER_FLAGS " -static") diff --git a/build/cmake/options.cmake b/build/cmake/options.cmake index 13cb93c358..606ba6f75f 100644 --- a/build/cmake/options.cmake +++ b/build/cmake/options.cmake @@ -47,6 +47,13 @@ if(WIN32) set(wxBUILD_VENDOR "custom" CACHE STRING "Short string identifying your company (used in DLL name)") endif() +wx_option(wxBUILD_OPTIMISE "use speed-optimised C/C++ compiler flags for release build" OFF) +if(MSVC) + set(wxBUILD_STRIPPED_RELEASE_DEFAULT OFF) +else() + set(wxBUILD_STRIPPED_RELEASE_DEFAULT ON) +endif() +wx_option(wxBUILD_STRIPPED_RELEASE "remove debug symbols in release build" ${wxBUILD_STRIPPED_RELEASE_DEFAULT}) wx_option(wxUSE_NO_RTTI "disable RTTI support" OFF) # STL options