title: cmake add_custom_command and DEPENDS/TARGET
body: <p>I have this in my toplevel CMakeLists.txt:</p>
  
  <pre><code>add_subdirectory (src) # add_executable (${PROJECT_NAME} ${_SOURCES})
  add_subdirectory (data)
  </code></pre>
  
  <p>In data subdirectory I want to create a file, when ${PROJECT_NAME} is build. The following doesn't work, returns  target "foo" does not exist:</p>
  
  <pre><code>add_custom_command(
          OUTPUT "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.desktop"
          WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
          COMMAND ${INTLTOOLMERGE} -d -u ../po ${PROJECT_NAME}.desktop.in "${PROJECT_NAME}.desktop"
          COMMENT "Creating desktop file"
          DEPENDS ${PROJECT_NAME}
      )
  </code></pre>
  
  <p>This also doesn't work. Returns: The target name "foo" is unknown in this context</p>
  
  <pre><code>add_custom_command(
          TARGET ${PROJECT_NAME}
          WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
          COMMAND ${INTLTOOLMERGE} -d -u ../po ${PROJECT_NAME}.desktop.in "${PROJECT_NAME}.desktop"
          COMMENT "Creating desktop file"
      )
  </code></pre>
  
  <p>But this works as expected:</p>
  
  <pre><code>add_custom_command(
          OUTPUT "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.desktop"
          WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
          COMMAND ${INTLTOOLMERGE} -d -u ../po ${PROJECT_NAME}.desktop.in "${PROJECT_NAME}.desktop"
          COMMENT "Creating desktop file"
      )
      add_custom_target (desktopfile DEPENDS "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.desktop")
      add_dependencies (${PROJECT_NAME} desktopfile)
  </code></pre>
  
  <p>Question:</p>
  
  <p>1.- How can I use add_custom_command to run the command when "foo" is build <em>without</em> using a target?<p></p>
  
  <p>2.- How come add_dependencies knows about "foo" but pure add_custom_command doesn't?</p>
  
  <p><strong>update #1</strong>: Simple code:</p>
  
  <pre><code># /CMakeLists.txt
  cmake_minimum_required (VERSION 3.0)
  project ("foo")
  
  add_subdirectory (src)
  add_subdirectory (data)
  
  # : EOF~
  
  # src/CMakeLists.txt
  add_executable (${PROJECT_NAME} main.c)
  
  # : EOF:~
  
  # data/CMakeLists.txt
  
  add_custom_command (
      TARGET ${PROJECT_NAME}
      POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E sleep 5
      COMMENT "We're going to try to pause here for 5 seconds"
  )
  
  # EOF:~
  
  # src/main.c
  #include &lt;stdio.h&gt;
  
  int main () {
      printf ("Hello world");
      return 0;
  }
  </code></pre>