Jim February 2016

Macro retrieving from CMake

I have the following code:

#if defined(__WIN32) || defined(__WIN64)
// Windows compiler compiles this code
#  define WINDOWS_PLATFORM
#elif defined(__linux__)
// GCC compiles
#  define LINUX_PLATFORM
#else
#  error "unsupported platform"
#endif

Is CMake able to check for the macros WINDOWS_PLATFORM or LINUX_PLATFORM and set the source file path accordingly to win/ or posix/ ?

Answers


ixSci February 2016

CMake has its own variables to check if you are on a particular platform. For example, using the following code you can check if you are on one of the most popular platforms and adjust whatever you need accordingly:

if(WIN32)
...
elseif(APPLE)
...
elseif(UNIX AND NOT APPLE AND NOT CYGWIN)
...
endif()

So you don't need any custom macros there — CMake has such a functional built-in.

Post Status

Asked in February 2016
Viewed 2,114 times
Voted 9
Answered 1 times

Search




Leave an answer