title: cmake execute process before anything else
body: <p>I've a problem with CMake executing a process before doing anything else.</p>
  
  <p>The following code snippet shows the situation:</p>
  
  <pre><code>if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/generated")
    file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated")
    execute_process(
      # This tool generates library sources, which are not known before
      COMMAND "source_file_generator_command"
      # This tool iterates over the generated source tree and creates
      # a proper CMakeLists.txt in the 'generated' directory from the
      # source files found there
      COMMAND "cmake_lists_generator_command"
      WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated"
    )
  endif()
  
  # At this point the generated subdirectory (with the also
  # generated CMakeLists.txt file) shall be included
  add_subdirectory(
    "${CMAKE_CURRENT_BINARY_DIR}/generated"
    "${CMAKE_CURRENT_BINARY_DIR}/generated_build"
  )
  # But the 'add_subdirectory' statement fails due to non-existing
  # CMakeLists.txt in the 'generated' source directory at this point
  </code></pre>
  
  <p>The problem is, as commented above, that the CMakeLists.txt file in the subdirectory which should be added is generated on the fly by a special script (the generated sources are not known before) during the first CMake run. Literally, I need CMake to wait until all the statements within the if/else block are executed and process the add_subdirectory statement not until everything is done (the CMakeLists.txt is generated). Is there an adequate solution for such a use case?</p>
  
  <p>Thanks for your help,</p>
  
  <p>Felix </p>