[Bulk] Re: [CMake] custom_command
Javier Gonzalez
javierggt at yahoo.com
Thu Oct 4 10:20:54 EDT 2007
Hi again,
Thanks Eric for the reply. I think what you propose doesn't work for me
and please correct me if I'm wrong. I would like to keep the dependency
and it seems to me that when I use CONFIGURE_FILE the file is not
generated again (if I remove it, for example).
I will do what you say and use cmake -E for some things but anyway my
problem at this point is not with doing the thing portably but with
getting the thing done in the first place.
Any other comments?
Javier
Eric Noulard wrote:
> 2007/10/4, Javier Gonzalez <javierggt at yahoo.com>:
>
>> Hi all,
>>
>> I'm having trouble creating files using ADD_CUSTOM_COMMAND. Take a look
>> at this
>> CMakeLists.txt:
>>
>> ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Dir_2/file
>> COMMAND mkdir -p
>>
> [...]
>
>> ADD_EXECUTABLE( my_exe my_source.cc
>> Dir_1/file
>> ${CMAKE_CURRENT_BINARY_DIR}/Dir_2/file
>> )
>>
>> If I build in the source directory it works (that meaning that the files
>> are created). When I do it in another directory, only the second one is
>> created but the build succeeds. The file my_source.cc is a dummy file
>> with just an empty main().
>>
>> I expected that it would fail, since neither
>> ${CMAKE_CURRENT_BINARY_DIR}/Dir_1/file nor
>> ${CMAKE_CURRENT_SOURCE_DIR}/Dir_1/file exist and is not created but
>> there are no complains!
>>
>> If I add a dummy target for each file and then add the dependencies,
>> then it works but I thought that was not the idea.
>>
>> What am I missing?
>>
>
>
> I don't really know why this fails but if your need is about
> "simple" file copy of file copy with some var substitution in it
> you should use CONFIGUE_FILE macro
>
> CONFIGURE_FILE(Dir_2/file.in
> ${CMAKE_CURRENT_BINARY_DIR}/Dir_2/file
> COPYONLY)
>
> CONFIGURE_FILE(Dir_1/file.in
> ${CMAKE_CURRENT_BINARY_DIR}/Dir_1/file
> COPYONLY)
>
> should be just what you need
>
> If you need more than that and really want to mkdir and cp
> yourself you should use CMake command mode because
> it more portable:
>
> cmake -E copy or copy_if_different etc..
> however command lacks "make_directory" command
> which is not yet in 2.4.6. May be in 2.4.7
> run
> cmake -E
> in order to get the list of supported command.
>
> for example in a ADD_CUSTOM_COMMAND you may write
>
> COMMAND ${CMAKE_COMMAND} -E copy <infile> <outfile>
>
>
>
More information about the CMake
mailing list