wildcards in DEPENDS

Alexander Neundorf neundorf at kde.org
Thu Nov 27 21:10:04 CET 2008


On Wednesday 26 November 2008, Matthias Kretz wrote:
> On Tuesday 25 November 2008 22:35:34 Alexander Neundorf wrote:
> > The macro macro_add_file_dependencies() is only available in kdelibs/ and
> > projects using kdelibs/, i.e. it shouldn't be used in automoc. The macro
> > is in kdelibs/cmake/modules/MacroAddFileDependencies.cmake, you can just
> > copy it.
>
> Hmm, I found the macro also in the cmake installation dir as the FindQt4
> shipping with cmake also uses it.

You're right, sorry.

> > But, why is this dependency required now ? Currently the source files
> > don't depend on the automoc-generated file and it works ?
>
> Yes it works most of the time except for make target/fast there's a race
> and it breaks sometimes.
> So actually this part of the patch is not directly related to the
> automoc4_init change.
>
> > About the add_custom_target(automoc4_init): this is done now
> > unconditionally. I.e. if you do find_package(Automoc4) twice, it will be
> > executed twice, cmake will then complain about the target being added
> > twice.
>
> Ah, I thought cmake would still read the automoc code only once.
>
> > So you should test wether the target has already been added.
> > With CMake >= 2.6.2 you can do
> > if(NOT TARGET automoc4_init)
> >  ...
> >
> > With version before that you can do
> > get_target_property(AUTOMOC4_INIT_TYPE automoc4_init TYPE)
> > if the target has already been created, you will get "UTILITY" as result
> > (which is TRUE if tested in an if()), and "AUTOMOC4_INIT_TYPE-NOTFOUND"
> > if it hasn't been created yet (which is false if tested with if()).
>
> I used if(AUTOMOC4_INIT_FILE) now, that should be suffiently safe and a bit
> easier, ok?

Not really. E.g.:

src/CMakeLists.txt:
add_subdirectory(sub1)
add_subdirectory(sub2)

src/sub1/CMakeLists.txt
find_package(Automoc4)

src/sub2/CMakeLists.txt
find_package(Automoc4)

Then AUTOMOC4_INIT_FILE will not be set when entering src/sub2/CMakeLists.txt, 
since this doesn't go up to the parent directory.

Targets are global, so testing for the target is safe.
If you want to require at least cmake 2.6.0, you can also set a GLOBAL 
property and test for this.

> > Is it still necessary to have different versions for Windows and
> > non-Windows ?
>
> I don't know. I'd like the Windows people to give the non-Windows code
> another try and hopefully we can remove the special casing for Windows
> again.

Ok.

> > Instead of putting all files into automoc4_init.files on every cmake run,
> > could you do it similar to as you did it before ?
> > I.e. instead if touching the file in the add_custom_command(), add that
> > filename to automoc4_init.files, so in the next make, the automoc4_init
> > target will just touch these files and not all ?
> > This could be done by adding that to the automoc4 executable or by
> > executing an additional command in the same add_custom_command (echo
> > should work)
>
> It's hard to do that without creating new races. (Think of the user hitting
> Ctrl+C at the most inconvenient point in time.) 

Like in the middle of writing to that file ?

> And what would happen if
> two or more automoc4 processes write to the file at the same time?

Yes, that's right.

> Also the current implementation seems reasonably fast (kdelibs: 3ms,
> kdebase: 4ms, phonon: 0ms. After 'echo 3 > /proc/sys/vm/drop_caches':
> kdelibs: 77ms, kdebase: 260ms, phonon: 27ms.)

What did you measure here exactly ?

Alex


More information about the Kde-buildsystem mailing list