[CMake] Creating symbolic links
Tyler Roscoe
tyler at cryptio.net
Thu Feb 5 11:22:26 EST 2009
On Thu, Feb 05, 2009 at 08:19:31AM -0800, Tyler Roscoe wrote:
> On Thu, Feb 05, 2009 at 09:11:10AM -0500, Schrader, Glenn wrote:
> > I'm having some trouble with one of my CMakeLists.txt files. What I want to do is to create a symbolic link to a file in another directory if it doesn't already exist. The commands that looked to my like they should work are:
> >
> > ADD_CUSTOM_TARGET(run echo "run a test")
> > ADD_CUSTOM_COMMAND(OUTPUT myLink COMMAND ln;-s;${OTHERDIR}/myLink;myLink)
> > ADD_DEPENDENCIES(run myLink)
> >
> > Not only does 'make run' not create a symbolic link, the ln command doesn't show up anywhere in the generated makefiles.
>
> I'm surprised this works at all, since myLink is not a target and
> therefore you shouldn't be able to add a dependency on it.
>
> Look in the faq to see the pattern for how to use add_custom_command and
> add_custom_target. I think your example above should work if your
> add_custom_target looks like:
>
> > ADD_CUSTOM_TARGET(run echo "run a test" DEPENDS myLink)
Also, I would use "${CMAKE_COMMAND} -E create_symlink" rather than
calling ln directly. It probably doesn't matter since symlinks won't
work on Windows anyway, but it's a good practice to keep things as
platform-agnostic as possible.
tyler
More information about the CMake
mailing list