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()