title: CMake call add_subdirectory within custom command
body: <p>I'm working with a code generator that produces C++ and a CMakeLists.txt file, unfortunately I cannot use this in my main CMakeLists.txt file for testing purposes.</p>
  
  <p>For example you have the following CMakeLists.txt file:</p>
  
  <pre><code>project(SomeProject CXX C)
  
  add_custom_command(OUTPUT ${SRCS}
      COMMAND ${CODEGEN_CLI_PATH} -i "${INPUT}" -o "${OUT}"
      COMMENT "Generating sources"
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
      VERBATIM
  )
  
  add_custom_target(CODEGEN
      DEPENDS
      ${SRCS}
  )
  
  # Needs to be executed after the custom command
  add_subdirectory(${GENERATED_CMAKE_LISTS_LOCATION})
  </code></pre>
  
  <p>Is it possible to use functions such as <code>add_subdirectory</code> only after you execute custom commands for a particular target, such as <code>CODEGEN</code>?</p>
  
  <p>I've already tried to execute it by adding an extra line to the existing custom command:</p>
  
  <pre><code>    COMMAND ${CMAKE_COMMAND} -D DIR=${GENERATED_CMAKE_LISTS_LOCATION} -P add_subdirectories.cmake
  </code></pre>
  
  <p>Unfortuantly this doesn't work because it isn't allowed to execute functions like <code>add_subdirectory</code> in script mode.</p>
  
  <p>Neither I can manage to call custom made functions (that are executing <code>add_subdirectory</code>) from <code>add_custom_command</code> that are located in the same file.</p>