[CMake] Complex command

Ryan Pavlik rpavlik at iastate.edu
Fri Aug 6 15:18:12 EDT 2010


  On 8/6/10 1:12 PM, Magnus Therning wrote:
> I was trying to put something like this into a CMake file:
>
> add_custom_command( ...
>      COMMAND ...
>      COMMAND ([[ -f foo ]] || ln -sf foo bar); true
>      )
>
> But CMake won't have it.  Skipping the sub-shell is all right with CMake:
>
> add_custom_command( ...
>      COMMAND ...
>      COMMAND [[ -f foo ]] || ln -sf foo bar
>      )
>
> But then make doesn't like it if the file doesn't exist, it exits with an
> error.
>
> I put the command in an external shell script instead, but would rather
> not do
> that.
>
> Any suggestions?
>
> /M

You could create/dynamically at configure time write out a cmake file 
that does something to the effect of:
if(EXISTS foo)
     execute_process(COMMAND ${CMAKE_COMMAND}) -E create_symlink 
oldfilename newfilename)
endif()

then make your custom command run cmake in script mode on that file.  
This will let you be cross-platform in a good way.

-- 
Ryan Pavlik
Human-Computer Interaction Graduate Student
Virtual Reality Applications Center
Iowa State University

rpavlik at iastate.edu
http://academic.cleardefinition.com/



More information about the CMake mailing list