camke 中判断操作系统平台有两种方法:

    1. 判断变量CMAKE_SYSTEM_NAME
    1. MESSAGE(STATUS "operation system is ${CMAKE_SYSTEM}")
    2. IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    3. MESSAGE(STATUS "current platform: Linux ")
    4. ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
    5. MESSAGE(STATUS "current platform: Windows")
    6. ELSEIF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
    7. MESSAGE(STATUS "current platform: FreeBSD")
    8. ELSE ()
    9. MESSAGE(STATUS "other platform: ${CMAKE_SYSTEM_NAME}")
    10. ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")

    注意:上面的代码必须在指定了project之后,否则CMAKE_SYSTEM_NAME就是空的

    1. 通过宏定义
    1. IF (WIN32)
    2. MESSAGE(STATUS "Now is windows")
    3. ELSEIF (APPLE)
    4. MESSAGE(STATUS "Now is Apple systens.")
    5. ELSEIF (UNIX)
    6. MESSAGE(STATUS "Now is UNIX-like OS's.")
    7. ENDIF ()

    https://blog.csdn.net/sean_8180/article/details/81189996