CMake是为了解决美国国家医学图书馆出资的Visible Human Project专案下的Insight Segmentation and Registration Toolkit (ITK) 软件的跨平台建构的需求而创造出来的。我们在编写CmakeList.txt文件时,可以通过if判断当前所处的系统环境
IF (WIN32)
MESSAGE(STATUS "Now is windows")
ELSEIF (APPLE)
MESSAGE(STATUS "Now is Apple systens.")
ELSEIF (UNIX)
MESSAGE(STATUS "Now is UNIX-like OS's. Including aPPLE os x and CygWin")
ENDIF ()
还可以通过IF命令进行其他判断,比如在MySQL数据库项目中,顶层CmakeList.txt的开始部分就是如下内容,来去定cmake的最小版本。
IF(WIN32)
# CMake 2.8.12 is needed for Visual Studio 2013
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
ELSE()
# There's a bug in unzipping prior to 2.8.2
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.2)
ENDIF()