[CMake] add_custom_command: regenerate all on modifcation?

Alan W. Irwin irwin at beluga.phys.uvic.ca
Fri May 30 11:33:19 EDT 2008


On 2008-05-30 12:50+0400 Dave Milter wrote:

> The problem become arris on big project.
> It used qt, and when I add new file, it regenerate all stuff,
> like moc files, ui_*.h files and so on,
> this lead to rebuild corresponding C++ files,
> and this is too long for me, and I also do not see, why
> this should be so?
>
> So I create smple test project to show the problem:
> -------------------------------------------------------------------
> PROJECT(test_rebuild)
>
> ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/new_func.hpp
> 	COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/generate_new_func.sh >
> ${CMAKE_CURRENT_BINARY_DIR}/new_func.hpp
> #	MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/generate_new_func.sh
> 	DEPENDS  ${CMAKE_CURRENT_SOURCE_DIR}/generate_new_func.sh
> )
>
> INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
>
> SET(tr_SRCS
> #	test.cpp
> 	foo.cpp
> 	main.cpp
> )
>
> SET(tr_HDRS
> #	test.hpp
> 	foo.hpp
> 	${CMAKE_CURRENT_BINARY_DIR}/new_func.hpp
> )
>
>
>
> ADD_EXECUTABLE(test_rebuild
> 	${tr_SRCS}
> 	${tr_HDRS}
> )
> -------------------------------------------------------------------
>
> There is file new_func.hpp generated by generate_new_func.sh script,
> there is foo.cpp which depends on new_func.hpp.
>
> test.cpp and test.hpp do not depend on any other files.
>
> But every time when I comment test.cpp test.hpp or uncomment
> new_func.hpp regenerated and foo.cpp rebuild happened.
>
> is it possible to fix this behaviour?

You are performing a bad test because your commenting/uncommenting is
changing the CMake code which is not how you should be testing for
source-file dependencies. Instead, use the "touch" command (at least on
Unix) to see how your build responds to _source file_ changes (not CMake
file changes).

Once you get the right testing procedure in place, try using the following
chain of dependencies (noting the large conceptual difference between target
dependencies and file dependencies).  Make test_rebuild depend on a custom
target which you define which does nothing but file_depend on
${CMAKE_CURRENT_BINARY_DIR}/new_func.hpp.  I know that procedure works fine
since PLplot uses it.  Another alternative is simply to set the GENERATED
property to a true value using SET_SOURCE_FILES_PROPERTIES.  I have no
personal experience with that, but I have heard on list here that it works.

Note, I have only done a general summary here for you since I assume you
will follow up on this by reading the CMake documentation for
ADD_CUSTOM_TARGET, ADD_DEPENDENCIES, SET_SOURCE_FILES_PROPERTIES, etc. to
get the specifics for yourself.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list