Browse Source

Modules: refactor compiler find to use modern foreach

Michael Hirsch 2 years ago
parent
commit
ec2ad53d18

+ 1 - 1
Modules/CMakeCInformation.cmake

@@ -67,7 +67,7 @@ if (NOT _INCLUDED_FILE)
 endif ()
 
 if(CMAKE_C_SIZEOF_DATA_PTR)
-  foreach(f ${CMAKE_C_ABI_FILES})
+  foreach(f IN LISTS CMAKE_C_ABI_FILES)
     include(${f})
   endforeach()
   unset(CMAKE_C_ABI_FILES)

+ 1 - 1
Modules/CMakeCXXCompiler.cmake.in

@@ -46,7 +46,7 @@ set(CMAKE_CXX_COMPILER_ID_RUN 1)
 set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;m;mm;mpp;CPP;ixx;cppm;ccm;cxxm;c++m)
 set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC)
 
-foreach (lang C OBJC OBJCXX)
+foreach (lang IN ITEMS C OBJC OBJCXX)
   if (CMAKE_${lang}_COMPILER_ID_RUN)
     foreach(extension IN LISTS CMAKE_${lang}_SOURCE_FILE_EXTENSIONS)
       list(REMOVE_ITEM CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${extension})

+ 2 - 2
Modules/CMakeCXXInformation.cmake

@@ -66,7 +66,7 @@ if (NOT _INCLUDED_FILE)
 endif ()
 
 if(CMAKE_CXX_SIZEOF_DATA_PTR)
-  foreach(f ${CMAKE_CXX_ABI_FILES})
+  foreach(f IN LISTS CMAKE_CXX_ABI_FILES)
     include(${f})
   endforeach()
   unset(CMAKE_CXX_ABI_FILES)
@@ -182,7 +182,7 @@ if(NOT CMAKE_SHARED_MODULE_CXX_FLAGS)
 endif()
 
 # Initialize CXX link type selection flags from C versions.
-foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+foreach(type IN ITEMS SHARED_LIBRARY SHARED_MODULE EXE)
   if(NOT CMAKE_${type}_LINK_STATIC_CXX_FLAGS)
     set(CMAKE_${type}_LINK_STATIC_CXX_FLAGS
       ${CMAKE_${type}_LINK_STATIC_C_FLAGS})

+ 3 - 3
Modules/CMakeDetermineCompiler.cmake

@@ -15,7 +15,7 @@ macro(_cmake_find_compiler lang)
     set(_${lang}_COMPILER_LIST "${CMAKE_${lang}_COMPILER_LIST}")
     set(CMAKE_${lang}_COMPILER_LIST "")
     # Prefer vendors of compilers from reference languages.
-    foreach(l ${_languages})
+    foreach(l IN LISTS _languages)
       list(APPEND CMAKE_${lang}_COMPILER_LIST
         ${_${lang}_COMPILER_NAMES_${CMAKE_${l}_COMPILER_ID}})
     endforeach()
@@ -33,7 +33,7 @@ macro(_cmake_find_compiler lang)
 
   # Look for directories containing compilers of reference languages.
   set(_${lang}_COMPILER_HINTS "${CMAKE_${lang}_COMPILER_HINTS}")
-  foreach(l ${_languages})
+  foreach(l IN LISTS _languages)
     if(CMAKE_${l}_COMPILER AND IS_ABSOLUTE "${CMAKE_${l}_COMPILER}")
       get_filename_component(_hint "${CMAKE_${l}_COMPILER}" PATH)
       if(IS_DIRECTORY "${_hint}")
@@ -99,7 +99,7 @@ macro(_cmake_find_compiler lang)
     if (CMAKE_${lang}_COMPILER MATCHES "^/usr/bin/(.+)$")
       _query_xcrun("${CMAKE_MATCH_1}" RESULT_VAR xcrun_result)
     elseif (CMAKE_${lang}_COMPILER STREQUAL "CMAKE_${lang}_COMPILER-NOTFOUND")
-      foreach(comp ${CMAKE_${lang}_COMPILER_LIST})
+      foreach(comp IN LISTS CMAKE_${lang}_COMPILER_LIST)
         _query_xcrun("${comp}" RESULT_VAR xcrun_result)
         if(xcrun_result)
           break()

+ 2 - 2
Modules/CMakeDetermineFortranCompiler.cmake

@@ -140,11 +140,11 @@ if(NOT CMAKE_Fortran_COMPILER_ID_RUN)
   set(CMAKE_Fortran_COMPILER_ID_TOOL_MATCH_INDEX 2)
 
   set(_version_info "")
-  foreach(m MAJOR MINOR PATCH TWEAK)
+  foreach(m IN ITEMS MAJOR MINOR PATCH TWEAK)
     set(_COMP "_${m}")
     string(APPEND _version_info "
 #if defined(COMPILER_VERSION${_COMP})")
-    foreach(d 1 2 3 4 5 6 7 8)
+    foreach(d RANGE 1 8)
       string(APPEND _version_info "
 # undef DEC
 # undef HEX

+ 1 - 1
Modules/CMakeFortranInformation.cmake

@@ -43,7 +43,7 @@ if (NOT _INCLUDED_FILE)
 endif ()
 
 if(CMAKE_Fortran_SIZEOF_DATA_PTR)
-  foreach(f ${CMAKE_Fortran_ABI_FILES})
+  foreach(f IN LISTS CMAKE_Fortran_ABI_FILES)
     include(${f})
   endforeach()
   unset(CMAKE_Fortran_ABI_FILES)

+ 1 - 1
Modules/CMakeOBJCInformation.cmake

@@ -67,7 +67,7 @@ if (NOT _INCLUDED_FILE)
 endif ()
 
 if(CMAKE_OBJC_SIZEOF_DATA_PTR)
-  foreach(f ${CMAKE_OBJC_ABI_FILES})
+  foreach(f IN LISTS CMAKE_OBJC_ABI_FILES)
     include(${f})
   endforeach()
   unset(CMAKE_OBJC_ABI_FILES)

+ 1 - 1
Modules/CMakeOBJCXXCompiler.cmake.in

@@ -50,7 +50,7 @@ if (CMAKE_OBJC_COMPILER_ID_RUN)
   endforeach()
 endif()
 
-foreach (lang C CXX OBJC)
+foreach (lang IN ITEMS C CXX OBJC)
   foreach(extension IN LISTS CMAKE_OBJCXX_SOURCE_FILE_EXTENSIONS)
     if (CMAKE_${lang}_COMPILER_ID_RUN)
       list(REMOVE_ITEM CMAKE_${lang}_SOURCE_FILE_EXTENSIONS ${extension})

+ 2 - 2
Modules/CMakeOBJCXXInformation.cmake

@@ -62,7 +62,7 @@ if (NOT _INCLUDED_FILE)
 endif ()
 
 if(CMAKE_OBJCXX_SIZEOF_DATA_PTR)
-  foreach(f ${CMAKE_OBJCXX_ABI_FILES})
+  foreach(f IN LISTS CMAKE_OBJCXX_ABI_FILES)
     include(${f})
   endforeach()
   unset(CMAKE_OBJCXX_ABI_FILES)
@@ -178,7 +178,7 @@ if(NOT CMAKE_SHARED_MODULE_OBJCXX_FLAGS)
 endif()
 
 # Initialize OBJCXX link type selection flags from OBJC versions.
-foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
+foreach(type IN ITEMS SHARED_LIBRARY SHARED_MODULE EXE)
   if(NOT CMAKE_${type}_LINK_STATIC_OBJCXX_FLAGS)
     set(CMAKE_${type}_LINK_STATIC_OBJCXX_FLAGS
       ${CMAKE_${type}_LINK_STATIC_OBJC_FLAGS})