-
Notifications
You must be signed in to change notification settings - Fork 190
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
Preserving forwarding of empty string arguments #461
Open
CraigHutchinson
wants to merge
7
commits into
cpm-cmake:master
Choose a base branch
from
CraigHutchinson:preserve_empty_strings
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b70460a
Test forwarding of arguments to `FetchCOntent_Declare`
CraigHutchinson cbe5144
Preserving forwarding of empty string arguments
CraigHutchinson b847af6
Support EVAL CODE on CMake <3.18
CraigHutchinson 5c1ce67
Fix docs typo
CraigHutchinson f4fd660
Maintain key-value CMake formatting
CraigHutchinson 3e11e3b
Merge branch 'master' into preserve_empty_strings
CraigHutchinson e6e6524
Merge branch 'master' into preserve_empty_strings
CraigHutchinson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR) | ||
|
||
include(${CPM_PATH}/CPM.cmake) | ||
include(${CPM_PATH}/testing.cmake) | ||
|
||
# Intercept underlying `FetchContent_Declare` | ||
function(FetchContent_Declare) | ||
set_property(GLOBAL PROPERTY last_FetchContent_Declare_ARGN "${ARGN}") | ||
endfunction() | ||
cpm_declare_fetch(PACKAGE VERSION INFO EMPTY "" ANOTHER) | ||
|
||
# TEST:`cpm_declare_fetch` shall forward empty arguments | ||
get_property(last_FetchContent_Declare_ARGN GLOBAL PROPERTY last_FetchContent_Declare_ARGN) | ||
assert_equal("${last_FetchContent_Declare_ARGN}" "PACKAGE;EMPTY;;ANOTHER") | ||
|
||
# TEST:`CPMDeclarePackage` shall store all including empty | ||
CPMDeclarePackage(FOO EMPTY "" ANOTHER) | ||
assert_equal("${CPM_DECLARATION_FOO}" "EMPTY;;ANOTHER") | ||
|
||
# Stub the actual fetch | ||
set(fibonacci_POPULATED YES) | ||
set(fibonacci_SOURCE_DIR ".") | ||
set(fibonacci_BINARY_DIR ".") | ||
macro(FetchContent_GetProperties) | ||
|
||
endmacro() | ||
|
||
# TEST:`CPMAddPackage` shall call `FetchContent_declare` with unmodified arguments including any | ||
# Empty-string arguments | ||
CPMAddPackage( | ||
NAME fibonacci | ||
GIT_REPOSITORY https://github.com/cpm-cmake/testpack-fibonacci.git | ||
VERSION 1.2.3 EMPTY_OPTION "" COMMAND_WITH_EMPTY_ARG foo "" bar | ||
) | ||
get_property(last_FetchContent_Declare_ARGN GLOBAL PROPERTY last_FetchContent_Declare_ARGN) | ||
assert_equal( | ||
"${last_FetchContent_Declare_ARGN}" | ||
"fibonacci;EMPTY_OPTION;;COMMAND_WITH_EMPTY_ARG;foo;;bar;GIT_REPOSITORY;https://github.com/cpm-cmake/testpack-fibonacci.git;GIT_TAG;v1.2.3" | ||
) | ||
|
||
# Intercept underlying `cpm_add_package_multi_arg` | ||
function(cpm_add_package_multi_arg) | ||
set_property(GLOBAL PROPERTY last_cpm_add_package_multi_arg_ARGN "${ARGN}") | ||
endfunction() | ||
|
||
# TEST: CPM Module file shall store all arguments including empty strings | ||
include(${CPM_MODULE_PATH}/Findfibonacci.cmake) | ||
get_property( | ||
last_cpm_add_package_multi_arg_ARGN GLOBAL PROPERTY last_cpm_add_package_multi_arg_ARGN | ||
) | ||
assert_equal( | ||
"${last_cpm_add_package_multi_arg_ARGN}" | ||
"NAME;fibonacci;GIT_REPOSITORY;https://github.com/cpm-cmake/testpack-fibonacci.git;VERSION;1.2.3;EMPTY_OPTION;;COMMAND_WITH_EMPTY_ARG;foo;;bar" | ||
) | ||
|
||
# remove generated files | ||
file(REMOVE_RECURSE ${CPM_MODULE_PATH}) | ||
file(REMOVE ${CPM_PACKAGE_LOCK_FILE}) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is, however, a specific case to be aware of which can result in unexpected behavior. Because macros treat their arguments as string substitutions rather than as variables, if they use ARGN in a place where a variable name is expected, the variable it will refer to will be in the scope from which the macro is called, not the ARGN from the macro’s own arguments.
From chapter 9.2 professional-cmake