[CMake] add_custom_command issue

Michael Wild themiwi at gmail.com
Mon Mar 1 04:10:41 EST 2010


On 1. Mar, 2010, at 9:25 , Surya Kiran Gullapalli wrote:

>> 
>> add_custom_target(TroFilesTarget DEPENDS ${trofiles})
>> add_dependencies(LibraryTarget TroFilesTarget)
>> 
>> 
> Thanks,
> that worked. the problem now is this.
> 
> The individual .tro files which are created are dependent on the file from
> which it is created. say source_cxx_tro is dependent on source.cxx. Ideally
> source_cxx_tro should be generated only when source.cxx is changed (or
> touched).
> 
> But the source_cxx_tro is generated when ever I run the build. Can we avoid
> this ?
> 
> Thanks,
> Surya


you have to tell add_custom_command on what the output depends:

add_custom_command (OUTPUT ${trofile}
  COMMAND perl trans.pl ${file} -o ${file_tro}
  DEPENDS ${file}
  )

Also, you might consider to add trans.pl to the dependency list, since if that one changes, the files should also be regenerated. Further, relying on perl to be present and being named like this isn't a good idea, you should use find_package(Perl REQUIRED) instead, and then use ${PERL_EXECUTABLE} in place of just the plain "perl" command.

HTH

Michael

PS: Please always include the cmake-list in your answer so that others can profit from the discussion...


More information about the CMake mailing list