When working with CMake, it’s common to execute specific commands depending on the platform and operating system detected. During my research across various internet sources, I’ve encountered two commonly used snippets:
Method 1:
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
# WINDOWS
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
# APPLE
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
# LINUX
endif()
Method 2:
if(WIN32)
# WINDOWS
elseif(APPLE)
# APPLE
elseif(LINUX)
# LINUX
endif()
What is the difference between these two methods, and why is the first one mostly preferred over the second one?