Add CMake option for real debug compiler builds
All checks were successful
Source release / source-package (push) Successful in 45s

Keep the existing MARS debug logging switch separate from compiler
debug flags. ENABLE_DEBUG still controls the legacy DO_DEBUG/XDPRINTF
code paths, while the new ENABLE_DEBUG_BUILD option enables a real
debug build with -g3, -O0 and -fno-omit-frame-pointer.

When ENABLE_DEBUG_BUILD is set on single-config generators, CMake also
forces CMAKE_BUILD_TYPE=Debug so gdb/valgrind builds can be enabled
without manually passing compiler flags.
This commit is contained in:
Mario Fetka
2026-05-26 09:39:23 +02:00
parent 8017c0c078
commit 8175bcae50

View File

@@ -60,8 +60,9 @@ INCLUDE(${CMAKE_ROOT}/Modules/GNUInstallDirs.cmake)
INCLUDE(${CMAKE_MODULE_PATH}/MarsNweInstallDirs.cmake)
# Add options for build
option(ENABLE_DEBUG "Should we build with Debug?" ON)
option(ENABLE_DEBUG_DOSUTILS "Should we build with Mars Nwe Dosutils Debugging?" OFF)
option(ENABLE_DEBUG "Compile in MARS NWE debug logging code (DO_DEBUG)" OFF)
option(ENABLE_DEBUG_BUILD "Build with debug compiler flags (-g3 -O0 -fno-omit-frame-pointer)" OFF)
option(ENABLE_DEBUG_DOSUTILS "Enable NCP 17/02 debugging support for mars_dosutils" OFF)
option(ENABLE_INTERNAL_RIP_SAP "Should we build Mars Nwe with Internal Router?" ON)
option(ENABLE_SHADOW_PWD "Should we build Mars Nwe with Shadow Password Support?" ON)
option(ENABLE_QUOTA_SUPPORT "Should we build Mars Nwe with Quota Support?" ON)
@@ -72,6 +73,28 @@ option(MARS_NWE_BUILD_DOSUTILS "Build DOS client utilities with Open Watcom" OFF
set(MARS_NWE_SMART_ADMIN_GROUP "root" CACHE STRING "Unix group allowed to log in to the SMArT/nwwebui admin interface")
# ENABLE_DEBUG controls the legacy DO_DEBUG code paths used by XDPRINTF().
# ENABLE_DEBUG_BUILD is separate and only changes compiler flags / build type.
# This allows release builds with compiled-in Mars debug logging, and also
# explicit -g/-O0 builds when debugging the server with gdb or valgrind.
if(ENABLE_DEBUG_BUILD)
if(NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
endif()
add_compile_options(
$<$<COMPILE_LANGUAGE:C>:-g3>
$<$<COMPILE_LANGUAGE:C>:-O0>
$<$<COMPILE_LANGUAGE:C>:-fno-omit-frame-pointer>
)
endif()
if(NOT CMAKE_CONFIGURATION_TYPES)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "RelWithDebInfo" "MinSizeRel")
endif()
IF (ENABLE_DEBUG)
SET (MARS_NWE_DEBUG "1")
ELSE (ENABLE_DEBUG)