Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: export -DGDAL_DEBUG as PUBLIC for debug builds #11314

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

rouault
Copy link
Member

@rouault rouault commented Nov 20, 2024

Fixes #11311

@SunBlack can you give this a try?

@rouault rouault added backport release/3.10 Backport to release/3.10 branch funded through GSP Work funded through the GDAL Sponsorship Program labels Nov 20, 2024
@SunBlack
Copy link
Contributor

Can confirm: Fix works 👍

gdal.cmake Outdated
@@ -196,6 +196,10 @@ if (MINGW AND BUILD_SHARED_LIBS)
set_target_properties(${GDAL_LIB_TARGET_NAME} PROPERTIES SUFFIX "-${GDAL_SOVERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif ()

# To also export for external users what we did with add_compile_definitions($<$<CONFIG:DEBUG>:DEBUG>)
# in cmake/helpers/GdalCompilationFlags.cmake
target_compile_definitions(${GDAL_LIB_TARGET_NAME} PUBLIC $<$<CONFIG:DEBUG>:DEBUG>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this a good idea. At least as long as the macro is not prefixed with GDAL_ or similar.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, DEBUG is used in public GDAL include files, so ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really needs a prefix...

Copy link
Contributor

@SunBlack SunBlack Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @dg0yt meant to say: DEBUG is such a generic name that you can't be sure that another library isn't using it or being influenced by it in some way. So setting it now could have an effect on other libraries. But if the DEBUG flag is set for the debug build in every case: Why not switch to NDEBUG, which is what the compilers set?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux, I can mix a debug build of my app with a release lib of GDAL...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I've revised the PR to export GDAL_DEBUG for BUILD_TYPE=DEBUG, and I've changed the tests in the public headers to test for "#if defined(DEBUG) || defined(GDAL_DEBUG)``. That should be backwards compatible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux, I can mix a debug build of my app with a release lib of GDAL...

with the C API yes, but not if you use some parts of the C++ API

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux, I can mix a debug build of my app with a release lib of GDAL...

ok, actually you can. I read the reverse. So... if you use a debug build of GDAL with a release lib of your code (or actually a debug one, that doesn't have -DDEBUG when including GDAL) and you use the GDAL C++ API, then you would run into the issue this PR fixes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about also renaming the macro within the cpp files and GdalCompilationFlags.cmake on this way DEBUG could be completely removed with GDAL 4.0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about also renaming the macro within the cpp files and GdalCompilationFlags.cmake on this way DEBUG could be completely removed with GDAL 4.0.

That could probably be done in GDAL 3.11. I didn't want to do the full rename in this PR, to keep it in a state where it is backportable to the 3.10 maintenance branch

@rouault rouault changed the title CMake: also export -DDEBUG as PUBLIC for debug builds CMake: export -DGDAL_DEBUG as PUBLIC for debug builds Nov 20, 2024
@SunBlack SunBlack mentioned this pull request Nov 21, 2024
@rouault rouault merged commit 1b4b295 into OSGeo:master Nov 26, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport release/3.10 Backport to release/3.10 branch funded through GSP Work funded through the GDAL Sponsorship Program
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing DEBUG macro
3 participants