[TOC]

概述

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

使用CMAKE_SYSTEM_NAME进行判断

1
2
3
4
5
6
7
8
9
10
11
12
# =================================== 编译系统相关的变量配置选项 =================================
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
set(HOST_OS "linux")
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(HOST_OS "windows")
elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(HOST_OS "FreeBSD")
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(HOST_OS "osx")
else ()
message(ERROR "Other Host Platform: ${CMAKE_SYSTEM_NAME}")
endif ()