CPM.cmake icon indicating copy to clipboard operation
CPM.cmake copied to clipboard

Preserving forwarding of empty string arguments using placeholder strings

Open TheLartians opened this issue 5 months ago • 0 comments

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 avatar May 05 '26 16:05 TheLartians