[CMake] An efficiency issue

Radu Serban radu at llnl.gov
Fri Jan 18 13:45:22 EST 2008


Hello,

I tried (unsuccessfully) to figure out a way to minimize the number of times 
a sub-module is configured so I thought I'll ask for advice. My situation is 
such that the configuration of a particular submodule can be very lengthy 
(lots of code generation and transformation) and therefore, I'd like to make 
sure that happens as few times as possible (ideally once).

My bottom line question: Is there any *simple* way to check if a certain 
point in the CMakeLists.txt file was reached a second time with *exactly* 
the same settings as the previous time?

Here's a simple example to illustrate my situation:
Suppose I have the following top-level CMakeLists.txt file:
------------------
PROJECT(test)
OPTION(ENABLE_OPTION "turn on option" OFF)
IF(ENABLE_OPTION)
   FIND_LIBRARY(MATH_LIB m /usr/lib)
ENDIF(ENABLE_OPTION)
IF(MATH_LIB)
   ADD_SUBDIRECTORY(module)
ENDIF(MATH_LIB)
-------------
and in the module subdirectory I have:
-------------
MESSAGE("Configure module -- this takes very looooong")
-------------

If I run 'cmake -i' and, when prompted, I turn on ENABLE_OPTION then cmake 
finds the math library and therefore configures the submodule (first time), 
but then I have to confirm the actual math library that was found and cmake 
will do a second configuration of the submodule.

Obviously, for this simple case, I can concoct some sort of solution (e.g. 
store the value of MATH_LIB that was used the last time and configure the 
module only if that's changed), but this is not feasible when I have many 
more prerequisites.

Any advice? I suspect there must be an elegant solution to this...

Thanks,
--Radu


More information about the CMake mailing list