[CMake] override variable in macro
Juan Sanchez
Juan.Sanchez at amd.com
Fri Sep 21 14:38:35 EDT 2007
Ok,
But cpp doesn't discriminate between ${BAR} and BAR.
#include <iostream>
using namespace std;
#define foo(x) x = 3; cout << x << "\n";
int main()
{
int y = 1;
foo(y);
cout << y << endl;
}
Juan
Bill Hoffman wrote:
> Juan Sanchez wrote:
>> I would argue that the following snippet of code should either print
>> "CAT" twice or die. Unfortunately it first prints "DOG" and then "CAT".
>>
>> Thanks,
>>
>> Juan
>>
>> MACRO(FOO BAR)
>> SET (BAR "CAT")
>> MESSAGE("${BAR}")
>> ENDMACRO(FOO)
>>
>> FOO(DOG)
>> MESSAGE("${BAR}")
>>
>>
> So, expand the macro and you get:
>
> SET(BAR "CAT") # text in a macro is just text, BAR is just more text
> MESSAGE("DOG") # ${BAR} is replaced by DOG sort of like a cpp macro
> MESSAGE(${BAR}) # now we print BAR which was set to CAT in the macro
>
> -Bill
>
>
>
>
--
Juan Sanchez
Juan.Sanchez at amd.com
800-538-8450 Ext. 54395
512-602-4395
More information about the CMake
mailing list