title: List of variables in CMake
body: <p>Is there a way to have a list of <em>variables</em> in CMake?
  Specifically, what I want to do is call an existing function that takes multiple variables and checks whether they evaluate to <em>true</em>.</p>
  
  <p>In some cases, some of those variables will be empty lists (which evaluate to <em>false</em>) and the function fails (as intended). But sometimes I don't even need these variables, so it would be fine if they are empty and the function should not fail due to that. Is there a way to pass some variables only in some instances? </p>
  
  <p>The code I currently deal with is a CMake module to find a package:</p>
  
  <pre><code>include(FindPackageHandleStandardArgs)
  
  # create empty list
  list(APPEND mylib_LIBRARIES "")
  
  # in some cases, the list contains elements
  if(A)
      list(APPEND mylib_LIBRARIES "foo")
  endif(A)
  
  # if the list mylib_LIBRARIES is empty, this will fail
  find_package_handle_standard_args(mylib REQUIRED_VARS bar mylib_LIBRARIES)
  </code></pre>
  
  <p>If <strong><code>A</code></strong> evaluates to true, <code>${mylib_LIBRARIES}</code> does contain content and everything is fine. Otherwise, the list is empty which evaluates to <em>false</em> internally and the last line gives an error.</p>
  
  <p>Ideally, there would be a way to create a meta-variable that holds a list of variables that I want to pass to the function. Then, I could add <code>mylib_LIBRARIES</code> only in certain cases.</p>
  
  <p>Pseudo code:</p>
  
  <pre><code>include(FindPackageHandleStandardArgs)
  
  # create empty list
  list(APPEND mylib_LIBRARIES "")
  
  # the bar variable is always used
  meta_list(APPEND METALIST bar)
  
  # in some cases add the used variable mylib_LIBRARIES to the METALIST
  if(A)
      list(APPEND mylib_LIBRARIES "foo")
      meta_list(APPEND METALIST mylib_LIBRARIES)
  endif(A)
  
  # METALIST will contain exactly the variables that need evaluation
  find_package_handle_standard_args(mylib REQUIRED_VARS ${METALIST})
  </code></pre>
  
  <hr>
  
  <p>Note: having multiple calls to <code>find_package_handle_standard_args</code> is not practical due to combinatorical explosion.</p>