-
Notifications
You must be signed in to change notification settings - Fork 173
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
base: master
Are you sure you want to change the base?
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!
cmake/CPM.cmake
Outdated
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20") | ||
cmake_path(GET GIT_EXECUTABLE PARENT_PATH extra_search_path) | ||
cmake_path(GET extra_search_path PARENT_PATH extra_search_path) | ||
else() | ||
get_filename_component(extra_search_path ${GIT_EXECUTABLE} DIRECTORY) | ||
get_filename_component(extra_search_path ${extra_search_path} DIRECTORY) | ||
get_filename_component(extra_search_path ${extra_search_path} DIRECTORY) | ||
endif() |
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.
Do we need the branch for different CMake versions or can we simply use the get_filename_component
version to keep the code more simple?
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 am suspicious get_filename_component
will soon be deprecated and eventually removed. I think we can simplify the code to use the older functions for now, but may still eventually need to update it to this. It may take years for it's removal though, so if your preference is for simpler code I'm fine with that.
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.
Upon further reflection, I believe CMake itself will eventually support PATCHES
for FetchContent()
and this is likely to happen BEFORE get_filename_component()
is deprecated. I'll make the change and run some tests.
This is a functionality that I truly want to see in a release!
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.
Addressed in 523c14a
cmake/CPM.cmake
Outdated
# Convert to absolute path for CMake 3.20 (available since March 3rd, 2021) and later, this may | ||
# cause users with older versions of CMake to strictly call out an absolute path. | ||
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20") | ||
cmake_path(ABSOLUTE_PATH PATCH_FILE) |
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.
Can we not use something like get_filename_component(ABSOLUTE_PATH ${PATCH_FILE} PATCH_FILE)
to be compatible with CMake < 3.20?
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 feel there was a difference between the two, but I can test with get_filename_component
sometime next week.
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.
Addressed in 523c14a
…l cmake versions 3.14 and above.
This PR makes the following changes:
PATCHES
multi-value keyword added toCPMAddPackage()
Example usage:
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: