[CMake] Reading settings from generated files

Bill Hoffman bill.hoffman at kitware.com
Tue May 20 14:07:21 EDT 2008


Andrea Gualano wrote:
> Hello everybody,
> I have solved my original problem with a good amount of shell scripting, 
> but this seems to defy the purpose of a cross-platform tool.
> Also, my question looks closely related to this other recent thread: 
> "Custom-Targets with unknown outputs", so I think this discussion may be 
> useful to other people.
> 
> Eric Noulard wrote:
>> If you want to override a CACHE entry which may already exist you'll
>> have to use FORCE
>> SET (CMAKE_C_FLAGS "${MORE_FLAGS}" CACHE STRING "generated flags" FORCE)
>> But in fact I don't know if  CMake -P may/currently shares the
>> CMakeCache.txt?
> 
> Actually, it looks like cmake -P does not modify the cache.
> 
>> Basically your need is to be able to run CMake twice, the first one
>> fort generating
>> some files and the second one to build.
>>
>> May be your read_flags.cmake could generate a file more_flags.cmake
>> then your CMakeList.txt should do
>>
>> IF(EXISTS more_flags.cmake)
>>    INCLUDE(more_flags.cmake)
>> ENDIF(EXISTS more_flags.cmake)
>>
>>
>> or
>> INCLUDE(more_flags.cmake OPTIONAL)
> 
> What I have done (and it does work) is:
> - cmake
> - make custom_target #this also generates more_flags.cmake
> - cmake #again
> - make
> 
> What is missing now, is that the second cmake should be invoked by the 
> custom target. This should make all dependecies work right.
> 
> Has anyone ever used this kind of two phase configuration?
> 

I don't think this is possible.  A cmake run from make works like this:

make
1. check all the input files to see if cmake needs to be run
2. re-run cmake if needed
3. run a recursive make to build stuff after the makefiles have been 
updated.

There really is not a way to add an additional step into that process.

-Bill


More information about the CMake mailing list