mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-17 22:58:14 -05:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
369f1316f6 | ||
|
|
a9c8c6fe1b | ||
|
|
2fa48378e2 | ||
|
|
4276c79d28 | ||
|
|
ee6d879a50 | ||
|
|
d6d5d0d5ab | ||
|
|
16c6a3b0af | ||
|
|
52ee7c9d53 | ||
|
|
699c7a0038 | ||
|
|
daf9d766c6 | ||
|
|
439bfcf134 | ||
|
|
02ecc4608a | ||
|
|
4608688d85 | ||
|
|
cda03b434e |
@@ -1,74 +1,5 @@
|
||||
include: ["cmake/.cmake-format-additional_commands-cpm"]
|
||||
format:
|
||||
tab_size: 2
|
||||
line_width: 100
|
||||
dangle_parens: true
|
||||
|
||||
parse:
|
||||
additional_commands:
|
||||
cpmaddpackage:
|
||||
pargs:
|
||||
nargs: '*'
|
||||
flags: []
|
||||
spelling: CPMAddPackage
|
||||
kwargs: &cpmaddpackagekwargs
|
||||
NAME: 1
|
||||
FORCE: 1
|
||||
VERSION: 1
|
||||
GIT_TAG: 1
|
||||
DOWNLOAD_ONLY: 1
|
||||
GITHUB_REPOSITORY: 1
|
||||
GITLAB_REPOSITORY: 1
|
||||
GIT_REPOSITORY: 1
|
||||
SVN_REPOSITORY: 1
|
||||
SVN_REVISION: 1
|
||||
SOURCE_DIR: 1
|
||||
DOWNLOAD_COMMAND: 1
|
||||
FIND_PACKAGE_ARGUMENTS: 1
|
||||
NO_CACHE: 1
|
||||
GIT_SHALLOW: 1
|
||||
URL: 1
|
||||
URL_HASH: 1
|
||||
URL_MD5: 1
|
||||
DOWNLOAD_NAME: 1
|
||||
DOWNLOAD_NO_EXTRACT: 1
|
||||
HTTP_USERNAME: 1
|
||||
HTTP_PASSWORD: 1
|
||||
EXCLUDE_FROM_ALL: 1
|
||||
SYSTEM: 1
|
||||
SOURCE_SUBDIR: 1
|
||||
OPTIONS: +
|
||||
cpmfindpackage:
|
||||
pargs:
|
||||
nargs: '*'
|
||||
flags: []
|
||||
spelling: CPMFindPackage
|
||||
kwargs: *cpmaddpackagekwargs
|
||||
cpmdeclarepackage:
|
||||
pargs:
|
||||
nargs: '*'
|
||||
flags: []
|
||||
spelling: CPMDeclarePackage
|
||||
kwargs: *cpmaddpackagekwargs
|
||||
packageproject:
|
||||
pargs:
|
||||
nargs: '*'
|
||||
flags: []
|
||||
spelling: packageProject
|
||||
kwargs:
|
||||
NAME: 1
|
||||
VERSION: 1
|
||||
INCLUDE_DIR: 1
|
||||
INCLUDE_DESTINATION: 1
|
||||
BINARY_DIR: 1
|
||||
COMPATIBILITY: 1
|
||||
VERSION_HEADER: 1
|
||||
DEPENDENCIES: +
|
||||
cpmusepackagelock:
|
||||
pargs: 1
|
||||
spelling: CPMUsePackageLock
|
||||
cpmregisterpackage:
|
||||
pargs: 1
|
||||
spelling: CPMRegisterPackage
|
||||
cpmgetpackageversion:
|
||||
pargs: 2
|
||||
spelling: CPMGetPackageVersion
|
||||
|
||||
5
.github/workflows/publish.yaml
vendored
5
.github/workflows/publish.yaml
vendored
@@ -15,8 +15,9 @@ jobs:
|
||||
- name: Set CPM version by tag
|
||||
run: |
|
||||
mkdir dist
|
||||
sed "s/1.0.0-development-version/${GITHUB_REF/refs\/tags\/v}/g" cmake/CPM.cmake > dist/CPM.cmake
|
||||
sed "s/1.0.0-development-version/${GITHUB_REF/refs\/tags\/v}/g" cmake/get_cpm.cmake > dist/get_cpm.cmake
|
||||
sed -e "s/1.0.0-development-version/${GITHUB_REF/refs\/tags\/v}/g" cmake/CPM.cmake > dist/CPM.cmake
|
||||
sed -e "s/1.0.0-development-version/${GITHUB_REF/refs\/tags\/v}/g" \
|
||||
-e "s/CPM_HASH_SUM_PLACEHOLDER/$(sha256sum dist/CPM.cmake | cut -d' ' -f1)/" cmake/get_cpm.cmake > dist/get_cpm.cmake
|
||||
|
||||
- name: Upload CPM.cmake to release
|
||||
uses: svenstaro/upload-release-action@v1-release
|
||||
|
||||
2
.github/workflows/style.yaml
vendored
2
.github/workflows/style.yaml
vendored
@@ -19,7 +19,7 @@ jobs:
|
||||
- name: Setup cmake
|
||||
uses: jwlawson/actions-setup-cmake@v1.13
|
||||
with:
|
||||
cmake-version: '3.25.x'
|
||||
cmake-version: '3.27.x'
|
||||
|
||||
- name: Install format dependencies
|
||||
run: pip3 install clang-format==14.0.6 cmake_format==0.6.11 pyyaml
|
||||
|
||||
2
.github/workflows/test.yaml
vendored
2
.github/workflows/test.yaml
vendored
@@ -19,7 +19,7 @@ jobs:
|
||||
os: [ubuntu-latest, windows-2022, macos-latest]
|
||||
# we want to ensure compatibility with a recent CMake version as well as the lowest officially supported
|
||||
# legacy version that we define as the default version of the second-latest Ubuntu LTS release currently available
|
||||
cmake_version: ['3.16.3', '3.25.1']
|
||||
cmake_version: ['3.16.3', '3.27.5']
|
||||
exclude:
|
||||
# there seems to be an issue with CMake 3.16 not finding a C++ compiler on windows-2022
|
||||
- os: windows-2022
|
||||
|
||||
40
README.md
40
README.md
@@ -12,7 +12,7 @@ It's built as a thin wrapper around CMake's [FetchContent](https://cmake.org/cma
|
||||
|
||||
## Manage everything
|
||||
|
||||
Any downloadable project or resource can be added as a version-controlled dependency though CPM, it is not necessary to modify or package anything.
|
||||
Any downloadable project or resource can be added as a version-controlled dependency through CPM, it is not necessary to modify or package anything.
|
||||
Projects using modern CMake are automatically configured and their targets can be used immediately.
|
||||
For everything else, the targets can be created manually after the dependency has been downloaded (see the [snippets](#snippets) below for examples).
|
||||
|
||||
@@ -37,7 +37,7 @@ include(cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage("gh:fmtlib/fmt#7.1.3")
|
||||
CPMAddPackage("gh:nlohmann/json@3.10.5")
|
||||
CPMAddPackage("gh:catchorg/Catch2@3.2.1")
|
||||
CPMAddPackage("gh:catchorg/Catch2@3.4.0")
|
||||
|
||||
# link dependencies
|
||||
target_link_libraries(main fmt::fmt nlohmann_json::nlohmann_json Catch2::Catch2WithMain)
|
||||
@@ -142,6 +142,7 @@ Dependencies using CPM will automatically use the updated script of the outermos
|
||||
- **Some CMake policies set to `NEW`** Including CPM.cmake will lead to several CMake policies being set to `NEW`. Users which need the old behavior will need to manually modify their CMake code to ensure they're set to `OLD` at the appropriate places. The policies are:
|
||||
- [CMP0077](https://cmake.org/cmake/help/latest/policy/CMP0077.html) and [CMP0126](https://cmake.org/cmake/help/latest/policy/CMP0126.html). They make setting package options from `CMPAddPackage` possible.
|
||||
- [CMP0135](https://cmake.org/cmake/help/latest/policy/CMP0135.html) It allows for proper package rebuilds of packages which are archives, source cache is not used, and the package URL is changed to an older version.
|
||||
- [CMP0150](https://cmake.org/cmake/help/latest/policy/CMP0150.html) Relative paths provided to `GIT_REPOSITORY` are treated as relative to the parent project's remote.
|
||||
|
||||
For projects with more complex needs and where an extra setup step doesn't matter, it may be worth to check out an external C++ package manager such as [vcpkg](https://github.com/microsoft/vcpkg), [conan](https://conan.io) or [hunter](https://github.com/ruslo/hunter).
|
||||
Dependencies added with `CPMFindPackage` should work with external package managers.
|
||||
@@ -332,7 +333,40 @@ If you know others, feel free to add them here through a PR.
|
||||
<p align="center"><b>AALTITOAD - verifier and simulator for Tick Tock Automata</b></p>
|
||||
</a>
|
||||
</td>
|
||||
<td/>
|
||||
<td>
|
||||
<a href="https://github.com/ZIMO-Elektronik">
|
||||
<p align="center">
|
||||
<img src="https://avatars.githubusercontent.com/u/117935012?s=400&u=9a871a46dd13437f0adcae166e9efbe518ff0b99&v=4" alt="ZIMO-Elektronik" width="100pt" />
|
||||
</p>
|
||||
<p align="center"><b>ZIMO-Elektronik</b></p>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="https://github.com/ada-url/ada">
|
||||
<p align="center">
|
||||
<img src="https://avatars.githubusercontent.com/u/120840559?s=200&v=4" alt="ada" width="100pt" />
|
||||
</p>
|
||||
<p align="center"><b>ada - WHATWG-compliant and fast URL parser written in modern C++</b></p>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="https://github.com/exaloop/codon">
|
||||
<p align="center">
|
||||
<img src="https://github.com/exaloop/codon/blob/develop/docs/img/logo.png?raw=true" alt="codon" width="100pt" />
|
||||
</p>
|
||||
<p align="center"><b>codon - A high-performance, zero-overhead, extensible Python compiler using LLVM</b></p>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="https://github.com/RoaringBitmap/CRoaring">
|
||||
<p align="center">
|
||||
<img src="https://avatars.githubusercontent.com/u/16548876?s=200&v=4" alt="CRoaring" width="100pt" />
|
||||
</p>
|
||||
<p align="center"><b>CRoaring - Roaring bitmaps in C (and C++), with SIMD (AVX2, AVX-512 and NEON) optimizations: used by Apache Doris, ClickHouse, and StarRocks</b></p>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
69
cmake/.cmake-format-additional_commands-cpm
Normal file
69
cmake/.cmake-format-additional_commands-cpm
Normal file
@@ -0,0 +1,69 @@
|
||||
parse:
|
||||
additional_commands:
|
||||
cpmaddpackage:
|
||||
pargs:
|
||||
nargs: '*'
|
||||
flags: []
|
||||
spelling: CPMAddPackage
|
||||
kwargs: &cpmaddpackagekwargs
|
||||
NAME: 1
|
||||
FORCE: 1
|
||||
VERSION: 1
|
||||
GIT_TAG: 1
|
||||
DOWNLOAD_ONLY: 1
|
||||
GITHUB_REPOSITORY: 1
|
||||
GITLAB_REPOSITORY: 1
|
||||
GIT_REPOSITORY: 1
|
||||
SVN_REPOSITORY: 1
|
||||
SVN_REVISION: 1
|
||||
SOURCE_DIR: 1
|
||||
DOWNLOAD_COMMAND: 1
|
||||
FIND_PACKAGE_ARGUMENTS: 1
|
||||
NO_CACHE: 1
|
||||
GIT_SHALLOW: 1
|
||||
URL: 1
|
||||
URL_HASH: 1
|
||||
URL_MD5: 1
|
||||
DOWNLOAD_NAME: 1
|
||||
DOWNLOAD_NO_EXTRACT: 1
|
||||
HTTP_USERNAME: 1
|
||||
HTTP_PASSWORD: 1
|
||||
EXCLUDE_FROM_ALL: 1
|
||||
SYSTEM: 1
|
||||
SOURCE_SUBDIR: 1
|
||||
OPTIONS: +
|
||||
cpmfindpackage:
|
||||
pargs:
|
||||
nargs: '*'
|
||||
flags: []
|
||||
spelling: CPMFindPackage
|
||||
kwargs: *cpmaddpackagekwargs
|
||||
cpmdeclarepackage:
|
||||
pargs:
|
||||
nargs: '*'
|
||||
flags: []
|
||||
spelling: CPMDeclarePackage
|
||||
kwargs: *cpmaddpackagekwargs
|
||||
packageproject:
|
||||
pargs:
|
||||
nargs: '*'
|
||||
flags: []
|
||||
spelling: packageProject
|
||||
kwargs:
|
||||
NAME: 1
|
||||
VERSION: 1
|
||||
INCLUDE_DIR: 1
|
||||
INCLUDE_DESTINATION: 1
|
||||
BINARY_DIR: 1
|
||||
COMPATIBILITY: 1
|
||||
VERSION_HEADER: 1
|
||||
DEPENDENCIES: +
|
||||
cpmusepackagelock:
|
||||
pargs: 1
|
||||
spelling: CPMUsePackageLock
|
||||
cpmregisterpackage:
|
||||
pargs: 1
|
||||
spelling: CPMRegisterPackage
|
||||
cpmgetpackageversion:
|
||||
pargs: 2
|
||||
spelling: CPMGetPackageVersion
|
||||
@@ -5,7 +5,7 @@
|
||||
# MIT License
|
||||
# -----------
|
||||
#[[
|
||||
Copyright (c) 2019-2022 Lars Melchior and contributors
|
||||
Copyright (c) 2019-2023 Lars Melchior and contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -99,6 +99,12 @@ macro(cpm_set_policies)
|
||||
cmake_policy(SET CMP0135 NEW)
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0135 NEW)
|
||||
endif()
|
||||
|
||||
# treat relative git repository paths as being relative to the parent project's remote
|
||||
if(POLICY CMP0150)
|
||||
cmake_policy(SET CMP0150 NEW)
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0150 NEW)
|
||||
endif()
|
||||
endmacro()
|
||||
cpm_set_policies()
|
||||
|
||||
@@ -528,7 +534,6 @@ function(CPMAddPackage)
|
||||
BITBUCKET_REPOSITORY
|
||||
GIT_REPOSITORY
|
||||
SOURCE_DIR
|
||||
DOWNLOAD_COMMAND
|
||||
FIND_PACKAGE_ARGUMENTS
|
||||
NO_CACHE
|
||||
SYSTEM
|
||||
@@ -537,7 +542,7 @@ function(CPMAddPackage)
|
||||
SOURCE_SUBDIR
|
||||
)
|
||||
|
||||
set(multiValueArgs URL OPTIONS)
|
||||
set(multiValueArgs URL OPTIONS DOWNLOAD_COMMAND)
|
||||
|
||||
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
|
||||
|
||||
@@ -1096,15 +1101,17 @@ function(cpm_prettify_package_arguments OUT_VAR IS_IN_COMMENT)
|
||||
DOWNLOAD_ONLY
|
||||
GITHUB_REPOSITORY
|
||||
GITLAB_REPOSITORY
|
||||
BITBUCKET_REPOSITORY
|
||||
GIT_REPOSITORY
|
||||
SOURCE_DIR
|
||||
DOWNLOAD_COMMAND
|
||||
FIND_PACKAGE_ARGUMENTS
|
||||
NO_CACHE
|
||||
SYSTEM
|
||||
GIT_SHALLOW
|
||||
EXCLUDE_FROM_ALL
|
||||
SOURCE_SUBDIR
|
||||
)
|
||||
set(multiValueArgs OPTIONS)
|
||||
set(multiValueArgs URL OPTIONS DOWNLOAD_COMMAND)
|
||||
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
foreach(oneArgName ${oneValueArgs})
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
|
||||
|
||||
set(CPM_DOWNLOAD_VERSION 1.0.0-development-version)
|
||||
set(CPM_HASH_SUM "CPM_HASH_SUM_PLACEHOLDER")
|
||||
|
||||
if(CPM_SOURCE_CACHE)
|
||||
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
@@ -11,23 +16,9 @@ endif()
|
||||
# Expand relative path. This is important if the provided path contains a tilde (~)
|
||||
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
|
||||
|
||||
function(download_cpm)
|
||||
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
|
||||
file(DOWNLOAD
|
||||
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
|
||||
${CPM_DOWNLOAD_LOCATION}
|
||||
)
|
||||
endfunction()
|
||||
|
||||
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
|
||||
download_cpm()
|
||||
else()
|
||||
# resume download if it previously failed
|
||||
file(READ ${CPM_DOWNLOAD_LOCATION} check)
|
||||
if("${check}" STREQUAL "")
|
||||
download_cpm()
|
||||
endif()
|
||||
unset(check)
|
||||
endif()
|
||||
file(DOWNLOAD
|
||||
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
|
||||
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
|
||||
)
|
||||
|
||||
include(${CPM_DOWNLOAD_LOCATION})
|
||||
|
||||
@@ -7,7 +7,7 @@ project(CPMExampleCatch2)
|
||||
include(../../cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage("gh:cpm-cmake/testpack-fibonacci@2.0")
|
||||
CPMAddPackage("gh:catchorg/Catch2@3.2.1")
|
||||
CPMAddPackage("gh:catchorg/Catch2@3.4.0")
|
||||
|
||||
# ---- Create binary ----
|
||||
|
||||
|
||||
14
examples/simdjson/CMakeLists.txt
Normal file
14
examples/simdjson/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
project(CPMSIMDJSONExample)
|
||||
|
||||
# ---- Dependencies ----
|
||||
|
||||
include(../../cmake/CPM.cmake)
|
||||
CPMAddPackage("gh:simdjson/simdjson@3.5.0")
|
||||
|
||||
# ---- Executable ----
|
||||
|
||||
add_executable(CPMSIMDJSONExample main.cpp)
|
||||
target_compile_features(CPMSIMDJSONExample PRIVATE cxx_std_17)
|
||||
target_link_libraries(CPMSIMDJSONExample simdjson::simdjson)
|
||||
31
examples/simdjson/main.cpp
Normal file
31
examples/simdjson/main.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "simdjson.h"
|
||||
using namespace simdjson;
|
||||
|
||||
int main() {
|
||||
ondemand::parser parser;
|
||||
auto cars_json = R"( [
|
||||
{ "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
|
||||
{ "make": "Kia", "model": "Soul", "year": 2012, "tire_pressure": [ 30.1, 31.0, 28.6, 28.7 ] },
|
||||
{ "make": "Toyota", "model": "Tercel", "year": 1999, "tire_pressure": [ 29.8, 30.0, 30.2, 30.5 ] }
|
||||
] )"_padded;
|
||||
|
||||
// Iterating through an array of objects
|
||||
for (ondemand::object car : parser.iterate(cars_json)) {
|
||||
// Accessing a field by name
|
||||
std::cout << "Make/Model: " << std::string_view(car["make"]) << "/"
|
||||
<< std::string_view(car["model"]) << std::endl;
|
||||
|
||||
// Casting a JSON element to an integer
|
||||
uint64_t year = car["year"];
|
||||
std::cout << "- This car is " << 2020 - year << " years old." << std::endl;
|
||||
|
||||
// Iterating through an array of floats
|
||||
double total_tire_pressure = 0;
|
||||
for (double tire_pressure : car["tire_pressure"]) {
|
||||
total_tire_pressure += tire_pressure;
|
||||
}
|
||||
std::cout << "- Average tire pressure: " << (total_tire_pressure / 4) << std::endl;
|
||||
}
|
||||
}
|
||||
25
test/integration/test_download_command.rb
Normal file
25
test/integration/test_download_command.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
require_relative './lib'
|
||||
|
||||
# Tests using a multi-argumenet download command to fetch a dependency
|
||||
|
||||
class DownloadCommand < IntegrationTest
|
||||
|
||||
def test_fetch_dependency_using_download_command
|
||||
prj = make_project from_template: 'using-adder'
|
||||
|
||||
prj.create_lists_from_default_template package: <<~PACK
|
||||
set(DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/_deps/testpack-adder-src)
|
||||
CPMAddPackage(
|
||||
NAME testpack-adder
|
||||
SOURCE_DIR ${DOWNLOAD_DIR}
|
||||
DOWNLOAD_COMMAND git clone --depth 1 --branch v1.0.0 https://github.com/cpm-cmake/testpack-adder.git ${DOWNLOAD_DIR}
|
||||
OPTIONS "ADDER_BUILD_TESTS OFF"
|
||||
)
|
||||
PACK
|
||||
|
||||
# configure with unpopulated cache
|
||||
assert_success prj.configure
|
||||
assert_success prj.build
|
||||
end
|
||||
|
||||
end
|
||||
17
test/integration/test_relative_urls.rb
Normal file
17
test/integration/test_relative_urls.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require_relative './lib'
|
||||
|
||||
class RelativeURLs < IntegrationTest
|
||||
def setup
|
||||
# relative URLs were introduced in CMake 3.27
|
||||
@relative_urls_supported = (!ENV['CMAKE_VERSION']) || (Gem::Version.new(ENV['CMAKE_VERSION']) >= Gem::Version.new('3.27'))
|
||||
end
|
||||
|
||||
def test_add_project_with_relative_urls
|
||||
omit_if !@relative_urls_supported do
|
||||
prj = make_project from_template: 'using-fibadder'
|
||||
prj.create_lists_from_default_template package: 'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.1.0-relative-urls")'
|
||||
assert_success prj.configure
|
||||
assert_success prj.build
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user