[CMake] Eclipse generator - basic macros

Miguel A. Figueroa-Villanueva miguelf at ieee.org
Tue Jul 14 18:47:48 EDT 2009


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

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


More information about the CMake mailing list