title: How to pass list variable in CMake's execute_process?
body: <p>I want to execute a CMake command in a subdirectory with <code>execute_process</code>, and also pass some cache variables as <code>-D</code> options.</p>
  
  <p>If the variable is of type string, it works. However, if the variable is a list, the <a href="https://stackoverflow.com/a/33248574/1492613">typical method</a> of passing a list in command line does not seem to work.</p>
  
  <p>I tried all of the combinations listed in that answer. I even tried to join <code>mylist</code> with  <code>"\\;"</code> or <code>"\\\\;"</code>. However, the <code>execute_process</code> seems to always unpack the <code>'-DVal2=a\\;b\\;c\\;'</code> or <code>'-DVal2=a;b;c'</code> to <code>-Dval2=a b c</code>.</p>
  
  <p>How can I prevent this? Only <code>-DVal2=a\\;b\\;c</code> works, but it's very annoying.</p>
  
  <pre><code>set(
      mylist
      a
      b
      c
  )
  
  set(
      cmake_args
      "-DVal1=abc"
      "'-DVal2=${mylist}'" #does not work, the execute_process will unpack it into seperated args
  )
  
  execute_process(
          COMMAND ${CMAKE_COMMAND} ${cmake_args} ${CMAKE_SOURCE_DIR}/subproject
          OUTPUT_FILE ${CMAKE_BINARY_DIR}/config.log
          ERROR_FILE ${CMAKE_BINARY_DIR}/config.log
          WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/subproject
          RESULT_VARIABLE config_result
  )
  </code></pre>