mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-18 07:07:47 -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
86
test/integration/test_shorthand_syntax.rb
Normal file
86
test/integration/test_shorthand_syntax.rb
Normal file
@@ -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/testpack-adder@1.0.0")'
|
||||
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/testpack-adder@1.0.0"
|
||||
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/testpack-adder@1.0.0"
|
||||
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
|
||||
Reference in New Issue
Block a user