Preserving forwarding of empty string arguments using placeholder strings
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, andcpm_decode_empty_argumentsfunctions to reliably encode and decode empty string arguments, preventing their loss during CMake argument parsing. - Updated
CPMAddPackageto use the new encoding/decoding functions, ensuring empty arguments are preserved when parsing and forwarding arguments. - Modified
cpm_declare_fetchto forward arguments, including empty ones, unmodified toFetchContent_Declare. - Updated
CPMDeclarePackageto store all arguments, including empty strings. - Adjusted test input in
broken_dependency/CMakeLists.txt.into quote empty arguments, ensuring they are handled as intended.
Testing improvements:
- Added a comprehensive test
forward_arguments.cmaketo verify that empty arguments are correctly encoded, decoded, and forwarded through all relevant CPM and CMake APIs. - Improved test isolation in
options.cmakeby ensuring the test build directory is cleaned before use.
Configuration and formatting:
- Set
line_ending: autoin.cmake-formatfor consistent line endings across platforms.