mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-21 19:57:24 -05:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e558d795f9 | ||
|
|
76748fe542 | ||
|
|
e453671327 | ||
|
|
5192f713d2 | ||
|
|
282b98423a | ||
|
|
2ff0f5f58f | ||
|
|
9343f7c69a | ||
|
|
044edb1fd2 | ||
|
|
07a4d626a1 | ||
|
|
0d529f73cd | ||
|
|
96dba3b03c | ||
|
|
ba256b71c1 | ||
|
|
b3a875e2dd |
25
README.md
25
README.md
@@ -4,11 +4,11 @@
|
||||
|
||||
CPM is a simple GIT dependency manager written in CMake. The main use-case is abstracting CMake's `FetchContent` and managing dependencies in small to medium sized projects.
|
||||
|
||||
# Supported projects
|
||||
## Supported projects
|
||||
|
||||
Any project that you can add via `add_subdirectory` should already work with CPM.
|
||||
|
||||
# Usage
|
||||
## Usage
|
||||
|
||||
To add a new dependency to your project simply add the Projects target name, the git URL and the version. If the git tag for this version does not match the pattern `v$VERSION`, then the exact branch or tag can be specified with the `GIT_TAG` argument. CMake options can also be supplied with the package.
|
||||
|
||||
@@ -31,26 +31,30 @@ CPMAddPackage(
|
||||
)
|
||||
|
||||
# add executable
|
||||
set (CMAKE_CXX_STANDARD 17)
|
||||
add_executable(my-project my-project.cpp)
|
||||
set_target_properties(my-project PROPERTIES CXX_STANDARD 17)
|
||||
target_link_libraries(my-project LarsParser)
|
||||
```
|
||||
|
||||
See the [examples directory](https://github.com/TheLartians/CPM/tree/master/examples) for more examples.
|
||||
|
||||
# Adding CPM
|
||||
## Adding CPM
|
||||
|
||||
To add CPM to your current project, simply include add `cmake/CPM.cmake` to your projects `cmake` directory. The command below will perform this automatically.
|
||||
To add CPM to your current project, simply add `cmake/CPM.cmake` to your project's `cmake` directory. The command below will perform this automatically.
|
||||
|
||||
```bash
|
||||
wget -O cmake/CPM.cmake https://raw.githubusercontent.com/TheLartians/CPM/master/cmake/CPM.cmake
|
||||
```
|
||||
|
||||
# Options
|
||||
## Updating CPM
|
||||
|
||||
If you set the CMake option `CPM_REMOTE_PACKAGES_ONLY` to `On`, packages will always be fetched via the URL. Setting `CPM_LOCAL_PACKAGES_ONLY` to `On` will only add packages via `find_package`.
|
||||
To update CPM to the newest version, simply update the script in the project's cmake directory, for example by running the command above. Dependencies using CPM will automatically use the updated script of the outermost project.
|
||||
|
||||
# Advantages
|
||||
## Options
|
||||
|
||||
Setting the CMake option `CPM_USE_LOCAL_PACKAGES` will activate finding packages via `find_package`. If the option `CPM_LOCAL_PACKAGES_ONLY` is set, CPM will only use local packages.
|
||||
|
||||
## Advantages
|
||||
|
||||
- **Small repos** CPM takes care of project dependencies, allowing you to focus on creating small, well-tested frameworks.
|
||||
- **Cross-Plattform** CPM adds projects via `add_subdirectory`, which is compatible with all cmake toolchains and generators.
|
||||
@@ -58,7 +62,8 @@ If you set the CMake option `CPM_REMOTE_PACKAGES_ONLY` to `On`, packages will al
|
||||
- **No installation required** No need to install anything. Just add the script to your project and you're good to go.
|
||||
- **No Setup required** There is a good chance your existing projects already work as CPM dependencies.
|
||||
|
||||
# Limitations
|
||||
## Limitations
|
||||
|
||||
- **First version used** In diamond-shaped dependency graphs (e.g. `A` depends on `C`(v1.1) and `A` depends on `B` depends on `C`(v1.2)) the first added dependency will be used (in this case `C`@1.1). If the current version is older than the version beeing added, or if provided options are incompatible, a CMake warning will be emitted.
|
||||
- **First version used** In diamond-shaped dependency graphs (e.g. `A` depends on `C`(v1.1) and `A` depends on `B` depends on `C`(v1.2)) the first added dependency will be used (in this case `C`@1.1). If the current version is older than the version beeing added, or if provided options are incompatible, a CMake warning will be emitted. To resolve, add the new version of the common dependency to the outer project.
|
||||
- **No auto-update** To update a dependency, version numbers or git tags in the cmake scripts must be adapted manually.
|
||||
- **No pre-built binaries** Unless they are installed or included in the linked repository.
|
||||
|
||||
@@ -1,3 +1,30 @@
|
||||
# TheLartians/CPM - A simple Git dependency manager
|
||||
# =================================================
|
||||
# See https://github.com/TheLartians/CPM for usage and update instructions.
|
||||
#
|
||||
# MIT License
|
||||
#[[ -----------
|
||||
Copyright (c) 2019 Lars Melchior
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
]]
|
||||
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
if(CPM_DIRECTORY)
|
||||
@@ -6,11 +33,13 @@ if(CPM_DIRECTORY)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CPM_VERSION 0.7 CACHE INTERNAL "")
|
||||
|
||||
set(CPM_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "")
|
||||
set(CPM_PACKAGES "" CACHE INTERNAL "")
|
||||
|
||||
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_REMOTE_PACKAGES_ONLY "Always download packages" OFF)
|
||||
|
||||
include(FetchContent)
|
||||
include(CMakeParseArguments)
|
||||
@@ -19,13 +48,8 @@ if(NOT CPM_INDENT)
|
||||
set(CPM_INDENT "CPM:")
|
||||
endif()
|
||||
|
||||
function(CPM_REGISTER_PACKAGE PACKAGE VERSION)
|
||||
LIST(APPEND CPM_PACKAGES ${CPM_ARGS_NAME})
|
||||
function(CPMRegisterPackage PACKAGE VERSION)
|
||||
set(CPM_PACKAGES ${CPM_PACKAGES} CACHE INTERNAL "")
|
||||
CPM_SET_PACKAGE_VERSION(${PACKAGE} ${VERSION})
|
||||
endfunction()
|
||||
|
||||
function(CPM_SET_PACKAGE_VERSION PACKAGE VERSION)
|
||||
set("CPM_PACKAGE_${PACKAGE}_VERSION" ${VERSION} CACHE INTERNAL "")
|
||||
endfunction()
|
||||
|
||||
@@ -43,7 +67,6 @@ function(CPM_PARSE_OPTION OPTION)
|
||||
endfunction()
|
||||
|
||||
function(CPMAddPackage)
|
||||
|
||||
set(oneValueArgs
|
||||
NAME
|
||||
VERSION
|
||||
@@ -56,7 +79,7 @@ function(CPMAddPackage)
|
||||
|
||||
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if (CPM_ARGS_VERSION AND NOT CPM_ARGS_OPTIONS AND NOT ${CPM_REMOTE_PACKAGES_ONLY})
|
||||
if(${CPM_USE_LOCAL_PACKAGES} OR ${CPM_LOCAL_PACKAGES_ONLY})
|
||||
find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION} QUIET)
|
||||
|
||||
if(${CPM_PACKAGE_FOUND})
|
||||
@@ -67,6 +90,10 @@ function(CPMAddPackage)
|
||||
)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(${CPM_LOCAL_PACKAGES_ONLY})
|
||||
message(SEND_ERROR "CPM: ${CPM_ARGS_NAME} not found via find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT CPM_ARGS_VERSION)
|
||||
@@ -87,8 +114,6 @@ function(CPMAddPackage)
|
||||
CPM_PARSE_OPTION(${OPTION})
|
||||
if(NOT "${${OPTION_KEY}}" STREQUAL ${OPTION_VALUE})
|
||||
message(WARNING "${CPM_INDENT} ignoring package option for ${CPM_ARGS_NAME}: ${OPTION_KEY} = ${OPTION_VALUE} (${${OPTION_KEY}})")
|
||||
else()
|
||||
message(STATUS "${CPM_INDENT} NOT ignoring package option for ${CPM_ARGS_NAME}: ${OPTION_KEY} = ${OPTION_VALUE} (${${OPTION_KEY}})")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
@@ -96,7 +121,7 @@ function(CPMAddPackage)
|
||||
return()
|
||||
endif()
|
||||
|
||||
CPM_REGISTER_PACKAGE(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})
|
||||
CPMRegisterPackage(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})
|
||||
|
||||
if (CPM_ARGS_OPTIONS)
|
||||
foreach(OPTION ${CPM_ARGS_OPTIONS})
|
||||
@@ -124,4 +149,4 @@ function (CPM_FETCH_PACKAGE PACKAGE)
|
||||
set(CPM_INDENT "${CPM_INDENT} ${PACKAGE}:")
|
||||
FetchContent_MakeAvailable(${PACKAGE})
|
||||
set(CPM_INDENT "${CPM_OLD_INDENT}")
|
||||
endfunction()
|
||||
endfunction()
|
||||
|
||||
@@ -46,8 +46,8 @@ CPMAddPackage(
|
||||
)
|
||||
|
||||
# add executable
|
||||
set (CMAKE_CXX_STANDARD 17)
|
||||
add_executable(cpm-test-complex main.cpp)
|
||||
set_target_properties(cpm-test-complex PROPERTIES CXX_STANDARD 17)
|
||||
target_link_libraries(cpm-test-complex LHC LarsParser Glue)
|
||||
|
||||
# tests
|
||||
|
||||
@@ -12,8 +12,8 @@ CPMAddPackage(
|
||||
)
|
||||
|
||||
# add executable
|
||||
set (CMAKE_CXX_STANDARD 17)
|
||||
add_executable(cpm-test-simple main.cpp)
|
||||
set_target_properties(cpm-test-simple PROPERTIES CXX_STANDARD 17)
|
||||
target_link_libraries(cpm-test-simple LarsParser)
|
||||
|
||||
# tests
|
||||
|
||||
Reference in New Issue
Block a user