[cmake-developers] kde4_automoc issue

Brad King brad.king at kitware.com
Mon Jul 17 15:58:52 EDT 2006


Alexander Neundorf wrote:
> On Monday 17 July 2006 16:01, you wrote:
>> Brad King wrote:
>>> Alexander Neundorf wrote:
>>>> if (need_automoc)
>>>>    # create a file with all files for automoc
>>>>    file(WRITE kfoo_automoc_files ${automocfiles)
>>>>    # create a target which will be built before the actual target
>>>>    ADD_CUSTOM_TARGET(kfoo_automoc COMMAND <scan all files from
>>>> kfoo_automoc and run moc if required> )
>>>>    ADD_DEPENDENCIES(kfoo kfoo_automoc)
>>>> endif
>>>>
>>>> This would move the automoc from cmake time to buildtime, which is a
>>>> good thing.
>>> Try this:
>>>
>>> ADD_CUSTOM_TARGET(kfoo_automoc)
>>> ADD_CUSTOM_COMMAND(
>>>   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/kfoo_automoc.stamp
>>>   COMMAND <scan all files and run moc, then touch kfoo_automoc.stamp>
>>>   DEPENDS <all files>
>>>   )
>> Oops, I meant something more like:
>>
>> ADD_CUSTOM_COMMAND(
>>   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/kfoo_automoc.stamp
>>   COMMAND <scan all files and run moc, then touch kfoo_automoc.stamp>
>>   DEPENDS <all files>
>>   )
>> ADD_CUSTOM_TARGET(kfoo_automoc
>>   DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/kfoo_automoc.stamp
>>   )
> 
> What is this intermediate target good for ?

To make sure all moc-ing occurs before implicit #include dependencies
are scanned.

> Doesn't this mean once kfoo_automoc.stamp has been created it won't run 
> again ?

No, because the custom command depends on all the input files, so if any
one has changed the rule will run again.

> And the stamp would have to be on file-level, so that I can check for every 
> single source file whether it has to be scanned again.

With this design at least nothing will happen when it is up to date.  If
any file has changed all will be rescanned.  File-level dependencies can
be achieved if we add an IF(file1 IS_NEWER file2) command which can be
used to test each .cpp file against the .stamp file.

-Brad



More information about the cmake-developers mailing list