Reputation: 55
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/ ?
Upvotes: 0
Views: 219
Reputation: 13698
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.
Upvotes: 3