diff --git a/README.md b/README.md index 4293038..d33f0ac 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,13 @@ To update CPM to the newest version, simply update the script in the project's c For projects with more complex needs and where an extra setup step doesn't matter, it is worth to check out fully featured C++ package managers such as [conan](https://conan.io), [vcpkg](https://github.com/microsoft/vcpkg) or [hunter](https://github.com/ruslo/hunter). Support for package managers is also [planned](https://github.com/TheLartians/CPM/issues/51) for a future version of CPM. -## Local packages +## Options + +### CPM_SOURCE_ROOT + +To avoid re-downloading dependencies, configure the project with the cmake option `-DCPM_SOURCE_ROOT=`. + +### CPM_USE_LOCAL_PACKAGES CPM can be configured to use `find_package` to search for locally installed dependencies first by setting the CMake option `CPM_USE_LOCAL_PACKAGES`. If the option `CPM_LOCAL_PACKAGES_ONLY` is set, CPM will emit an error if the dependency is not found locally. diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index bcdfbd6..51cdbfa 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -28,7 +28,7 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -set(CURRENT_CPM_VERSION 0.12) +set(CURRENT_CPM_VERSION 0.13) if(CPM_DIRECTORY) if(NOT ${CPM_DIRECTORY} MATCHES ${CMAKE_CURRENT_LIST_DIR}) @@ -46,7 +46,7 @@ set(CPM_DRY_RUN OFF CACHE INTERNAL "Don't download or configure dependencies (fo option(CPM_USE_LOCAL_PACKAGES "Use locally installed packages (find_package)" OFF) option(CPM_LOCAL_PACKAGES_ONLY "Use only locally installed packages" OFF) - +set(CPM_SOURCE_ROOT OFF CACHE PATH "Directory to downlaod CPM dependencies") include(FetchContent) include(CMakeParseArguments) @@ -66,6 +66,7 @@ function(CPMAddPackage) DOWNLOAD_ONLY GITHUB_REPOSITORY GITLAB_REPOSITORY + SOURCE_DIR ) set(multiValueArgs @@ -104,6 +105,14 @@ function(CPMAddPackage) set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION}) endif() + set(FETCH_CONTENT_DECLARE_EXTRA_OPTS "") + + if (CPM_SOURCE_ROOT AND NOT DEFINED CPM_ARGS_SOURCE_DIR) + string(TOLOWER ${CPM_ARGS_NAME} lname) + string(REPLACE "-" "_" source_path_name ${lname}) + list(APPEND FETCH_CONTENT_DECLARE_EXTRA_OPTS SOURCE_DIR ${CPM_SOURCE_ROOT}/${source_path_name}) + endif() + list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_TAG ${CPM_ARGS_GIT_TAG}) if(CPM_ARGS_DOWNLOAD_ONLY) @@ -150,7 +159,7 @@ function(CPMAddPackage) endforeach() endif() - CPM_DECLARE_PACKAGE(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION} ${CPM_ARGS_GIT_TAG} "${CPM_ARGS_UNPARSED_ARGUMENTS}") + CPM_DECLARE_PACKAGE(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION} ${CPM_ARGS_GIT_TAG} "${CPM_ARGS_UNPARSED_ARGUMENTS}" ${FETCH_CONTENT_DECLARE_EXTRA_OPTS}) CPM_FETCH_PACKAGE(${CPM_ARGS_NAME} ${DOWNLOAD_ONLY}) CPMGetProperties(${CPM_ARGS_NAME}) SET(${CPM_ARGS_NAME}_SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}" PARENT_SCOPE)