Compare commits

..

5 Commits

Author SHA1 Message Date
Lars Melchior
02d57a1601 Update URLs for new CPM.cmake organisation (#194)
* update URLs for new CPM.cmake organisation

* trigger travis
2021-02-08 21:31:06 +01:00
Claus Klein
5f614e5eb6 update most package versions (#190)
* update most package versions

extent build_all.py to inject cmake modules
and use Ninja generator

* fix build problems while build on debian

use SYSTEM include paths (for clang++)
we should not use local installed header!

* fix banchmark example

finalize cmake project code injection as an option

* fix build problems on travis CI

gtest needs c++17

* Update examples/build_all.py

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

* reindent py script requested by review

indent with only 2 spaces again

* changes according the review

the gtest build error seems to be a make -j cpucount problem

* revert filter too

Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
2021-02-07 17:08:04 +01:00
Xavier Muller
1f5cb903e5 fix superbuild cmake < 3.17 (#193)
* CPM_INDENT in the global scope as suggest

* Fix FetchContent failure with cmake < 3.17

* format
2021-02-07 17:07:47 +01: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
Borislav Stanimirov
fe8d15ba82 Expand CPM_SOURCE_CACHE path provided as a configure argument (#186)
Otherwise if one configures with -DCPM_SOURCE_CACHE=~/something (tilde to be expanded to $HOME), https://gitlab.kitware.com/cmake/cmake/-/issues/21729 hits, EXISTS always fails, and file(DOWNLOAD) fails
2021-01-21 16:31:55 +01:00
23 changed files with 200 additions and 77 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
build/
/build* /build*
/.vscode /.vscode
*.DS_Store *.DS_Store

View File

@@ -1,7 +1,7 @@
[![Build Status](https://travis-ci.com/TheLartians/CPM.cmake.svg?branch=master)](https://travis-ci.com/TheLartians/CPM.cmake) [![Build Status](https://travis-ci.com/cpm-cmake/CPM.cmake.svg?branch=master)](https://travis-ci.com/cpm-cmake/CPM.cmake)
[![Actions Status](https://github.com/TheLartians/CPM.cmake/workflows/MacOS/badge.svg)](https://github.com/TheLartians/CPM.cmake/actions) [![Actions Status](https://github.com/cpm-cmake/CPM.cmake/workflows/MacOS/badge.svg)](https://github.com/cpm-cmake/CPM.cmake/actions)
[![Actions Status](https://github.com/TheLartians/CPM.cmake/workflows/Windows/badge.svg)](https://github.com/TheLartians/CPM.cmake/actions) [![Actions Status](https://github.com/cpm-cmake/CPM.cmake/workflows/Windows/badge.svg)](https://github.com/cpm-cmake/CPM.cmake/actions)
[![Actions Status](https://github.com/TheLartians/CPM.cmake/workflows/Ubuntu/badge.svg)](https://github.com/TheLartians/CPM.cmake/actions) [![Join the chat at https://gitter.im/TheLartians/CPM.cmake](https://badges.gitter.im/TheLartians/CPM.cmake.svg)](https://gitter.im/TheLartians/CPM.cmake?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Actions Status](https://github.com/cpm-cmake/CPM.cmake/workflows/Ubuntu/badge.svg)](https://github.com/cpm-cmake/CPM.cmake/actions)
<br /> <br />
<p align="center"> <p align="center">
@@ -80,19 +80,19 @@ CPMAddPackage(
target_link_libraries(tests Catch2) target_link_libraries(tests Catch2)
``` ```
See the [examples directory](https://github.com/TheLartians/CPM.cmake/tree/master/examples) for complete examples with source code and check [below](#snippets) or in the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/More-Snippets) for example snippets. See the [examples directory](https://github.com/cpm-cmake/CPM.cmake/tree/master/examples) for complete examples with source code and check [below](#snippets) or in the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/More-Snippets) for example snippets.
## Adding CPM ## Adding CPM
To add CPM to your current project, simply add the [latest release](https://github.com/TheLartians/CPM.cmake/releases/latest) of `CPM.cmake` or `get_cpm.cmake` to your project's `cmake` directory. To add CPM to your current project, simply add the [latest release](https://github.com/cpm-cmake/CPM.cmake/releases/latest) of `CPM.cmake` or `get_cpm.cmake` to your project's `cmake` directory.
The command below will perform this automatically. The command below will perform this automatically.
```bash ```bash
mkdir -p cmake mkdir -p cmake
wget -O cmake/CPM.cmake https://github.com/TheLartians/CPM.cmake/releases/latest/download/get_cpm.cmake wget -O cmake/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake
``` ```
You can also download CPM.cmake directly from your project's `CMakeLists.txt`. See the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/Downloading-CPM.cmake-in-CMake) for more details. You can also download CPM.cmake directly from your project's `CMakeLists.txt`. See the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/Downloading-CPM.cmake-in-CMake) for more details.
## Updating CPM ## Updating CPM
@@ -112,7 +112,7 @@ Dependencies using CPM will automatically use the updated script of the outermos
## Limitations ## Limitations
- **No pre-built binaries** For every new build directory, all dependencies are initially downloaded and built from scratch. To avoid extra downloads it is recommend to set the [`CPM_SOURCE_CACHE`](#CPM_SOURCE_CACHE) environmental variable. Using a caching compiler such as [ccache](https://github.com/TheLartians/Ccache.cmake) can drastically reduce build time. - **No pre-built binaries** For every new build directory, all dependencies are initially downloaded and built from scratch. To avoid extra downloads it is recommend to set the [`CPM_SOURCE_CACHE`](#CPM_SOURCE_CACHE) environmental variable. Using a caching compiler such as [ccache](https://github.com/TheLartians/Ccache.cmake) can drastically reduce build time.
- **Dependent on good CMakeLists** Many libraries do not have CMakeLists that work well for subprojects. Luckily this is slowly changing, however, until then, some manual configuration may be required (see the snippets [below](#snippets) for examples). For best practices on preparing projects for CPM, see the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/Preparing-projects-for-CPM.cmake). - **Dependent on good CMakeLists** Many libraries do not have CMakeLists that work well for subprojects. Luckily this is slowly changing, however, until then, some manual configuration may be required (see the snippets [below](#snippets) for examples). For best practices on preparing projects for CPM, see the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/Preparing-projects-for-CPM.cmake).
- **First version used** In diamond-shaped dependency graphs (e.g. `A` depends on `C`@1.1 and `B`, which itself depends on `C`@1.2 the first added dependency will be used (in this case `C`@1.1). In this case, B requires a newer version of `C` than `A`, so CPM will emit a warning. This can be easily resolved by adding a new version of the dependency in the outermost project, or by introducing a [package lock file](#package-lock). - **First version used** In diamond-shaped dependency graphs (e.g. `A` depends on `C`@1.1 and `B`, which itself depends on `C`@1.2 the first added dependency will be used (in this case `C`@1.1). In this case, B requires a newer version of `C` than `A`, so CPM will emit a warning. This can be easily resolved by adding a new version of the dependency in the outermost project, or by introducing a [package lock file](#package-lock).
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). 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).
@@ -127,7 +127,7 @@ Additionally, it is difficult to cross-compile projects (e.g. for mobile), as th
CPM.cmake allows dependencies to be unambiguously defined and builds them from source. CPM.cmake allows dependencies to be unambiguously defined and builds them from source.
Note that the behaviour differs from `find_package`, as variables exported to the parent scope (such as `<PackageName>_LIBRARIES`) will not be visible after adding a package using CPM.cmake. Note that the behaviour differs from `find_package`, as variables exported to the parent scope (such as `<PackageName>_LIBRARIES`) will not be visible after adding a package using CPM.cmake.
The behaviour can be [achieved manually](https://github.com/TheLartians/CPM.cmake/issues/132#issuecomment-644955140), if required. The behaviour can be [achieved manually](https://github.com/cpm-cmake/CPM.cmake/issues/132#issuecomment-644955140), if required.
## Comparison to pure FetchContent / ExternalProject ## Comparison to pure FetchContent / ExternalProject
@@ -160,7 +160,7 @@ export CPM_SOURCE_CACHE=$HOME/.cache/CPM
Note that passing the variable as a configure option to CMake will always override the value set by the environmental variable. Note that passing the variable as a configure option to CMake will always override the value set by the environmental variable.
You can use `CPM_SOURCE_CACHE` on GitHub Actions workflows [cache](https://github.com/actions/cache) and combine it with ccache, to make your CI faster. See the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/Caching-with-CPM.cmake-and-ccache-on-GitHub-Actions) for more info. You can use `CPM_SOURCE_CACHE` on GitHub Actions workflows [cache](https://github.com/actions/cache) and combine it with ccache, to make your CI faster. See the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/Caching-with-CPM.cmake-and-ccache-on-GitHub-Actions) for more info.
### CPM_DOWNLOAD_ALL ### CPM_DOWNLOAD_ALL
@@ -201,7 +201,7 @@ cmake -Bbuild
cmake --build build --target cpm-update-package-lock cmake --build build --target cpm-update-package-lock
``` ```
See the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/Package-lock) for more info. See the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/Package-lock) for more info.
## Built with CPM.cmake ## Built with CPM.cmake
@@ -240,7 +240,7 @@ If you know others, feel free to add them here through a PR.
## Snippets ## Snippets
These examples demonstrate how to include some well-known projects with CPM. These examples demonstrate how to include some well-known projects with CPM.
See the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/More-Snippets) for more snippets. See the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/More-Snippets) for more snippets.
### [Catch2](https://github.com/catchorg/Catch2) ### [Catch2](https://github.com/catchorg/Catch2)
@@ -371,4 +371,4 @@ For a full example on using CPM to download and configure lua with sol2 see [her
### Full Examples ### Full Examples
See the [examples directory](https://github.com/TheLartians/CPM.cmake/tree/master/examples) for full examples with source code and check out the [wiki](https://github.com/TheLartians/CPM.cmake/wiki/More-Snippets) for many more example snippets. See the [examples directory](https://github.com/cpm-cmake/CPM.cmake/tree/master/examples) for full examples with source code and check out the [wiki](https://github.com/cpm-cmake/CPM.cmake/wiki/More-Snippets) for many more example snippets.

View File

@@ -1,6 +1,6 @@
# CPM.cmake - CMake's missing package manager # CPM.cmake - CMake's missing package manager
# =========================================== # ===========================================
# See https://github.com/TheLartians/CPM.cmake for usage and update instructions. # See https://github.com/cpm-cmake/CPM.cmake for usage and update instructions.
# #
# MIT License # MIT License
# ----------- # -----------
@@ -38,9 +38,12 @@ if(CPM_DIRECTORY)
"${CPM_INDENT} \ "${CPM_INDENT} \
A dependency is using a more recent CPM version (${CURRENT_CPM_VERSION}) than the current project (${CPM_VERSION}). \ A dependency is using a more recent CPM version (${CURRENT_CPM_VERSION}) than the current project (${CPM_VERSION}). \
It is recommended to upgrade CPM to the most recent version. \ It is recommended to upgrade CPM to the most recent version. \
See https://github.com/TheLartians/CPM.cmake for more information." See https://github.com/cpm-cmake/CPM.cmake for more information."
) )
endif() endif()
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
include(FetchContent)
endif()
return() return()
endif() endif()
@@ -133,7 +136,10 @@ include(CMakeParseArguments)
# Initialize logging prefix # Initialize logging prefix
if(NOT CPM_INDENT) if(NOT CPM_INDENT)
set(CPM_INDENT "CPM:") set(CPM_INDENT
"CPM:"
CACHE INTERNAL ""
)
endif() endif()
function(cpm_find_package NAME VERSION) function(cpm_find_package NAME VERSION)
@@ -464,14 +470,16 @@ endmacro()
function(cpm_add_to_package_lock Name) function(cpm_add_to_package_lock Name)
if(NOT CPM_DONT_CREATE_PACKAGE_LOCK) if(NOT CPM_DONT_CREATE_PACKAGE_LOCK)
file(APPEND ${CPM_PACKAGE_LOCK_FILE} "# ${Name}\nCPMDeclarePackage(${Name} \"${ARGN}\")\n") cpm_prettify_package_arguments(PRETTY_ARGN false ${ARGN})
file(APPEND ${CPM_PACKAGE_LOCK_FILE} "# ${Name}\nCPMDeclarePackage(${Name}\n${PRETTY_ARGN})\n")
endif() endif()
endfunction() endfunction()
function(cpm_add_comment_to_package_lock Name) function(cpm_add_comment_to_package_lock Name)
if(NOT CPM_DONT_CREATE_PACKAGE_LOCK) if(NOT CPM_DONT_CREATE_PACKAGE_LOCK)
cpm_prettify_package_arguments(PRETTY_ARGN true ${ARGN})
file(APPEND ${CPM_PACKAGE_LOCK_FILE} file(APPEND ${CPM_PACKAGE_LOCK_FILE}
"# ${Name} (unversioned)\n# CPMDeclarePackage(${Name} \"${ARGN}\")\n" "# ${Name} (unversioned)\n# CPMDeclarePackage(${Name}\n${PRETTY_ARGN}#)\n"
) )
endif() endif()
endfunction() endfunction()
@@ -625,3 +633,68 @@ function(cpm_is_git_tag_commit_hash GIT_TAG RESULT)
endif() endif()
endif() endif()
endfunction() endfunction()
function(cpm_prettify_package_arguments OUT_VAR IS_IN_COMMENT)
set(oneValueArgs
NAME
FORCE
VERSION
GIT_TAG
DOWNLOAD_ONLY
GITHUB_REPOSITORY
GITLAB_REPOSITORY
GIT_REPOSITORY
SOURCE_DIR
DOWNLOAD_COMMAND
FIND_PACKAGE_ARGUMENTS
NO_CACHE
GIT_SHALLOW
)
set(multiValueArgs OPTIONS)
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
foreach(oneArgName ${oneValueArgs})
if(DEFINED CPM_ARGS_${oneArgName})
if(${IS_IN_COMMENT})
string(APPEND PRETTY_OUT_VAR "#")
endif()
if(${oneArgName} STREQUAL "SOURCE_DIR")
string(REPLACE ${CMAKE_SOURCE_DIR} "\${CMAKE_SOURCE_DIR}" CPM_ARGS_${oneArgName}
${CPM_ARGS_${oneArgName}}
)
endif()
string(APPEND PRETTY_OUT_VAR " ${oneArgName} ${CPM_ARGS_${oneArgName}}\n")
endif()
endforeach()
foreach(multiArgName ${multiValueArgs})
if(DEFINED CPM_ARGS_${multiArgName})
if(${IS_IN_COMMENT})
string(APPEND PRETTY_OUT_VAR "#")
endif()
string(APPEND PRETTY_OUT_VAR " ${multiArgName}\n")
foreach(singleOption ${CPM_ARGS_${multiArgName}})
if(${IS_IN_COMMENT})
string(APPEND PRETTY_OUT_VAR "#")
endif()
string(APPEND PRETTY_OUT_VAR " \"${singleOption}\"\n")
endforeach()
endif()
endforeach()
if(NOT "${CPM_ARGS_UNPARSED_ARGUMENTS}" STREQUAL "")
if(${IS_IN_COMMENT})
string(APPEND PRETTY_OUT_VAR "#")
endif()
string(APPEND PRETTY_OUT_VAR " ")
foreach(CPM_ARGS_UNPARSED_ARGUMENT ${CPM_ARGS_UNPARSED_ARGUMENTS})
string(APPEND PRETTY_OUT_VAR " ${CPM_ARGS_UNPARSED_ARGUMENT}")
endforeach()
string(APPEND PRETTY_OUT_VAR "\n")
endif()
set(${OUT_VAR}
${PRETTY_OUT_VAR}
PARENT_SCOPE
)
endfunction()

View File

@@ -1,6 +1,8 @@
set(CPM_DOWNLOAD_VERSION 1.0.0-development-version) set(CPM_DOWNLOAD_VERSION 1.0.0-development-version)
if(CPM_SOURCE_CACHE) if(CPM_SOURCE_CACHE)
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE}) elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
@@ -11,7 +13,7 @@ endif()
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}") message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD file(DOWNLOAD
https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} ${CPM_DOWNLOAD_LOCATION}
) )
endif() endif()

View File

@@ -10,9 +10,9 @@ find_package(Threads REQUIRED)
CPMAddPackage( CPMAddPackage(
NAME asio NAME asio
VERSION 1.16.1 VERSION 1.18.1
GITHUB_REPOSITORY chriskohlhoff/asio GITHUB_REPOSITORY chriskohlhoff/asio
GIT_TAG asio-1-16-1 # asio uses non-standard version tag, we must specify GIT_TAG GIT_TAG asio-1-18-1 # asio uses non-standard version tag, we must specify GIT_TAG
) )
# ASIO doesn't use CMake, we have to configure it manually. Extra notes for using on Windows: # ASIO doesn't use CMake, we have to configure it manually. Extra notes for using on Windows:
@@ -24,7 +24,7 @@ CPMAddPackage(
if(asio_ADDED) if(asio_ADDED)
add_library(asio INTERFACE) add_library(asio INTERFACE)
target_include_directories(asio INTERFACE ${asio_SOURCE_DIR}/asio/include) target_include_directories(asio SYSTEM INTERFACE ${asio_SOURCE_DIR}/asio/include)
target_compile_definitions(asio INTERFACE ASIO_STANDALONE ASIO_NO_DEPRECATED) target_compile_definitions(asio INTERFACE ASIO_STANDALONE ASIO_NO_DEPRECATED)
@@ -65,3 +65,4 @@ endif()
add_executable(CPMExampleASIOStandalone main.cpp) add_executable(CPMExampleASIOStandalone main.cpp)
target_link_libraries(CPMExampleASIOStandalone asio) target_link_libraries(CPMExampleASIOStandalone asio)
target_compile_features(CPMExampleASIOStandalone PRIVATE cxx_std_11)

View File

@@ -15,17 +15,17 @@ CPMAddPackage(
CPMAddPackage( CPMAddPackage(
NAME benchmark NAME benchmark
GITHUB_REPOSITORY google/benchmark GITHUB_REPOSITORY google/benchmark
VERSION 1.5.0 VERSION 1.5.2
OPTIONS "BENCHMARK_ENABLE_TESTING Off" OPTIONS "BENCHMARK_ENABLE_TESTING Off"
) )
if(benchmark_ADDED) if(benchmark_ADDED)
# patch google benchmark target # Don't use C++14 because it doesn't work in some configurations.
set_target_properties(benchmark PROPERTIES CXX_STANDARD 17) set_target_properties(benchmark PROPERTIES CXX_STANDARD 11)
endif() endif()
# ---- Executable ---- # ---- Executable ----
add_executable(CPMExampleBenchmark "main.cpp") add_executable(CPMExampleBenchmark "main.cpp")
set_target_properties(CPMExampleBenchmark PROPERTIES CXX_STANDARD 17)
target_link_libraries(CPMExampleBenchmark fibonacci benchmark) target_link_libraries(CPMExampleBenchmark fibonacci benchmark)
target_compile_features(CPMExampleBenchmark PRIVATE cxx_std_17)

View File

@@ -5,7 +5,7 @@ project(CPMExampleBoost)
# ---- Create binary ---- # ---- Create binary ----
add_executable(CPMExampleBoost main.cpp) add_executable(CPMExampleBoost main.cpp)
set_target_properties(CPMExampleBoost PROPERTIES CXX_STANDARD 17) target_compile_features(CPMExampleBoost PRIVATE cxx_std_17)
# ---- Dependencies ---- # ---- Dependencies ----
@@ -18,4 +18,6 @@ CPMFindPackage(
FIND_PACKAGE_ARGUMENTS "COMPONENTS system" FIND_PACKAGE_ARGUMENTS "COMPONENTS system"
) )
target_link_libraries(CPMExampleBoost PRIVATE Boost::system pthread) find_package(Threads REQUIRED)
target_link_libraries(CPMExampleBoost PRIVATE Boost::system Threads::Threads)

View File

@@ -1,5 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os
from pathlib import Path from pathlib import Path
from subprocess import PIPE, run from subprocess import PIPE, run
@@ -9,14 +11,16 @@ examples = [
assert(len(examples) > 0) assert(len(examples) > 0)
def runCommand(command): def runCommand(command):
print('- %s' % command) print('- %s' % command)
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True) result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)
if result.returncode != 0: if result.returncode != 0:
print("error while running '%s':\n" % command, ' ' + str(result.stderr).replace('\n','\n ')) print("error while running '%s':\n" % command, ' ' + str(result.stderr).replace('\n', '\n '))
exit(result.returncode) exit(result.returncode)
return result.stdout return result.stdout
print('') print('')
for example in examples: for example in examples:
print("running example %s" % example.name) print("running example %s" % example.name)
@@ -24,6 +28,6 @@ for example in examples:
project = Path(".") / 'build' / example.name project = Path(".") / 'build' / example.name
configure = runCommand('cmake -H%s -B%s' % (example, project)) configure = runCommand('cmake -H%s -B%s' % (example, project))
print(' ' + '\n '.join([line for line in configure.split('\n') if 'CPM:' in line])) print(' ' + '\n '.join([line for line in configure.split('\n') if 'CPM:' in line]))
build = runCommand('cmake --build %s -j4' % (project)) build = runCommand('cmake --build %s -- -j%i' % (project, os.cpu_count() / 2))
print(' ' + '\n '.join([line for line in build.split('\n') if 'Built target' in line])) print(' ' + '\n '.join([line for line in build.split('\n') if 'Built target' in line]))
print('') print('')

View File

@@ -15,14 +15,14 @@ CPMAddPackage(
CPMAddPackage( CPMAddPackage(
NAME Catch2 NAME Catch2
GITHUB_REPOSITORY catchorg/Catch2 GITHUB_REPOSITORY catchorg/Catch2
VERSION 2.5.0 VERSION 2.13.4
) )
# ---- Create binary ---- # ---- Create binary ----
add_executable(CPMExampleCatch2 main.cpp) add_executable(CPMExampleCatch2 main.cpp)
target_link_libraries(CPMExampleCatch2 fibonacci Catch2) target_link_libraries(CPMExampleCatch2 fibonacci Catch2)
set_target_properties(CPMExampleCatch2 PROPERTIES CXX_STANDARD 17) target_compile_features(CPMExampleCatch2 PRIVATE cxx_std_17)
# ---- Enable testing ---- # ---- Enable testing ----

View File

@@ -8,7 +8,7 @@ include(../../cmake/CPM.cmake)
CPMAddPackage( CPMAddPackage(
NAME cereal NAME cereal
VERSION 1.2.2 VERSION 1.3.0
GITHUB_REPOSITORY USCiLab/cereal GITHUB_REPOSITORY USCiLab/cereal
OPTIONS "SKIP_PORTABILITY_TEST ON" "JUST_INSTALL_CEREAL ON" OPTIONS "SKIP_PORTABILITY_TEST ON" "JUST_INSTALL_CEREAL ON"
) )
@@ -17,4 +17,4 @@ CPMAddPackage(
add_executable(CPMExampleCereal main.cpp) add_executable(CPMExampleCereal main.cpp)
target_link_libraries(CPMExampleCereal cereal) target_link_libraries(CPMExampleCereal cereal)
set_target_properties(CPMExampleCereal PROPERTIES CXX_STANDARD 17) target_compile_features(CPMExampleCereal PRIVATE cxx_std_17)

View File

@@ -17,4 +17,4 @@ CPMAddPackage(
add_executable(CPMExampleCXXOpts main.cpp) add_executable(CPMExampleCXXOpts main.cpp)
target_link_libraries(CPMExampleCXXOpts cxxopts) target_link_libraries(CPMExampleCXXOpts cxxopts)
set_target_properties(CPMExampleCXXOpts PROPERTIES CXX_STANDARD 17) target_compile_features(CPMExampleCXXOpts PRIVATE cxx_std_17)

View File

@@ -15,14 +15,14 @@ CPMAddPackage(
CPMAddPackage( CPMAddPackage(
NAME doctest NAME doctest
GITHUB_REPOSITORY onqtam/doctest GITHUB_REPOSITORY onqtam/doctest
GIT_TAG 2.3.2 GIT_TAG 2.4.5
) )
# ---- Create binary ---- # ---- Create binary ----
add_executable(CPMExampleDoctest main.cpp) add_executable(CPMExampleDoctest main.cpp)
target_link_libraries(CPMExampleDoctest fibonacci doctest) target_link_libraries(CPMExampleDoctest fibonacci doctest)
set_target_properties(CPMExampleDoctest PROPERTIES CXX_STANDARD 17) target_compile_features(CPMExampleDoctest PRIVATE cxx_std_17)
# ---- Enable testing ---- # ---- Enable testing ----

View File

@@ -16,11 +16,11 @@ CPMAddPackage(
if(EnTT_ADDED) if(EnTT_ADDED)
add_library(EnTT INTERFACE) add_library(EnTT INTERFACE)
target_include_directories(EnTT INTERFACE ${EnTT_SOURCE_DIR}/src) target_include_directories(EnTT SYSTEM INTERFACE ${EnTT_SOURCE_DIR}/src)
endif() endif()
# ---- Executable ---- # ---- Executable ----
add_executable(CPMEnTTExample "main.cpp") add_executable(CPMEnTTExample main.cpp)
set_target_properties(CPMEnTTExample PROPERTIES CXX_STANDARD 17) target_compile_features(CPMEnTTExample PRIVATE cxx_std_17)
target_link_libraries(CPMEnTTExample EnTT) target_link_libraries(CPMEnTTExample EnTT)

View File

@@ -8,12 +8,12 @@ include(../../cmake/CPM.cmake)
CPMAddPackage( CPMAddPackage(
NAME fmt NAME fmt
GIT_TAG 6.1.2 GIT_TAG 7.1.3
GITHUB_REPOSITORY fmtlib/fmt GITHUB_REPOSITORY fmtlib/fmt
) )
# ---- Executable ---- # ---- Executable ----
add_executable(CPMFmtExample "main.cpp") add_executable(CPMFmtExample main.cpp)
set_target_properties(CPMFmtExample PROPERTIES CXX_STANDARD 17) target_compile_features(CPMFmtExample PRIVATE cxx_std_17)
target_link_libraries(CPMFmtExample fmt) target_link_libraries(CPMFmtExample fmt)

View File

@@ -15,8 +15,8 @@ CPMAddPackage(
CPMAddPackage( CPMAddPackage(
NAME googletest NAME googletest
GITHUB_REPOSITORY google/googletest GITHUB_REPOSITORY google/googletest
GIT_TAG release-1.8.1 GIT_TAG release-1.10.0
VERSION 1.8.1 VERSION 1.10.0
OPTIONS "INSTALL_GTEST OFF" "gtest_force_shared_crt" OPTIONS "INSTALL_GTEST OFF" "gtest_force_shared_crt"
) )
@@ -24,7 +24,7 @@ CPMAddPackage(
add_executable(CPMExampleGtest main.cpp) add_executable(CPMExampleGtest main.cpp)
target_link_libraries(CPMExampleGtest fibonacci gtest gtest_main gmock) target_link_libraries(CPMExampleGtest fibonacci gtest gtest_main gmock)
set_target_properties(CPMExampleGtest PROPERTIES CXX_STANDARD 17) target_compile_features(CPMExampleGtest PRIVATE cxx_std_17)
# ---- Enable testing ---- # ---- Enable testing ----

View File

@@ -8,19 +8,19 @@ include(../../cmake/CPM.cmake)
CPMAddPackage( CPMAddPackage(
NAME nlohmann_json NAME nlohmann_json
VERSION 3.6.1 VERSION 3.9.1
# not using the repo as it takes forever to clone # not using the repo as it takes forever to clone
URL https://github.com/nlohmann/json/releases/download/v3.6.1/include.zip URL https://github.com/nlohmann/json/releases/download/v3.9.1/include.zip
URL_HASH SHA256=69cc88207ce91347ea530b227ff0776db82dcb8de6704e1a3d74f4841bc651cf URL_HASH SHA256=6bea5877b1541d353bd77bdfbdb2696333ae5ed8f9e8cc22df657192218cad91
) )
if(nlohmann_json_ADDED) if(nlohmann_json_ADDED)
add_library(nlohmann_json INTERFACE) add_library(nlohmann_json INTERFACE)
target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR}) target_include_directories(nlohmann_json SYSTEM INTERFACE ${nlohmann_json_SOURCE_DIR}/include)
endif() endif()
# ---- Executable ---- # ---- Executable ----
add_executable(CPMJSONExample "main.cpp") add_executable(CPMJSONExample main.cpp)
set_target_properties(CPMJSONExample PROPERTIES CXX_STANDARD 17) target_compile_features(CPMJSONExample PRIVATE cxx_std_17)
target_link_libraries(CPMJSONExample nlohmann_json) target_link_libraries(CPMJSONExample nlohmann_json)

View File

@@ -14,11 +14,11 @@ CPMAddPackage(
if(linenoise_ADDED) if(linenoise_ADDED)
add_library(linenoise ${linenoise_SOURCE_DIR}/linenoise.c) add_library(linenoise ${linenoise_SOURCE_DIR}/linenoise.c)
target_include_directories(linenoise PUBLIC ${linenoise_SOURCE_DIR}) target_include_directories(linenoise SYSTEM PUBLIC ${linenoise_SOURCE_DIR})
endif() endif()
# ---- Executable ---- # ---- Executable ----
add_executable(CPMlinenoiseExample "main.cpp") add_executable(CPMlinenoiseExample main.cpp)
set_target_properties(CPMlinenoiseExample PROPERTIES CXX_STANDARD 17) target_compile_features(CPMlinenoiseExample PRIVATE cxx_std_17)
target_link_libraries(CPMlinenoiseExample linenoise) target_link_libraries(CPMlinenoiseExample linenoise)

View File

@@ -8,19 +8,19 @@ include(../../cmake/CPM.cmake)
CPMAddPackage( CPMAddPackage(
NAME range-v3 NAME range-v3
URL https://github.com/ericniebler/range-v3/archive/0.5.0.zip URL https://github.com/ericniebler/range-v3/archive/0.11.0.zip
VERSION 0.5.0 VERSION 0.11.0
# the range-v3 CMakeLists screws with configuration options # the range-v3 CMakeLists screws with configuration options
DOWNLOAD_ONLY True DOWNLOAD_ONLY True
) )
if(range-v3_ADDED) if(range-v3_ADDED)
add_library(range-v3 INTERFACE IMPORTED) add_library(range-v3 INTERFACE IMPORTED)
target_include_directories(range-v3 INTERFACE "${range-v3_SOURCE_DIR}/include") target_include_directories(range-v3 SYSTEM INTERFACE "${range-v3_SOURCE_DIR}/include")
endif() endif()
# ---- Executable ---- # ---- Executable ----
add_executable(CPMRangev3Example "main.cpp") add_executable(CPMRangev3Example main.cpp)
set_target_properties(CPMRangev3Example PROPERTIES CXX_STANDARD 17) target_compile_features(CPMRangev3Example PRIVATE cxx_std_17)
target_link_libraries(CPMRangev3Example range-v3) target_link_libraries(CPMRangev3Example range-v3)

View File

@@ -15,11 +15,11 @@ CPMAddPackage(
if(simple_match_ADDED) if(simple_match_ADDED)
add_library(simple_match INTERFACE IMPORTED) add_library(simple_match INTERFACE IMPORTED)
target_include_directories(simple_match INTERFACE "${simple_match_SOURCE_DIR}/include") target_include_directories(simple_match SYSTEM INTERFACE "${simple_match_SOURCE_DIR}/include")
endif() endif()
# ---- Executable ---- # ---- Executable ----
add_executable(CPMSimpleMatchExample "main.cpp") add_executable(CPMSimpleMatchExample main.cpp)
set_target_properties(CPMSimpleMatchExample PROPERTIES CXX_STANDARD 17) target_compile_features(CPMSimpleMatchExample PRIVATE cxx_std_17)
target_link_libraries(CPMSimpleMatchExample simple_match) target_link_libraries(CPMSimpleMatchExample simple_match)

View File

@@ -20,7 +20,7 @@ if(lua_ADDED)
list(REMOVE_ITEM lua_sources "${lua_SOURCE_DIR}/lua.c" "${lua_SOURCE_DIR}/luac.c") list(REMOVE_ITEM lua_sources "${lua_SOURCE_DIR}/lua.c" "${lua_SOURCE_DIR}/luac.c")
add_library(lua STATIC ${lua_sources}) add_library(lua STATIC ${lua_sources})
target_include_directories(lua PUBLIC $<BUILD_INTERFACE:${lua_SOURCE_DIR}>) target_include_directories(lua SYSTEM PUBLIC $<BUILD_INTERFACE:${lua_SOURCE_DIR}>)
endif() endif()
CPMAddPackage( CPMAddPackage(
@@ -32,12 +32,12 @@ CPMAddPackage(
if(sol2_ADDED) if(sol2_ADDED)
add_library(sol2 INTERFACE IMPORTED) add_library(sol2 INTERFACE IMPORTED)
target_include_directories(sol2 INTERFACE ${sol2_SOURCE_DIR}/include) target_include_directories(sol2 SYSTEM INTERFACE ${sol2_SOURCE_DIR}/include)
target_link_libraries(sol2 INTERFACE lua) target_link_libraries(sol2 INTERFACE lua)
endif() endif()
# ---- Executable ---- # ---- Executable ----
add_executable(CPMSol2Example "main.cpp") add_executable(CPMSol2Example main.cpp)
set_target_properties(CPMSol2Example PROPERTIES CXX_STANDARD 17) target_compile_features(CPMSol2Example PRIVATE cxx_std_17)
target_link_libraries(CPMSol2Example sol2) target_link_libraries(CPMSol2Example sol2)

View File

@@ -9,11 +9,11 @@ include(../../cmake/CPM.cmake)
CPMAddPackage( CPMAddPackage(
NAME spdlog NAME spdlog
GITHUB_REPOSITORY gabime/spdlog GITHUB_REPOSITORY gabime/spdlog
VERSION 1.7.0 VERSION 1.8.2
) )
# ---- Executable ---- # ---- Executable ----
add_executable(CPMSpdlogExample "main.cpp") add_executable(CPMSpdlogExample main.cpp)
set_target_properties(CPMSpdlogExample PROPERTIES CXX_STANDARD 17) target_compile_features(CPMSpdlogExample PRIVATE cxx_std_17)
target_link_libraries(CPMSpdlogExample spdlog) target_link_libraries(CPMSpdlogExample spdlog)

View File

@@ -9,15 +9,13 @@ include(../../cmake/CPM.cmake)
CPMAddPackage( CPMAddPackage(
NAME yaml-cpp NAME yaml-cpp
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
# 0.6.2 uses deprecated CMake syntax
VERSION 0.6.3 VERSION 0.6.3
# 0.6.3 is not released yet, so use the most recent commit GIT_TAG yaml-cpp-0.6.3
GIT_TAG 012269756149ae99745b6dafefd415843d7420bb
OPTIONS "YAML_CPP_BUILD_TESTS Off" "YAML_CPP_BUILD_CONTRIB Off" "YAML_CPP_BUILD_TOOLS Off" OPTIONS "YAML_CPP_BUILD_TESTS Off" "YAML_CPP_BUILD_CONTRIB Off" "YAML_CPP_BUILD_TOOLS Off"
) )
# ---- Executable ---- # ---- Executable ----
add_executable(CPMYamlExample "main.cpp") add_executable(CPMYamlExample main.cpp)
set_target_properties(CPMYamlExample PROPERTIES CXX_STANDARD 17) target_compile_features(CPMYamlExample PRIVATE cxx_std_17)
target_link_libraries(CPMYamlExample yaml-cpp) target_link_libraries(CPMYamlExample yaml-cpp)

View File

@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
include(${CPM_PATH}/CPM.cmake)
include(${CPM_PATH}/testing.cmake)
# cmake-format: off
cpm_prettify_package_arguments(PRETTY_ARGN false
NAME Dependency
SOURCE_DIR ${CMAKE_SOURCE_DIR}/local_dependency/dependency
UPDATE_DISCONNECTED ON
TESTCUSTOMDATA TRUE
)
# cmake-format: on
set(EXPECTED_UNCOMMENTED
" NAME Dependency
SOURCE_DIR \${CMAKE_SOURCE_DIR}/local_dependency/dependency
UPDATE_DISCONNECTED ON TESTCUSTOMDATA TRUE
"
)
assert_equal(${PRETTY_ARGN} ${EXPECTED_UNCOMMENTED})
# cmake-format: off
cpm_prettify_package_arguments(PRETTY_ARGN true
NAME Dependency
SOURCE_DIR ${CMAKE_SOURCE_DIR}/local_dependency/dependency
UPDATE_DISCONNECTED ON
TESTCUSTOMDATA TRUE
)
# cmake-format: on
set(EXPECTED_COMMENTED
"# NAME Dependency
# SOURCE_DIR \${CMAKE_SOURCE_DIR}/local_dependency/dependency
# UPDATE_DISCONNECTED ON TESTCUSTOMDATA TRUE
"
)
assert_equal(${PRETTY_ARGN} ${EXPECTED_COMMENTED})
cpm_prettify_package_arguments(PRETTY_ARGN true "local directory")
set(EXPECTED_COMMENTED_LOCALDIR "# local directory
"
)
assert_equal(${PRETTY_ARGN} ${EXPECTED_COMMENTED_LOCALDIR})