Skip to content

Preserving forwarding of empty string arguments using placeholder strings#699

Open
TheLartians wants to merge 27 commits into
masterfrom
lars/preserve_empty_strings
Open

Preserving forwarding of empty string arguments using placeholder strings#699
TheLartians wants to merge 27 commits into
masterfrom
lars/preserve_empty_strings

Conversation

@TheLartians

@TheLartians TheLartians commented May 5, 2026

Copy link
Copy Markdown
Member

About

This PR builds on #461 to ensure that empty arguments do not get lost, but instead of using eval and replacing the main CPM function with macros it encodes empty arguments with a special string, which gets decoded back to an empty string after parsing. In #461 @ClausKlein raised an unaddressed point about using ARGN in macros leading to unexpected results, not the macro is entirely contained by CPM methods, so it should be safe.

This PR addresses #460 and supersedes #461 and #687.

Copilot summary

This pull request introduces robust handling of empty string arguments in CPM's CMake functions, ensuring that empty arguments are preserved and correctly forwarded through all relevant APIs. This addresses long-standing issues with CMake's argument parsing, especially for packages and commands that require empty arguments. The update also includes new tests to verify this behavior and minor improvements to formatting and test setup.

Argument encoding/decoding and forwarding:

  • Added cpm_encode_empty_arguments, cpm_decode_empty_argument, and cpm_decode_empty_arguments functions to reliably encode and decode empty string arguments, preventing their loss during CMake argument parsing.
  • Updated CPMAddPackage to use the new encoding/decoding functions, ensuring empty arguments are preserved when parsing and forwarding arguments.
  • Modified cpm_declare_fetch to forward arguments, including empty ones, unmodified to FetchContent_Declare.
  • Updated CPMDeclarePackage to store all arguments, including empty strings.
  • Adjusted test input in broken_dependency/CMakeLists.txt.in to quote empty arguments, ensuring they are handled as intended.

Testing improvements:

  • Added a comprehensive test forward_arguments.cmake to verify that empty arguments are correctly encoded, decoded, and forwarded through all relevant CPM and CMake APIs.
  • Improved test isolation in options.cmake by ensuring the test build directory is cleaned before use.

Configuration and formatting:

  • Set line_ending: auto in .cmake-format for consistent line endings across platforms.

@TheLartians TheLartians marked this pull request as draft May 5, 2026 16:15
@TheLartians TheLartians changed the title Preserving forwarding of empty string arguments without using eval Preserving forwarding of empty string arguments without replacing the main entry points with macros May 5, 2026
@TheLartians TheLartians changed the title Preserving forwarding of empty string arguments without replacing the main entry points with macros Preserving forwarding of empty string arguments without replacing the main functions with macros May 5, 2026
@TheLartians TheLartians requested a review from Copilot May 5, 2026 16:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/unit/forward_arguments.cmake Outdated
Comment thread cmake/CPM.cmake Outdated
Comment thread cmake/CPM.cmake
Comment thread cmake/CPM.cmake Outdated
Comment thread cmake/CPM.cmake Outdated
Comment thread test/unit/forward_arguments.cmake Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmake/CPM.cmake
Comment thread cmake/CPM.cmake Outdated
Comment thread cmake/CPM.cmake
@TheLartians TheLartians marked this pull request as ready for review May 5, 2026 18:58
@TheLartians TheLartians changed the title Preserving forwarding of empty string arguments without replacing the main functions with macros Preserving forwarding of empty string arguments using placeholder strings May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants