[CMake] Accessing Variables from within a *.cmake file

Hashim Mir hmir at rim.com
Thu Feb 23 11:52:22 EST 2012


Nope, I am not running it with -P.

My BuildSetup.cmake sets the flags that are passed in to the compiler 
ex: set(CMAKE_CXX_FLAGS ...)

-----Original Message-----
From: David Cole [mailto:david.cole at kitware.com] 
Sent: February-23-12 11:45 AM
To: Hashim Mir
Cc: John Drescher; cmake at cmake.org
Subject: Re: [CMake] Accessing Variables from within a *.cmake file

On Thu, Feb 23, 2012 at 10:58 AM, Hashim Mir <hmir at rim.com> wrote:
> There is a PROJECT() at the top of my CMakeLists.txt file.
>
> However, I am trying to access the variable from within my BuildSetup.cmake file, so it is considered even before the CMakeLists.txt file.
>
> -----Original Message-----
> From: John Drescher [mailto:drescherjm at gmail.com]
> Sent: February-23-12 10:48 AM
> To: Hashim Mir
> Cc: cmake at cmake.org
> Subject: Re: [CMake] Accessing Variables from within a *.cmake file
>
> On Thu, Feb 23, 2012 at 10:39 AM, Hashim Mir <hmir at rim.com> wrote:
>> Hi,
>>
>>
>> I am trying to control the flow of my program based on the value of a 
>> cmake variable called CMAKE_SIZEOF_VOID_P.
>>
>>
>>
>> To start off, I wanted to just see what value this variable took 
>> under multiple different configurations, by issuing the following 
>> command in my cmakelists.txt file:
>>
>>
>>
>> message(${CMAKE_SIZEOF_VOID_P})
>>
>>
>>
>> This works perfectly. However, whenever I try to run the above 
>> command on my *.cmake file, I get no value returned to me (it just throws an error).
>>
>
> Is there a PROJECT()
>
> before you include your .cmake
>
> John
>
> ---------------------------------------------------------------------
> This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.
> --
>
> 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


Are you running it with "cmake -P" ?

If so, the variable CMAKE_SIZEOF_VOID_P is not defined, unless you define it yourself, and pass it in using -D when you call the -P script.

It is only defined after enabling the C or CXX language (which is a side effect of the project command) during a CMake configure run.

What does BuildSetup.cmake do?


HTH,
David

---------------------------------------------------------------------
This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.


More information about the CMake mailing list