CPM.cmake icon indicating copy to clipboard operation
CPM.cmake copied to clipboard

Clarification on "offline" builds

Open LnnrtS opened this issue 4 years ago • 2 comments

As I understood the documentation, I should be able to configure a cmake project with CPM packages without internet access as long as the I am using a local cache and it contains the package in the version needed.

One question I have about this: when I specify GIT_TAG master how does it know if the cache is still valid without checking online?

When I try to use it that way without internet access, it actually fails somewhere in the FetchContent module while trying to access the online repository. (I checked the cache is active, populated and CPM shows it is finding a cache entry).

So the "offline" mode only works if you specify a commit hash? Would be good to add this to the documentation I think.

LnnrtS avatar Nov 23 '20 15:11 LnnrtS

Hey, thanks for the question! The issue seems to be that when the GIT_TAG is referencing a branch rather than a specific commit or tag, FetchContent will try to fetch the most recent version when updating the build. Note that the update step can be manually disabled by providing the corresponding configuration arguments (see the FetchContent docs).

I would however recommend to always specify a specific commit or git tag, as it will lock the dependencies version. This will enable full offline support and also guarantee that your project will always be buildable and run as intended in the future.

TheLartians avatar Nov 26 '20 17:11 TheLartians

Hi, I had the same problem. What i did :

  1. Write a "dumb" PING repository that CMake try to download and if it can't it supposes you are offline : https://github.com/TestingRepositories/Ping
  2. Add this in my cmake folder https://github.com/flagarde/CMakeCM/blob/master/modules/Ping.cmake
  3. Use this to fill FETCHCONTENT_UPDATES_DISCONNECTED , for example :

CPMFindPackage(NAME doctest GITHUB_REPOSITORY ${DOCTEST_REPOSITORY} GIT_TAG ${DOCTEST_VERSION} FETCHCONTENT_UPDATES_DISCONNECTED ${IS_OFFLINE} OPTIONS ${DOCTEST_OPTIONS} )

flagarde avatar Dec 18 '20 10:12 flagarde