* 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>
* 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>
* trigger CI to see if sol2 example is reliably failing
* attempt patch from github comment
* fix patch
* add info to comment on patch
* run fix-format
* simplify patchfile
`WIN32` checks whether current build context is windows. This is not correct in case of cross-compiling, because we are interested in finding host's tools, not SDK's tools.
* replace deprecated calls to FetchContent_Populate
The single argument signature for FetchContent_Populate is deprecated with CMake 3.30.
It was used, in order to call add_subdirectory manually with the EXCLUDE_FROM_ALL and SYSTEM flags.
These have been added to FetchContent_Declare with 3.25 and 3.28.
Calling FetchContent_MakeAvailable will internally call add_subdirectory with EXCLUDE_FROM_ALL and SYSTEM.
There is therefore no need to call this manually.
* fix: OPTIONS passed to CPMAddPackage not set
where previously parsed in cpm_add_subdirectory which is not called
on the new code path.
* refactor: remove an unnecessary else branch
* ci: include cmake 3.30 in test matrix
* fix: forward SOURCE_SUBDIR to FetchContent_Declare
For CMake version <3.28 this is done by calling add_subdirectory manually.
For newer version FetchContent_Declare/MakeAvailable handles this for us.
* fix: only set options if download_only is false
this replicates the old behaviour
* fix: DOWNLOAD_ONLY test
* refactor: always use *_Populate to reduce code paths
* Revert "refactor: always use *_Populate to reduce code paths"
This reverts commit 0e8ca2a0e9.
---------
Co-authored-by: Avus <48911667+Avus@users.noreply.github.com>
* 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.
* 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>
If I have a project, which has:
1. /CMakeLists.txt:
```cmake
cmake_minimum_required(VERSION 3.29)
project(test)
include(./cmake/CPM.cmake)
add_subdirectory(subdir)
cpmfindpackage(
NAME
nlohmann_json
VERSION
3.11.2
URL
"https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz"
EXCLUDE_FROM_ALL
ON)
if(NOT TARGET nlohmann_json::nlohmann_json)
message(FATAL_ERROR "BUG")
endif()
```
2. /subdir/CMakeLists.txt
```cmake
cpmfindpackage(
NAME
nlohmann_json
VERSION
3.11.2
URL
"https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz"
EXCLUDE_FROM_ALL
ON)
```
When nlohmann_json is first founded by find_package,
CPM.cmake register this package and later call to CPMFindPackage will
not actually perform a find_package again, which leads to this buggy
behavior.
As CPM write a FindXXX.cmake file for packages added by CPM to pervert
find_package to get local package, I think directly use cpm_find_package
to check if a package is already added is good enough.
* Update CMake and main to add another library and download FASTER.
* Apply style formatters
* Update README.md's boost example and add information on determining source archive location at GitHub.
* Update README.md
---------
Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
* 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>
Add [SPDX][1] licensing/copyright tags to the `get_cpm.cmake` script,
so that anybody that copies the `get_cpm.cmake` script into their repo
(following the instructions in the README.md)
will automatically comply with CPM's MIT license.
[1]: https://spdx.dev/
* 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
Repositions the "Adding CPM" section higher in the Readme to increase incentive to try it out and make it easier to find for updating CPM in existing projects.
* 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>
* Optimized multi-threading.
* Remove old multi-threading implementation.
* Release files instead of removing.
* Lock before choosing to check cache or download.
* Unlock directly after verifying directory exists.
* 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>
* get_cpm: Recover from failed download
If the download fails during the cmake config step
an empty `CPM_<version>.cmake` file is created.
So far the script only checks the files existence,
so there is no second try until the empty file is deleted manually.
This adds a check if the file is empty
and resumes the download on next config if it is.
* More descriptive function name
* Small helper function for logging :
This PR add an helper function only when `message(STATUS ...)` as the other are `backtracing` and adding the helper function add on stack.
It should fix#328#342 with a few line of code.
* Formatting
* Instead of spdlog's bundled fmt re-use it from CPM.cmake
* Add comment about re-using fmt for spdlog
* Update examples/spdlog/CMakeLists.txt
Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
* run cmake-format
* disable cmake-format around code block
Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>