CMake Checking Platform: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
(Create page (info from CMake docs and from the Useful Variables page))
 
m (→‎CMake System: Add space)
Line 14: Line 14:
A cleaner and more cross-compiling-compatible way to check the current platform is through the CMAKE_SYSTEM variables
A cleaner and more cross-compiling-compatible way to check the current platform is through the CMAKE_SYSTEM variables


; CMAKE_SYSTEM_NAME : The name of the system targeted by the build.  The three common values are '''Windows''', '''Darwin''', and '''Linux''', though several others exist, such as '''Android''' and '''CrayLinuxEnvironment'''.  Platforms without an operating system, such as embedded devices, are given'''Generic''' as a system name.
; CMAKE_SYSTEM_NAME : The name of the system targeted by the build.  The three common values are '''Windows''', '''Darwin''', and '''Linux''', though several others exist, such as '''Android''' and '''CrayLinuxEnvironment'''.  Platforms without an operating system, such as embedded devices, are given '''Generic''' as a system name.
; CMAKE_SYSTEM_VERSION : Version of the operating system.  Exactly what this gets set to depends on the system.
; CMAKE_SYSTEM_VERSION : Version of the operating system.  Exactly what this gets set to depends on the system.
; CMAKE_HOST_SYSTEM_NAME : The name of the system hosting the build.  Has the same value set as '''CMAKE_SYSTEM_NAME'''.
; CMAKE_HOST_SYSTEM_NAME : The name of the system hosting the build.  Has the same value set as '''CMAKE_SYSTEM_NAME'''.

Revision as of 01:08, 20 September 2017

There are several different ways to check the current system/platform in CMake, and each interacts with cross-compiling in different ways.

Platform Variables

CMake sets certain variables to true depending on the current platform and toolchain in use.

UNIX
is TRUE on all UNIX-like OS's, including Apple OS X and CygWin
WIN32
is TRUE on Windows. Prior to 2.8.4 this included CygWin
APPLE
is TRUE on Apple systems. Note this does not imply the system is Mac OS X, only that __APPLE__ is #defined in C/C++ header files.
MINGW
is TRUE when using the MinGW compiler in Windows
MSYS
is TRUE when using the MSYS developer environment in Windows
CYGWIN
is TRUE on Windows when using the CygWin version of cmake

CMake System

A cleaner and more cross-compiling-compatible way to check the current platform is through the CMAKE_SYSTEM variables

CMAKE_SYSTEM_NAME
The name of the system targeted by the build. The three common values are Windows, Darwin, and Linux, though several others exist, such as Android and CrayLinuxEnvironment. Platforms without an operating system, such as embedded devices, are given Generic as a system name.
CMAKE_SYSTEM_VERSION
Version of the operating system. Exactly what this gets set to depends on the system.
CMAKE_HOST_SYSTEM_NAME
The name of the system hosting the build. Has the same value set as CMAKE_SYSTEM_NAME.