Compare commits

...

1 Commits

Author SHA1 Message Date
pgorgon-hem
634800c619 Added directory inside cache to make it shown more friendly in CLion (#268)
* Added directory inside cache to make it shown more friendly in CLion

* Changed hash generation to omit collision with old cache scheme. Removed moving old directory for compatibility reason.

* Added CPM_USE_NAMED_CACHE_DIRECTORIES option

* Fixed formatting

* Added description of CPM_USE_NAMED_CACHE_DIRECTORIES into README.md

Co-authored-by: Paweł Gorgoń <pgorgon@hem-e.com>
2021-09-15 21:39:31 +02:00
2 changed files with 16 additions and 2 deletions

View File

@@ -196,6 +196,11 @@ These options can also be set as environmental variables.
In the case that `find_package` requires additional arguments, the parameter `FIND_PACKAGE_ARGUMENTS` may be specified in the `CPMAddPackage` call. The value of this parameter will be forwarded to `find_package`.
### CPM_USE_NAMED_CACHE_DIRECTORIES
If set, CPM use additional directory level in cache to improve readability of packages names in IDEs like CLion. It changes cache structure, so all dependencies are downloaded again. There is no problem to mix both structures in one cache directory but then there may be 2 copies of some dependencies.
This can also be set as an environmental variable.
## Local package override
Library developers are often in the situation where they work on a locally checked out dependency at the same time as on a consumer project.

View File

@@ -76,6 +76,10 @@ option(CPM_INCLUDE_ALL_IN_PACKAGE_LOCK
"Add all packages added through CPM.cmake to the package lock"
$ENV{CPM_INCLUDE_ALL_IN_PACKAGE_LOCK}
)
option(CPM_USE_NAMED_CACHE_DIRECTORIES
"Use additional directory of package name in cache on the most nested level."
$ENV{CPM_USE_NAMED_CACHE_DIRECTORIES}
)
set(CPM_VERSION
${CURRENT_CPM_VERSION}
@@ -595,8 +599,13 @@ function(CPMAddPackage)
string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS})
list(SORT origin_parameters)
string(SHA1 origin_hash "${origin_parameters}")
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
if(CPM_USE_NAMED_CACHE_DIRECTORIES)
string(SHA1 origin_hash "${origin_parameters};NEW_CACHE_STRUCTURE_TAG")
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash}/${CPM_ARGS_NAME})
else()
string(SHA1 origin_hash "${origin_parameters}")
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
endif()
# Expand `download_directory` relative path. This is important because EXISTS doesn't work for
# relative paths.
get_filename_component(download_directory ${download_directory} ABSOLUTE)