-
Notifications
You must be signed in to change notification settings - Fork 188
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
base: master
Are you sure you want to change the base?
Preserving forwarding of empty string arguments #461
Conversation
43f9f96
to
477d827
Compare
So the code using Potential resolution is to fix <3.18 by passing arguments the normal way and maybe warn when empty-values are provided as arguments as not-supported etc. TBC |
98782df
to
be08173
Compare
CI Integration is failing due to. @TheLartians is this something CI related or some side-effect of this change?
|
From the diff of the PR it seems the |
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.
I'm having a hard time understanding this PR. To be sure, the issue is that it is currently impossible to disable recursive cloning using FetchContent
?
- IMO the solution replacing the whole
CPMAddPackage
call with something usingeval
looks complicated and potentially risky for such a niche issue. Is there an easier way to handle it? E.g. in here it was recommended to simply point the flag to a non-submodule directory instead. - Could you add a test case to check that it works as intended?
20579 is unfortunately just a hack which doesn't fit with user expectations imho. CMake applied the fix to that in https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4729 which resolved this behavior for Internally using EVAL feels somewhat hacky but it appears to be the defacto workaround given the language limitations from what I can see!
💯 I will be updating and provide additional tests soon. |
I applied the same fix as is used under |
303ae81
to
f4fd660
Compare
Also: - Support cmake-format on Windows by using auto lione-ending
Unit test added - Fails pre-changes and all passing post-fixes (Shall note that |
Thanks for adding the test case! What do you think about using placeholder arguments instead of eval as suggested here? |
That sounds great, I will take a deeper look really soon. It would be nice to not need Eval, albeit that is was used internally for CMake it doesn't mean it's the best and only option. |
What is the state of this MR? We have problems to prevent the cloning of git submodules using this CMP0097 CMake policy. i.e.: # NOTE(CK): Set GIT_SUBMODULES to empty string to NOT initializes submodules!
cmake_policy(SET CMP0097 NEW)
CPMAddPackage(
NAME project_options
GIT_TAG v0.30.0
GITHUB_REPOSITORY aminya/project_options
# FIXME: GIT_SUBMODULES ""
GIT_SUBMODULES "docs"
# NOTE(CK): Workaround existing dir to prevent load of submodule
) |
@TheLartians Appologies I have changed roles and not using CMake for a while ( 😢 ) and forgot to review the alternative approach. I did have a look and wasn't quite as keen on it as the implementation needed somewhat more time to decipher so not sure its as easy to maintain. May I propose that we use the approach wihtin this PR to unblock @ClausKlein and the non-eval alternative implementation could be reviewed as a separate PR improving this feature? |
I may be a bit too paranoid, but using a mechanism like eval for something simple like argument forwarding leaves me with a bad feeling. In my suggestion we essentially replace empty arguments using a placeholder string and remove it right before forwarding them. I agree that it does add a bit more code and complexity than your version, but with proper docstrings and tests cases I hope that maintainability shouldn't be too big of an issue for this. |
No!ExternalProject have a lot of parameters and with just every
I.e.: |
What is about this MR? Perhaps this helps to find a solution: forwarding-command-arguments-in-cmake |
macro(CPMAddPackage) | ||
set(__ARGN "${ARGN}") | ||
list(LENGTH __ARGN __ARGN_Length) | ||
if(__ARGN_Length EQUAL 1) | ||
cpm_add_package_single_arg(${ARGN}) | ||
else() | ||
# Forward preserving empty string arguments | ||
# (https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4729) | ||
set(__ARGN_Quoted) | ||
foreach(__ARG IN LISTS __ARGN) | ||
string(APPEND __ARGN_Quoted " [==[${__ARG}]==]") | ||
endforeach() | ||
cpm_cmake_eval("cpm_add_package_multi_arg( ${__ARGN_Quoted} )") | ||
endif() | ||
endmacro() |
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
Hi. Have we reached a consensus regarding this PR yet? It seems we have either this version or this alternative as a possibility? Personally if the upstream FetchContent module is using Without this feature it's currently impossible to disable cloning submodules with CPM, which can add quite a bit of extra things to download during project configuration. |
Yeah, I agree that going with the eval mechanism for now is ok, considering it is blocking an important feature. I still want to double-check the PR before, but unfortunately I do not have a lot of time at the moment. |
Background
This PR solves CPM issue #460
Empty-string arguments are not handled by Cmake well. There is a workaround here that is a hack for one specific parameter
GIT_SUBMODULES
https://gitlab.kitware.com/cmake/cmake/-/issues/20579 but there is also a proper fix to forwarding empty-string arguments applied under https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4729 which closed the Issue. CPM needs the same/similar also.This PR
This PR mirrors the changes in https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4729 so that CPM will forward all arguments onto
FetchContent
>ExternalProject
unmodified when they contain empty string argumentsChanges
cmake_parse_arguments(PARSE_ARGV
which supports Empty-string arguments e.g. key-value pairs such asGIT_SUBMODULES ""
cmake_language(EVAL
for perfect-forwarding of empty-string argument listsAlso:
Separate concern
For separate PR (future):
CPMFindPackage
not updatedToDO
package-lock_prettify
TYPO-Fixed