[CMake] Is it possible to call or include CMakeCache from another CMakeCache?

Michael Hertling mhertling at online.de
Thu Jul 28 21:07:10 EDT 2011


On 07/19/2011 05:50 PM, Kevyn-Alexandre Paré wrote:
> Hi David,
> 
> thx for the reply see below.
> 
> On 2011-07-19, at 6:41 AM, David Cole wrote:
> 
>> On Mon, Jul 18, 2011 at 3:51 PM, Kevyn-Alexandre Paré
>> <kapare at rogue-research.com> wrote:
>>> Hi,
>>>
>>> Is it possible to call or include CMakeCache from another CMakeCache?
>>>
>>> I want to replace my 2 CMakeCache to one.
>>>
>>> ex:
>>>
>>> cmake -C Config-Generic.txt :qConfig-Project.txt ../
>>>
>>> Any idea if it's possible to include the Config-Generic.txt inside the Config-Project.txt?
>>>
>>> Best Regards,
>>>
>>> Kevyn-Alexandre Paré
>>>
>>>
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.cmake.org/mailman/listinfo/cmake
>>>
>>
>> Ii don't think this really sounds like a wise idea...
> 
> That's the reason why I post the question. But why it's not, this is why I'm asking.
> 
>>
>> What is it you're trying to accomplish?
> 
> Sorry if I didn't gives enough explanation. I'm trying to remove the cut & paste on each project for:
> 
> CMAKE_BACKWARDS_COMPATIBILITY
> CMAKE_C_COMPILER
> CMAKE_CXX_COMPILER
> CMAKE_SYSTEM_PROCESSOR
> CMAKE_BUILD_TYPE
> and a lot of other flag 
> 
> by putting all of these in a generic CMakeCache file. So I could reuse that generic config file for other project.
> 
> 
>> If you have two CMakeCache
>> files, then you have two separate projects, and you've run CMake on
>> each of them to get the two CMakeCache files.
> 
> No this isn't what we are trying to accomplish. It's possible to use cmake with multiple cache file:
> 
> cmake -C Cache1.txt -C Cache2.txt <path to cmakelist.txt>
> 
>> So why do you want to
>> combine them into one?
> 
> Since I'm having a generic cache file that contain the generic project detail. I was interested from the cache specific to INCLUDE that generic cache file like a simple header file (like in C).
> 
>> If you only want one project, then why not
>> simply merge the two CMakeLists files together into one project?
> 
> Because at the end since we are having multiple project we were hoping to reuse and not cut and paste.
> 
>>
>> Let us know what you're trying to achieve, maybe there's a better
>> supported way to do it.
> 
> I hope with these explanation it's clearer !?
> 
>> Combining multiple CMakeCache files is not
>> something that the CMake dev team expects you to do...
> 
> Ok so why supporting multiple cache parameters?
> 
> 
>> Trying to do so
>> will very likely lead to weird, inexplicable issues.....
> 
> Right now I don't have strange behaviour  and everything is working fine. But if in the future that option will not be supported. I would really like to be advise on what is the best way to do this.

If you know in advance which variables you want to keep centrally, you
might use the LOAD_CACHE() command; see the following example projects:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(LOADCACHE NONE)
SET(CMAKE_VERBOSE_MAKEFILE ON)
IF(EXISTS "${CACHEPATH}/CMakeCache.txt")
    LOAD_CACHE("${CACHEPATH}" READ_WITH_PREFIX DEFAULT_ VARIABLE)
ENDIF()
IF(DEFINED DEFAULT_VARIABLE)
    MESSAGE("DEFAULT_VARIABLE: ${DEFAULT_VARIABLE}")
ELSE()
    MESSAGE("DEFAULT_VARIABLE undefined")
ENDIF()

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(VARIABLE NONE)
SET(CMAKE_VERBOSE_MAKEFILE ON)
SET(VARIABLE "xyz" CACHE STRING "Variable")

If the first project is configured with CACHEPATH set to the path of
the latter project's CMakeCache.txt file, the VARIABLE will be taken
from that cache and made available as DEFAULT_VARIABLE. Note that
DEFAULT_VARIABLE itself won't be cached without further ado, and
variables like CMAKE_C_COMPILER must be set before the PROJECT()
or ENABLE_LANGUAGE() command to take effect during the initial
configuration.

Regards,

Michael


More information about the CMake mailing list