Skip to content

Commit

Permalink
add CPM_SOURCE_ROOT option (#81)
Browse files Browse the repository at this point in the history
* add CPM_SOURCE_ROOT option

* update version and readme
  • Loading branch information
TheLartians authored Oct 7, 2019
1 parent 504761f commit 8625173
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<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`.
If the option `CPM_LOCAL_PACKAGES_ONLY` is set, CPM will emit an error if the dependency is not found locally.
Expand Down
15 changes: 12 additions & 3 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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)
Expand All @@ -66,6 +66,7 @@ function(CPMAddPackage)
DOWNLOAD_ONLY
GITHUB_REPOSITORY
GITLAB_REPOSITORY
SOURCE_DIR
)

set(multiValueArgs
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8625173

Please sign in to comment.