[CMake] Running cmake multiple times to resolve cache variables

Bill Hoffman bill.hoffman at kitware.com
Fri Oct 10 12:41:40 EDT 2008


Luke Kucalaba wrote:
> I think the reason we need to run cmake.exe multiple times is because we
> typically have a "main" project that automatically sets the options of
> dependent projects.  For example, our main executable project has an
> option "ENABLE_NETWORKING", which then triggers automatic changes for
> various global CACHE variables that are used in subdirectories
> (sub-projects) that have already been processed (using CACHE STRING
> FORCE).  This requires the user to run cmake.exe again to reprocess
> those subdirectories.  Is this not something that we should be doing?
> Or am I not understanding how the multiple passes of cmake works?
> 
> Luke

I still don't get your problem.  The use of CACHE FORCE is usually a bad 
idea.   A CMake project should not need to be run twice to work 
correctly.  Basically, you have created cmake files that do not use the 
correct order of evaluation.

Here is one example of that:

add_library(foo ...)
# I use SOME_LIB before it is set
target_link_library(foo ${SOME_LIB})

# Now I add a sub directory A, that sets SOME_LIB as a cache variable
add_subdirectory(A)
    A: set(SOME_LIB mylib CACHE FORCE)

This would require two runs of cmake to get the value of SOME_LIB 
correct in the toplevel cmake file.

Basically, if your project requires double runs of CMake, then it has a bug.

-Bill





More information about the CMake mailing list