Skip to content

Commit

Permalink
cmake: fix ENABLE_DEBUG=ON builds in default/release mode
Browse files Browse the repository at this point in the history
`ENABLE_DEBUG=ON` enables curl-level debug features. Building and
running the curl test suite requires setting this option.

Before this patch, while building the `testdeps` target with debug
features on with the default ('Release') CMake config, the build stopped
with this linker error:
```
ld: CMakeFiles/unit1395.dir/unit1395.c.o: in function `test':
unit1395.c:(.text+0x1a0): undefined reference to `dedotdotify'
A failure has been detected in another branch of the parallel make
```
Ref: https://github.com/curl/curl/actions/runs/9037287098/job/24835990826#step:3:2483

It happened because `dedotdotify` compiled as a static function into
`libcurlu` due to the undefined `DEBUGBUILD` macro. Then `unit1395`
failed to link it.

Even though the build requires the `DEBUGBUILD` macro, our CMake logic
defined it when building with CMake's 'Debug' configuration only. That
configuration is not required to build or run the test suite, nor to use
curl-level debug features.

This patch fixes this by always defining `DEBUGBUILD` when setting
`ENABLE_DEBUG=ON`. Decoupling this custom option from the selected CMake
Release/Debug configuration.

This change may also allow dropping Debug mode in AppVeyor CMake builds,
possibly making them build faster and run smoother.

Ref: curl#13583
Closes curl#13592
  • Loading branch information
vszakats committed May 12, 2024
1 parent 5b9955e commit e96f1d6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OF
include(PickyWarnings)

if(ENABLE_DEBUG)
# DEBUGBUILD will be defined only for Debug builds
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS DEBUGBUILD)
set(ENABLE_CURLDEBUG ON)
endif()

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ include_directories(
${CURL_BINARY_DIR}/include # To be able to reach "curl/curl.h"
)

if (ENABLE_CURLDEBUG) # running unittests require curl to compiled with CURLDEBUG
if(ENABLE_CURLDEBUG) # running unittests require curl to compiled with CURLDEBUG
foreach(_testfile ${UNITPROGS})
add_executable(${_testfile} EXCLUDE_FROM_ALL ${_testfile}.c ${UNITFILES})
add_dependencies(testdeps ${_testfile})
Expand Down

0 comments on commit e96f1d6

Please sign in to comment.