Skip to content

Commit

Permalink
Updates based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
flagarde committed Mar 2, 2023
1 parent 03027e0 commit deeefc3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
29 changes: 15 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

project(
CPM
CPM.cmake
VERSION 0.37.0
LANGUAGES NONE
)

include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPMConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CPMConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CPM"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmakeConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CPM.cmakeConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CPM.cmake"
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/CPMConfigVersion.cmake" COMPATIBILITY SameMajorVersion
"${CMAKE_CURRENT_BINARY_DIR}/CPM.cmakeConfigVersion.cmake" COMPATIBILITY SameMinorVersion
ARCH_INDEPENDENT
)

Expand All @@ -38,23 +38,24 @@ if(NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
else()
set(CPM_RELEASE TRUE)
endif()
# Trick to use the find_package
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake" "${CMAKE_CURRENT_BINARY_DIR}/CPM.cmake" COPYONLY
)
set(CPM_DIR "${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE)
include(cmake/CPM.cmake)
endif()

# Trick to use the find_package
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake" "${CMAKE_CURRENT_BINARY_DIR}/CPM.cmake" COPYONLY)
# Unset in case CPM has been used to install itself
unset(CPM.cmake_FOUND)
set(CPM.cmake_DIR "${CMAKE_CURRENT_BINARY_DIR}")
find_package(CPM.cmake ${PROJECT_VERSION} REQUIRED CONFIG)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
# Without it : Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target
# architecture is known. Please enable at least one language before including GNUInstallDirs.
enable_language(C)
include(GNUInstallDirs)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/CPMConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/CPMConfigVersion.cmake"
FILES "${CMAKE_CURRENT_BINARY_DIR}/CPM.cmakeConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/CPM.cmakeConfigVersion.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CPM"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CPM.cmake"
)
endif()
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,25 @@ The command below will perform this automatically.
mkdir -p 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/cpm-cmake/CPM.cmake/wiki/Downloading-CPM.cmake-in-CMake) for more details.

### Preliminary :
You can use `FetchContent` to obtain CPM for the official repository :
```cmake
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(MyProject)
include(FetchContent)
FetchContent_Declare(
CPM.cmake
GIT_REPOSITORY https://github.com/cpm-cmake/CPM.cmake.git
GIT_TAG v0.38.0
)
FetchContent_MakeAvailable(CPM.cmake)
CPMAddPackage("gh:fmtlib/fmt#7.1.3")
```

## Updating CPM

To update CPM to the newest version, update the script in the project's root directory, for example by running the command above.
Expand Down
File renamed without changes.

0 comments on commit deeefc3

Please sign in to comment.