[CMake] add_custom_command issue

Michael Wild themiwi at gmail.com
Mon Mar 1 04:55:06 EST 2010


On 1. Mar, 2010, at 10:38 , Surya Kiran Gullapalli wrote:

>> 
>> 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}
>> )
>> 
> 
> I'm sorry. I should have been more clearer. I've already done this. But what
> I'm getting is the .tro files are generated even when the corresponding
> source file doesn't change.
> 
> I have some thing like this.
> 
> *ForEach (file ${AllFiles})*
> *List(APPEND trofiles ${TransOutFile})*
> * Add_Custom_Command (*
> *      OUTPUT ${TransOutFile}*
> *      COMMAND ${PERL_EXECUTABLE}
> ${CUE_MAKE_DIR}/trcomp.pl${infileModified} -o ${TransOutFile} # this
> create .tro file from .cxx/.hxx
> file*
> *      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}*
> *      DEPENDS ${file}*
> *      VERBATIM*
> *      )*
> *End_Loop *
> *
> *
> *  Add_Custom_Command (*
> *    OUTPUT ${trxfile}*
> *    COMMAND ${PERL_EXECUTABLE} ${CUE_MAKE_DIR}/trlink.pl -o ${trxfile}
> ${trofiles} // this combines all the .tro files to .trx file.*
> *    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}*
> *    COMMENT "Creating translation files for ${LibName} module"*
> *    DEPENDS ${trofiles}*
> *    VERBATIM*
> *    )*
> 
> *Add_Custom_Target (${TargetName}TrxFile DEPENDS ${trxfile})* # Create
> custom target to create .trx file from .tro files.
> 
> *Add_Dependencies (${TargetName} ${TargetName}TrxFile)* # the library is now
> dependent on the previous custom target.
> 
> 
> So when i build the library, these tro files gets generated and subsequently
> this .trx file.
> 
> I build it again (without modifying any source files)
> The library itself does not get built, but this library depends upon trx
> file which in turn depend upon .tro files which in turn depends upon the
> source files. The source files are not changed and hence i expect the tro
> files does not get generated. But they are getting generated.
> 
> Am I missing something here ?
> 
> Thanks,
> Surya

The only reason I can think of is that you're not using absolute paths somewhere. Make sure that the variables allFiles, TransOutFile and trxfile contain absolute paths (i.e. start with CMAKE_BINARY_DIR, CMAKE_SOURCE_DIR, CMAKE_CURRENT_BINARY_DIR or similar.

HTH

Michael



More information about the CMake mailing list