Skip to content

Commit

Permalink
if CPM_LOCAL_PACKAGES_ONLY, make find_package fail.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arniiiii committed Aug 19, 2024
1 parent 21527a7 commit 011d3dd
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ endfunction()
# method to overwrite internal FetchContent properties, to allow using CPM.cmake to overload
# FetchContent calls. As these are internal cmake properties, this method should be used carefully
# and may need modification in future CMake versions. Source:
# https://github.com/Kitware/CMake/blob/dc3d0b5a0a7d26d43d6cfeb511e224533b5d188f/Modules/FetchContent.cmake#L1152
# https://github.com/Kitware/CMake/blob/dc3d0b5a0a7d26d43d6cfeb511e224533b5d188f/Modules/FetchContent.cmake #L1152
function(cpm_override_fetchcontent contentName)
cmake_parse_arguments(PARSE_ARGV 1 arg "" "SOURCE_DIR;BINARY_DIR" "")
if(NOT "${arg_UNPARSED_ARGUMENTS}" STREQUAL "")
Expand Down Expand Up @@ -716,26 +716,30 @@ function(CPMAddPackage)
endif()

if(NOT CPM_ARGS_FORCE)
if(CPM_USE_LOCAL_PACKAGES OR CPM_LOCAL_PACKAGES_ONLY)
if(CPM_USE_LOCAL_PACKAGES)
cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS})

string(REPLACE " " ";" EDITED_CPM_ARGS_FIND_PACKAGE_ARGUMENTS "${CPM_ARGS_FIND_PACKAGE_ARGUMENTS}")

if(CPM_PACKAGE_FOUND)
cpm_export_variables(${CPM_ARGS_NAME})
return()
elseif(CPM_USE_LOCAL_PACKAGES)
message(
WARNING
"${CPM_INDENT} ${CPM_ARGS_NAME} not found via find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION} ${EDITED_CPM_ARGS_FIND_PACKAGE_ARGUMENTS})"
)
else()
string(REPLACE " " ";" EDITED_CPM_ARGS_FIND_PACKAGE_ARGUMENTS
"${CPM_ARGS_FIND_PACKAGE_ARGUMENTS}"
)
message(
FATAL_ERROR
WARNING
"${CPM_INDENT} ${CPM_ARGS_NAME} not found via find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION} ${EDITED_CPM_ARGS_FIND_PACKAGE_ARGUMENTS})"
)
endif()
endif()
if(CPM_LOCAL_PACKAGES_ONLY)
cpm_find_package(
${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" REQUIRED ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS}
)

cpm_export_variables(${CPM_ARGS_NAME})
return()
endif()
endif()

CPMRegisterPackage("${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}")
Expand Down Expand Up @@ -1070,7 +1074,7 @@ function(
list(APPEND addSubdirectoryExtraArgs EXCLUDE_FROM_ALL)
endif()
if("${SYSTEM}" AND "${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.25")
# https://cmake.org/cmake/help/latest/prop_dir/SYSTEM.html#prop_dir:SYSTEM
# https://cmake.org/cmake/help/latest/prop_dir/SYSTEM.html #prop_dir:SYSTEM
list(APPEND addSubdirectoryExtraArgs SYSTEM)
endif()
if(OPTIONS)
Expand Down

0 comments on commit 011d3dd

Please sign in to comment.