[CMake] Xcode generator fails to heed add_custom_command() DEPENDS
Paul Smith
paul at mad-scientist.net
Sun Jul 14 13:55:43 EDT 2013
Hi all. I have a set of rules I'm using to "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.
I'm using CMake 2.8.11.2 on all systems.
I want to install my file "myapp" into the "bin" directory, so I have
statements like this (I actually use a macro in my environment but I've
instantiated it directly here to be extra sure that's not the problem):
add_executable(myapp
MyAppFoo.cpp
MyAppFoo.h ...)
target_link_libraries(myapp MyLibFoo MyLibBar ...)
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}")
The error I get from xcodebuild is:
=== BUILD NATIVE TARGET myapp OF PROJECT Cloud WITH CONFIGURATION RelWithDebInfo ===
Check dependencies
PhaseScriptExecution "CMake Rules" AppSrc/Cloud.build/RelWithDebInfo/myapp.build/Script-1D1966C325804FD4A165A3B7.sh
cd /Users/paul/builddir
/bin/sh -c /Users/paul/builddir/AppSrc/Cloud.build/RelWithDebInfo/myapp.build/Script-1D1966C325804FD4A165A3B7.sh
make: *** No rule to make target `/Users/paul/builddir/AppSrc/RelWithDebInfo/myapp', needed by `/Users/paul/builddir/dist/bin/myapp'. Stop.
Command /bin/sh failed with exit code 2
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution "CMake Rules" AppSrc/Cloud.build/RelWithDebInfo/myapp.build/Script-1D1966C325804FD4A165A3B7.sh
(1 failure)
It seems to be some kind of prerequisite definition error, where it's
trying to build the pseudo-target "stage_myapp" to copy the file to the
staging directory BEFORE it's created the target to copy. The DEPENDS
statement in add_custom_target() doesn't appear to be working correctly
in Xcode.
Note that if I comment out the custom target stuff then it goes ahead
and builds myapp using exactly the pathname that it says it has no rule
to build (/Users/paul/builddir/AppSrc/RelWithDebInfo/myapp).
I can't move forward with my project until I can find some way to manage
this. Any help would be greatly appreciated!!
More information about the CMake
mailing list