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

[ENH] option to use local folder for <dep> if present

Open MuellerSeb opened this issue 1 year ago • 1 comments

Hey there,

ATM I am doing this, to use a local folder for my dependency if it is present (used for source-distribution of our package since users want to be able to compile without internet connection):

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/<dep>")
  set(CPM_<dep>_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/<dep>" CACHE PATH "Local source path for <dep>.")
else()
  set(CPM_<dep>_SOURCE "" CACHE PATH "Local source path for <dep>.")
endif()

Maybe this could be added as an option to CPMAddPackage to clean this up. With this approach, CPM_<dep>_SOURCE can still be overwritten by ccmake and similar.

Cheers, Sebastian

MuellerSeb avatar Jun 22 '23 09:06 MuellerSeb

For vending dependencies I would create a directory <PROJECT_ROOT>/external and set the CPM_SOURCE_CACHE environmental variable to that path.

In case you are not planning to make your project available as a dependency itself, you can also make this the default behaviour by setting CPM_SOURCE_CACHE to ${CMAKE_CURRENT_SOURCE_DIR}/external in the main project's CMakeLists.txt before including CPM.cmake.

TheLartians avatar Jul 12 '23 14:07 TheLartians