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

when use cache the depends lib appeared outside the project in clion

Open oskycar opened this issue 1 year ago • 3 comments

image

My main project is cpm-test. I used CPM to add some libs in lib lib2 directory's CMakelists.txt. when no cache used , the source file was download and showd in cmake-build-debug/_deps dir . But when I set the CPM_SOURCE_CACHE var, all the depends lib was showed outside the project , It seems strange and inconvenient

oskycar avatar Jun 07 '24 08:06 oskycar

That's just where the source code lives, as we currently don't copy it from the cache to the build directory. CLion is correct in showing the outside location as external dependencies are external and shouldn't be touched by users. Not sure if there is a good solution without copying the dependencies.

Copying the cache to build could actually be a valid option in the future, especially for dealing with potential problems with the upcoming patches feature (#558), but for now there is no plan for an implementation.

TheLartians avatar Jun 07 '24 17:06 TheLartians

Personally and at work, I've set the cache to be project specific (<project_root>/extern or <project_root>/out/deps).

This has in my opinion a few advantages: You don't have to think about Patches messing up some other project. The cache doesn't get "polluted" with stuff that isn't needed anymore when deleting a project. In CLion the project overview should be what you expect (though I don't use CLion)

The additional storage space from having the same deps downloaded 10+ times, turned out to be irrelevant.

Avus-c avatar Jun 08 '24 08:06 Avus-c

  1. Add set(CPM_SOURCE_CACHE "${CMAKE_CURRENT_SOURCE_DIR}/.cache/cpm" CACHE STRING "CPM cache path") in your CMakeLists.txt before any other add_subdirectory or CPMAddPackage.
  2. git ignore .cache/

awkr avatar Jun 09 '25 06:06 awkr