cpm-cmake / CPM.cmake

📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

MuellerSeb opened this issue · 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

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.