cmake/Modules/CMakeDetermineSystem.cmake

191 lines
7.7 KiB
CMake
Raw Normal View History

2016-10-30 18:24:19 +01:00
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
2009-10-04 10:30:41 +03:00
2018-04-23 21:13:27 +02:00
# This module is used by the Makefile generator to determine the following variables:
# CMAKE_SYSTEM_NAME - on unix this is uname -s, for windows it is Windows
# CMAKE_SYSTEM_VERSION - on unix this is uname -r, for windows it is empty
# CMAKE_SYSTEM - ${CMAKE_SYSTEM}-${CMAKE_SYSTEM_VERSION}, for windows: ${CMAKE_SYSTEM}
#
# Expected uname -s output:
#
2013-03-16 19:13:01 +02:00
# AIX AIX
# BSD/OS BSD/OS
# FreeBSD FreeBSD
# HP-UX HP-UX
# IRIX IRIX
# Linux Linux
2009-10-11 10:55:36 +03:00
# GNU/kFreeBSD GNU/kFreeBSD
2013-03-16 19:13:01 +02:00
# NetBSD NetBSD
# OpenBSD OpenBSD
# OFS/1 (Digital Unix) OSF1
# SCO OpenServer 5 SCO_SV
# SCO UnixWare 7 UnixWare
# SCO UnixWare (pre release 7) UNIX_SV
# SCO XENIX Xenix
# Solaris SunOS
# SunOS SunOS
# Tru64 Tru64
# Ultrix ULTRIX
# cygwin CYGWIN_NT-5.1
# MacOSX Darwin
# find out on which system cmake runs
2013-03-16 19:13:01 +02:00
if(CMAKE_HOST_UNIX)
find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
if(CMAKE_UNAME)
2017-07-20 19:35:53 +02:00
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "AIX")
exec_program(${CMAKE_UNAME} ARGS -v OUTPUT_VARIABLE _CMAKE_HOST_SYSTEM_MAJOR_VERSION)
exec_program(${CMAKE_UNAME} ARGS -r OUTPUT_VARIABLE _CMAKE_HOST_SYSTEM_MINOR_VERSION)
set(CMAKE_HOST_SYSTEM_VERSION "${_CMAKE_HOST_SYSTEM_MAJOR_VERSION}.${_CMAKE_HOST_SYSTEM_MINOR_VERSION}")
unset(_CMAKE_HOST_SYSTEM_MAJOR_VERSION)
unset(_CMAKE_HOST_SYSTEM_MINOR_VERSION)
else()
exec_program(${CMAKE_UNAME} ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
endif()
2015-04-27 22:25:09 +02:00
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|CYGWIN.*|Darwin|^GNU$")
2017-07-20 19:35:53 +02:00
exec_program(${CMAKE_UNAME} ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
RETURN_VALUE val)
2014-08-03 19:52:23 +02:00
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND
CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "Power Macintosh")
# OS X ppc 'uname -m' may report 'Power Macintosh' instead of 'powerpc'
set(CMAKE_HOST_SYSTEM_PROCESSOR "powerpc")
endif()
2013-03-16 19:13:01 +02:00
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "OpenBSD")
exec_program(arch ARGS -s OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
2011-06-19 15:41:06 +03:00
RETURN_VALUE val)
2013-03-16 19:13:01 +02:00
else()
2017-07-20 19:35:53 +02:00
exec_program(${CMAKE_UNAME} ARGS -p OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
RETURN_VALUE val)
2013-03-16 19:13:01 +02:00
if("${val}" GREATER 0)
2017-07-20 19:35:53 +02:00
exec_program(${CMAKE_UNAME} ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
RETURN_VALUE val)
2013-03-16 19:13:01 +02:00
endif()
endif()
# check the return of the last uname -m or -p
if("${val}" GREATER 0)
set(CMAKE_HOST_SYSTEM_PROCESSOR "unknown")
endif()
set(CMAKE_UNAME ${CMAKE_UNAME} CACHE INTERNAL "uname command")
# processor may have double quote in the name, and that needs to be removed
2015-04-27 22:25:09 +02:00
string(REPLACE "\"" "" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
string(REPLACE "/" "_" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
2013-03-16 19:13:01 +02:00
endif()
else()
if(CMAKE_HOST_WIN32)
if (DEFINED ENV{PROCESSOR_ARCHITEW6432})
set (CMAKE_HOST_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITEW6432}")
else()
set (CMAKE_HOST_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
endif()
endif()
endif()
# if a toolchain file is used, the user wants to cross compile.
# in this case read the toolchain file and keep the CMAKE_HOST_SYSTEM_*
2013-03-16 19:13:01 +02:00
# variables around so they can be used in CMakeLists.txt.
# In all other cases, the host and target platform are the same.
2013-03-16 19:13:01 +02:00
if(CMAKE_TOOLCHAIN_FILE)
# at first try to load it as path relative to the directory from which cmake has been run
2013-03-16 19:13:01 +02:00
include("${CMAKE_BINARY_DIR}/${CMAKE_TOOLCHAIN_FILE}" OPTIONAL RESULT_VARIABLE _INCLUDED_TOOLCHAIN_FILE)
if(NOT _INCLUDED_TOOLCHAIN_FILE)
# if the file isn't found there, check the default locations
2013-03-16 19:13:01 +02:00
include("${CMAKE_TOOLCHAIN_FILE}" OPTIONAL RESULT_VARIABLE _INCLUDED_TOOLCHAIN_FILE)
endif()
2013-03-16 19:13:01 +02:00
if(_INCLUDED_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "${_INCLUDED_TOOLCHAIN_FILE}" CACHE FILEPATH "The CMake toolchain file" FORCE)
else()
message(FATAL_ERROR "Could not find toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
set(CMAKE_TOOLCHAIN_FILE "NOTFOUND" CACHE FILEPATH "The CMake toolchain file" FORCE)
endif()
endif()
# if CMAKE_SYSTEM_NAME is here already set, either it comes from a toolchain file
# or it was set via -DCMAKE_SYSTEM_NAME=...
# if that's the case, assume we are crosscompiling
2013-03-16 19:13:01 +02:00
if(CMAKE_SYSTEM_NAME)
if(NOT DEFINED CMAKE_CROSSCOMPILING)
set(CMAKE_CROSSCOMPILING TRUE)
endif()
set(PRESET_CMAKE_SYSTEM_NAME TRUE)
elseif(CMAKE_VS_WINCE_VERSION)
set(CMAKE_SYSTEM_NAME "WindowsCE")
set(CMAKE_SYSTEM_VERSION "${CMAKE_VS_WINCE_VERSION}")
set(CMAKE_SYSTEM_PROCESSOR "${MSVC_C_ARCHITECTURE_ID}")
set(CMAKE_CROSSCOMPILING TRUE)
set(PRESET_CMAKE_SYSTEM_NAME TRUE)
else()
set(CMAKE_SYSTEM_NAME "${CMAKE_HOST_SYSTEM_NAME}")
2015-11-17 17:22:37 +01:00
if(NOT DEFINED CMAKE_SYSTEM_VERSION)
set(CMAKE_SYSTEM_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
endif()
2013-03-16 19:13:01 +02:00
set(CMAKE_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
set(CMAKE_CROSSCOMPILING FALSE)
set(PRESET_CMAKE_SYSTEM_NAME FALSE)
endif()
2016-10-30 18:24:19 +01:00
include(Platform/${CMAKE_SYSTEM_NAME}-Determine OPTIONAL)
2013-03-16 19:13:01 +02:00
macro(ADJUST_CMAKE_SYSTEM_VARIABLES _PREFIX)
if(NOT ${_PREFIX}_NAME)
set(${_PREFIX}_NAME "UnknownOS")
endif()
# fix for BSD/OS , remove the /
2013-03-16 19:13:01 +02:00
if(${_PREFIX}_NAME MATCHES BSD.OS)
set(${_PREFIX}_NAME BSDOS)
endif()
2009-10-11 10:55:36 +03:00
# fix for GNU/kFreeBSD, remove the GNU/
2013-03-16 19:13:01 +02:00
if(${_PREFIX}_NAME MATCHES kFreeBSD)
set(${_PREFIX}_NAME kFreeBSD)
endif()
2009-10-11 10:55:36 +03:00
2013-03-16 19:13:01 +02:00
# fix for CYGWIN which has windows version in it
if(${_PREFIX}_NAME MATCHES CYGWIN)
set(${_PREFIX}_NAME CYGWIN)
endif()
# set CMAKE_SYSTEM to the CMAKE_SYSTEM_NAME
2013-03-16 19:13:01 +02:00
set(${_PREFIX} ${${_PREFIX}_NAME})
# if there is a CMAKE_SYSTEM_VERSION then add a -${CMAKE_SYSTEM_VERSION}
2013-03-16 19:13:01 +02:00
if(${_PREFIX}_VERSION)
set(${_PREFIX} ${${_PREFIX}}-${${_PREFIX}_VERSION})
endif()
2013-03-16 19:13:01 +02:00
endmacro()
ADJUST_CMAKE_SYSTEM_VARIABLES(CMAKE_SYSTEM)
ADJUST_CMAKE_SYSTEM_VARIABLES(CMAKE_HOST_SYSTEM)
2013-03-16 19:13:01 +02:00
# this file is also executed from cpack, then we don't need to generate these files
# in this case there is no CMAKE_BINARY_DIR
2013-03-16 19:13:01 +02:00
if(CMAKE_BINARY_DIR)
# write entry to the log file
2013-03-16 19:13:01 +02:00
if(PRESET_CMAKE_SYSTEM_NAME)
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"The target system is: ${CMAKE_SYSTEM_NAME} - ${CMAKE_SYSTEM_VERSION} - ${CMAKE_SYSTEM_PROCESSOR}\n")
2013-03-16 19:13:01 +02:00
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"The host system is: ${CMAKE_HOST_SYSTEM_NAME} - ${CMAKE_HOST_SYSTEM_VERSION} - ${CMAKE_HOST_SYSTEM_PROCESSOR}\n")
2013-03-16 19:13:01 +02:00
else()
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"The system is: ${CMAKE_SYSTEM_NAME} - ${CMAKE_SYSTEM_VERSION} - ${CMAKE_SYSTEM_PROCESSOR}\n")
2013-03-16 19:13:01 +02:00
endif()
# if a toolchain file is used, it needs to be included in the configured file,
2013-03-16 19:13:01 +02:00
# so settings done there are also available if they don't go in the cache and in try_compile()
set(INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED)
2015-08-17 11:37:30 +02:00
if(CMAKE_TOOLCHAIN_FILE)
2013-03-16 19:13:01 +02:00
set(INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED "include(\"${CMAKE_TOOLCHAIN_FILE}\")")
endif()
# configure variables set in this file for fast reload, the template file is defined at the top of this file
2013-03-16 19:13:01 +02:00
configure_file(${CMAKE_ROOT}/Modules/CMakeSystem.cmake.in
${CMAKE_PLATFORM_INFO_DIR}/CMakeSystem.cmake
2014-08-03 19:52:23 +02:00
@ONLY)
2013-03-16 19:13:01 +02:00
endif()