Fix CMake compilation with -Wp,-D_FORTIFY_SOURCE=2 flags #12842
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Handle both -D_FORTIFY_SOURCE=2 and -Wp,-D_FORTIFY_SOURCE=2 variants when removing FORTIFY_SOURCE flags for unit test compilation with -O0.
What does this PR do?
Fixes a CMake compilation error that occurs when building GDAL unit tests on systems using hardened compiler flags with the
-Wp,-D_FORTIFY_SOURCE=2
format.The existing code in
autotest/cpp/CMakeLists.txt
only removes the-D_FORTIFY_SOURCE=2
variant when compiling unit tests with-O0
optimization, but doesn't handle the-Wp,-D_FORTIFY_SOURCE=2
variant used by modern hardened build environments. This leaves dangling-Wp,
prefixes that cause compilation to fail with "too many filenames" errors.The fix adds string replacement for both variants to ensure clean flag removal.
What are related issues/pull requests?
Fixes #12840
Tasklist
Environment
Provide environment details, if relevant:
Testing
gdal-fixed-with-Wp.log
gdal-fixed-without-Wp.log
gdal-fixed-no-flags.log