فهرست منبع

Merge topic 'FetchContent-avoid-IN_LIST' into release-3.24

5c7b6b29f9 FetchContent: Don't use if(... IN_LIST ...)

Acked-by: Kitware Robot <[email protected]>
Merge-request: !7423
Brad King 3 سال پیش
والد
کامیت
c24620fa8b
1فایلهای تغییر یافته به همراه8 افزوده شده و 2 حذف شده
  1. 8 2
      Modules/FetchContent.cmake

+ 8 - 2
Modules/FetchContent.cmake

@@ -1178,7 +1178,11 @@ function(FetchContent_Declare contentName)
 
   # Always check this even if we won't save these details.
   # This helps projects catch errors earlier.
-  if("OVERRIDE_FIND_PACKAGE" IN_LIST ARGN AND "FIND_PACKAGE_ARGS" IN_LIST ARGN)
+  # Avoid using if(... IN_LIST ...) so we don't have to alter policy settings
+  list(FIND ARGN OVERRIDE_FIND_PACKAGE index_OVERRIDE_FIND_PACKAGE)
+  list(FIND ARGN FIND_PACKAGE_ARGS index_FIND_PACKAGE_ARGS)
+  if(index_OVERRIDE_FIND_PACKAGE GREATER_EQUAL 0 AND
+     index_FIND_PACKAGE_ARGS GREATER_EQUAL 0)
     message(FATAL_ERROR
       "Cannot specify both OVERRIDE_FIND_PACKAGE and FIND_PACKAGE_ARGS "
       "when declaring details for ${contentName}"
@@ -1750,7 +1754,9 @@ function(__FetchContent_setupFindPackageRedirection contentName)
     DEFINED
   )
 
-  if(NOT wantFindPackage AND NOT OVERRIDE_FIND_PACKAGE IN_LIST contentDetails)
+  # Avoid using if(... IN_LIST ...) so we don't have to alter policy settings
+  list(FIND contentDetails OVERRIDE_FIND_PACKAGE indexResult)
+  if(NOT wantFindPackage AND indexResult EQUAL -1)
     # No find_package() redirection allowed
     return()
   endif()