Better support for custom commands that generate multiple files needed.

Alexander Neundorf neundorf at kde.org
Fri Apr 7 18:30:34 CEST 2006


On Wednesday 05 April 2006 22:10, David Faure wrote:
> kdelibs/kabc says:
>
>
> add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/addressee.cpp
>    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/scripts
>    COMMAND ${PERL_EXECUTABLE}
>    ARGS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/makeaddressee
>    DEPENDS  ${CMAKE_CURRENT_SOURCE_DIR}/scripts/makeaddressee
>    ${CMAKE_CURRENT_SOURCE_DIR}/scripts/addressee.src.cpp
>    ${CMAKE_CURRENT_SOURCE_DIR}/scripts/addressee.src.h
>    ${CMAKE_CURRENT_SOURCE_DIR}/scripts/entrylist
>    ${CMAKE_CURRENT_SOURCE_DIR}/scripts/field.src.cpp
>    )
>
> The above script in fact generates both addressee.cpp and addressee.h
>
> I had a problem due to addressee.h being deleted but not addressee.cpp, so
> the above command wouldn't be run, and compilation would fail. No idea how
> I ended up with only addressee.cpp and no .h, but well... the old
> buildsystem handled this case since Makefiles support the notion of "custom
> commands that generate multiple files" :
> addressee.cpp addressee.h field.cpp: [....]
>
> I tried to add something like Alex's recent fix for kcfg files:
> add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/addressee.h DEPENDS
> ${CMAKE_CURRENT_BINARY_DIR}/addressee.cpp) but this doesn't help; the .cpp
> exists so the dependency does nothing, if the .h is missing.
>
> Could add_custom_command's OUTPUT variable be changed to support a list of
> output files?

How can this be implemented in a plain Makefile ?

Maybe:

option 1)

generated.h: helper_target
generated.cpp: helper_target

helper_target: file1.foo
	some_generator -in file1.foo -header generated.h -impl generated.cpp

Would this work ?
Then it should be possible to do this in cmake with a combination of 
add_custom_target (the helper_target) and add_custom_command.

option 2)

generated.h: file1.foo
	some_generator -in file1.foo -header generated.h -impl generated.cpp
generated.cpp: file1.foo
	some_generator -in file1.foo -header generated.h -impl generated.cpp

might break if in parallel build both are executed at the same time, right ?

option 3)

generated.h: generated.cpp
generated.cpp: file1.foo
	some_generator -in file1.foo -header generated.h -impl generated.cpp

This is probably as I did it now. It works for parallel builds, but doesn't 
regenerate generated.h if generated.cpp is current.

Any other ideas ?

Bye
Alex
-- 
Work: alexander.neundorf AT jenoptik.com - http://www.jenoptik-los.de
Home: neundorf AT kde.org                - http://www.kde.org
      alex AT neundorf.net               - http://www.neundorf.net


More information about the Kde-buildsystem mailing list