CMAKE判断操作系统平台

方法一:(通过CMAKE内置宏)

if (CMAKE_HOST_WIN32)
    set(WINDOWS 1)
elseif (CMAKE_HOST_APPLE)
    set(MACOS 1)
elseif (CMAKE_HOST_UNIX)
    set(LINUX 1)
endif ()

方法二:(通知CMAKE系统名)

MESSAGE(STATUS "operation system is ${CMAKE_SYSTEM}")
 
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    SET(LINUX 1)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
    SET(WINDOWS 1)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
    SET(FREEBSD 1)
ELSE ()
    SET(UNKNOW 1)
ENDIF()

你可能感兴趣的:(C/C++,c++)