mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-16 22:27:41 -05:00
Add DEPENDENCY_ADDED property (#50)
* add DEPENDENCY_ADDED property * update examples * Update README.md * Update README.md * Update CPM.cmake * Update README.md
This commit is contained in:
28
README.md
28
README.md
@@ -29,7 +29,11 @@ The origin is usually specified by a `GIT_REPOSITORY`, but [svn revisions and di
|
||||
If `GIT_TAG` hasn't been explicitly specified it defaults to `v(VERSION)`, a common convention for github projects.
|
||||
`GIT_TAG` can also be set to a branch name such as `master` to download the most recent version.
|
||||
|
||||
Besides downloading and to configuring the dependency, the variables `(DEPENDENCY)_SOURCE_DIR` and `(DEPENDENCY)_BINARY_DIR` are defined in the local scope to point to the source and binary directory of the dependency, where `(DEPENDENCY)` is the name of the dependency.
|
||||
Besides downloading and to configuring the dependency, the following variables are defined in the local scope, where `(DEPENDENCY)` is the name of the dependency.
|
||||
|
||||
- `(DEPENDENCY)_SOURCE_DIR` is the path to the source of the dependency.
|
||||
- `(DEPENDENCY)_BINARY_DIR` is the path to the build directory of the dependency.
|
||||
- `(DEPENDENCY)_ADDED` is set to `YES` if the dependency has not been added before, otherwise it is set to `NO`.
|
||||
|
||||
## Full Example
|
||||
|
||||
@@ -98,7 +102,7 @@ CPMAddPackage(
|
||||
GIT_REPOSITORY https://github.com/google/benchmark.git
|
||||
VERSION 1.4.1
|
||||
OPTIONS
|
||||
"BENCHMARK_ENABLE_TESTING Off"
|
||||
"BENCHMARK_ENABLE_TESTING Off"
|
||||
)
|
||||
|
||||
# needed to compile with C++17
|
||||
@@ -118,8 +122,10 @@ CPMAddPackage(
|
||||
URL_HASH SHA256=69cc88207ce91347ea530b227ff0776db82dcb8de6704e1a3d74f4841bc651cf
|
||||
)
|
||||
|
||||
add_library(nlohmann_json INTERFACE)
|
||||
target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR})
|
||||
if (nlohmann_json_ADDED)
|
||||
add_library(nlohmann_json INTERFACE)
|
||||
target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR})
|
||||
endif()
|
||||
```
|
||||
|
||||
### [Lua](https://www.lua.org)
|
||||
@@ -134,13 +140,15 @@ CPMAddPackage(
|
||||
DOWNLOAD_ONLY YES
|
||||
)
|
||||
|
||||
FILE(GLOB lua_sources ${lua_SOURCE_DIR}/*.c)
|
||||
add_library(lua STATIC ${lua_sources})
|
||||
if (lua_ADDED)
|
||||
FILE(GLOB lua_sources ${lua_SOURCE_DIR}/*.c)
|
||||
add_library(lua STATIC ${lua_sources})
|
||||
|
||||
target_include_directories(lua
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${lua_SOURCE_DIR}>
|
||||
)
|
||||
target_include_directories(lua
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${lua_SOURCE_DIR}>
|
||||
)
|
||||
endif()
|
||||
```
|
||||
|
||||
## Local packages
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
set(CURRENT_CPM_VERSION 0.9)
|
||||
set(CURRENT_CPM_VERSION 0.10)
|
||||
|
||||
if(CPM_DIRECTORY)
|
||||
if(NOT ${CPM_DIRECTORY} MATCHES ${CMAKE_CURRENT_LIST_DIR})
|
||||
@@ -139,6 +139,7 @@ function(CPMAddPackage)
|
||||
CPMGetProperties(${CPM_ARGS_NAME})
|
||||
SET(${CPM_ARGS_NAME}_SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}" PARENT_SCOPE)
|
||||
SET(${CPM_ARGS_NAME}_BINARY_DIR "${${CPM_ARGS_NAME}_BINARY_DIR}" PARENT_SCOPE)
|
||||
SET(${CPM_ARGS_NAME}_ADDED NO PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
@@ -156,6 +157,7 @@ function(CPMAddPackage)
|
||||
CPMGetProperties(${CPM_ARGS_NAME})
|
||||
SET(${CPM_ARGS_NAME}_SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}" PARENT_SCOPE)
|
||||
SET(${CPM_ARGS_NAME}_BINARY_DIR "${${CPM_ARGS_NAME}_BINARY_DIR}" PARENT_SCOPE)
|
||||
SET(${CPM_ARGS_NAME}_ADDED YES PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function (CPM_DECLARE_PACKAGE PACKAGE VERSION GIT_TAG)
|
||||
|
||||
@@ -18,8 +18,10 @@ CPMAddPackage(
|
||||
"BENCHMARK_ENABLE_TESTING Off"
|
||||
)
|
||||
|
||||
# patch google benchmark target
|
||||
set_target_properties(benchmark PROPERTIES CXX_STANDARD 17)
|
||||
if (benchmark_ADDED)
|
||||
# patch google benchmark target
|
||||
set_target_properties(benchmark PROPERTIES CXX_STANDARD 17)
|
||||
endif()
|
||||
|
||||
# ---- Executable ----
|
||||
|
||||
|
||||
@@ -12,8 +12,10 @@ CPMAddPackage(
|
||||
URL_HASH SHA256=69cc88207ce91347ea530b227ff0776db82dcb8de6704e1a3d74f4841bc651cf
|
||||
)
|
||||
|
||||
add_library(nlohmann_json INTERFACE)
|
||||
target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR})
|
||||
if(nlohmann_json_ADDED)
|
||||
add_library(nlohmann_json INTERFACE)
|
||||
target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
# ---- Executable ----
|
||||
|
||||
|
||||
@@ -11,8 +11,10 @@ CPMAddPackage(
|
||||
DOWNLOAD_ONLY True
|
||||
)
|
||||
|
||||
add_library(simple_match INTERFACE IMPORTED)
|
||||
target_include_directories(simple_match INTERFACE "${simple_match_SOURCE_DIR}/include")
|
||||
if(simple_match_ADDED)
|
||||
add_library(simple_match INTERFACE IMPORTED)
|
||||
target_include_directories(simple_match INTERFACE "${simple_match_SOURCE_DIR}/include")
|
||||
endif()
|
||||
|
||||
# ---- Executable ----
|
||||
|
||||
|
||||
@@ -7,15 +7,15 @@ include(../../cmake/CPM.cmake)
|
||||
CPMAddPackage(
|
||||
NAME yaml-cpp
|
||||
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
|
||||
# 0.6.2 uses old CMake syntax
|
||||
# 0.6.2 uses depricated CMake syntax
|
||||
VERSION 0.6.3
|
||||
# 0.6.3 not released yet
|
||||
# 0.6.3 is not released yet, so use the most recent commit
|
||||
GIT_TAG 012269756149ae99745b6dafefd415843d7420bb
|
||||
OPTIONS
|
||||
"YAML_CPP_BUILD_TESTS Off"
|
||||
"YAML_CPP_BUILD_CONTRIB Off"
|
||||
"YAML_CPP_BUILD_TOOLS Off"
|
||||
)
|
||||
)
|
||||
|
||||
# ---- Executable ----
|
||||
|
||||
|
||||
Reference in New Issue
Block a user