-
Notifications
You must be signed in to change notification settings - Fork 190
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
feature: allow additional arguments after shorthand syntax #546
Open
SGSSGene
wants to merge
4
commits into
cpm-cmake:master
Choose a base branch
from
SGSSGene:feat/shorthand_with_options
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5a7b584
feature: allow additional arguments after shorthand syntax
SGSSGene 6fd2dde
fix: use shorthand syntax in examples
SGSSGene 045e598
test: add test for shorthand syntax with options
SGSSGene d8f2f1e
doc: extend README mentioning shorthand syntax with options
SGSSGene 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 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 |
---|---|---|
|
@@ -87,7 +87,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 | ||
|
@@ -111,6 +111,13 @@ CPMAddPackage("https://example.com/my-package-1.2.3.zip#MD5=68e20f674a48be38d60e | |
CPMAddPackage("https://example.com/[email protected]") | ||
``` | ||
|
||
Additionally, the shorthand syntax can be combined with the other options from above: | ||
```cmake | ||
CPMAddPackage("gh:nlohmann/[email protected]" | ||
OPTIONS "JSON_BuildTests OFF" | ||
) | ||
``` | ||
|
||
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. | ||
|
@@ -403,12 +410,8 @@ CPMAddPackage("gh:jbeder/yaml-cpp#[email protected]") | |
### [nlohmann/json](https://github.com/nlohmann/json) | ||
|
||
```cmake | ||
CPMAddPackage( | ||
NAME nlohmann_json | ||
VERSION 3.9.1 | ||
GITHUB_REPOSITORY nlohmann/json | ||
OPTIONS | ||
"JSON_BuildTests OFF" | ||
CPMAddPackage("gh:nlohmann/[email protected]" | ||
OPTIONS "JSON_BuildTests OFF" | ||
) | ||
``` | ||
|
||
|
@@ -437,20 +440,15 @@ 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 | ||
OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" "CXXOPTS_ENABLE_INSTALL YES" | ||
CPMAddPackage("gh:jarro2783/[email protected]" | ||
OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" "CXXOPTS_ENABLE_INSTALL YES" | ||
) | ||
``` | ||
|
||
### [google/benchmark](https://github.com/google/benchmark) | ||
|
||
```cmake | ||
CPMAddPackage( | ||
NAME benchmark | ||
GITHUB_REPOSITORY google/benchmark | ||
VERSION 1.5.2 | ||
CPMAddPackage("gh:google/[email protected]" | ||
OPTIONS "BENCHMARK_ENABLE_TESTING Off" | ||
) | ||
|
||
|
@@ -463,11 +461,8 @@ endif() | |
### [Lua](https://www.lua.org) | ||
|
||
```cmake | ||
CPMAddPackage( | ||
NAME lua | ||
GIT_REPOSITORY https://github.com/lua/lua.git | ||
VERSION 5.3.5 | ||
DOWNLOAD_ONLY YES | ||
CPMAddPackage("gh:lua/[email protected]" | ||
DOWNLOAD_ONLY YES | ||
) | ||
|
||
if (lua_ADDED) | ||
|
This file contains 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 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 |
---|---|---|
|
@@ -83,9 +83,38 @@ def test_update_single_package | |
# ...and notably no test for adder, which must be disabled from the option override from above | ||
assert_equal ['simple', 'using-adder'], exes | ||
} | ||
update_with_option_off_and_build_with_shorthand_syntax = -> { | ||
prj.create_lists_from_default_template package: <<~PACK | ||
CPMAddPackage(gh:cpm-cmake/[email protected] | ||
OPTIONS "ADDER_BUILD_TESTS OFF" | ||
) | ||
PACK | ||
assert_success prj.configure | ||
assert_success prj.build | ||
|
||
exe_dir = File.join(prj.bin_dir, 'bin') | ||
assert File.directory? exe_dir | ||
|
||
exes = 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 | ||
|
||
# we should end up with two executables | ||
# * simple - the simple example from adder | ||
# * using-adder - for this project | ||
# ...and notably no test for adder, which must be disabled from the option override from above | ||
assert_equal ['simple', 'using-adder'], exes | ||
|
||
} | ||
|
||
create_with_commit_sha.() | ||
update_to_version_1.() | ||
update_with_option_off_and_build.() | ||
update_with_option_off_and_build_with_shorthand_syntax.() | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like having this run as part of a larger test makes reasoning about the test itself difficult. Do you think you could move checking the shorthand extra arguments into its own isolated test case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure 👍