From 19691a22fda814e70ff3416dedce91f74b9dde56 Mon Sep 17 00:00:00 2001 From: kgv Date: Sat, 28 Aug 2021 01:42:10 +0300 Subject: [PATCH] 0032545: Configuration, CMake - add BUILD_FORCE_RelWithDebInfo option for generating VS project files with Debug info in Release mode --- CMakeLists.txt | 10 ++++++++++ adm/cmake/ffmpeg.cmake | 6 +++--- adm/cmake/occt_defs_flags.cmake | 13 +++++++++++++ adm/cmake/occt_toolkit.cmake | 7 ++++++- adm/cmake/vardescr.cmake | 3 +++ adm/scripts/cmake_custom.bat.template | 1 + adm/scripts/cmake_gen.bat | 2 ++ 7 files changed, 38 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43440b6388..d98acc0ff9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,16 @@ if (NOT DEFINED BUILD_RELEASE_DISABLE_EXCEPTIONS) set (BUILD_RELEASE_DISABLE_EXCEPTIONS ON CACHE BOOL "${BUILD_RELEASE_DISABLE_EXCEPTIONS_DESCR}") endif() +if (MSVC) + set (BUILD_FORCE_RelWithDebInfo OFF CACHE BOOL "${BUILD_FORCE_RelWithDebInfo_DESCR}") +else() + set (BUILD_FORCE_RelWithDebInfo OFF) +endif() + +if (BUILD_FORCE_RelWithDebInfo) + set (CMAKE_CONFIGURATION_TYPES Release Debug CACHE INTERNAL "" FORCE) +endif() + # option to enable or disable use of precompiled headers if (NOT DEFINED BUILD_USE_PCH) set (BUILD_USE_PCH OFF CACHE BOOL "${BUILD_USE_PCH_DESCR}") diff --git a/adm/cmake/ffmpeg.cmake b/adm/cmake/ffmpeg.cmake index e4cd736e7c..f619d2d410 100644 --- a/adm/cmake/ffmpeg.cmake +++ b/adm/cmake/ffmpeg.cmake @@ -191,13 +191,13 @@ foreach (LIBRARY_NAME ${CSF_FFmpeg}) else() install (FILES "${3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}}" CONFIGURATIONS Release - DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin") + DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/${INSTALL_DIR_BIN}") install (FILES "${3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}}" CONFIGURATIONS RelWithDebInfo - DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bini") + DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/${INSTALL_DIR_BIN}i") install (FILES "${3RDPARTY_FFMPEG_DLL_${LIBRARY_NAME}}" CONFIGURATIONS Debug - DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind") + DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/${INSTALL_DIR_BIN}d") endif() else() get_filename_component(3RDPARTY_FFMPEG_LIBRARY_ABS ${3RDPARTY_FFMPEG_LIBRARY_${LIBRARY_NAME}} REALPATH) diff --git a/adm/cmake/occt_defs_flags.cmake b/adm/cmake/occt_defs_flags.cmake index 03eaea60ea..200790c048 100644 --- a/adm/cmake/occt_defs_flags.cmake +++ b/adm/cmake/occt_defs_flags.cmake @@ -40,6 +40,19 @@ elseif (MSVC) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHa") endif() +if (MSVC) + # string pooling (GF), function-level linking (Gy) + set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GF /Gy") + set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GF /Gy") + if (BUILD_FORCE_RelWithDebInfo) + # generate debug info (Zi), inline expansion level (Ob1) + set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /Ob1") + set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi /Ob1") + # generate debug info (debug), OptimizeReferences=true (OPT:REF), EnableCOMDATFolding=true (OPT:ICF) + set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /debug /OPT:REF /OPT:ICF") + endif() +endif() + # remove _WINDOWS flag if it exists string (REGEX MATCH "/D_WINDOWS" IS_WINDOWSFLAG "${CMAKE_CXX_FLAGS}") if (IS_WINDOWSFLAG) diff --git a/adm/cmake/occt_toolkit.cmake b/adm/cmake/occt_toolkit.cmake index a3826f3f9a..2f96c6f148 100644 --- a/adm/cmake/occt_toolkit.cmake +++ b/adm/cmake/occt_toolkit.cmake @@ -236,8 +236,13 @@ else() add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE} ${RESOURCE_FILES} ${${PROJECT_NAME}_MOC_FILES}) if (MSVC) + if (BUILD_FORCE_RelWithDebInfo) + set (aReleasePdbConf "Release") + else() + set (aReleasePdbConf) + endif() install (FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin\${OCCT_INSTALL_BIN_LETTER}/${PROJECT_NAME}.pdb - CONFIGURATIONS Debug RelWithDebInfo + CONFIGURATIONS Debug ${aReleasePdbConf} RelWithDebInfo DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}") endif() diff --git a/adm/cmake/vardescr.cmake b/adm/cmake/vardescr.cmake index 06dab5b4ca..0733af0ac2 100644 --- a/adm/cmake/vardescr.cmake +++ b/adm/cmake/vardescr.cmake @@ -38,6 +38,9 @@ set (BUILD_ENABLE_FPE_SIGNAL_HANDLER_DESCR Corresponding environment variable (CSF_FPE) can be changed manually in custom.bat/sh scripts without regeneration by CMake.") +set (BUILD_FORCE_RelWithDebInfo_DESCR +"Generate PDB files within normal Release build.") + set (BUILD_USE_PCH_DESCR "Use precompiled headers to accelerate the build. Precompiled headers are generated automatically by Cotire tool.") diff --git a/adm/scripts/cmake_custom.bat.template b/adm/scripts/cmake_custom.bat.template index 51813eaa09..eabc8290b0 100644 --- a/adm/scripts/cmake_custom.bat.template +++ b/adm/scripts/cmake_custom.bat.template @@ -22,6 +22,7 @@ rem set BUILD_RELEASE_DISABLE_EXCEPTIONS=ON rem set BUILD_WITH_DEBUG=OFF rem set BUILD_ENABLE_FPE_SIGNAL_HANDLER=ON rem set BUILD_USE_PCH=OFF +rem set BUILD_FORCE_RelWithDebInfo=OFF rem Use semicolon-separated list of toolkits if you want to disable all modules rem and build only some toolkits. diff --git a/adm/scripts/cmake_gen.bat b/adm/scripts/cmake_gen.bat index 38c6918305..f60e47b129 100644 --- a/adm/scripts/cmake_gen.bat +++ b/adm/scripts/cmake_gen.bat @@ -24,6 +24,7 @@ set BUILD_RELEASE_DISABLE_EXCEPTIONS=ON set BUILD_WITH_DEBUG=OFF set BUILD_ENABLE_FPE_SIGNAL_HANDLER=ON set BUILD_USE_PCH=OFF +set BUILD_FORCE_RelWithDebInfo=OFF set BUILD_MODULE_ApplicationFramework=ON set BUILD_MODULE_DataExchange=ON @@ -71,6 +72,7 @@ cmake -G "%arch_compile%" ^ -D BUILD_WITH_DEBUG:BOOL=%BUILD_WITH_DEBUG% ^ -D BUILD_ENABLE_FPE_SIGNAL_HANDLER:BOOL=%BUILD_ENABLE_FPE_SIGNAL_HANDLER% ^ -D BUILD_USE_PCH:BOOL=%BUILD_USE_PCH% ^ + -D BUILD_FORCE_RelWithDebInfo:BOOL=%BUILD_FORCE_RelWithDebInfo% ^ -D INSTALL_DIR:PATH="%INSTALL_DIR%" ^ -D USE_D3D:BOOL=%USE_D3D% ^ -D USE_FFMPEG:BOOL=%USE_FFMPEG% ^