[CMake] #cmakedefine and the #if vs #ifdef argument

Michael Wild themiwi at gmail.com
Mon Jun 22 15:04:11 EDT 2009


On 18. Jun, 2009, at 21:25, Alexander Neundorf wrote:

> On Thursday 18 June 2009, Michael Wild wrote:
>> On 17. Jun, 2009, at 23:27, Alexander Neundorf wrote:
>>> On Thursday 11 June 2009, Hostile Fork wrote:
>>>> Hello list!
>>>>
>>>> As a learning exercise, I am adding CMake and CTest to a small  
>>>> open-
>>>> source library I made which currently has no build system:
>>>>
>>>> 	http://hostilefork.com/nstate/
>>>> 	http://hostilefork.com/nocycle/
>>>>
>>>> For the first step, I have been applying the "configure_file"
>>>> methodology to this header:
>>>>
>>>> 	http://github.com/hostilefork/nocycle/blob/1ac238aea7af9e02f3a49f0c7eb9
>>>> 910 74c8eb3fd/NocycleSettings.hpp
>>>>
>>>> ( Following these directions:
>>>> http://www.vtk.org/Wiki/CMake_HowToDoPlatformChecks )
>>>>
>>>> It seems the #cmakedefine lines are replaced with one of these two
>>>> cases:
>>>>
>>>> 	#define VAR_THAT_IS_ON
>>>> 	/* #undef VAR_THAT_IS_OFF */
>>>>
>>>> However... in the past I have been persuaded by the argument that  
>>>> the
>>>> use of #if is superior to #ifdef for conditional compilation.
>>>> ( Roddy's comment here on StackOverflow summarizes the advantages
>>>> pretty well:
>>>> http://stackoverflow.com/questions/135069/ifdef-vs-if-which-is-bettersaf
>>>> er )
>>>>
>>>> Is it possible to get CMake to produce something more like:
>>>>
>>>> 	#define VAR_THAT_IS_ON 1
>>>> 	#define VAR_THAT_IS_OFF 0
>>>
>>> Did you try using
>>> #cmakedefine01 VAR_THAT_IS_ON
>>> I think this should do what you want.
>>>
>>> Alex
>>
>> Now, that is useful! Sadly, it is undocumented and I never found it;
>> this would have saved me quite some time...
>>
>> Attached patch extends the doc to mention this feature.
>
> PLease put it in the bug tracker.
>
> Thanks
> Alex
>

Done: http://public.kitware.com/Bug/view.php?id=9189

Michael



More information about the CMake mailing list