Platform detection in CMake

2NinerRomeo picture 2NinerRomeo · Mar 16, 2012 · Viewed 55.6k times · Source

I've added some functionality from boost::asio, which has precipitated some compiler "warnings":

Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately.

That problem was dealt with here. I'd like to have CMake detect when I am building on Windows and make the appropriate definitions or command line arguments.

Answer

karlphillip picture karlphillip · Mar 16, 2012

Inside the CMakeLists.txt file you can do:

IF (WIN32)
  # set stuff for windows
ELSE()
  # set stuff for other systems
ENDIF()