]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
build: do not apply curl debug macros to `tests/server` by default
authorViktor Szakats <commit@vsz.me>
Wed, 12 Mar 2025 21:41:57 +0000 (22:41 +0100)
committerViktor Szakats <commit@vsz.me>
Fri, 14 Mar 2025 11:59:32 +0000 (12:59 +0100)
It seems unnecessary and possibly unexpected to build test servers with
debug-enabled features and memory tracking whenever the tested curl is
built like that (which is a requirement for some tests, so curl is
mostly built like that when running tests.) It also makes building
servers a little bit faster with cmake for the most common cases.

You can apply debug options to `tests/server` with these new options:
- `./configure`: `--enable-server-debug`.
- cmake: `-DENABLE_SERVER_DEBUG`.

Also sync the way we pass these macros in autotools, with CMake builds.
Before this patch, autotools passed them via `curl_config.h`. After this
patch it passes them on the command-line, like cmake builds do.

This patch also make these option no longer passed to examples and
`http/client` in cmake builds, where they were no-ops anyway.

Ref: #15000
Closes #16705

14 files changed:
CMakeLists.txt
configure.ac
docs/INSTALL-CMAKE.md
lib/CMakeLists.txt
lib/Makefile.am
m4/curl-confopts.m4
src/CMakeLists.txt
src/Makefile.am
tests/libtest/CMakeLists.txt
tests/libtest/Makefile.am
tests/server/CMakeLists.txt
tests/server/Makefile.am
tests/unit/CMakeLists.txt
tests/unit/Makefile.am

index 108f76063770400fceab55591667ef689a9d72e0..5cef817cddb144a6c767996966ce8e6f0da9535b 100644 (file)
@@ -290,13 +290,14 @@ if(ENABLE_DEBUG)
   message(WARNING "This curl build is Debug-enabled and insecure, do not use in production.")
 endif()
 option(ENABLE_CURLDEBUG "Enable TrackMemory debug feature" ${ENABLE_DEBUG})
+option(ENABLE_SERVER_DEBUG "Apply curl debug options to test servers" OFF)
 
+set(CURL_DEBUG_MACROS "")
 if(ENABLE_DEBUG)
-  set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "DEBUGBUILD")
+  list(APPEND CURL_DEBUG_MACROS "DEBUGBUILD")
 endif()
-
 if(ENABLE_CURLDEBUG)
-  set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "CURLDEBUG")
+  list(APPEND CURL_DEBUG_MACROS "CURLDEBUG")
 endif()
 
 option(CURL_CLANG_TIDY "Run the build through clang-tidy" OFF)
index c8558c15cbb4da9cc1ef1e24b657355a897a46b4..68adbc998ef6aa22f377531bb8e52e4ad0bc664d 100644 (file)
@@ -49,6 +49,7 @@ CURL_CHECK_OPTION_OPTIMIZE
 CURL_CHECK_OPTION_WARNINGS
 CURL_CHECK_OPTION_WERROR
 CURL_CHECK_OPTION_CURLDEBUG
+AM_CONDITIONAL(CURLDEBUG, test x$want_curldebug = xyes)
 CURL_CHECK_OPTION_SYMBOL_HIDING
 CURL_CHECK_OPTION_ARES
 CURL_CHECK_OPTION_RT
@@ -588,6 +589,25 @@ else
 fi
 AM_CONDITIONAL(BUILD_UNITTESTS, test x$want_unittests = xyes)
 
+dnl Apply curl debug options to test servers
+OPT_SERVER_DEBUG="default"
+AC_ARG_ENABLE(server-debug,
+AS_HELP_STRING([--enable-server-debug],[Enable debug options for test servers])
+AS_HELP_STRING([--disable-server-debug],[Disable debug options for test servers]),
+OPT_SERVER_DEBUG=$enableval)
+case "$OPT_SERVER_DEBUG" in
+  no)
+    dnl --disable-server-debug option used
+    want_server_debug="no"
+    ;;
+  *)
+    dnl --enable-server-debug option used or not specified
+    want_server_debug="no"
+    ;;
+esac
+AC_MSG_RESULT([$want_server_debug])
+AM_CONDITIONAL(ENABLE_SERVER_DEBUG, test x$want_server_debug = xyes)
+
 dnl **********************************************************************
 dnl Compilation based checks should not be done before this point.
 dnl **********************************************************************
index 629118fdf6aa03da66da7dbcb8a5470234e9cb1e..38d1fec1ba4686a21b9f95e1e0eb9030ea588f76 100644 (file)
@@ -245,6 +245,7 @@ target_link_libraries(my_target PRIVATE CURL::libcurl)
 - `ENABLE_CURLDEBUG`:                       Enable TrackMemory debug feature. Default: =`ENABLE_DEBUG`
 - `ENABLE_CURL_MANUAL`:                     Build the man page for curl and enable its `-M`/`--manual` option. Default: `ON`
 - `ENABLE_DEBUG`:                           Enable curl debug features (for developing curl itself). Default: `OFF`
+- `ENABLE_SERVER_DEBUG`:                    Apply curl debug options to test servers. Default: `OFF`
 - `IMPORT_LIB_SUFFIX`:                      Import library suffix. Default: `_imp` for MSVC-like toolchains, otherwise empty.
 - `LIBCURL_OUTPUT_NAME`:                    Basename of the curl library. Default: `libcurl`
 - `PICKY_COMPILER`:                         Enable picky compiler options. Default: `ON`
index 32e4943d08ac6b5ec365a8941ddf677c0654184a..6fd362acaeb413c17f674d7dbd588443ae4e330e 100644 (file)
@@ -24,6 +24,7 @@
 set(LIB_NAME "libcurl")
 set(LIBCURL_OUTPUT_NAME "libcurl" CACHE STRING "Basename of the curl library")
 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "BUILDING_LIBCURL")
+set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}")
 
 configure_file("curl_config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/curl_config.h")
 
index 7edbb9303c0015130f8a0d34d699762ff234a845..209e24511fd84f8509962fca45b8f3fc146e7ab6 100644 (file)
@@ -64,6 +64,12 @@ include Makefile.soname
 AM_CPPFLAGS += -DBUILDING_LIBCURL
 AM_LDFLAGS =
 AM_CFLAGS =
+if DEBUGBUILD
+AM_CPPFLAGS += -DDEBUGBUILD
+endif
+if CURLDEBUG
+AM_CPPFLAGS += -DCURLDEBUG
+endif
 
 # Makefile.inc provides the CSOURCES and HHEADERS defines
 include Makefile.inc
index d667dd9daeae0d2e93f7719e90d8c6dc53349e0f..5149e8a34ae94b8862af6732941a45b6b6e1269a 100644 (file)
@@ -131,7 +131,6 @@ AS_HELP_STRING([--disable-curldebug],[Disable curl debug memory tracking]),
       dnl as a request to disable curldebug.
       if test "$want_debug" = "yes"; then
         AC_MSG_RESULT([(assumed) yes])
-        AC_DEFINE(CURLDEBUG, 1, [to enable curl debug memory tracking])
       else
         AC_MSG_RESULT([no])
       fi
@@ -148,7 +147,6 @@ AS_HELP_STRING([--disable-curldebug],[Disable curl debug memory tracking]),
       dnl --disable-curldebug had been given setting shell variable
       dnl want_curldebug to 'no'.
       want_curldebug="yes"
-      AC_DEFINE(CURLDEBUG, 1, [to enable curl debug memory tracking])
       AC_MSG_RESULT([yes])
       ;;
   esac
@@ -183,7 +181,6 @@ AS_HELP_STRING([--disable-debug],[Disable debug build options]),
     *)
       dnl --enable-debug option used
       want_debug="yes"
-      AC_DEFINE(DEBUGBUILD, 1, [enable debug build options])
       ;;
   esac
   AC_MSG_RESULT([$want_debug])
index d0d5980c3546712eae8088dc2926e8c830ff56f1..289c99c0cfd168b083f6364ceccf0e1e808845c1 100644 (file)
@@ -22,6 +22,7 @@
 #
 ###########################################################################
 set(EXE_NAME curl)
+set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}")
 
 set(_curl_cfiles_gen "")
 set(_curl_hfiles_gen "")
index a97b0bcbee2db3ddbe2990c00e0fb18d6bd493fe..59406def6acd11fa799adbb3b80c7757943b04e6 100644 (file)
@@ -51,6 +51,12 @@ bin_PROGRAMS = curl
 if USE_CPPFLAG_CURL_STATICLIB
 AM_CPPFLAGS += -DCURL_STATICLIB
 endif
+if DEBUGBUILD
+AM_CPPFLAGS += -DDEBUGBUILD
+endif
+if CURLDEBUG
+AM_CPPFLAGS += -DCURLDEBUG
+endif
 
 AM_LDFLAGS =
 if USE_UNICODE
index 60b1bd42f4eeec9d86f69cccbc20e4e3e17eecdb..c0c428f0b20be1d3a0977a680300246110f90a0d 100644 (file)
@@ -80,6 +80,7 @@ foreach(_target IN LISTS LIBTESTPROGS)
     "${PROJECT_SOURCE_DIR}/src"            # for "tool_binmode.h"
     "${PROJECT_SOURCE_DIR}/tests/libtest"  # to be able to build generated tests
   )
+  set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}")
   if(NOT CURL_TEST_BUNDLES)
     set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS ${_upper_target})
   endif()
index cccea6723ed60ab63c21bb471216be662c7b35ae..191064e38f8843cfe547de81142f1c8676756dce 100644 (file)
@@ -65,6 +65,12 @@ noinst_LTLIBRARIES =
 if USE_CPPFLAG_CURL_STATICLIB
 AM_CPPFLAGS += -DCURL_STATICLIB
 endif
+if DEBUGBUILD
+AM_CPPFLAGS += -DDEBUGBUILD
+endif
+if CURLDEBUG
+AM_CPPFLAGS += -DCURLDEBUG
+endif
 
 AM_LDFLAGS =
 AM_CFLAGS =
index b7bd88151e945472cfc19830d9ef86bb8d7e64bd..d0c1b9e0e440d14210d983bc7e3408b9252464d8 100644 (file)
@@ -26,7 +26,7 @@
 curl_transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
 include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
 
-if(ENABLE_CURLDEBUG)
+if(ENABLE_SERVER_DEBUG AND ENABLE_CURLDEBUG)
   set_source_files_properties("../../lib/memdebug.c" "../../lib/curl_multibyte.c" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
 endif()
 
@@ -40,6 +40,9 @@ foreach(_target IN LISTS noinst_PROGRAMS)
     "${PROJECT_SOURCE_DIR}/src"  # for "tool_binmod.h", "tool_xattr.h"
   )
   target_link_libraries(${_target_name} ${CURL_LIBS})
+  if(ENABLE_SERVER_DEBUG)
+    set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}")
+  endif()
   # Test servers simply are standalone programs that do not use libcurl
   # library.  For convenience and to ease portability of these servers,
   # some source code files from the libcurl subdirectory are also used
index fb0d48d57fbf8c56608ad95b349dafbb377c361f..b256ecfa42e0e1cd22ac4a36d858c8d782cb9364 100644 (file)
@@ -45,6 +45,14 @@ CFLAGS += @CURL_CFLAG_EXTRAS@
 if DOING_NATIVE_WINDOWS
 AM_CPPFLAGS += -DCURL_STATICLIB
 endif
+if ENABLE_SERVER_DEBUG
+if DEBUGBUILD
+AM_CPPFLAGS += -DDEBUGBUILD
+endif
+if CURLDEBUG
+AM_CPPFLAGS += -DCURLDEBUG
+endif
+endif
 
 # Makefile.inc provides neat definitions
 include Makefile.inc
index 95f708942ba55d04cfb20dee572a6955a27d7c39..10eafec5913cbeef4c2d9288293d5604abde3416 100644 (file)
@@ -50,6 +50,7 @@ foreach(_target IN LISTS UNITPROGS)
     "${PROJECT_SOURCE_DIR}/src"
     "${PROJECT_SOURCE_DIR}/tests/libtest"
   )
+  set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}")
   if(CURL_TEST_BUNDLES)
     target_include_directories(${_target_name} PRIVATE "${PROJECT_SOURCE_DIR}/tests/unit")
   endif()
index 8f3d3d171e76cde19799e03e4c019a7fcea94d01..e9360447b4d9667672fb65a22fb2e98718d7c085 100644 (file)
@@ -51,6 +51,12 @@ LDADD = $(top_builddir)/src/libcurltool.la   \
         @LIBCURL_PC_LDFLAGS_PRIVATE@ @LIBCURL_PC_LIBS_PRIVATE@
 
 AM_CPPFLAGS += -DCURL_STATICLIB -DUNITTESTS
+if DEBUGBUILD
+AM_CPPFLAGS += -DDEBUGBUILD
+endif
+if CURLDEBUG
+AM_CPPFLAGS += -DCURLDEBUG
+endif
 
 if BUILD_UNITTESTS
 if USE_TEST_BUNDLES