From 23aa083cd47b955d8ff9e19525f77cc0a5ca48bf Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Wed, 12 Apr 2023 02:43:13 +0000 Subject: [PATCH] build: support RelWithDebInfo for vcpkg Make some tweaks to the cmake files to support CMAKE_BUILD_TYPE=RelWithDebInfo, release with debug information for MSVC vcpkg builds. Signed-off-by: Rafael Kitover --- CMakeLists.txt | 28 +++++++++++++++++++--------- cmake/FindSDL2.cmake | 2 +- cmake/Set-Toolchain-vcpkg.cmake | 10 ++++++++++ src/wx/CMakeLists.txt | 2 +- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1995f44f..385e5988 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,11 @@ elseif(NOT CMAKE_BUILD_TYPE MATCHES "^(Release|Debug|RelWithDebInfo|MinSizeRel)$ message(FATAL_ERROR "Invalid CMAKE_BUILD_TYPE: '${CMAKE_BUILD_TYPE}', must be one of: 'Release', 'Debug', 'RelWithDebInfo' or 'MinSizeRel'") endif() +# Link debug libs for RelWithDebInfo +if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO "Debug") +endif() + include(CTest) if(BUILD_TESTING) @@ -168,6 +173,14 @@ endif() find_package(SFML 2.4 COMPONENTS network system) +if(CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo) + if(SFML_STATIC_LIBRARIES AND SFML_NETWORK_LIBRARY_STATIC_DEBUG AND SFML_SYSTEM_LIBRARY_STATIC_DEBUG) + set(SFML_LIBRARIES ${SFML_NETWORK_LIBRARY_STATIC_DEBUG} ${SFML_SYSTEM_LIBRARY_STATIC_DEBUG}) + elseif(SFML_NETWORK_LIBRARY_DYNAMIC_DEBUG AND SFML_SYSTEM_LIBRARY_DYNAMIC_DEBUG) + set(SFML_LIBRARIES ${SFML_NETWORK_LIBRARY_DYNAMIC_DEBUG} ${SFML_SYSTEM_LIBRARY_DYNAMIC_DEBUG}) + endif() +endif() + if(SFML_FOUND) set(ENABLE_LINK_DEFAULT ON) endif() @@ -652,9 +665,8 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang AND NOT MSVC endif() if(ENABLE_ASAN) - string(TOLOWER ${CMAKE_BUILD_TYPE} build) - if(NOT build STREQUAL "debug") - message(FATAL_ERROR "asan requires debug build, set -DCMAKE_BUILD_TYPE=Debug") + if(NOT CMAKE_BUILD_TYPE STREQUAL Debug) + message(FATAL_ERROR "asan requires a debug build, set -DCMAKE_BUILD_TYPE=Debug") endif() string(TOLOWER ${ENABLE_ASAN} SANITIZER) @@ -809,9 +821,11 @@ elseif(MSVC) set(runtime "/MD") endif() - if(CMAKE_BUILD_TYPE STREQUAL Debug) + if(CMAKE_BUILD_TYPE MATCHES "^(Debug|RelWithDebInfo)$") set(runtime "${runtime}d") + endif() + if(CMAKE_BUILD_TYPE STREQUAL Debug) add_compiler_flags(${runtime} /ZI /W4 /Ob0 /Od /RTC1 /DDEBUG /EHsc) else() # Enable severe warnings for release builds, but suppress macro @@ -819,11 +833,7 @@ elseif(MSVC) add_compiler_flags(/W1 /wd4005 /DNDEBUG /EHsc) if(CMAKE_BUILD_TYPE STREQUAL Release) - if(X86_32) - add_compiler_flags(${runtime} /O2 /Ob3) - else() - add_compiler_flags(${runtime} /O2 /Ob3) - endif() + add_compiler_flags(${runtime} /O2 /Ob3) elseif(CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo) add_compiler_flags(${runtime} /Zi /Ob1) elseif(CMAKE_BUILD_TYPE STREQUAL MinSizeRel) diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake index ed47bcc0..35794eff 100644 --- a/cmake/FindSDL2.cmake +++ b/cmake/FindSDL2.cmake @@ -169,7 +169,7 @@ ENDIF(NOT APPLE) IF(MINGW) SET(MINGW32_LIBRARY -lmingw32 CACHE STRING "MinGW library") - IF(NOT CMAKE_BUILD_TYPE STREQUAL Debug) + if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|RelWithDebInfo)$") SET(MINGW32_LIBRARY ${MINGW32_LIBRARY} -mwindows) ENDIF() ENDIF(MINGW) diff --git a/cmake/Set-Toolchain-vcpkg.cmake b/cmake/Set-Toolchain-vcpkg.cmake index 3b65195e..4371d4d4 100644 --- a/cmake/Set-Toolchain-vcpkg.cmake +++ b/cmake/Set-Toolchain-vcpkg.cmake @@ -349,4 +349,14 @@ endfunction() vcpkg_set_toolchain() +# Make vcpkg use debug libs for RelWithDebInfo +set(orig_build_type ${CMAKE_BUILD_TYPE}) + +if(CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo) + set(CMAKE_BUILD_TYPE Debug) +endif() + include(${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) + +set(CMAKE_BUILD_TYPE ${orig_build_type}) +unset(orig_build_type) diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index 7399a86c..fe1a975f 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -1174,7 +1174,7 @@ if(NOT TRANSLATIONS_ONLY) unset(pdb_file) - if(MSVC AND CMAKE_BUILD_TYPE STREQUAL Debug) + if(MSVC AND CMAKE_BUILD_TYPE MATCHES "^(Debug|RelWithDebInfo)$") set(pdb_file visualboyadvance-m.pdb) endif()