Skip to content

[cmake] Enable IN_LIST compare policy #4999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ if(POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()

# Enable the IN_LIST operator, as in:
# `if(<element_variable> IN_LIST <list_variable>)`
if(POLICY CMP0057)
cmake_policy(SET CMP0057 NEW)
endif()

# Add path for custom CMake modules.
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
Expand Down Expand Up @@ -491,11 +497,10 @@ function(is_sdk_requested name result_var_name)
if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${name}")
set("${result_var_name}" "TRUE" PARENT_SCOPE)
else()
list(FIND SWIFT_SDKS "${name}" sdk_index)
if(${sdk_index} EQUAL -1)
set("${result_var_name}" "FALSE" PARENT_SCOPE)
else()
if("${name}" IN_LIST SWIFT_SDKS)
set("${result_var_name}" "TRUE" PARENT_SCOPE)
else()
set("${result_var_name}" "FALSE" PARENT_SCOPE)
endif()
endif()
endfunction()
Expand Down
3 changes: 1 addition & 2 deletions apinotes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ endforeach()
file(GLOB SWIFT_API_NOTES_INPUT_FILES "${SWIFT_API_NOTES_PATH}/*.apinotes")
foreach(file ${SWIFT_API_NOTES_INPUT_FILES})
get_filename_component(name "${file}" NAME_WE)
list(FIND SWIFT_API_NOTES_INPUTS "${name}" name_index)
if(name_index EQUAL -1)
if(NOT "${name}" IN_LIST SWIFT_API_NOTES_INPUTS)
message(SEND_ERROR "Found apinotes for ${name}; please add to CMakeLists.txt")
endif()
endforeach()
3 changes: 1 addition & 2 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,7 @@ function(_add_swift_library_single target name)
else()
string(REPLACE swift "" module_name "${name}")
endif()
list(FIND SWIFT_API_NOTES_INPUTS "${module_name}" overlay_index)
if(NOT ${overlay_index} EQUAL -1)
if("${module_name}" IN_LIST SWIFT_API_NOTES_INPUTS)
set(SWIFTLIB_SINGLE_API_NOTES "${module_name}")
endif()

Expand Down
3 changes: 1 addition & 2 deletions cmake/modules/AddSwiftUnittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ function(add_swift_unittest test_dirname)
endif()

if(SWIFT_RUNTIME_USE_SANITIZERS)
list(FIND SWIFT_RUNTIME_USE_SANITIZERS "Thread" THREAD_INDEX)
if(NOT THREAD_INDEX EQUAL -1)
if("Thread" IN_LIST SWIFT_RUNTIME_USE_SANITIZERS)
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY COMPILE_FLAGS
" -fsanitize=thread")
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
Expand Down
7 changes: 3 additions & 4 deletions cmake/modules/SwiftAddCustomCommandTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ include(SwiftUtils)
function(_make_acct_argument_list)
set(args)
foreach(k ${ARGN})
list(FIND options ${k} option_index)
if(${option_index} EQUAL -1)
list(APPEND args ${${k}_keyword} ${ACCT_${k}})
else()
if(${k} IN_LIST options)
list(APPEND args ${${k}_keyword})
else()
list(APPEND args ${${k}_keyword} ${ACCT_${k}})
endif()
endforeach()
set(args ${args} PARENT_SCOPE)
Expand Down
6 changes: 2 additions & 4 deletions cmake/modules/SwiftComponents.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ macro(swift_configure_components)
endforeach()

foreach(component ${SWIFT_INSTALL_COMPONENTS})
list(FIND _SWIFT_DEFINED_COMPONENTS "${component}" index)
if(${index} EQUAL -1)
if(NOT "${component}" IN_LIST _SWIFT_DEFINED_COMPONENTS)
message(FATAL_ERROR "unknown install component: ${component}")
endif()

Expand All @@ -96,8 +95,7 @@ function(swift_is_installing_component component result_var_name)
if("${component}" STREQUAL "never_install")
set("${result_var_name}" FALSE PARENT_SCOPE)
else()
list(FIND _SWIFT_DEFINED_COMPONENTS "${component}" index)
if(${index} EQUAL -1)
if(NOT "${component}" IN_LIST _SWIFT_DEFINED_COMPONENTS)
message(FATAL_ERROR "unknown install component: ${component}")
endif()

Expand Down
9 changes: 3 additions & 6 deletions cmake/modules/SwiftList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ include(SwiftUtils)
function(list_subtract lhs rhs result_var_name)
set(result)
foreach(item IN LISTS lhs)
list(FIND rhs "${item}" index)
if(${index} EQUAL -1)
if(NOT "${item}" IN_LIST rhs)
list(APPEND result "${item}")
endif()
endforeach()
Expand All @@ -14,8 +13,7 @@ endfunction()
function(list_intersect lhs rhs result_var_name)
set(result)
foreach(item IN LISTS lhs)
list(FIND rhs "${item}" index)
if(NOT ${index} EQUAL -1)
if("${item}" IN_LIST rhs)
list(APPEND result "${item}")
endif()
endforeach()
Expand All @@ -25,8 +23,7 @@ endfunction()
function(list_union lhs rhs result_var_name)
set(result)
foreach(item IN LISTS lhs rhs)
list(FIND result "${item}" index)
if(${index} EQUAL -1)
if(NOT "${item}" IN_LIST result)
list(APPEND result "${item}")
endif()
endforeach()
Expand Down
3 changes: 1 addition & 2 deletions cmake/modules/SwiftXcodeSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ function(check_imported_target_has_imported_configuration target config)
message(FATAL_ERROR "No import configuration of ${target} specified?!")
endif()

list(FIND IMPORTED_CONFIGS_LIST "${config}" FOUND_CONFIG)
if (FOUND_CONFIG EQUAL -1)
if(NOT "${config}" IN_LIST IMPORTED_CONFIGS_LIST)
message(FATAL_ERROR "${target} does not have imported config '${config}'?! Instead: ${IMPORTED_CONFIGS_LIST}")
endif()
endfunction()
Expand Down
3 changes: 1 addition & 2 deletions stdlib/public/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ set(SWIFT_RUNTIME_SWIFT_LINK_FLAGS)

if(SWIFT_RUNTIME_USE_SANITIZERS)
# TODO: Refactor this
list(FIND SWIFT_RUNTIME_USE_SANITIZERS "Thread" THREAD_INDEX)
if (NOT THREAD_INDEX EQUAL -1)
if("Thread" IN_LIST SWIFT_RUNTIME_USE_SANITIZERS)
list(APPEND SWIFT_RUNTIME_CXX_FLAGS "-fsanitize=thread")
list(APPEND SWIFT_RUNTIME_LINK_FLAGS "-fsanitize=thread")
list(APPEND SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS "-sanitize=thread")
Expand Down