[llvm] r318457 - [CMake][runtimes] Use cmake_parse_arguments in runtimes functions

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 16 13:28:54 PST 2017


Author: phosek
Date: Thu Nov 16 13:28:54 2017
New Revision: 318457

URL: http://llvm.org/viewvc/llvm-project?rev=318457&view=rev
Log:
[CMake][runtimes] Use cmake_parse_arguments in runtimes functions

Passing lists to functions in CMake is tricky, any list argument
has to be quoted otherwise it'll be expanded. To avoid this issue,
use cmake_parse_arguments in runtime functions and pass lists using
a keyword argument which eliminates any ambiguity when dealing with
lists.

Differential Revision: https://reviews.llvm.org/D40087

Modified:
    llvm/trunk/runtimes/CMakeLists.txt

Modified: llvm/trunk/runtimes/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/runtimes/CMakeLists.txt?rev=318457&r1=318456&r2=318457&view=diff
==============================================================================
--- llvm/trunk/runtimes/CMakeLists.txt (original)
+++ llvm/trunk/runtimes/CMakeLists.txt Thu Nov 16 13:28:54 2017
@@ -298,7 +298,9 @@ else() # if this is included from LLVM's
     list(APPEND runtime_names ${projName})
   endforeach()
 
-  function(runtime_default_target deps prefixes)
+  function(runtime_default_target)
+    cmake_parse_arguments(ARG "" "" "DEPS;PREFIXES" ${ARGN})
+
     include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
     set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
 
@@ -317,7 +319,7 @@ else() # if this is included from LLVM's
 
     llvm_ExternalProject_Add(runtimes
                              ${CMAKE_CURRENT_SOURCE_DIR}
-                             DEPENDS ${deps}
+                             DEPENDS ${ARG_DEPS}
                              # Builtins were built separately above
                              CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
                                         -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
@@ -325,7 +327,7 @@ else() # if this is included from LLVM's
                                         -DCMAKE_C_COMPILER_WORKS=ON
                                         -DCMAKE_CXX_COMPILER_WORKS=ON
                                         -DCMAKE_ASM_COMPILER_WORKS=ON
-                             PASSTHROUGH_PREFIXES ${prefixes}
+                             PASSTHROUGH_PREFIXES ${ARG_PREFIXES}
                              EXTRA_TARGETS ${extra_targets}
                                            ${test_targets}
                                            ${SUB_COMPONENTS}
@@ -337,11 +339,12 @@ else() # if this is included from LLVM's
 
   # runtime_register_target(target)
   #   Utility function to register external runtime target.
-  function(runtime_register_target name target deps prefixes)
+  function(runtime_register_target name target)
+    cmake_parse_arguments(ARG "" "" "DEPS" ${ARGN})
     include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
     set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
 
-    set(${name}_deps ${deps})
+    set(${name}_deps ${ARG_DEPS})
     if(NOT name STREQUAL target)
       list(APPEND ${name}_deps runtimes-${target})
     endif()
@@ -398,7 +401,6 @@ else() # if this is included from LLVM's
                                         -DLLVM_RUNTIMES_TARGET=${name}
                                         ${${name}_extra_args}
                              TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib
-                             PASSTHROUGH_PREFIXES ${prefixes}
                              EXTRA_TARGETS ${${name}_extra_targets}
                                            ${${name}_test_targets}
                              USE_TOOLCHAIN
@@ -410,10 +412,15 @@ else() # if this is included from LLVM's
     # The runtimes target is a configuration of all the runtime libraries
     # together in a single CMake invocaiton.
     if(NOT LLVM_RUNTIME_TARGETS)
-      runtime_default_target(${deps} ${prefixes})
+      runtime_default_target(
+        DEPS ${deps}
+        PREFIXES ${prefixes}
+        )
     else()
       if("default" IN_LIST LLVM_RUNTIME_TARGETS)
-        runtime_default_target(${deps} ${prefixes})
+        runtime_default_target(
+          DEPS ${deps}
+          PREFIXES ${prefixes})
         list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
       else()
         add_custom_target(runtimes)
@@ -435,7 +442,9 @@ else() # if this is included from LLVM's
           list(GET target_list 1 target)
         endif()
 
-        runtime_register_target(${name} ${target} ${deps} ${prefixes})
+        runtime_register_target(${name} ${target}
+          DEPS ${deps}
+          )
 
         add_dependencies(runtimes runtimes-${name})
         add_dependencies(runtimes-configure runtimes-${name}-configure)




More information about the llvm-commits mailing list