49 Commits

Author SHA1 Message Date
Alecto Irene Perez
d9364ce284 Implement #624: Use shorter hashes with CPM_SOURCE_CACHE (#631)
* Add ASSERT_CONTENTS_EQUAL test macro in testing.cmake

Checks if the contents of a file matches the given input

* Use shorter hashes with CPM_SOURCE_CACHE (#624)

Uses shorter hashes with CPM_SOURCE_CACHE. Falls back to a longer hash
if necessary (ie, if there's a collision with an existing hash).

See: https://github.com/cpm-cmake/CPM.cmake/issues/624

* Update integration tests to support shorter hashes

* trigger ci

* run cmake-format

* if already available, use the legacy cache hash

* create temporary file in current binary dir

* add test case for legacy hash

---------

Co-authored-by: Lars Melchior <lars.melchior@gmail.com>
Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
2025-05-18 19:02:47 +02:00
Simon Gene Gottlieb
d7614381ab 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>
2025-05-03 19:12:08 +02:00
Patrick Stewart
9ddfe1b6a8 Add find_package overrides that also work in CONFIG mode (#498) (#604) 2024-12-20 16:38:22 +01:00
Scott B
d416d9b22c Adding PATCHES keyword. (#558)
* Adding PATCHES keyword.

* Formatting fix.

* Move cpm_add_patches() outside if/else scopes.

* cmake-format: add PATCHES to CPMAddPackage.

* Integration tests for PATCHES command.

* Use get_filename_component() in place of cmake_path() for use with all cmake versions 3.14 and above.

* Added an example and improved comment for cpm_add_patches.
2024-06-12 15:43:27 +02:00
Gerhard Olsson
0370507fed Custom cache directory name (#543)
* Custom cache directory name

Enable setting a custom directory name for cached packages.
Required if e.g. patch_command uses external variables or
just to set a human readable name.

* fixup! review comment CUSTOM_CACHE_DIR -> CUSTOM_CACHE_KEY

* run cmake-format

---------

Co-authored-by: Olsson Gerhard <gerhard.olsson@volvo.com>
Co-authored-by: Lars Melchior <lars.melchior@gmail.com>
2024-04-08 18:24:10 +02:00
Simon Gene Gottlieb
0e450ef450 fix,doc: spelling errors (#551) 2024-04-07 21:36:07 +00:00
Claus Klein
3c25130ffa Feature/add missing packageproject options (#524)
* Add missing packageproject options

* Fix typos with codespell

* Update test/style/CMakeLists.txt

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>

* fix-cmake-format

---------

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
2024-01-17 09:06:16 +01:00
Chris Wright
369f1316f6 Treat relative paths as relative to parent project's remote (#522)
* Treat relative paths as relative to parent project's remote

* replace unit test case with integration test

* run relative URL test only on supported CMake versions (3.27)

* omit cmake 2.25.x test runner as replaced by 2.27.x

---------

Co-authored-by: Chris Wright <chris.wright@mqa.co.uk>
Co-authored-by: Lars Melchior <lars.melchior@gmail.com>
2023-11-30 20:01:03 +01:00
Lars Melchior
16c6a3b0af Fix download_command by declaring it a multi-value option (#473) 2023-09-18 15:37:35 +02:00
Lars Melchior
b9b512a869 Add CMake version as workflow matrix parameter (#451)
* add CMake version as workflow matrix parameter

* change system test behaviour based on specified CMake version

* use explicit version strings

* set CMake version for both test steps

* exclude windows-2022, cmake 3.16 combination
2023-02-22 17:33:50 +01:00
Lars Melchior
12daf366c7 Add SYSTEM option (#449)
* add system property for cpm_add_subdirectory

* add test case for system property

* lock CMake version in test workflow

* refactor to make SYSTEM an extra config option and update tests

* remove old comment change

* use consistent CMake version and extension for all workflows

* make warning more specific and try to trigger on windows

* another attempt to trigger warning on MSVC

* update readme

* simplify test case and use git tag

* add SYSTEM option to .cmake-format

* forward system arg for source overrides

* enable system implicitly for the single argument syntax

* Use SYSTEM option for FetchContent and add_subdirectory (#441)

* Use SYSTEM option for FetchContent and add_subdirectory

* Add SYSTEM option to syntax and doku

* Update CPM.cmake

* Update .cmake-format

---------

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>

---------

Co-authored-by: Claus Klein <claus.klein@arcormail.de>
2023-02-21 15:51:33 +01:00
PercentBoat4164
09b056ae20 Add file locking to support parallel runs. (#427)
* Add file locking to support parallel runs.

* Fixed formatting.

* Prevent double locking file.

* Fix SegFault from test 2.

* Remove unnecessary debugging messages.

* Lock the package directory rather than the cache directory.
Only synchronize if CPM_SOURCE_CACHE is defined.

* Lock the version specific cache entry rather than the package specific entry.

* Remove unnecessary arguments in conditional statements.

* Change back to locking entire cache directory.

* Only check CPM_HAS_CACHE_LOCK.

* Lock on a per-package basis rather than the entire cache.

* Clean up the locked file.

* Unlock then remove to fix Windows.

* Specify use of cmake.lock as the lock file.

* - Changed CPM_HAS_CACHE_LOCK to ${CPM_ARGS_NAME}_CPM_HAS_CACHE_LOCK.
- Removed redundant variable initialization.

* Add unit test.

* Actually test if resulting git cache is clean in unit test.

* - Added comments
- Fixed formatting
- Removed unnecessary imports

* convert parallelism test to integration test

* remove comment

* - Removed now unnecessary variable.
 - Only delete file instead of unlocking it then deleting it.

* Forgot to change variable name.

* Add similar changes to the missed section.

* Fixed formatting.

* Unlock the file, but do not delete it.

* Only unlock the file if it exists.

* Changed cache.cmake test to ignore non-directory entries.

* Integration test lib make_project:
* keyword args
* 'name' arg to allow multiple projects from the same test

* - Moved checks to function.
- Fixed small grammatical errors.

* - Fix formatting

* Switch to snake case.

---------

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
Co-authored-by: Lars Melchior <lars.melchior@gmail.com>
Co-authored-by: Borislav Stanimirov <b.stanimirov@abv.bg>
2023-01-28 14:36:44 +01:00
Craig Hutchinson
03705fcce1 Added export of CPM_LAST_PACKAGE_NAME (#403) 2022-09-28 21:39:31 +02:00
Thomas Mosegaard Pedersen
ede60451a9 CPMAddPackage fails if the SOURCE_DIR directory is deleted. (#370)
* Fixed: Deleted SOURCE_DIR directory would abort just after git stash save --quiet;--include-untracked

* Fixed: Review comments

* Added: Integration test for deleted SOURCE_DIR with FetchContent

* Fixed: Review comments

* Fixed: Review comments
2022-07-26 07:15:11 +00:00
Lars Melchior
a575ab57b7 Allow overriding FetchContent using CPM (#352)
* Override FetchContent paramers, fixes #281

* add check to verify that dependency is cached

* update test comment

* rename test file and class

* update test indentation
2022-05-16 21:28:44 +02:00
Robert Maynard
11c7ec8afa Use CMake 3.14+ documented way to pass the source dir -S. (#337)
The `-H<src_dir>` was never officially documented by CMake
2022-01-27 23:45:35 +01:00
Borislav Stanimirov
c58e98a0a0 Initial version of integration tests (#330)
* Initial commit for integration tests. Experimental. Playing with potential syntax

* Some experimental code to setup tests

* Piecewise building of CMakeLists

* First check

* Alternative approach. Using ruby's test/unit

* Parse CMakeCache. Separate lib

* First integration test

* Latest Format.cmake. Passing style

* Allow user-provided integration test dir. Allow reuse

* Separate class with utils for cache (no longer pure Hash)

* Allow running of tests from any dir

* Add integration tests to CI

* Use an in-source integration test directory

* Allow relative integration test dir from env

* Custom assertion for a success of CommandResult

* Windows-latest-latest

* Enrich CMakeCache class with more CPM data

* Added test for CPM-specific CMakeCache values

* Style

* Style

* test_update_single_package

* WiP for source cache test

* Small source_cache test

* Style

* Moved env clean to cleanup to make setup methods simpler (not require super)

* WiP for integration test documentation

* WiP for integration test documentation

* Project file creation tweaks

* Split docs into multiple files. Complete tutorial. Reference.

* Tips

* Typo

* Setup Ruby inistead of requiring windows-2022

* Revert "Setup Ruby inistead of requiring windows-2022"

This reverts commit 8aa2732145.
2022-01-19 00:18:41 +01:00
Lars Melchior
718ea71759 Allow passing lists in the options (#302)
* allow list options by passing option parameter as string, not value

* add test

* remove debug message

* run formatter
2021-12-05 16:07:20 +01:00
Andrea Barbadoro
f552da96bd Detecting when the cache is dirty (#284)
* Check that the cache working directory is clean

* cpm_check_working_dir_is_clean for non git repo will not terminate cmake

* sileneced check for git repo, in case of error

* style(CPM.cmake): fixed indentation for ERROR_QUIET

* refactor(CPM.cmake): added logic to handle a cache folder inside a (not correlated) git repo

this is accomplished by checking if we are in the directory where .git lives

* style(CPM.cmake): stray tab to spaces

* test(dirty-cache-check): added unit test to check cpm_check_working_dir_is_clean

the test creates a file in a folder and then uses git to create a repo in that folder, to check various conditions

* Update test/unit/dirty-cache-check.cmake

added user.name and user.email to comply with test machine where git is not completely configured

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>

* feat(cpm_check_working_dir_is_clean): now it takes a git tag (works with hashes too) to check for uncommitted and commited changes

* refactor(cpm_check_working_dir_is_clean): early return for the most common case of uncommited changes in a repo

* refactor(cpm_check_git_working_dir_is_clean): removed edgecase detection (a non-git folder in an unrelated git repo)

now the contract is that com_check_git_working_dir_is_clean is given the base folder of a git repo

Co-authored-by: Andrew Gribble <ag131012@renishaw.com>
Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
2021-09-15 11:38:49 +02:00
Olivier Le Doeuff
ea6a8eb895 Fix CPMAddPackage when FetchContent_MakeAvailable already added package (#288)
Add fetchcontent_dependency unit test:
* This test should highlight the fact that cpm_add_subdirectory is always called, even when
  cpm_fetch_package isn't populating the dependency
* NO_CACHE YES highlight a bug introduced in 32b063eba5 where
  cpm_fetch_package was checking undefined ${lower_case_name}_POPULATED variable

https://github.com/cpm-cmake/CPM.cmake/issues/287
2021-08-29 22:02:18 +02:00
pgorgon-hem
91585e3864 Added support for bitbucket repositories (#256)
* Added support for bitbucket repositories:
* added variable BITBUCKET_REPOSITORY
* added short syntax in form "bb:user/repo"
* added description of that to readme.md

* Added test for bitbucket short syntax

* Used elseif syntax in handling of git services (github, gitlab, bitbucket).

* Added HEMRND/TestingFramework example located on bitbucket.org

* Reformatted CMakeLists.txt in TestingFramework example

* Bumped version of TestingFramework. It supports older version of c++ standard.

Co-authored-by: Paweł Gorgoń <pgorgon@hem-e.com>
2021-06-08 19:15:40 +02:00
flagarde
ee08119642 Scope package options to avoid changing the local scope (#235)
* Fix #222

* Fix #222

* move policy change and local options to cpm_add_subdirectory

* change default policy as well

see https://gitlab.kitware.com/cmake/cmake/-/issues/20312

* add test

* update check to not use the NOT operator

(interestingly it works as expected locally)

* simplify test by not using options

* check options in tests

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
2021-03-25 15:59:34 +01:00
Lars Melchior
32b063eba5 Fix support for source subdirectories (#238)
* add support for source subdirectories

* style fixes

* remove debug log

* grammar fix in comment
2021-03-25 10:42:51 +01:00
Lars Melchior
8e8dcc9a8d moved test repostitory to CPM.cmake namespace (#228) 2021-03-04 11:01:01 +02:00
Borislav Stanimirov
a3d1048ad6 Infer package name and version from URL (#220)
* Function to extract name and version from url. Some tests

* Rewrite. Previous version was not safe enough. More tests

* Allow underscore as a name-version separator (<name>_<ver>)

* CPMAddPackage can infer name and version from url

* Allow URL parse from single arg and uncomment tests

* Info about shorthand syntax in README

* Fix style

* Fixed typo

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>

* Explicit hash algorithm in shorthand URL example.
Also added tests which include a hash algorithm provided
We can't document a default until it's confirmed here: https://gitlab.kitware.com/cmake/cmake/-/issues/21859

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
2021-02-23 20:15:45 +01:00
Borislav Stanimirov
3f6cbe7383 Single-argument shorthand syntax for CPMAddPackage (#207)
* Added quotes in equality checks so lists can be compared

* Function to parse argument of CPMAddPackage in case a single one was provided

* Error on URL type in CPMAddPackage single-arg

* Fixed format

* Support single argument syntax of CPMAddPackage

* Documenting and showcasing the new shorthand syntax of CPMAddPackage

* Auto EXCLUDE_FROM_ALL for the shorthand syntax

* Fixed accidental paste of TOLOWER

* Document why some test cases are commented out

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>

* Update README.md

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>

* Removed GitHub as the default package shorthand provider

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
2021-02-22 21:12:06 +01:00
Borislav Stanimirov
4cbf443363 If a name isn't provided, try to infer it from the git repo (#202)
* Added assert_not_defined check

* Function to get package name form git uri and tests

* Autofix format

* If name is not provided, try to infer it from the git repo

* Unset result of cpm_package_name_from_git_uri if there is no match
- Also reordered tests to ensure that the result is actually unset when needed

* Removed trailing spaces in README

* Updated the main example with the new minimal syntax

* Well... autofix format again

* Update error message for missing name to reflect the possible auto-infer step

* Autofix format... yet again :)
2021-02-17 12:41:25 +01:00
Lars Melchior
fd539b8ff3 Add dependencies using EXCLUDE_FROM_ALL flag (#198)
* add dependencies using EXCLUDE_FROM_ALL flag

* respect DOWNLOAD_ONLY flag

* set EXCLUDE_FROM_ALL as an optional flag

* use one value arg for consistency

* fix argument passing

* add unit test

* update cmake-format
2021-02-16 10:26:16 +00:00
alexandreSalconiDenis
7000572bbe Feature/prettify package lock (#162)
* add prettify macro

* apply the prettier and change the name of the output arg

* add parameter inside macro

* resolve path if its cmake_sourc_dir

* add missing uparsed argument

* add early unit test for prettifier

* retab prettify_cpm_add_package

* rename prettify_cpm_add_package  cpm_prettyfy_package_arguments

* convert macro to function and fix unit test

* fix typo in the name of the parse argument in prettyfy function

* change the unit test to test only the function

* add test for the commented part

* remove dead code

* fix typo

* run cmake-format on CPM.cmake

* reformated unit test prettify

* flip the logic to add space on new argument unparsed to avoir space at the end

* remove debug message

* apply most suggestion from pr 162, disable formating only for small part in unit test

* add unit test to cover defauld source dir added inside lock

* run format tool on unit test

* remove dead code

* change the prettifier from 4 space to 2

* run format on unit test
2021-01-27 13:29:15 +01:00
Lars Melchior
ab6e8d6d8c Performance improvement: bypass FetchContent for cached dependencies (#182)
* skip FetchContent for cached dependencies

* set default value for CPM_SKIP_FETCH to avoid conflicts

* add tests to check exported values
2021-01-20 13:15:18 +01:00
Lars Melchior
1ebbac6332 Apply clang-format and cmake-format and add style check workflow (#171)
* apply clang-format and cmake-format and add style check workflow

* add declare package definition

* add additional public methods and rename internals

* change development verison tag to 1.0.0

* rename internal method

* rename public method

* rename test var

* update copyright and fix comment

* typo

* run fix-format

* fix test function names
2021-01-06 14:40:33 +01:00
Lars Melchior
9ec279c75f bump version and update tests (#131) 2020-06-15 10:16:30 +02:00
Kingsley Chen
392b2a864b Use shallow clone for git repositories by default (#129) (#130)
* Use shallow clone for git repositories by default (#129)

* use shallow clone for git repositories by default

* remove trailing spaces

* Enable shallow clone for actual tags

* Support short commit hash

* Enable shallow only when downloading dependencies into cache

* Always honor user specified GIT_SHALLOW opiton
2020-06-15 09:27:26 +02:00
Lars Melchior
139d3cacba Add NO_CACHE option (#128)
* add NO_CACHE option

* add unit test
2020-06-04 14:22:57 +02:00
Lars Melchior
54a2d80d1e Add option for local package override (#123)
* add option for local package override

* print info on the source directory
2020-05-29 09:58:39 +02:00
Lars Melchior
829262cbd3 omit unversioned and local dependencies in package lock (#122)
* omit unversioned and local dependencies in package lock

* update package lock for active project only
2020-05-28 13:29:25 +02:00
Lars Melchior
4aeea1d31d Add package lock (#121)
* add package lock creation

* change target name

* fix cpm_export_variables

* add test

* fix git repo detection addition

* remove test package lock from git

* add link to package lock wiki

* add CPMGetPackage
2020-05-27 19:07:06 +02:00
Lars Melchior
ca33abc236 create FindXXX.cmake modules for added CPM packages (#112)
* create FindXXX.cmake modules for added CPM packages

* don't use list(PREPEND) as it unsupported on older CMake versions

* use CMAKE_BINARY_DIR

* ensure CPM.cmake is initialized only once

* import CPM.cmake in modules
2020-04-29 09:18:54 +02:00
Lars Melchior
618cdefa0d Support CPM_SOURCE_CACHE on windows (#109)
* use semicolon as empty command and add test

* remove platform specific test coverage

* only run actions for pushes and prs into master (avoid duplication)

* remove cache test as it's already part of the test suite

* update version

* test cache reuse
2020-04-25 00:51:18 +02:00
Lars Melchior
01b69aad82 add support for SOURCE_DIR argument (#97)
* add support for SOURCE_DIR argument

* simplify code

* add test

* update comment
2020-02-25 13:29:21 +01:00
Lars Melchior
3a4516265c Add GitHub workflows (#93)
* add mac workflow

* rename and add windows and ubuntu workflows

* update tests

* update tests

* update travis
2019-10-24 18:14:58 +02:00
Lars Melchior
47bfb554ab reorganise source and add CPMFindPackage (#92)
* reorganise source and add CPMFindPackage

* add consistent find_package behaviour

* document CPMFindPackage

* reset examples to CPMAddPackage unless tested

* update version

* update README.md

* Update README.md
2019-10-24 15:42:25 +02:00
Lars Melchior
4064a45552 Add CPM_SOURCE_CACHE environmental variable support and keep existing sources (#83)
* read CPM_SOURCE_CACHE from environment

* update readme

* cleanup

* add cache tests
2019-10-10 20:13:10 +02:00
Lars Melchior
25a9158448 Add boost example (#70)
* add unit tests

* added boost

* cleanup

* add pthread

* Update README.md
2019-07-01 20:30:21 +02:00
Lars Melchior
3d75ed06a3 add unit tests and determine version from GIT_TAG (#66)
* add unit tests

* determine package version from git tag. closes #54.

* update readme

* bugfix

* update example

* update gitignore
2019-06-22 13:31:32 +02:00
Lars Melchior
11afa7a469 add complex test 2019-04-09 16:15:36 +02:00
Lars Melchior
5a56af6f06 update test 2019-04-09 15:51:25 +02:00
Lars Melchior
77ff8c59b7 create cmake dir 2019-04-09 15:31:31 +02:00
Lars Melchior
e620be2a5a init 2019-04-09 15:29:07 +02:00