[cmake-developers] [CMake 0014291]: add_custom_command() DEPENDS does not work with the Xcode generator

Mantis Bug Tracker mantis at public.kitware.com
Mon Jul 15 10:43:20 EDT 2013


The following issue has been SUBMITTED. 
====================================================================== 
http://www.cmake.org/Bug/view.php?id=14291 
====================================================================== 
Reported By:                Paul Smith
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   14291
Category:                   CMake
Reproducibility:            always
Severity:                   major
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2013-07-15 10:43 EDT
Last Modified:              2013-07-15 10:43 EDT
====================================================================== 
Summary:                    add_custom_command() DEPENDS does not work with the
Xcode generator
Description: 
I have a set of rules I'm using to copy ("stage") some files after they're
built.  I do not want to use install rules for this for various reasons.  The
statements I'm using work great with the Makefile generator and the Visual
Studio generator, but the build fails with the Xcode generator.

Xcode tries to run the "stage" rule before it builds the target to be staged,
even though the "stage" rule has a DEPENDS statement on the target.  The build
fails because the target does not exist:

  $ 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)

Steps to Reproduce: 
Create a simple C file:

cd ~
mkdir xcode-test
cd xcode-test

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

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

Then create a simple CMake file:

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)

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

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

Now build an Xcode generator, then run xcodebuild:

  $ cmake -G Xcode .
  $ xcodebuild build -configuration RelWithDebInfo


Additional Information: 
If you use the 'Unix Makefile' generator instead, it will work fine (even with
high parallelism).  Also I've tried replacing the "DEPENDS myapp" with a full
pathname to "myapp" and that fails as well, with the same error.

I've seen this same behavior on various different versions of Xcode: 4.1, 4.6,
and 4.6.3 at least.
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2013-07-15 10:43 Paul Smith     New Issue                                    
======================================================================




More information about the cmake-developers mailing list