Skip to content
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

Skip fetch only works when CPM_SOURCE_CACHE is defined #577

Open
ScottBailey opened this issue Jul 27, 2024 · 2 comments
Open

Skip fetch only works when CPM_SOURCE_CACHE is defined #577

ScottBailey opened this issue Jul 27, 2024 · 2 comments

Comments

@ScottBailey
Copy link
Contributor

ScottBailey commented Jul 27, 2024

When the environment variable CPM_SOURCE_CACHE is set, re-running cmake does not cause a fetch and patch.

When unset, fetch and patch both occur.

The problem observed (see #572 for more discussion) is that the unset path fetch does not overwrite the source and so the patch command fails.

#572 suggests a fix that could ignore errors during patching. I think this could be an issue when a user is testing version updates; it would be nice if we just, say, updated package A to latest version and running CMake told us the patches were incompatible/not applied. I don't think -t reports that?

In my testing, I see that when the environment variable is set, we skip the fetch and patch steps. Maybe we can add a cache variable to indicate the initial fetch and patch skips were successful?

Recreation of this is relatively simple, see https://github.com/ScottBailey/cpm-cmake-test-577 for an automated working example.

@lemire

@wolfpld
Copy link

wolfpld commented Sep 27, 2024

A simple solution seems to be to always enable the cache.

--- a/cmake/CPM.cmake
+++ b/cmake/CPM.cmake
@@ -154,7 +154,7 @@ set(CPM_DRY_RUN
 if(DEFINED ENV{CPM_SOURCE_CACHE})
   set(CPM_SOURCE_CACHE_DEFAULT $ENV{CPM_SOURCE_CACHE})
 else()
-  set(CPM_SOURCE_CACHE_DEFAULT OFF)
+  set(CPM_SOURCE_CACHE_DEFAULT ${CMAKE_CURRENT_BINARY_DIR}/.cpm-cache)
 endif()
 
 set(CPM_SOURCE_CACHE

@lemire
Copy link
Contributor

lemire commented Sep 30, 2024

Intriguing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants