Skip to content

Commit

Permalink
Add find_package overrides that also work in CONFIG mode (cpm-cmake#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
patstew committed Sep 24, 2024
1 parent 0bc73f4 commit 121410c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ set(CPM_SOURCE_CACHE
CACHE PATH "Directory to download CPM dependencies"
)

if(NOT CPM_DONT_UPDATE_MODULE_PATH)
if(${CMAKE_VERSION} VERSION_LESS "3.24.0" AND NOT CPM_DONT_UPDATE_MODULE_PATH)
set(CPM_MODULE_PATH
"${CMAKE_BINARY_DIR}/CPM_modules"
CACHE INTERNAL ""
Expand Down Expand Up @@ -269,10 +269,21 @@ endfunction()
# finding the system library
function(cpm_create_module_file Name)
if(NOT CPM_DONT_UPDATE_MODULE_PATH)
# erase any previous modules
file(WRITE ${CPM_MODULE_PATH}/Find${Name}.cmake
"include(\"${CPM_FILE}\")\n${ARGN}\nset(${Name}_FOUND TRUE)"
)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0")
string(TOLOWER ${Name} NameLower)
file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-config.cmake
"include(\"${CMAKE_CURRENT_LIST_DIR}/${NameLower}-extra.cmake\" OPTIONAL)\n"
"include(\"${CMAKE_CURRENT_LIST_DIR}/${Name}Extra.cmake\" OPTIONAL)\n"
)
file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-version.cmake
"set(PACKAGE_VERSION_COMPATIBLE TRUE)\n"
"set(PACKAGE_VERSION_EXACT TRUE)\n"
)
else()
file(WRITE ${CPM_MODULE_PATH}/Find${Name}.cmake
"include(\"${CPM_FILE}\")\n${ARGN}\nset(${Name}_FOUND TRUE)"
)
endif()
endif()
endfunction()

Expand Down

0 comments on commit 121410c

Please sign in to comment.