[CMake] Xcode generator fails to heed add_custom_command() DEPENDS

Paul Smith paul at mad-scientist.net
Sun Jul 14 14:23:06 EDT 2013


On Sun, 2013-07-14 at 13:55 -0400, Paul Smith wrote:
> The statements I'm using work great with the Makefile
> generator and the Visual Studio generator, but the build fails with
> the Xcode generator.
> 
> I'm using CMake 2.8.11.2 on all systems.

Here's a reproducible test case; run these commands from a terminal on
MacOS:

cd ~
mkdir xcode-test
cd xcode-test

cat > myapp.c <<EOF
  #include <stdio.h>

  int main()
  {
      printf("Hello world!\n");
      return 0;
  }
EOF

cat > CMakeLists.txt <<EOF
  cmake_minimum_required(VERSION 2.8)
  project(TestApp C)
  add_executable(myapp myapp.c)

  set(MYPREFIX "${TestApp_SOURCE_DIR}/dist" CACHE PATH "install prefix" FORCE)

  get_property(targetpath TARGET myapp PROPERTY LOCATION)
  get_filename_component(targetname ${targetpath} NAME)

  add_custom_command(OUTPUT "${MYPREFIX}/bin/${targetname}"
      COMMAND "${CMAKE_COMMAND}" -E make_directory "${MYPREFIX}/bin"
      COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_FILE:myapp>" "${MYPREFIX}/bin"
      DEPENDS ${targetname}
      COMMENT "Staging myapp to ${MYPREFIX}/bin"
      VERBATIM)

  add_custom_target("stage_myapp" ALL
      DEPENDS "${MYPREFIX}/bin/${targetname}")
EOF

Now run cmake with the Xcode generator, and build it, and it fails:

  $ cmake -G Xcode .
  -- The C compiler identification is Clang 4.2.0
  -- Check for working C compiler using: Xcode
  -- Check for working C compiler using: Xcode -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /Users/paul/xcode-test

  $ xcodebuild build -configuration RelWithDebInfo
    ...
  === BUILD NATIVE TARGET myapp OF PROJECT TestApp WITH CONFIGURATION RelWithDebInfo ===
  Check dependencies

  PhaseScriptExecution "CMake Rules" TestApp.build/RelWithDebInfo/myapp.build/Script-2C3540A800314C1082C9261D.sh
      cd /Users/build/pds/xcode-test
      /bin/sh -c /Users/paul/xcode-test/TestApp.build/RelWithDebInfo/myapp.build/Script-2C3540A800314C1082C9261D.sh
  make: *** No rule to make target `/Users/paul/xcode-test/RelWithDebInfo/myapp', needed by `/Users/paul/xcode-test/dist/bin/myapp'.  Stop.
  Command /bin/sh failed with exit code 2


  ** BUILD FAILED **


  The following build commands failed:
          PhaseScriptExecution "CMake Rules" TestApp.build/RelWithDebInfo/myapp.build/Script-2C3540A800314C1082C9261D.sh
  (1 failure)

If you clean up and rebuild with the makefile generator, it works fine.



More information about the CMake mailing list