-
Notifications
You must be signed in to change notification settings - Fork 208
feature: allow URI to use shorthand syntax with additional options #617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5483ab9
feature: add URI to use shorthand syntax with additional options
SGSSGene 0d48d18
fix: use shorthand syntax in examples
SGSSGene 360f5bb
test: add test for shorthand syntax with options
SGSSGene dcc8982
doc: extend README mentioning shorthand syntax with options
SGSSGene 1f3dd93
feat: URI keyword also sets EXCLUDE_FROM AND SYSTEM
SGSSGene 1f05115
doc: more explicit about the behavior of URI
SGSSGene e1ae7c2
doc: adjust README accordingly to PR-Review
SGSSGene e372127
test: fix inline documentation of test_simple
SGSSGene ee09aa1
move URI comment
TheLartians 89bab9a
added new test for shorthand syntax
TheLartians 29062cf
reset simple test
TheLartians 3012a10
add that URI must be the first argument
TheLartians File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected]") | ||
``` | ||
|
||
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/[email protected]" | ||
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#[email protected]") | |
|
||
```cmake | ||
CPMAddPackage( | ||
NAME nlohmann_json | ||
VERSION 3.9.1 | ||
GITHUB_REPOSITORY nlohmann/json | ||
OPTIONS | ||
"JSON_BuildTests OFF" | ||
URI "gh:nlohmann/[email protected]" | ||
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/[email protected]" | ||
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/[email protected]" | ||
OPTIONS "BENCHMARK_ENABLE_TESTING Off" | ||
) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
require_relative './lib' | ||
|
||
class TestShorthandSyntax < IntegrationTest | ||
|
||
def get_project_binaries prj | ||
exe_dir = File.join(prj.bin_dir, 'bin') | ||
assert File.directory? exe_dir | ||
return Dir[exe_dir + '/**/*'].filter { | ||
# on multi-configuration generators (like Visual Studio) the executables will be in bin/<Config> | ||
# also filter-out other artifacts like .pdb or .dsym | ||
!File.directory?(_1) && File.stat(_1).executable? | ||
}.map { | ||
# remove .exe extension if any (there will be one on Windows) | ||
File.basename(_1, '.exe') | ||
}.sort | ||
end | ||
|
||
def test_create_with_commit_sha | ||
prj = make_project from_template: 'using-adder' | ||
prj.create_lists_from_default_template package: | ||
'CPMAddPackage("gh:cpm-cmake/testpack-adder#cad1cd4b4cdf957c5b59e30bc9a1dd200dbfc716")' | ||
assert_success prj.configure | ||
|
||
cache = prj.read_cache | ||
assert_equal 1, cache.packages.size | ||
assert_equal '0', cache.packages['testpack-adder'].ver | ||
|
||
assert_success prj.build | ||
exes = get_project_binaries prj | ||
# No adder projects were built as EXCLUDE_FROM_ALL is implicitly set | ||
assert_equal ['using-adder'], exes | ||
end | ||
|
||
def test_create_with_version | ||
prj = make_project from_template: 'using-adder' | ||
prj.create_lists_from_default_template package: | ||
'CPMAddPackage("gh:cpm-cmake/[email protected]")' | ||
assert_success prj.configure | ||
|
||
cache = prj.read_cache | ||
assert_equal 1, cache.packages.size | ||
assert_equal '1.0.0', cache.packages['testpack-adder'].ver | ||
|
||
assert_success prj.build | ||
exes = get_project_binaries prj | ||
assert_equal ['using-adder'], exes | ||
end | ||
|
||
def test_create_with_all | ||
prj = make_project from_template: 'using-adder' | ||
prj.create_lists_from_default_template package: | ||
'CPMAddPackage( | ||
URI "gh:cpm-cmake/[email protected]" | ||
EXCLUDE_FROM_ALL false | ||
)' | ||
assert_success prj.configure | ||
|
||
cache = prj.read_cache | ||
assert_equal cache.packages.size, 1 | ||
assert_equal cache.packages['testpack-adder'].ver, '1.0.0' | ||
|
||
assert_success prj.build | ||
exes = get_project_binaries prj | ||
assert_equal exes, ['simple', 'test-adding', 'using-adder'] | ||
end | ||
|
||
def test_create_with_tests_but_without_examples | ||
prj = make_project from_template: 'using-adder' | ||
prj.create_lists_from_default_template package: | ||
'CPMAddPackage( | ||
URI "gh:cpm-cmake/[email protected]" | ||
OPTIONS "ADDER_BUILD_EXAMPLES OFF" "ADDER_BUILD_TESTS TRUE" | ||
EXCLUDE_FROM_ALL false | ||
)' | ||
assert_success prj.configure | ||
|
||
cache = prj.read_cache | ||
assert_equal cache.packages.size, 1 | ||
assert_equal cache.packages['testpack-adder'].ver, '1.0.0' | ||
|
||
assert_success prj.build | ||
exes = get_project_binaries prj | ||
assert_equal exes, ['test-adding', 'using-adder'] | ||
end | ||
|
||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.