Skip to content

Commit 4a3cb8c

Browse files
committed
Set CPM_SOURCE_CACHE in CMake presets and update docs
Moved CPM_SOURCE_CACHE configuration from CMakeLists.txt to CMakePresets.json for all presets, ensuring consistent and automatic cache setup. Updated README to document this behavior and removed redundant cache setup code from setup.cmake and README.
1 parent c13e524 commit 4a3cb8c

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ Use `CPMAddPackage` to fetch cpp-library directly in your `CMakeLists.txt`:
101101
```cmake
102102
cmake_minimum_required(VERSION 3.24)
103103
104-
# Setup CPM cache before project()
105-
if(PROJECT_IS_TOP_LEVEL AND NOT CPM_SOURCE_CACHE AND NOT DEFINED ENV{CPM_SOURCE_CACHE})
106-
set(CPM_SOURCE_CACHE "${CMAKE_SOURCE_DIR}/.cache/cpm" CACHE PATH "CPM source cache")
107-
message(STATUS "Setting cpm cache dir to: ${CPM_SOURCE_CACHE}")
108-
endif()
109104
include(cmake/CPM.cmake)
110105
111106
# Fetch cpp-library before project()
@@ -426,6 +421,8 @@ cpp-library generates a `CMakePresets.json` file with the following configuratio
426421
- **`clang-tidy`**: Static analysis build
427422
- **`init`**: Template regeneration (regenerates CMakePresets.json, CI workflows, etc.)
428423

424+
All presets automatically configure `CPM_SOURCE_CACHE` to `${sourceDir}/.cache/cpm` for faster dependency resolution. You can override this by setting the `CPM_SOURCE_CACHE` environment variable.
425+
429426
### Version Management
430427

431428
Version is automatically detected from git tags:

setup.cmake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,6 @@ endif()
314314
file(WRITE "${PROJECT_DIR}/CMakeLists.txt"
315315
"cmake_minimum_required(VERSION 3.24)
316316
317-
# Setup CPM cache before project()
318-
if(PROJECT_IS_TOP_LEVEL AND NOT CPM_SOURCE_CACHE AND NOT DEFINED ENV{CPM_SOURCE_CACHE})
319-
set(CPM_SOURCE_CACHE "${CMAKE_SOURCE_DIR}/.cache/cpm" CACHE PATH "CPM source cache")
320-
message(STATUS "Setting cpm cache dir to: ${CPM_SOURCE_CACHE}")
321-
endif()
322317
include(cmake/CPM.cmake)
323318
324319
# Fetch cpp-library before project()

templates/CMakePresets.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"CMAKE_BUILD_TYPE": "Release",
1212
"BUILD_TESTING": "OFF",
1313
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
14-
"CMAKE_CXX_EXTENSIONS": "OFF"
14+
"CMAKE_CXX_EXTENSIONS": "OFF",
15+
"CPM_SOURCE_CACHE": "${sourceDir}/.cache/cpm"
1516
}
1617
},
1718
{
@@ -24,7 +25,8 @@
2425
"CMAKE_BUILD_TYPE": "Debug",
2526
"BUILD_TESTING": "ON",
2627
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
27-
"CMAKE_CXX_EXTENSIONS": "OFF"
28+
"CMAKE_CXX_EXTENSIONS": "OFF",
29+
"CPM_SOURCE_CACHE": "${sourceDir}/.cache/cpm"
2830
}
2931
},
3032
{
@@ -38,7 +40,8 @@
3840
"BUILD_TESTING": "OFF",
3941
"BUILD_DOCS": "ON",
4042
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
41-
"CMAKE_CXX_EXTENSIONS": "OFF"
43+
"CMAKE_CXX_EXTENSIONS": "OFF",
44+
"CPM_SOURCE_CACHE": "${sourceDir}/.cache/cpm"
4245
}
4346
},
4447
{
@@ -52,7 +55,8 @@
5255
"BUILD_TESTING": "ON",
5356
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
5457
"CMAKE_CXX_EXTENSIONS": "OFF",
55-
"CMAKE_CXX_CLANG_TIDY": "clang-tidy"
58+
"CMAKE_CXX_CLANG_TIDY": "clang-tidy",
59+
"CPM_SOURCE_CACHE": "${sourceDir}/.cache/cpm"
5660
}
5761
},
5862
{
@@ -66,7 +70,8 @@
6670
"BUILD_TESTING": "OFF",
6771
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
6872
"CMAKE_CXX_EXTENSIONS": "OFF",
69-
"CPP_LIBRARY_FORCE_INIT": "ON"
73+
"CPP_LIBRARY_FORCE_INIT": "ON",
74+
"CPM_SOURCE_CACHE": "${sourceDir}/.cache/cpm"
7075
}
7176
}
7277
],

0 commit comments

Comments
 (0)