-
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
Adding PATCHES keyword. #558
Conversation
@ScottBailey I tried this For my own setup it works as expected: It applies patches But with docker linux I got a bug : It doesn't apply patches. Here's the branch with my attempt to test it. Try I don't know why in the docker image it fails and on my native machine it works correctly. We need further investigation. |
Hm, it seems removing CPM_SOURCE_CACHE triggers the error |
Cool, thanks! If I have time, I'll investigate tomorrow. Truthfully, patching in CMake has a lot of problems. It's not going to work in all cases. Where it fails, Ultimately, it makes dependency management much more convenient and intuitive. |
I tried some debugging when it happens ( when CPM_SOURCE_CACHE is not set) It seems to not invoke your function because of an if statement |
Good catch, I think I may have fixed it in 311cd3f. |
Yep, it seems to work now. Good job! |
Will close #494 |
The PATCHES command is currently a gaping hole in CMake's @Gerodote Please feel free to review and comment on the change. |
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.
Hey, thanks a lot for adding this feature and a test case, it does look very useful! In general this looks very good, I just have a few questions about potential code simplifications.
set(CPM_ARGS_UNPARSED_ARGUMENTS | ||
${temp_list} | ||
PARENT_SCOPE | ||
) |
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.
Generally, if modifying the parent scope, I feel it would be a good idea to provide the variable name in the parent as an argument to the function to make it easier for us to read the called function. Do you think it would make sense here as well?
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 not sure I understand the suggestion? Can you point me to an example?
In this case, we put cpm_add_patches
into a function to keep the code more readable. I suppose we could send CPM_ARGS_UNPARSED_ARGUMENTS
in as an argument, but I feel like the documentation would always be VARIABLE_TO_UPDATE _must_ _be_ CPM_ARGS_UNPARSED_ARGUMENTS
. This could be more confusing overall, I think.
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.
@TheLartians 523c14a addresses the other comments, but I'm not sure what to do here... Suggestions? Thanks!
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 see your point that the function is basically just an outsourced section of a larger function, but in general I like to have clearly defined input and outputs in functions - in CMake's case using arguments so the caller can decide what goes in and comes out. In my experience ist helps a lot with readability. In any way it's just a style preference and not a blocker for this PR.
…l cmake versions 3.14 and above.
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.
Thanks again for the feature and the changes!
Looks great and I'm happy that we no longer run different code based on the current CMake version! I have two small comments, both of which are not blocking merging the PR.
I'll keep the PR open a bit in case you want to make changes and release the feature in the next days.
set(CPM_ARGS_UNPARSED_ARGUMENTS | ||
${temp_list} | ||
PARENT_SCOPE | ||
) |
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 see your point that the function is basically just an outsourced section of a larger function, but in general I like to have clearly defined input and outputs in functions - in CMake's case using arguments so the caller can decide what goes in and comes out. In my experience ist helps a lot with readability. In any way it's just a style preference and not a blocker for this PR.
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.
This looks great, thanks again for taking the time to implement this feature and the changes requested!
Feature is released in |
This PR makes the following changes:
PATCHES
multi-value keyword added toCPMAddPackage()
example/highway
to show real world usageExample usage:
CPMAddPackage( NAME src_lib URL file:///home/bailey/research/CPM/src_lib.tar URL_HASH SHA256=0ce4bb954871b9d0250e5edfdd288dc44b295db60b2b3b832668eab52763e99b PATCHES 000-srclib-2.patch 000-srclib-3.patch )
Patches are applied in the order listed using the
patch
executable. In case of a Windows host, ifpatch.exe
is not immediately found, a second search forpatch.exe
alongsidegit.exe
is performed.This code change is essentially syntactical sugar. We take the element(s) from
PATCHES
and put them together with&&
s behind aPATCH_COMMAND
that is added toCPM_ARGS_UNPARSED_ARGUMENTS
.This functionality is available manually, but it's quite ugly.
The above command written manually looks something like this: