Build: Modernize some `foreach` calls to use `IN LISTS`/`IN ITEMS`

stage/master/nightly/2022/09/23
Alex Turbov 2022-08-21 02:00:05 +04:00 committed by Brad King
parent 914d21de58
commit a509602699
14 changed files with 114 additions and 119 deletions

View File

@ -17,8 +17,8 @@ unset(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
if(MSVC AND NOT CMAKE_VERSION VERSION_LESS 3.15)
# Filter out MSVC runtime library flags that may have come from
# the cache of an existing build tree or from scripts.
foreach(l C CXX)
foreach(c DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
foreach(l IN ITEMS C CXX)
foreach(c IN ITEMS DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
string(REGEX REPLACE "[-/]M[DT]d?( |$)" "" "CMAKE_${l}_FLAGS_${c}" "${CMAKE_${l}_FLAGS_${c}}")
endforeach()
endforeach()
@ -165,7 +165,7 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
# Allow the user to enable/disable all system utility library options by
# defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV NGHTTP2 ZLIB ZSTD)
foreach(util ${UTILITIES})
foreach(util IN LISTS UTILITIES)
if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
@ -215,7 +215,7 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
mark_as_advanced(CMAKE_USE_SYSTEM_KWIML)
# Mention to the user what system libraries are being used.
foreach(util ${UTILITIES} KWIML)
foreach(util IN LISTS UTILITIES ITEMS KWIML)
if(CMAKE_USE_SYSTEM_${util})
message(STATUS "Using system-installed ${util}")
endif()
@ -235,7 +235,7 @@ endmacro()
macro(CMAKE_SETUP_TESTING)
if(BUILD_TESTING)
set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
foreach(util CURL EXPAT ZLIB)
foreach(util IN ITEMS CURL EXPAT ZLIB)
if(CMAKE_USE_SYSTEM_${util})
set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
endif()
@ -250,7 +250,7 @@ macro(CMAKE_SETUP_TESTING)
set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
foreach(exe cmake ctest cpack)
foreach(exe IN ITEMS cmake ctest cpack)
add_executable(${exe} IMPORTED)
set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
endforeach()
@ -860,8 +860,8 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE)
-Wshadow -Wpointer-arith -Wformat-security -Wundef
)
foreach(FLAG_LANG C CXX)
foreach(FLAG ${${FLAG_LANG}_FLAGS_LIST})
foreach(FLAG_LANG IN ITEMS C CXX)
foreach(FLAG IN LISTS ${FLAG_LANG}_FLAGS_LIST)
if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
set(CMAKE_${FLAG_LANG}_FLAGS "${CMAKE_${FLAG_LANG}_FLAGS} ${FLAG}")
endif()

View File

@ -98,7 +98,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND
endif()
endif()
foreach(lang C CXX)
foreach(lang IN ITEMS C CXX)
# Suppress warnings from PGI compiler.
if (CMAKE_${lang}_COMPILER_ID STREQUAL "PGI")
set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -w")
@ -138,9 +138,9 @@ OFF to disable /MP completely." )
endif()
# Get rid of excess -Wunused-but-set-variable on release builds with LCC >= 1.26
foreach(l C CXX)
foreach(l IN ITEMS C CXX)
if(CMAKE_${l}_COMPILER_ID STREQUAL "LCC" AND NOT CMAKE_${l}_COMPILER_VERSION VERSION_LESS 1.26)
foreach(c MINSIZEREL RELEASE RELWITHDEBINFO)
foreach(c IN ITEMS MINSIZEREL RELEASE RELWITHDEBINFO)
string(APPEND "CMAKE_${l}_FLAGS_${c}" " -Wno-unused-but-set-variable")
endforeach()
endif()

View File

@ -881,16 +881,13 @@ if(WIN32 AND NOT CYGWIN)
target_link_libraries(cmcldeps CMakeLib)
endif()
foreach(v CURL_CA_BUNDLE CURL_CA_PATH)
foreach(v IN ITEMS CURL_CA_BUNDLE CURL_CA_PATH)
if(${v})
set_property(SOURCE cmCurl.cxx APPEND PROPERTY COMPILE_DEFINITIONS ${v}="${${v}}")
endif()
endforeach()
foreach(check
STAT_HAS_ST_MTIM
STAT_HAS_ST_MTIMESPEC
)
foreach(check IN ITEMS STAT_HAS_ST_MTIM STAT_HAS_ST_MTIMESPEC)
if(KWSYS_CXX_${check}_COMPILED) # abuse KWSys check cache entry
set(CMake_${check} 1)
else()
@ -1217,7 +1214,7 @@ if(WIN32)
# MinGW's windres tool with spaces in the path to the include directories.
add_library(CMakeVersion OBJECT "${CMAKE_CURRENT_BINARY_DIR}/CMakeVersion.rc")
set_property(TARGET CMakeVersion PROPERTY INCLUDE_DIRECTORIES "")
foreach(_tool ${_tools})
foreach(_tool IN LISTS _tools)
target_sources(${_tool} PRIVATE $<TARGET_OBJECTS:CMakeVersion>)
endforeach()
endif()
@ -1229,7 +1226,7 @@ endif()
# Install tools
foreach(_tool ${_tools})
foreach(_tool IN LISTS _tools)
CMake_OPTIONAL_COMPONENT(${_tool})
install(TARGETS ${_tool} DESTINATION ${CMAKE_BIN_DIR} ${COMPONENT})
endforeach()

View File

@ -100,13 +100,13 @@ if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
endif()
endmacro()
macro(install_qt_plugins _comps _plugins_var)
foreach(_qt_comp ${${_comps}})
foreach(_qt_comp IN LISTS ${_comps})
if (INSTALLED_QT_VERSION VERSION_LESS 6)
set(_qt_module_plugins ${Qt${INSTALLED_QT_VERSION}${_qt_comp}_PLUGINS})
else()
get_target_property(_qt_module_plugins Qt${INSTALLED_QT_VERSION}::${_qt_comp} QT_PLUGINS)
endif()
foreach(_qt_plugin ${_qt_module_plugins})
foreach(_qt_plugin IN LISTS _qt_module_plugins)
if (INSTALLED_QT_VERSION VERSION_GREATER_EQUAL 6)
# Qt6 provides the plugins as individual packages that need to be found.
find_package(Qt${INSTALLED_QT_VERSION}${_qt_plugin} QUIET
@ -308,13 +308,13 @@ install(TARGETS cmake-gui
${CMAKE_INSTALL_DESTINATION_ARGS})
if(UNIX AND NOT APPLE)
foreach (size IN ITEMS 32 128)
foreach(size IN ITEMS 32 128)
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/CMakeSetup${size}.png"
DESTINATION "${CMAKE_XDGDATA_DIR}/icons/hicolor/${size}x${size}/apps"
${COMPONENT}
RENAME "CMakeSetup.png")
endforeach ()
endforeach()
# install a desktop file so CMake appears in the application start menu
# with an icon

View File

@ -1,6 +1,6 @@
foreach (_retval 0 1)
foreach(_retval IN ITEMS 0 1)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/memtester.cxx.in" "${CMAKE_CURRENT_BINARY_DIR}/ret${_retval}.cxx" @ONLY)
endforeach ()
endforeach()
include_directories(${CMake_SOURCE_DIR}/Source ${CMake_BINARY_DIR}/Source)

View File

@ -205,7 +205,7 @@ if(BUILD_TESTING)
select_wince_sdk(reg_wince wince_sdk)
set(reg_tegra "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;sdkRoot]")
set(reg_nasm "[HKEY_CURRENT_USER\\SOFTWARE\\nasm]")
foreach(reg vs10 vs11 vs12 vs14 ws80 ws81 ws10_0 wp80 wp81 wince tegra nasm)
foreach(reg IN ITEMS vs10 vs11 vs12 vs14 ws80 ws81 ws10_0 wp80 wp81 wince tegra nasm)
get_filename_component(r "${reg_${reg}}" ABSOLUTE)
if(IS_DIRECTORY "${r}" AND NOT "${r}" STREQUAL "/registry")
set(${reg} 1)
@ -227,7 +227,7 @@ if(BUILD_TESTING)
set(vs_versions vs15)
endif()
endif()
foreach(info ${vs_versions})
foreach(info IN LISTS vs_versions)
cmake_host_system_information(RESULT found QUERY "${info_${info}}")
if(found)
set(${info} 1)
@ -730,13 +730,15 @@ if(BUILD_TESTING)
# mainly it tests that cmake doesn't crash when generating these project files.
if(CMAKE_GENERATOR MATCHES "^(Unix Makefiles|Ninja)$"
AND NOT "${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
foreach(extraGenerator
foreach(
extraGenerator
IN ITEMS
"CodeBlocks"
"CodeLite"
"Eclipse CDT4"
"Kate"
"Sublime Text 2"
)
)
string(REPLACE " " "" extraGeneratorTestName "Simple_${extraGenerator}Generator")
add_test(${extraGeneratorTestName} ${CMAKE_CTEST_COMMAND}
--build-and-test
@ -1127,7 +1129,7 @@ if(BUILD_TESTING)
set(CPACK_GENERATOR_STRING_${CPackGen} ${CPackGen})
endif()
set(CPackRun_CPackGen "-DCPackGen=${CPACK_GENERATOR_STRING_${CPackGen}}")
foreach(CPackComponentWay ${CWAYLST})
foreach(CPackComponentWay IN LISTS CWAYLST)
set(CPackRun_CPackComponentWay "-DCPackComponentWay=${CPackComponentWay}")
add_test(CPackComponentsForAll-${CPackGen}-${CPackComponentWay}
${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE}
@ -1433,64 +1435,66 @@ if(BUILD_TESTING)
endif()
# test for Find modules, simple cases
foreach(_mod IN ITEMS
ALSA
Boost
BLAS
BZip2
CURL
Cups
Doxygen
DevIL
EnvModules
EXPAT
Fontconfig
Freetype
GDAL
GIF
Git
GLEW
GLUT
GnuTLS
GSL
GTK2
Iconv
ICU
Intl
Jasper
JNI
JPEG
JsonCpp
LAPACK
LibArchive
LibLZMA
LibRHash
Libinput
LibUV
LibXml2
LibXslt
LTTngUST
ODBC
OpenACC
OpenAL
OpenCL
OpenGL
OpenMP
OpenSP
OpenSSL
MPI
PNG
Patch
PostgreSQL
Protobuf
SDL
SQLite3
TIFF
Vulkan
X11
XalanC
XercesC
)
foreach(
_mod
IN ITEMS
ALSA
BLAS
Boost
BZip2
Cups
CURL
DevIL
Doxygen
EnvModules
EXPAT
Fontconfig
Freetype
GDAL
GIF
Git
GLEW
GLUT
GnuTLS
GSL
GTK2
Iconv
ICU
Intl
Jasper
JNI
JPEG
JsonCpp
LAPACK
LibArchive
Libinput
LibLZMA
LibRHash
LibUV
LibXml2
LibXslt
LTTngUST
MPI
ODBC
OpenACC
OpenAL
OpenCL
OpenGL
OpenMP
OpenSP
OpenSSL
Patch
PNG
PostgreSQL
Protobuf
SDL
SQLite3
TIFF
Vulkan
X11
XalanC
XercesC
)
if(CMake_TEST_Find${_mod})
add_subdirectory(Find${_mod})
endif()
@ -1570,7 +1574,7 @@ if(BUILD_TESTING)
endif()
set(ExternalProject_BUILD_OPTIONS "")
foreach(vcs CVS SVN GIT HG)
foreach(vcs IN ITEMS CVS SVN GIT HG)
if(DEFINED CMake_TEST_ExternalProject_${vcs})
list(APPEND ExternalProject_BUILD_OPTIONS -DEP_TEST_${vcs}=${CMake_TEST_ExternalProject_${vcs}})
endif()
@ -2179,7 +2183,7 @@ if(BUILD_TESTING)
# The test (and tested property) works with .sln files, so it's skipped when:
# * cmake --build is set up to use MSBuild, since the MSBuild invocation does not use the .sln file
set(_last_test "")
foreach(config ${CMAKE_CONFIGURATION_TYPES})
foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES)
add_test(NAME VSExcludeFromDefaultBuild-${config} COMMAND ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/VSExcludeFromDefaultBuild"
@ -3539,11 +3543,7 @@ if(BUILD_TESTING)
# The directory should also contain a Configure.cmake file that
# sets "CMake_TEST_CONTRACT_<project>_<var>" variables to configure
# the code below.
foreach(project
PLplot
Trilinos
VTK
)
foreach(project IN ITEMS PLplot Trilinos VTK)
if(CMake_TEST_CONTRACT_${project})
include(Contracts/${project}/Configure.cmake)
ADD_TEST_MACRO(Contracts.${project} ${CMake_TEST_CONTRACT_${project}_RUN_TEST})

View File

@ -73,7 +73,7 @@ function(check_updates build)
string(REGEX REPLACE "${rev_regex}" "\\1" element "${r}")
set(element_${element} 1)
endforeach()
foreach(element ${rev_elements})
foreach(element IN LISTS rev_elements)
if(NOT element_${element})
list(APPEND MISSING "global <${element}> element")
endif()
@ -85,7 +85,7 @@ function(check_updates build)
if(MISSING)
# List the missing entries
string(APPEND MSG "Update.xml is missing expected entries:\n")
foreach(f ${MISSING})
foreach(f IN LISTS MISSING)
string(APPEND MSG " ${f}\n")
endforeach()
else()
@ -97,7 +97,7 @@ function(check_updates build)
if(EXTRA)
# List the extra entries
string(APPEND MSG "Update.xml has extra unexpected entries:\n")
foreach(f ${EXTRA})
foreach(f IN LISTS EXTRA)
string(APPEND MSG " ${f}\n")
endforeach()
else()

View File

@ -109,7 +109,7 @@ list(APPEND P4CMD ${P4_CLIENT})
message("Adding files to repository")
file(GLOB_RECURSE files ${TOP}/user-source/*)
foreach(filename ${files})
foreach(filename IN LISTS files)
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} add ${filename}
@ -140,14 +140,14 @@ run_child(
# Make changes in the working tree.
message("Changing content...")
update_content(user-source files_added files_removed dirs_added)
foreach(filename ${files_added})
foreach(filename IN LISTS files_added)
message("add: ${filename}")
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} add ${TOP}/user-source/${filename}
)
endforeach()
foreach(filename ${files_removed})
foreach(filename IN LISTS files_removed)
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${P4CMD} delete ${TOP}/user-source/${filename}

View File

@ -10,7 +10,7 @@ if(NOT CTEST_CONFIGURATION_TYPE)
set(CTEST_CMD "@CMAKE_CTEST_COMMAND@@CMAKE_EXECUTABLE_SUFFIX@")
get_filename_component(CTEST_DIR "${CTEST_CMD}" PATH)
get_filename_component(CTEST_EXE "${CTEST_CMD}" NAME)
foreach(cfg Release Debug MinSizeRel RelWithDebInfo)
foreach(cfg IN ITEMS Release Debug MinSizeRel RelWithDebInfo)
if(NOT CTEST_CONFIGURATION_TYPE)
if(EXISTS "${CTEST_DIR}/${cfg}/${CTEST_EXE}")
set(CTEST_CONFIGURATION_TYPE ${cfg})

View File

@ -527,7 +527,9 @@ function(add_RunCMake_test_try_compile)
set(CMAKE_CXX_STANDARD_DEFAULT 14)
endif()
endif()
foreach(var
foreach(
var
IN ITEMS
CMAKE_SYSTEM_NAME
CMAKE_C_COMPILER_ID
CMAKE_C_COMPILER_VERSION
@ -541,7 +543,7 @@ function(add_RunCMake_test_try_compile)
CMake_TEST_FILESYSTEM_1S
CMAKE_OBJC_STANDARD_DEFAULT
CMAKE_OBJCXX_STANDARD_DEFAULT
)
)
if(DEFINED ${var})
list(APPEND try_compile_ARGS -D${var}=${${var}})
endif()
@ -956,7 +958,7 @@ if(CMake_TEST_ANDROID_NDK OR CMake_TEST_ANDROID_STANDALONE_TOOLCHAIN)
if(NOT "${CMAKE_GENERATOR}" MATCHES "Make|Ninja|Visual Studio 1[456]")
message(FATAL_ERROR "Android tests supported only by Makefile, Ninja, and Visual Studio >= 14 generators")
endif()
foreach(v TEST_ANDROID_NDK TEST_ANDROID_STANDALONE_TOOLCHAIN)
foreach(v IN ITEMS TEST_ANDROID_NDK TEST_ANDROID_STANDALONE_TOOLCHAIN)
if(CMake_${v})
string(REPLACE ";" "|" ${v} "${CMake_${v}}")
list(APPEND Android_ARGS "-D${v}=${${v}}")

View File

@ -1,8 +1,10 @@
foreach(arg
foreach(
arg
IN ITEMS
RunCMake_GENERATOR
RunCMake_SOURCE_DIR
RunCMake_BINARY_DIR
)
)
if(NOT DEFINED ${arg})
message(FATAL_ERROR "${arg} not given!")
endif()
@ -31,7 +33,7 @@ function(run_cmake test)
set(platform_name msys)
endif()
foreach(o out err)
foreach(o IN ITEMS out err)
if(RunCMake-std${o}-file AND EXISTS ${top_src}/${RunCMake-std${o}-file})
file(READ ${top_src}/${RunCMake-std${o}-file} expect_std${o})
string(REGEX REPLACE "\n+$" "" expect_std${o} "${expect_std${o}}")
@ -176,7 +178,7 @@ function(run_cmake test)
"|[^\n]*Bullseye Testing Technology"
")[^\n]*\n)+"
)
foreach(o out err)
foreach(o IN ITEMS out err)
string(REGEX REPLACE "\r\n" "\n" actual_std${o} "${actual_std${o}}")
string(REGEX REPLACE "${ignore_line_regex}" "\\1" actual_std${o} "${actual_std${o}}")
string(REGEX REPLACE "\n+$" "" actual_std${o} "${actual_std${o}}")

View File

@ -11,7 +11,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
# to be in the same directory.
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
foreach(config ${CMAKE_CONFIGURATION_TYPES})
foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER "${config}" config)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

View File

@ -26,7 +26,7 @@ if(NOT result EQUAL 0)
message(FATAL_ERROR "Listing app package content failed with: ${error}")
endif()
foreach(app_pkg_item ${EXPECTED_APP_PKG_CONTENT})
foreach(app_pkg_item IN LISTS EXPECTED_APP_PKG_CONTENT)
string(FIND ${APP_PKG_CONTENT_OUTPUT} ${app_pkg_item} _found)
if(_found EQUAL -1)
message(FATAL_ERROR "Generated app package is missing an expected item: ${app_pkg_item}")

View File

@ -161,7 +161,7 @@ endif()
set(doc_format_outputs "")
set(doc_format_last "")
foreach(format ${doc_formats})
foreach(format IN LISTS doc_formats)
set(doc_format_output "doc_format_${format}")
set(doc_format_log "build-${format}.log")
if(CMake_SPHINX_CMAKE_ORG)
@ -219,13 +219,7 @@ endforeach()
add_custom_target(documentation ALL DEPENDS ${doc_format_outputs})
if(CMake_SPHINX_DEPEND_ON_EXECUTABLES)
foreach(t
cmake
ccmake
cmake-gui
cpack
ctest
)
foreach(t IN ITEMS cmake ccmake cmake-gui cpack ctest)
if(TARGET ${t})
# Build documentation after main executables.
add_dependencies(documentation ${t})
@ -248,7 +242,7 @@ endif()
if(SPHINX_MAN)
file(GLOB man_rst RELATIVE ${CMake_SOURCE_DIR}/Help/manual
${CMake_SOURCE_DIR}/Help/manual/*.[1-9].rst)
foreach(m ${man_rst})
foreach(m IN LISTS man_rst)
if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$")
set(name "${CMAKE_MATCH_1}")
set(sec "${CMAKE_MATCH_2}")