configure_file - false vs "0"

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

configure_file - false vs "0"

James C. Sutherland
In my configure.h.in file I have:

    #cmakedefine TEST_VAR_VALUE

In my CMakeLists.txt file I have:

   configure_file( ${PROJECT_SOURCE_DIR}/src/config.h.in $
{PROJECT_SOURCE_DIR}/src/configure.h )
   set( TEST_VAR_VALUE  "0" )

This results in a configure.h file containing:
   /* #undef TEST_VAR_VALUE */

But what I would like is:
    #define TEST_VAR_VALUE 0


So basically cmake is seeing the value of TEST_VAR_VALUE as 0 and  
treating it as "false" rather than a value.

Any ideas how to accomplish this?

James
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: configure_file - false vs "0"

Michael Wild

On 9. Aug, 2009, at 18:06, James C. Sutherland wrote:

> In my configure.h.in file I have:
>
>   #cmakedefine TEST_VAR_VALUE
>
> In my CMakeLists.txt file I have:
>
>  configure_file( ${PROJECT_SOURCE_DIR}/src/config.h.in $
> {PROJECT_SOURCE_DIR}/src/configure.h )
>  set( TEST_VAR_VALUE  "0" )
>
> This results in a configure.h file containing:
>  /* #undef TEST_VAR_VALUE */
>
> But what I would like is:
>   #define TEST_VAR_VALUE 0
>
>
> So basically cmake is seeing the value of TEST_VAR_VALUE as 0 and  
> treating it as "false" rather than a value.
>
> Any ideas how to accomplish this?
>
> James
>


Use the (undocumented) #cmakedefine01.

I already submitted a patch, and the documentation has been fixed in  
CVS.

Michael

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: configure_file - false vs "0"

James C. Sutherland

On Aug 9, 2009, at 10:20 AM, Michael Wild wrote:

>
> On 9. Aug, 2009, at 18:06, James C. Sutherland wrote:
>
>> In my configure.h.in file I have:
>>
>>  #cmakedefine TEST_VAR_VALUE
>>
>> In my CMakeLists.txt file I have:
>>
>> configure_file( ${PROJECT_SOURCE_DIR}/src/config.h.in $
>> {PROJECT_SOURCE_DIR}/src/configure.h )
>> set( TEST_VAR_VALUE  "0" )
>>
>> This results in a configure.h file containing:
>> /* #undef TEST_VAR_VALUE */
>>
>> But what I would like is:
>>  #define TEST_VAR_VALUE 0
>>
>>
>> So basically cmake is seeing the value of TEST_VAR_VALUE as 0 and  
>> treating it as "false" rather than a value.
>>
>> Any ideas how to accomplish this?
>>
>> James
>>
>
>
> Use the (undocumented) #cmakedefine01.
>
> I already submitted a patch, and the documentation has been fixed in  
> CVS.
>
> Michael
>

Thanks!  That did it.
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: configure_file - false vs "0"

James C. Sutherland

On Aug 9, 2009, at 10:33 AM, James C. Sutherland wrote:

>
> On Aug 9, 2009, at 10:20 AM, Michael Wild wrote:
>
>>
>> On 9. Aug, 2009, at 18:06, James C. Sutherland wrote:
>>
>>> In my configure.h.in file I have:
>>>
>>> #cmakedefine TEST_VAR_VALUE
>>>
>>> In my CMakeLists.txt file I have:
>>>
>>> configure_file( ${PROJECT_SOURCE_DIR}/src/config.h.in $
>>> {PROJECT_SOURCE_DIR}/src/configure.h )
>>> set( TEST_VAR_VALUE  "0" )
>>>
>>> This results in a configure.h file containing:
>>> /* #undef TEST_VAR_VALUE */
>>>
>>> But what I would like is:
>>> #define TEST_VAR_VALUE 0
>>>
>>>
>>> So basically cmake is seeing the value of TEST_VAR_VALUE as 0 and  
>>> treating it as "false" rather than a value.
>>>
>>> Any ideas how to accomplish this?
>>>
>>> James
>>>
>>
>>
>> Use the (undocumented) #cmakedefine01.
>>
>> I already submitted a patch, and the documentation has been fixed  
>> in CVS.
>>
>> Michael
>>
>
> Thanks!  That did it.


Okay - I spoke too soon.  It gave me a partial solution.

What if I want to have something like
   #define TEST_VAR_VALUE 5

In the .in file:
   #cmakedefine TEST_VAR_VALUE ${TEST_VAR_VALUE}
doesn't work (for reasons mentioned above)

However,
   #cmakedefine01 TEST_VAR_VALUE ${TEST_VAR_VALUE}
results in
   #define TEST_VAR_VALUE 5 1
if I have
   set( TEST_VAR_VALUE 5 )
in my CMakeLists.txt file.

Can I get rid of the trailing value?
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: configure_file - false vs "0"

Michael Wild

On 9. Aug, 2009, at 18:39, James C. Sutherland wrote:

>
> On Aug 9, 2009, at 10:33 AM, James C. Sutherland wrote:
>
>>
>> On Aug 9, 2009, at 10:20 AM, Michael Wild wrote:
>>
>>>
>>> On 9. Aug, 2009, at 18:06, James C. Sutherland wrote:
>>>
>>>> In my configure.h.in file I have:
>>>>
>>>> #cmakedefine TEST_VAR_VALUE
>>>>
>>>> In my CMakeLists.txt file I have:
>>>>
>>>> configure_file( ${PROJECT_SOURCE_DIR}/src/config.h.in $
>>>> {PROJECT_SOURCE_DIR}/src/configure.h )
>>>> set( TEST_VAR_VALUE  "0" )
>>>>
>>>> This results in a configure.h file containing:
>>>> /* #undef TEST_VAR_VALUE */
>>>>
>>>> But what I would like is:
>>>> #define TEST_VAR_VALUE 0
>>>>
>>>>
>>>> So basically cmake is seeing the value of TEST_VAR_VALUE as 0 and  
>>>> treating it as "false" rather than a value.
>>>>
>>>> Any ideas how to accomplish this?
>>>>
>>>> James
>>>>
>>>
>>>
>>> Use the (undocumented) #cmakedefine01.
>>>
>>> I already submitted a patch, and the documentation has been fixed  
>>> in CVS.
>>>
>>> Michael
>>>
>>
>> Thanks!  That did it.
>
>
> Okay - I spoke too soon.  It gave me a partial solution.
>
> What if I want to have something like
> #define TEST_VAR_VALUE 5
>
> In the .in file:
> #cmakedefine TEST_VAR_VALUE ${TEST_VAR_VALUE}
> doesn't work (for reasons mentioned above)
>
> However,
> #cmakedefine01 TEST_VAR_VALUE ${TEST_VAR_VALUE}
> results in
> #define TEST_VAR_VALUE 5 1
> if I have
> set( TEST_VAR_VALUE 5 )
> in my CMakeLists.txt file.
>
> Can I get rid of the trailing value?
>

Aah, now I see what you want...

#define TEST_VAR_VALUE ${TEST_VAR_VALUE}

is what you want.
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: configure_file - false vs "0"

James C. Sutherland
>>>>>
>>>>> In my configure.h.in file I have:
>>>>>
>>>>> #cmakedefine TEST_VAR_VALUE
>>>>>
>>>>> In my CMakeLists.txt file I have:
>>>>>
>>>>> configure_file( ${PROJECT_SOURCE_DIR}/src/config.h.in $
>>>>> {PROJECT_SOURCE_DIR}/src/configure.h )
>>>>> set( TEST_VAR_VALUE  "0" )
>>>>>
>>>>> This results in a configure.h file containing:
>>>>> /* #undef TEST_VAR_VALUE */
>>>>>
>>>>> But what I would like is:
>>>>> #define TEST_VAR_VALUE 0
>>>>>
>>>>>
>>>>> So basically cmake is seeing the value of TEST_VAR_VALUE as 0  
>>>>> and treating it as "false" rather than a value.
>>>>>
>>>>> Any ideas how to accomplish this?
>>>>>
>>>>> James
>>>>>
>>>>
>>>>
>>>> Use the (undocumented) #cmakedefine01.
>>>>
>>>> I already submitted a patch, and the documentation has been fixed  
>>>> in CVS.
>>>>
>>>> Michael
>>>>
>>>
>>> Thanks!  That did it.
>>
>>
>> Okay - I spoke too soon.  It gave me a partial solution.
>>
>> What if I want to have something like
>> #define TEST_VAR_VALUE 5
>>
>> In the .in file:
>> #cmakedefine TEST_VAR_VALUE ${TEST_VAR_VALUE}
>> doesn't work (for reasons mentioned above)
>>
>> However,
>> #cmakedefine01 TEST_VAR_VALUE ${TEST_VAR_VALUE}
>> results in
>> #define TEST_VAR_VALUE 5 1
>> if I have
>> set( TEST_VAR_VALUE 5 )
>> in my CMakeLists.txt file.
>>
>> Can I get rid of the trailing value?
>>
>
> Aah, now I see what you want...
>
> #define TEST_VAR_VALUE ${TEST_VAR_VALUE}
>
> is what you want.


But if I do
   set( TEST_VAR_VALUE 0 )
then this results in TEST_VAR_VALUE being undefined rather than having  
the value of 0 as I want.  If the value is anything other than zero it  
works.  This is what I tried to explain in my original (probably  
unclear) post...

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: configure_file - false vs "0"

Bill Hoffman
James C. Sutherland wrote:

>> #define TEST_VAR_VALUE ${TEST_VAR_VALUE}
>>
>> is what you want.
>
>
> But if I do
>   set( TEST_VAR_VALUE 0 )
> then this results in TEST_VAR_VALUE being undefined rather than having
> the value of 0 as I want.  If the value is anything other than zero it
> works.  This is what I tried to explain in my original (probably
> unclear) post...
>
No it won't.   That is a #define not a #cmakedfine.  It will always be
there.

-Bill

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: configure_file - false vs "0"

Michael Wild
In reply to this post by James C. Sutherland

On 9. Aug, 2009, at 22:49, James C. Sutherland wrote:

>>>>>>
>>>>>> In my configure.h.in file I have:
>>>>>>
>>>>>> #cmakedefine TEST_VAR_VALUE
>>>>>>
>>>>>> In my CMakeLists.txt file I have:
>>>>>>
>>>>>> configure_file( ${PROJECT_SOURCE_DIR}/src/config.h.in $
>>>>>> {PROJECT_SOURCE_DIR}/src/configure.h )
>>>>>> set( TEST_VAR_VALUE  "0" )
>>>>>>
>>>>>> This results in a configure.h file containing:
>>>>>> /* #undef TEST_VAR_VALUE */
>>>>>>
>>>>>> But what I would like is:
>>>>>> #define TEST_VAR_VALUE 0
>>>>>>
>>>>>>
>>>>>> So basically cmake is seeing the value of TEST_VAR_VALUE as 0  
>>>>>> and treating it as "false" rather than a value.
>>>>>>
>>>>>> Any ideas how to accomplish this?
>>>>>>
>>>>>> James
>>>>>>
>>>>>
>>>>>
>>>>> Use the (undocumented) #cmakedefine01.
>>>>>
>>>>> I already submitted a patch, and the documentation has been  
>>>>> fixed in CVS.
>>>>>
>>>>> Michael
>>>>>
>>>>
>>>> Thanks!  That did it.
>>>
>>>
>>> Okay - I spoke too soon.  It gave me a partial solution.
>>>
>>> What if I want to have something like
>>> #define TEST_VAR_VALUE 5
>>>
>>> In the .in file:
>>> #cmakedefine TEST_VAR_VALUE ${TEST_VAR_VALUE}
>>> doesn't work (for reasons mentioned above)
>>>
>>> However,
>>> #cmakedefine01 TEST_VAR_VALUE ${TEST_VAR_VALUE}
>>> results in
>>> #define TEST_VAR_VALUE 5 1
>>> if I have
>>> set( TEST_VAR_VALUE 5 )
>>> in my CMakeLists.txt file.
>>>
>>> Can I get rid of the trailing value?
>>>
>>
>> Aah, now I see what you want...
>>
>> #define TEST_VAR_VALUE ${TEST_VAR_VALUE}
>>
>> is what you want.
>
>
> But if I do
>  set( TEST_VAR_VALUE 0 )
> then this results in TEST_VAR_VALUE being undefined rather than  
> having the value of 0 as I want.  If the value is anything other  
> than zero it works.  This is what I tried to explain in my original  
> (probably unclear) post...
>

$ cat CMakeLists.txt
cmake_minimum_required( VERSION 2.6 )
project( test )
set( TEST_VAR_VALUE1 0 )
set( TEST_VAR_VALUE2 1 )
set( TEST_VAR_VALUE3 "hello there" )
configure_file( config.h.in ${test_BINARY_DIR}/config.h )

$ cat config.h.in
#define TEST_VAR_VALUE1 ${TEST_VAR_VALUE1}
#define TEST_VAR_VALUE2 ${TEST_VAR_VALUE2}
#define TEST_VAR_VALUE3 ${TEST_VAR_VALUE3}

$ mkdir build && cd build && cmake ..
$ cat config.h
#define TEST_VAR_VALUE1 0
#define TEST_VAR_VALUE2 1
#define TEST_VAR_VALUE3 hello there


Which presumably is what you want... why would you think that  
SET(TEST_VAR_VALUE 0) "undefines" it? For that you either use  
SET(TEST_VAR_VALUE), or with newer versions of CMake you can use the  
clearer UNSET(TEST_VAR_VALUE).


Michael
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: configure_file - false vs "0"

Michael Jackson
In reply to this post by Bill Hoffman
On Sun, Aug 9, 2009 at 5:07 PM, Bill Hoffman<[hidden email]> wrote:

> James C. Sutherland wrote:
>
>>> #define TEST_VAR_VALUE ${TEST_VAR_VALUE}
>>>
>>> is what you want.
>>
>>
>> But if I do
>>  set( TEST_VAR_VALUE 0 )
>> then this results in TEST_VAR_VALUE being undefined rather than having the
>> value of 0 as I want.  If the value is anything other than zero it works.
>>  This is what I tried to explain in my original (probably unclear) post...
>>
> No it won't.   That is a #define not a #cmakedfine.  It will always be
> there.
>
> -Bill
>

You also need to set the value in the cmake file BEFORE calling the
configure_file() command. So what you really want is the following:

*.cmake file
set( TEST_VAR_VALUE 0 )
configure_file( ${PROJECT_SOURCE_DIR}/src/config.h.in
${PROJECT_SOURCE_DIR}/src/configure.h  @ONLY)


and in your config.h.in you will have:
#define TEST_VAR_VALUE @TEST_VAR_VALUE@

This results in TEST_VAR_VALUE  _always_ being defined in your
program. It will be defined to what ever you set it to in the *.cmake
file.

--
Mike Jackson                               [hidden email]
BlueQuartz Software                    www.bluequartz.net
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: configure_file - false vs "0"

James C. Sutherland
In reply to this post by Michael Wild
>>>
>>> Aah, now I see what you want...
>>>
>>> #define TEST_VAR_VALUE ${TEST_VAR_VALUE}
>>>
>>> is what you want.
>>
>>
>> But if I do
>> set( TEST_VAR_VALUE 0 )
>> then this results in TEST_VAR_VALUE being undefined rather than  
>> having the value of 0 as I want.  If the value is anything other  
>> than zero it works.  This is what I tried to explain in my original  
>> (probably unclear) post...
>>
>
> $ cat CMakeLists.txt
> cmake_minimum_required( VERSION 2.6 )
> project( test )
> set( TEST_VAR_VALUE1 0 )
> set( TEST_VAR_VALUE2 1 )
> set( TEST_VAR_VALUE3 "hello there" )
> configure_file( config.h.in ${test_BINARY_DIR}/config.h )
>
> $ cat config.h.in
> #define TEST_VAR_VALUE1 ${TEST_VAR_VALUE1}
> #define TEST_VAR_VALUE2 ${TEST_VAR_VALUE2}
> #define TEST_VAR_VALUE3 ${TEST_VAR_VALUE3}
>
> $ mkdir build && cd build && cmake ..
> $ cat config.h
> #define TEST_VAR_VALUE1 0
> #define TEST_VAR_VALUE2 1
> #define TEST_VAR_VALUE3 hello there
>
>
> Which presumably is what you want... why would you think that  
> SET(TEST_VAR_VALUE 0) "undefines" it? For that you either use  
> SET(TEST_VAR_VALUE), or with newer versions of CMake you can use the  
> clearer UNSET(TEST_VAR_VALUE).
>
>
> Michael

Thank you and Bill for your patience and help.  Indeed, I  
misunderstood the "#define" vs "#cmakedefine" in the config.h.in  
file.  This now works.

BTW, although I am somewhat new to build systems, I find cmake to be a  
very nice tool - definitely much simpler to use than autoconf!  I also  
dabbled with bjam and find cmake more usable (and the fact that it  
supports F90 is great).

Thanks again for the help.

_______________________________________________
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