Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: simplest cmake --install support (requires CMake 3.15+) #598

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Warning: this CMakeLists has been created only for supporting
# `cmake --install` && find_package(CPM) workflow. If you don't
# use it, then this file is not required, just download CPM.cmake
# as written in README.md.
cmake_minimum_required(VERSION 3.15) # minimal for `cmake --install`
include(cmake/CPM.cmake) # extract version
project(CPM LANGUAGES NONE)

include(GNUInstallDirs)
install(FILES ${CMAKE_CURRENT_LIST_DIR}/cmake/CPM.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/CPM)

# CPM-config.cmake stub
file(CONFIGURE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/CPM-config.cmake CONTENT [=[
include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake)
set(CPM_FOUND ON)
]=] @ONLY)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CPM-config.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/CPM)
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ wget -O cmake/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/latest/d

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.

### cmake --install workflow
You can also clone this repo and install the CPM.cmake into your prefix via `cmake -S . -B build && cmake --install build --prefix <your-cmake-install-prefix>`.

## Usage

After `CPM.cmake` has been [added](#adding-cpm) to your project, the function `CPMAddPackage` can be used to fetch and configure a dependency.
Expand Down