mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-17 14:47:30 -05:00
feature: allow URI to use shorthand syntax with additional options (#617)
* feature: add URI to use shorthand syntax with additional options
This allows to combine the shorthand syntax with URI and additional arguments:
```
CPMAddPackage(URI "gh:nlohmann/json@3.9.1" OPTIONS "JSON_BUildTests OFF")
```
This is much shorter than the longer syntax way of writing:
```
CPMAddPackage(
NAME nlohmann_json
VERSION 3.9.1
GITHUB_REPOSITORY nlohmann/json
OPTIONS
"JSON_BuildTests OFF"
)
```
* fix: use shorthand syntax in examples
* test: add test for shorthand syntax with options
* doc: extend README mentioning shorthand syntax with options
* feat: URI keyword also sets EXCLUDE_FROM AND SYSTEM
* doc: more explicit about the behavior of URI
* doc: adjust README accordingly to PR-Review
* test: fix inline documentation of test_simple
* move URI comment
* added new test for shorthand syntax
* reset simple test
* add that URI must be the first argument
---------
Co-authored-by: Lars Melchior <lars.melchior@gmail.com>
This commit is contained in:
committed by
GitHub
parent
97023e8b97
commit
d7614381ab
29
README.md
29
README.md
@@ -88,7 +88,7 @@ If an additional optional parameter `SYSTEM` is set to a truthy value, the SYSTE
|
||||
See the [add_subdirectory ](https://cmake.org/cmake/help/latest/command/add_subdirectory.html?highlight=add_subdirectory)
|
||||
and [SYSTEM](https://cmake.org/cmake/help/latest/prop_tgt/SYSTEM.html#prop_tgt:SYSTEM) target property for details.
|
||||
|
||||
A single-argument compact syntax is also supported:
|
||||
A shorthand syntax is also supported:
|
||||
|
||||
```cmake
|
||||
# A git package from a given uri with a version
|
||||
@@ -112,6 +112,19 @@ CPMAddPackage("https://example.com/my-package-1.2.3.zip#MD5=68e20f674a48be38d60e
|
||||
CPMAddPackage("https://example.com/my-package.zip@1.2.3")
|
||||
```
|
||||
|
||||
Additionally, if needed, extra arguments can be provided while using single argument syntax by using the shorthand syntax with the `URI` specifier.
|
||||
|
||||
```cmake
|
||||
CPMAddPackage(
|
||||
URI "gh:nlohmann/json@3.9.1"
|
||||
OPTIONS "JSON_BuildTests OFF"
|
||||
)
|
||||
```
|
||||
|
||||
The `URI` argument must be the first argument to `CPMAddPackage`.
|
||||
`URI` automatically sets `EXCLUDE_FROM_ALL YES` and `SYSTEM YES`.
|
||||
If this is not desired, `EXCLUDE_FROM_ALL NO` and `SYSTEM NO` can be set afterwards.
|
||||
|
||||
After calling `CPMAddPackage`, 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.
|
||||
@@ -412,11 +425,8 @@ CPMAddPackage("gh:jbeder/yaml-cpp#yaml-cpp-0.6.3@0.6.3")
|
||||
|
||||
```cmake
|
||||
CPMAddPackage(
|
||||
NAME nlohmann_json
|
||||
VERSION 3.9.1
|
||||
GITHUB_REPOSITORY nlohmann/json
|
||||
OPTIONS
|
||||
"JSON_BuildTests OFF"
|
||||
URI "gh:nlohmann/json@3.9.1"
|
||||
OPTIONS "JSON_BuildTests OFF"
|
||||
)
|
||||
```
|
||||
|
||||
@@ -446,8 +456,7 @@ For a working example of using CPM to download and configure the Boost C++ Libra
|
||||
```cmake
|
||||
# the install option has to be explicitly set to allow installation
|
||||
CPMAddPackage(
|
||||
GITHUB_REPOSITORY jarro2783/cxxopts
|
||||
VERSION 2.2.1
|
||||
URI "gh:jarro2783/cxxopts@2.2.1"
|
||||
OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" "CXXOPTS_ENABLE_INSTALL YES"
|
||||
)
|
||||
```
|
||||
@@ -456,9 +465,7 @@ CPMAddPackage(
|
||||
|
||||
```cmake
|
||||
CPMAddPackage(
|
||||
NAME benchmark
|
||||
GITHUB_REPOSITORY google/benchmark
|
||||
VERSION 1.5.2
|
||||
URI "gh:google/benchmark@1.5.2"
|
||||
OPTIONS "BENCHMARK_ENABLE_TESTING Off"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user