[CMake] Caching calculated values.

Amitha Perera perera at cs.rpi.edu
Mon Oct 22 13:53:23 EDT 2007


On Mon 22 Oct 2007, Josef Karthauser wrote:
> As each set of calculations are connected to a single CMakeList.txt
> file, it should be possible to avoid recalculating, and useing cached
> values where possible.  In order to do that however I need to know
> whether a CMakeLists.txt file is stale, with respect to the last time it
> ran, or not.  Is there an easy way for me to determine from within a
> CMakeLists.txt file, whether it is out-of-date?

In the VXL project, we use a serial number for that purpose.
Something like

# The serial number below will allow the maintainers to force builds
# to update cached results. Whenever you make a change that makes it
# necessary for cached values to be updated, increment the serial
# number. The format follows a DNS-style numbering: the current date
# followed by a modification time within the day.
#
SET( VXL_CONFIG_SERIAL_CURRENT "2006-16-03-002" )

IF( ${VXL_CONFIG_SERIAL_CURRENT} MATCHES "^${VXL_CONFIG_SERIAL_LAST}$"
)
  # The configuration is current
ELSE( ${VXL_CONFIG_SERIAL_CURRENT} MATCHES
"^${VXL_CONFIG_SERIAL_LAST}$" )
  SET( VXL_UPDATE_CONFIGURATION "ON" )
  # Record that we've done the new config.
  SET( VXL_CONFIG_SERIAL_LAST ${VXL_CONFIG_SERIAL_CURRENT} CACHE
  INTERNAL "Serial number of last configuration" )
ENDIF( ${VXL_CONFIG_SERIAL_CURRENT} MATCHES
"^${VXL_CONFIG_SERIAL_LAST}$" )

That way, we can update the serial number when the CMakeLists.txt file
changes in such a way that the configuration needs to be recomputed.
Compared to other approaches such as checking the file timestamp, this
has the advantage of allowing cosmetic changes to the CMakeLists.txt
file (change comments, etc) without forcing the configuration to be
re-computed.

In our case, VXL_UPDATE_CONFIGURATION is also an OPTION, so that users
can trigger a configuration re-computation if they feel it necessary.
We forcibly update it to OFF after the computations are re-done.

Amitha.


More information about the CMake mailing list