Skip to content

Commit 7fbf501

Browse files
authored
Merge pull request #4999 from modocache/cmake-in-list
[cmake] Enable IN_LIST compare policy
2 parents 195f1d4 + 3123b47 commit 7fbf501

File tree

9 files changed

+22
-28
lines changed

9 files changed

+22
-28
lines changed

CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ if(POLICY CMP0054)
88
cmake_policy(SET CMP0054 NEW)
99
endif()
1010

11+
# Enable the IN_LIST operator, as in:
12+
# `if(<element_variable> IN_LIST <list_variable>)`
13+
if(POLICY CMP0057)
14+
cmake_policy(SET CMP0057 NEW)
15+
endif()
16+
1117
# Add path for custom CMake modules.
1218
list(APPEND CMAKE_MODULE_PATH
1319
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
@@ -491,11 +497,10 @@ function(is_sdk_requested name result_var_name)
491497
if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${name}")
492498
set("${result_var_name}" "TRUE" PARENT_SCOPE)
493499
else()
494-
list(FIND SWIFT_SDKS "${name}" sdk_index)
495-
if(${sdk_index} EQUAL -1)
496-
set("${result_var_name}" "FALSE" PARENT_SCOPE)
497-
else()
500+
if("${name}" IN_LIST SWIFT_SDKS)
498501
set("${result_var_name}" "TRUE" PARENT_SCOPE)
502+
else()
503+
set("${result_var_name}" "FALSE" PARENT_SCOPE)
499504
endif()
500505
endif()
501506
endfunction()

apinotes/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ endforeach()
6666
file(GLOB SWIFT_API_NOTES_INPUT_FILES "${SWIFT_API_NOTES_PATH}/*.apinotes")
6767
foreach(file ${SWIFT_API_NOTES_INPUT_FILES})
6868
get_filename_component(name "${file}" NAME_WE)
69-
list(FIND SWIFT_API_NOTES_INPUTS "${name}" name_index)
70-
if(name_index EQUAL -1)
69+
if(NOT "${name}" IN_LIST SWIFT_API_NOTES_INPUTS)
7170
message(SEND_ERROR "Found apinotes for ${name}; please add to CMakeLists.txt")
7271
endif()
7372
endforeach()

cmake/modules/AddSwift.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,7 @@ function(_add_swift_library_single target name)
618618
else()
619619
string(REPLACE swift "" module_name "${name}")
620620
endif()
621-
list(FIND SWIFT_API_NOTES_INPUTS "${module_name}" overlay_index)
622-
if(NOT ${overlay_index} EQUAL -1)
621+
if("${module_name}" IN_LIST SWIFT_API_NOTES_INPUTS)
623622
set(SWIFTLIB_SINGLE_API_NOTES "${module_name}")
624623
endif()
625624

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ function(add_swift_unittest test_dirname)
6060
endif()
6161

6262
if(SWIFT_RUNTIME_USE_SANITIZERS)
63-
list(FIND SWIFT_RUNTIME_USE_SANITIZERS "Thread" THREAD_INDEX)
64-
if(NOT THREAD_INDEX EQUAL -1)
63+
if("Thread" IN_LIST SWIFT_RUNTIME_USE_SANITIZERS)
6564
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY COMPILE_FLAGS
6665
" -fsanitize=thread")
6766
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY

cmake/modules/SwiftAddCustomCommandTarget.cmake

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ include(SwiftUtils)
1616
function(_make_acct_argument_list)
1717
set(args)
1818
foreach(k ${ARGN})
19-
list(FIND options ${k} option_index)
20-
if(${option_index} EQUAL -1)
21-
list(APPEND args ${${k}_keyword} ${ACCT_${k}})
22-
else()
19+
if(${k} IN_LIST options)
2320
list(APPEND args ${${k}_keyword})
21+
else()
22+
list(APPEND args ${${k}_keyword} ${ACCT_${k}})
2423
endif()
2524
endforeach()
2625
set(args ${args} PARENT_SCOPE)

cmake/modules/SwiftComponents.cmake

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ macro(swift_configure_components)
7979
endforeach()
8080

8181
foreach(component ${SWIFT_INSTALL_COMPONENTS})
82-
list(FIND _SWIFT_DEFINED_COMPONENTS "${component}" index)
83-
if(${index} EQUAL -1)
82+
if(NOT "${component}" IN_LIST _SWIFT_DEFINED_COMPONENTS)
8483
message(FATAL_ERROR "unknown install component: ${component}")
8584
endif()
8685

@@ -96,8 +95,7 @@ function(swift_is_installing_component component result_var_name)
9695
if("${component}" STREQUAL "never_install")
9796
set("${result_var_name}" FALSE PARENT_SCOPE)
9897
else()
99-
list(FIND _SWIFT_DEFINED_COMPONENTS "${component}" index)
100-
if(${index} EQUAL -1)
98+
if(NOT "${component}" IN_LIST _SWIFT_DEFINED_COMPONENTS)
10199
message(FATAL_ERROR "unknown install component: ${component}")
102100
endif()
103101

cmake/modules/SwiftList.cmake

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ include(SwiftUtils)
33
function(list_subtract lhs rhs result_var_name)
44
set(result)
55
foreach(item IN LISTS lhs)
6-
list(FIND rhs "${item}" index)
7-
if(${index} EQUAL -1)
6+
if(NOT "${item}" IN_LIST rhs)
87
list(APPEND result "${item}")
98
endif()
109
endforeach()
@@ -14,8 +13,7 @@ endfunction()
1413
function(list_intersect lhs rhs result_var_name)
1514
set(result)
1615
foreach(item IN LISTS lhs)
17-
list(FIND rhs "${item}" index)
18-
if(NOT ${index} EQUAL -1)
16+
if("${item}" IN_LIST rhs)
1917
list(APPEND result "${item}")
2018
endif()
2119
endforeach()
@@ -25,8 +23,7 @@ endfunction()
2523
function(list_union lhs rhs result_var_name)
2624
set(result)
2725
foreach(item IN LISTS lhs rhs)
28-
list(FIND result "${item}" index)
29-
if(${index} EQUAL -1)
26+
if(NOT "${item}" IN_LIST result)
3027
list(APPEND result "${item}")
3128
endif()
3229
endforeach()

cmake/modules/SwiftXcodeSupport.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ function(check_imported_target_has_imported_configuration target config)
3131
message(FATAL_ERROR "No import configuration of ${target} specified?!")
3232
endif()
3333

34-
list(FIND IMPORTED_CONFIGS_LIST "${config}" FOUND_CONFIG)
35-
if (FOUND_CONFIG EQUAL -1)
34+
if(NOT "${config}" IN_LIST IMPORTED_CONFIGS_LIST)
3635
message(FATAL_ERROR "${target} does not have imported config '${config}'?! Instead: ${IMPORTED_CONFIGS_LIST}")
3736
endif()
3837
endfunction()

stdlib/public/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ set(SWIFT_RUNTIME_SWIFT_LINK_FLAGS)
77

88
if(SWIFT_RUNTIME_USE_SANITIZERS)
99
# TODO: Refactor this
10-
list(FIND SWIFT_RUNTIME_USE_SANITIZERS "Thread" THREAD_INDEX)
11-
if (NOT THREAD_INDEX EQUAL -1)
10+
if("Thread" IN_LIST SWIFT_RUNTIME_USE_SANITIZERS)
1211
list(APPEND SWIFT_RUNTIME_CXX_FLAGS "-fsanitize=thread")
1312
list(APPEND SWIFT_RUNTIME_LINK_FLAGS "-fsanitize=thread")
1413
list(APPEND SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS "-sanitize=thread")

0 commit comments

Comments
 (0)