title: How to set the global variable in a function for cmake?
body: <p>I'm writing a CMakeLists.txt to generate files and compile the generated files. I create a function to add some file path strings to a global list variable.</p>
  
  <p>My CMakeLists.txt:</p>
  
  <pre><code>set(source_list "nothing")
  function(test file_path)
      list(APPEND source_list ${file_path})
  endfunction(test)
  test(abc.txt)
  test(def.txt)
  message("At last, the source_list is:\"${source_list}\"")
  </code></pre>
  
  <p>The cmake output:</p>
  
  <pre><code>At last, the source_list is:"nothing"
  </code></pre>
  
  <p>Someone suggested that to use macro instead of function, but I do need use local variable, so I need to use the function instead of macro.</p>
  
  <p>How can I correctly set the global variable source_list in the function test()? Can't cmake do it in a simple and normal way?</p>