Use foreach(IN LISTS) syntax in CMake code
authorBen Boeckel <mathstuf@gmail.com>
Wed, 4 Feb 2015 16:39:06 +0000 (11:39 -0500)
committerBen Boeckel <mathstuf@gmail.com>
Sun, 8 Feb 2015 01:51:06 +0000 (20:51 -0500)
It avoids extra separation on semicolons if there are any and skips a
variable expansion.

CMakeLists.txt
src/inc/CMakeLists.txt
src/vm/wks/CMakeLists.txt

index ae7e9de..145b798 100644 (file)
@@ -22,7 +22,7 @@ function(get_compile_definitions DefinitionName)
     # Get the current list of definitions
     get_directory_property(COMPILE_DEFINITIONS_LIST COMPILE_DEFINITIONS)
 
-    foreach(DEFINITION ${COMPILE_DEFINITIONS_LIST})
+    foreach(DEFINITION IN LISTS COMPILE_DEFINITIONS_LIST)
         if (${DEFINITION} MATCHES "^\\$<\\$<CONFIG:([^>]+)>:([^>]+)>$")
             # The entries that contain generator expressions must have the -D inside of the 
             # expression. So we transform e.g. $<$<CONFIG:Debug>:_DEBUG> to $<$<CONFIG:Debug>:-D_DEBUG>
@@ -38,7 +38,7 @@ endfunction(get_compile_definitions)
 # Build a list of include directories by putting -I in front of each include dir.
 function(get_include_directories IncludeDirectories)
     get_directory_property(dirs INCLUDE_DIRECTORIES)
-    foreach(dir ${dirs})
+    foreach(dir IN LISTS dirs)
         set(INC_DIRECTORIES ${INC_DIRECTORIES} -I${dir})
     endforeach()
     set(${IncludeDirectories} ${INC_DIRECTORIES} PARENT_SCOPE)
@@ -49,7 +49,7 @@ endfunction(get_include_directories)
 # The parameters after the RetSources are the input files. 
 function(convert_to_absolute_path RetSources)
     set(Sources ${ARGN})
-    foreach(Source ${Sources})
+    foreach(Source IN LISTS Sources)
         set(AbsolutePathSources ${AbsolutePathSources} ${CMAKE_CURRENT_SOURCE_DIR}/${Source})
     endforeach()            
     set(${RetSources} ${AbsolutePathSources} PARENT_SCOPE)
@@ -76,17 +76,17 @@ if (WIN32)
   # For multi-configuration toolset (as Visual Studio)
   # set the different configuration defines.
   # First DEBUG
-  foreach (Definition ${CLR_DEFINES_DEBUG_INIT})
+  foreach (Definition IN LISTS CLR_DEFINES_DEBUG_INIT)
     set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:DEBUG>:${Definition}>)
   endforeach (Definition)
 
   # Then RELEASE
-  foreach (Definition ${CLR_DEFINES_RELEASE_INIT})
+  foreach (Definition IN LISTS CLR_DEFINES_RELEASE_INIT)
     set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:RELEASE>:${Definition}>)
   endforeach (Definition)
 
   # And then RELWITHDEBINFO
-  foreach (Definition ${CLR_DEFINES_RELWITHDEBINFO_INIT})
+  foreach (Definition IN LISTS CLR_DEFINES_RELWITHDEBINFO_INIT)
     set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:RELWITHDEBINFO>:${Definition}>)
   endforeach (Definition)
 
index e8f52de..d27a3b8 100644 (file)
@@ -31,7 +31,7 @@ get_include_directories(MIDL_INCLUDE_DIRECTORIES)
 
 # Run custom midl command over each idl file
 FIND_PROGRAM( MIDL midl.exe )
-foreach(GENERATE_IDL ${CORGUIDS_IDL_SOURCES})
+foreach(GENERATE_IDL IN LISTS CORGUIDS_IDL_SOURCES)
    get_filename_component(IDLNAME ${GENERATE_IDL} NAME_WE)
    set(OUT_NAME ${CMAKE_CURRENT_BINARY_DIR}/idls_out/${IDLNAME}_i.c)
    set(CORGUIDS_SOURCES ${CORGUIDS_SOURCES} ${OUT_NAME})
@@ -50,7 +50,7 @@ add_compile_options(/TC)
 else()
 
 #The MIDL tool exists for Windows only, so for other systems, we have the prebuilt xxx_i.c files checked in
-foreach(IDL_SOURCE ${CORGUIDS_IDL_SOURCES})
+foreach(IDL_SOURCE IN LISTS CORGUIDS_IDL_SOURCES)
    get_filename_component(IDLNAME ${IDL_SOURCE} NAME_WE)
    set(C_SOURCE ../pal/prebuilt/idl/${IDLNAME}_i.c)
    set(CORGUIDS_SOURCES ${CORGUIDS_SOURCES} ${C_SOURCE})
index 2f7c16d..a0d2745 100644 (file)
@@ -9,7 +9,7 @@ get_directory_property(COMPILE_DEFINITIONS_LIST COMPILE_DEFINITIONS)
 
 # Extract the definitions for the ASM code. Since there is a bug in the cmake that prevents us from
 # using the generator expressions, we split the definitions into lists based on the configuration.
-foreach(DEFINITION ${COMPILE_DEFINITIONS_LIST})
+foreach(DEFINITION IN LISTS COMPILE_DEFINITIONS_LIST)
     if (${DEFINITION} MATCHES "^\\$<\\$<CONFIG:([^>]+)>:([^>]+)>$")
         # The entry contains generator expression, so insert the definition into a definitions list
         # corresponding to the config
@@ -23,7 +23,7 @@ endforeach()
 # Add defines for the ASM. Unfortunately setting it on the target is ignored for asm by the cmake, so we have
 # to set it on the sources.
 set_property(SOURCE ${VM_SOURCES_WKS_AMD64_ASM} PROPERTY COMPILE_DEFINITIONS ${ASM_DEFINITIONS})
-foreach(CONFIG ${CMAKE_CONFIGURATION_TYPES})
+foreach(CONFIG IN LISTS CMAKE_CONFIGURATION_TYPES)
     string(TOUPPER ${CONFIG} CONFIG)
     set_property(SOURCE ${VM_SOURCES_WKS_AMD64_ASM} PROPERTY COMPILE_DEFINITIONS_${CONFIG} ${ASM_DEFINITIONS_${CONFIG}})
 endforeach()