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

Don't unconditionally download in get_cpm.cmake #554

Open
genevieve-me opened this issue Apr 9, 2024 · 5 comments
Open

Don't unconditionally download in get_cpm.cmake #554

genevieve-me opened this issue Apr 9, 2024 · 5 comments

Comments

@genevieve-me
Copy link

The provided get_cpm.cmake template will always try to download from github:

file(DOWNLOAD

This causes builds to fail when run by a sandboxed builder. For example, I was hoping to package ada-url for nixpkgs, which uses your template verbatim, and had to patch it to not download if CPM_DOWNLOAD_LOCATION was set, eg:

-file(DOWNLOAD
+if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
+  file(DOWNLOAD

Would you be open to making such a change upstream? Thanks!

@threeal
Copy link
Contributor

threeal commented Apr 9, 2024

In my opinion, adding the if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) check contradicts the SHA256 option set in the file(DOWNLOAD) command. If the download somehow failed and corrupted but the file exists, it may result in unexpected behavior.

@genevieve-me
Copy link
Author

Thank you for the feedback! I'm not very experienced with CMake, which is why I didn't file this as a PR, but if you have a suggestion for a better way (all that is really necessary here is some way of preventing the download) I'd be happy to test it and create a PR.

@TheLartians
Copy link
Member

TheLartians commented Apr 21, 2024

Hey, thanks for the issue! For sandboxed environments, I recommend vendoring dependencies (and CPM itself) by setting the CPM_SOURCE_CACHE environment to a populated cache directory on the Sandbox machine. If all dependencies are present this should allow configuring the project even without any connection to the internet.

@genevieve-me
Copy link
Author

Thank you for the suggestion! Unfortunately, even with CPM vendored under CPM_SOURCE_CACHE, I was experiencing build failures due to attempted downloads.

@TheLartians
Copy link
Member

TheLartians commented May 8, 2024

@genevieve-me that's unexpected, as one of the goal of this project is to make it simple to work with sandboxed / offline environments. Can you please try if the following works for you?

# while connected to the internet we clone a test project
git clone https://github.com/TheLartians/ModernCppStarter
cd ModernCppStarter
# define the source cache to a local directory or leave as-is if it's already defined
export CPM_SOURCE_CACHE=$(pwd)/cache 
# configure the project (this should populate the cache with CPM and some dependencies of the starter)
cmake -S test -B build
# once finished, delete the build directory to simulate a clean environment
rm -rf build

Now the cache is populated, and we should be able to configure the project without internet connection. With the same CPM_SOURCE_CACHE environment as above, disconnect from the internet (or move the project to a sandbox) and run the following.

# should work offline if the cache is populated
cmake -S test -B build
# we should also be able to build the project
cmake --build build

This works fine on my computer, so I assume that working in sandboxed environments with populated caches should work too. If you encounter issues can you share the full error message together with information about your system, like OS, CMake version etc?

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