Skip to content

Commit deeefc3

Browse files
committed
Updates based on comments
1 parent 03027e0 commit deeefc3

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

CMakeLists.txt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
22

33
project(
4-
CPM
4+
CPM.cmake
55
VERSION 0.37.0
66
LANGUAGES NONE
77
)
88

99
include(CMakePackageConfigHelpers)
1010
configure_package_config_file(
11-
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPMConfig.cmake.in"
12-
"${CMAKE_CURRENT_BINARY_DIR}/CPMConfig.cmake"
13-
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CPM"
11+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmakeConfig.cmake.in"
12+
"${CMAKE_CURRENT_BINARY_DIR}/CPM.cmakeConfig.cmake"
13+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CPM.cmake"
1414
)
1515
write_basic_package_version_file(
16-
"${CMAKE_CURRENT_BINARY_DIR}/CPMConfigVersion.cmake" COMPATIBILITY SameMajorVersion
16+
"${CMAKE_CURRENT_BINARY_DIR}/CPM.cmakeConfigVersion.cmake" COMPATIBILITY SameMinorVersion
1717
ARCH_INDEPENDENT
1818
)
1919

@@ -38,23 +38,24 @@ if(NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
3838
else()
3939
set(CPM_RELEASE TRUE)
4040
endif()
41-
# Trick to use the find_package
42-
configure_file(
43-
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake" "${CMAKE_CURRENT_BINARY_DIR}/CPM.cmake" COPYONLY
44-
)
45-
set(CPM_DIR "${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE)
46-
include(cmake/CPM.cmake)
4741
endif()
4842

43+
# Trick to use the find_package
44+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake" "${CMAKE_CURRENT_BINARY_DIR}/CPM.cmake" COPYONLY)
45+
# Unset in case CPM has been used to install itself
46+
unset(CPM.cmake_FOUND)
47+
set(CPM.cmake_DIR "${CMAKE_CURRENT_BINARY_DIR}")
48+
find_package(CPM.cmake ${PROJECT_VERSION} REQUIRED CONFIG)
49+
4950
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
5051
# Without it : Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target
5152
# architecture is known. Please enable at least one language before including GNUInstallDirs.
5253
enable_language(C)
5354
include(GNUInstallDirs)
5455
install(
55-
FILES "${CMAKE_CURRENT_BINARY_DIR}/CPMConfig.cmake"
56-
"${CMAKE_CURRENT_BINARY_DIR}/CPMConfigVersion.cmake"
56+
FILES "${CMAKE_CURRENT_BINARY_DIR}/CPM.cmakeConfig.cmake"
57+
"${CMAKE_CURRENT_BINARY_DIR}/CPM.cmakeConfigVersion.cmake"
5758
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake"
58-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CPM"
59+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CPM.cmake"
5960
)
6061
endif()

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,25 @@ The command below will perform this automatically.
112112
mkdir -p cmake
113113
wget -O cmake/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake
114114
```
115-
116115
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.
117116

117+
### Preliminary :
118+
You can use `FetchContent` to obtain CPM for the official repository :
119+
```cmake
120+
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
121+
project(MyProject)
122+
123+
include(FetchContent)
124+
FetchContent_Declare(
125+
CPM.cmake
126+
GIT_REPOSITORY https://github.com/cpm-cmake/CPM.cmake.git
127+
GIT_TAG v0.38.0
128+
)
129+
FetchContent_MakeAvailable(CPM.cmake)
130+
131+
CPMAddPackage("gh:fmtlib/fmt#7.1.3")
132+
```
133+
118134
## Updating CPM
119135

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

0 commit comments

Comments
 (0)