From 8175bcae50af236a8520761ac81fbc5a40c76bc8 Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Tue, 26 May 2026 09:39:23 +0200 Subject: [PATCH] Add CMake option for real debug compiler builds 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. --- CMakeLists.txt | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a1b484..141dc96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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( + $<$:-g3> + $<$:-O0> + $<$:-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)