From bf5e9ebafb925ef8fb22ecb4b1516b7899c68eb4 Mon Sep 17 00:00:00 2001 From: Lars Melchior Date: Mon, 20 May 2019 01:52:55 +0200 Subject: [PATCH] Add DEPENDENCY_ADDED property (#50) * add DEPENDENCY_ADDED property * update examples * Update README.md * Update README.md * Update CPM.cmake * Update README.md --- README.md | 28 ++++++++++++++++++---------- cmake/CPM.cmake | 4 +++- examples/benchmark/CMakeLists.txt | 6 ++++-- examples/json/CMakeLists.txt | 6 ++++-- examples/simple_match/CMakeLists.txt | 6 ++++-- examples/yaml/CMakeLists.txt | 6 +++--- 6 files changed, 36 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index a47ca50..99a53dd 100644 --- a/README.md +++ b/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 - $ -) + target_include_directories(lua + PUBLIC + $ + ) +endif() ``` ## Local packages diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index 5c91b64..50ace86 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.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) diff --git a/examples/benchmark/CMakeLists.txt b/examples/benchmark/CMakeLists.txt index 48293f6..921525a 100644 --- a/examples/benchmark/CMakeLists.txt +++ b/examples/benchmark/CMakeLists.txt @@ -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 ---- diff --git a/examples/json/CMakeLists.txt b/examples/json/CMakeLists.txt index c16a4ac..b91b930 100644 --- a/examples/json/CMakeLists.txt +++ b/examples/json/CMakeLists.txt @@ -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 ---- diff --git a/examples/simple_match/CMakeLists.txt b/examples/simple_match/CMakeLists.txt index 84631c3..e68f785 100644 --- a/examples/simple_match/CMakeLists.txt +++ b/examples/simple_match/CMakeLists.txt @@ -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 ---- diff --git a/examples/yaml/CMakeLists.txt b/examples/yaml/CMakeLists.txt index c91b97c..1237bb1 100644 --- a/examples/yaml/CMakeLists.txt +++ b/examples/yaml/CMakeLists.txt @@ -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 ----