[CMake] How to pass a configuration file to CMake?

Chuck Atkins chuck.atkins at kitware.com
Thu Jan 21 10:41:10 EST 2016


CMake strongly encourages the use of separate source and build directories
(unlike autotools).  So, try something like this:

mkdir build
cd build
cmake -C /path/to/SuperCoolCacheFile.cmake /path/to/source


- Chuck

On Thu, Jan 21, 2016 at 10:10 AM, Cedric Doucet <cedric.doucet at inria.fr>
wrote:

>
>
> Hi Petr,
>
> thank you very much for your answer!
>
> Indeed, comment string arguments seem to be mandatory.
> I modified my configuration file like this:
>
> set(ENABLE_DOWNLOAD True CACHE BOOL "Automatic installation of third-party
> libraries")
> set(GCC_ROOT "/local/cdoucet/gcc/4.9.2/" CACHE PATH "Root of GCC")
>
> Now, I get the following error message:
>
> CMake Error: The source directory "/local/cdoucet/simol/config.cmake" is a
> file, not a directory.
>
> I am quite surprised about this message because I thought a file was
> required to the command 'cmake -C'.
>
> Do you have any idea of what I am doing wrong here?
>
> ----- Petr Kmoch <petr.kmoch at gmail.com> a écrit :
> >
> Hi Cedric.
>
> I believe the comment string argument is mandatory in a set(... CACHE), so
> it should be something like this:
>
> set(ENABLE_DOWNLOAD True CACHE BOOL "Should download be enabled")
> set(GCC_ROOT "/local/cdoucet/gcc/4.9.2/" CACHE PATH "Path to root
> directory of GCC installation")
>
> Petr
>
>
> On Thu, Jan 21, 2016 at 3:43 PM, Cedric Doucet <cedric.doucet at inria.fr>
> wrote:
>
>>
>>
>> Hello,
>>
>> I do not manage to pass a configuration file to cmake.
>>
>> I type 'cmake -C ../config.cmake'
>>
>> where config.cmake belongs to the parent directory and contains these
>> lines:
>>
>> set(ENABLE_DOWNLOAD True CACHE BOOL)
>> set(GCC_ROOT "/local/cdoucet/gcc/4.9.2/" CACHE PATH)
>>
>> I get the following error message but I don't understand why:
>>
>> loading initial cache file ../config.cmake
>> CMake Error at /local/cdoucet/simol/config.cmake:1 (set):
>>   set given invalid arguments for CACHE mode.
>>
>>
>> CMake Error at /local/cdoucet/simol/config.cmake:2 (set):
>>   set given invalid arguments for CACHE mode.
>>
>>
>> CMake Error: The source directory "/local/cdoucet/simol/config.cmake" is
>> a file, not a directory.
>>
>>
>> Do you know how to solve this problem?
>>
>> ----- Cedric Doucet <cedric.doucet at inria.fr> a écrit :
>> >
>>
>> Hi Peter!
>>
>> Thank you very much!
>> It seems to be exactly what I want. :)
>> I will try to use it.
>>
>> Cédric
>>
>> ------------------------------
>>
>> *De: *"Petr Kmoch" <petr.kmoch at gmail.com>
>> *À: *"Cedric Doucet" <cedric.doucet at inria.fr>
>> *Cc: *cmake at cmake.org
>> *Envoyé: *Lundi 21 Décembre 2015 13:25:53
>> *Objet: *Re: [CMake] How to pass a configuration file to CMake?
>>
>> Hi Cedric.
>>
>> I have never used it myself, but I believe you're looking for CMake's
>> command-line option '-C <initial-cache>':
>> https://cmake.org/cmake/help/latest/manual/cmake.1.html
>>
>> Petr
>>
>> On Mon, Dec 21, 2015 at 1:12 PM, Cedric Doucet <cedric.doucet at inria.fr>
>> wrote:
>>
>>>
>>> Hello,
>>>
>>> I would like to know if it's possible to pass a configuration file to
>>> CMake.
>>> I have to pass a lot of information to CMake and the resulting command
>>> line is very long to type.
>>> Would it be possible to create a file containing all needed definitions
>>> and pass it to CMake?
>>>
>>> For exemple, instead of typing
>>>
>>> cmake -D CMAKE_BUILD_TYPE=Debug -D CMAKE_INSTALL_PREFIX=/home/me/there
>>> -D CMAKE_CXX_COMPILER=/usr/local/gcc/4.9.3/g++
>>>
>>> would it be possible to create a file containing
>>>
>>> CMAKE_BUILD_TYPE=Debug
>>> CMAKE_INSTALL_PREFIX=/home/me/there
>>> CMAKE_CXX_COMPILER=/usr/local/gcc/4.9.3/g++
>>>
>>> and pass it to CMake?
>>>
>>> Cédric
>>>
>>> --
>>>
>>> >
>>>
>>> > Powered by www.kitware.com
>>>
>>> >
>>>
>>> > Please keep messages on-topic and check the CMake FAQ at:
>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>
>>> >
>>>
>>> > Kitware offers various services to support the CMake community. For
>>> more information on each offering, please visit:
>>>
>>> >
>>>
>>> > CMake Support: http://cmake.org/cmake/help/support.html
>>>
>>> > CMake Consulting: http://cmake.org/cmake/help/consulting.html
>>>
>>> > CMake Training Courses: http://cmake.org/cmake/help/training.html
>>>
>>> >
>>>
>>> > Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> >
>>>
>>> > Follow this link to subscribe/unsubscribe:
>>>
>>> >http://public.kitware.com/mailman/listinfo/cmake
>>>
>>
>>
>> >
>>
>>
>>
>>
>> --
>>
>> >
>>
>> > Powered by www.kitware.com
>>
>> >
>>
>> > Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> >
>>
>> > Kitware offers various services to support the CMake community. For
>> more information on each offering, please visit:
>>
>> >
>>
>> > CMake Support: http://cmake.org/cmake/help/support.html
>>
>> > CMake Consulting: http://cmake.org/cmake/help/consulting.html
>>
>> > CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> >
>>
>> > Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> >
>>
>> > Follow this link to subscribe/unsubscribe:
>>
>> >http://public.kitware.com/mailman/listinfo/cmake
>>
>
>
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160121/eccb6131/attachment.html>


More information about the CMake mailing list