[CMake] adding dependencies on all targets to force CMake to rerun itself

Alan W. Irwin irwin at beluga.phys.uvic.ca
Wed Oct 10 17:44:53 EDT 2007


On 2007-10-10 12:40-0400 Philip Lowman wrote:

> Hi,
>
> I have a text file that is read in via a CMake macro that dynamically
> adjusts the include paths, preprocessor definitions, and link
> directives.  CMake automatically rebuilds the code as needed which is
> wonderful.
>
> One issue I haven't solved yet is modification of this text file doesn't
> force CMake to run itself again.  I was wondering if anyone would have
> any ideas how to do this.
>
> Basically I have something like this but I want all targets in the build
> to depend on changes to foo.txt so that CMake runs itself again.
>
> MACRO(Foo)
> 	FILE(READ ${PROJECT_SOURCE_DIR}/foo.txt contents)
> 	... define variables for include path, directory recursion,
>            etc., that get used later
> ENDMACRO(Foo)

It appears you are
reading the file to "define variables for include path, directory recursion,
etc., that get used later".  Why not simply do that task using CMake
instructions that are INCLUDEd from a file?

For example,

SET (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
INCLUDE (plplot)

That second command looks for
${PROJECT_SOURCE_DIR}/cmake/modules/plplot.cmake and includes the lines in
that file just like those lines were part of the current (usually top-level)
CMakeLists.txt file.  The INCLUDE command can be nested so we have something
like 60 *.cmake files in our cmake/modules directory.  That keeps everything
well organized and also keeps our top-level CMakeLists.txt file relatively
small. A change to any of these files which are INCLUDEd (either directly or
through nesting) in our top-level CMakeLists.txt file means that cmake is
automatically rerun which I believe is exactly what you want.

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