[CMake] Eclipse generator - basic macros

Benjamin Schindler bschindler at inf.ethz.ch
Tue Jul 14 20:46:21 EDT 2009



Miguel A. Figueroa-Villanueva wrote:
> On Tue, Jul 14, 2009 at 6:55 PM, Benjamin Schindler wrote:
>   
>> Hi
>>
>> That workaround works - I've done it when I sent the initial mail. But I can
>> imagine various situation when this can become an issue as well (like when
>> writing compiler or platform specific code), so I posted it here anyway to
>> start a discussion.
>> I think the probing for defined macros like you do for the includes (that
>> makes things like heaven compared to <2.6.4!!) would solve it nicely IMHO.
>>     
>
> Just to be clear...
>
> If you have compiler dependent code:
>
> #if defined(_MSC_VER)
> ...
> #elif defined(__GNUC__)
> ...
> #else
> ...
> #endif
>
> Then you could do something like the following in CMakeLists.txt:
>
> if (CMAKE_COMPILER_IS_GNUC)
>   add_definitions(-DWORKING_WITH_GCC) # or use COMPILE_DEFINITIONS property
> elseif (MSVC)
>   add_definitions(-DWORKING_WITH_MSVC) # or use COMPILE_DEFINITIONS property
> endif()
>
> and the code above would look like:
>
> #if defined(WORKING_WITH_MSVC)
> ...
> #elif defined(WORKING_WITH_GCC)
> ...
> #else
> ...
> #endif
>   
Yes, I could do that. But that's a hack - it should not be needed. All 
compilers have their macros which enables to differentiate between them, 
so why adding a new one?
> The only limitation that I see for compiler/platform specific stuff is
> that CMake needs to be able to differentiate somehow between them...
> right? or am I missing something else?
>
> --Miguel
>   
Thanks
Benjamin


More information about the CMake mailing list