add CPM_SOURCE_ROOT option (#81)

* add CPM_SOURCE_ROOT option

* update version and readme
This commit is contained in:
Lars Melchior
2019-10-07 16:34:07 +02:00
committed by GitHub
parent 504761fbf2
commit 8625173d8f
2 changed files with 19 additions and 4 deletions

View File

@@ -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). 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. 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=<path to an external download directory>`.
### 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`. 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. If the option `CPM_LOCAL_PACKAGES_ONLY` is set, CPM will emit an error if the dependency is not found locally.

View File

@@ -28,7 +28,7 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR) cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
set(CURRENT_CPM_VERSION 0.12) set(CURRENT_CPM_VERSION 0.13)
if(CPM_DIRECTORY) if(CPM_DIRECTORY)
if(NOT ${CPM_DIRECTORY} MATCHES ${CMAKE_CURRENT_LIST_DIR}) 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_USE_LOCAL_PACKAGES "Use locally installed packages (find_package)" OFF)
option(CPM_LOCAL_PACKAGES_ONLY "Use only locally installed packages" 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(FetchContent)
include(CMakeParseArguments) include(CMakeParseArguments)
@@ -66,6 +66,7 @@ function(CPMAddPackage)
DOWNLOAD_ONLY DOWNLOAD_ONLY
GITHUB_REPOSITORY GITHUB_REPOSITORY
GITLAB_REPOSITORY GITLAB_REPOSITORY
SOURCE_DIR
) )
set(multiValueArgs set(multiValueArgs
@@ -104,6 +105,14 @@ function(CPMAddPackage)
set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION}) set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION})
endif() 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}) list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_TAG ${CPM_ARGS_GIT_TAG})
if(CPM_ARGS_DOWNLOAD_ONLY) if(CPM_ARGS_DOWNLOAD_ONLY)
@@ -150,7 +159,7 @@ function(CPMAddPackage)
endforeach() endforeach()
endif() 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}) CPM_FETCH_PACKAGE(${CPM_ARGS_NAME} ${DOWNLOAD_ONLY})
CPMGetProperties(${CPM_ARGS_NAME}) CPMGetProperties(${CPM_ARGS_NAME})
SET(${CPM_ARGS_NAME}_SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}" PARENT_SCOPE) SET(${CPM_ARGS_NAME}_SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}" PARENT_SCOPE)