2 #=============================================================================
3 # Copyright 2002-2009 Kitware, Inc.
5 # Distributed under the OSI-approved BSD License (the "License");
6 # see accompanying file Copyright.txt for details.
8 # This software is distributed WITHOUT ANY WARRANTY; without even the
9 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # See the License for more information.
11 #=============================================================================
12 # (To distribute this file outside of CMake, substitute the full
13 # License text for the above reference.)
15 # This module is used by the Makefile generator to determin the following variables:
16 # CMAKE_SYSTEM_NAME - on unix this is uname -s, for windows it is Windows
17 # CMAKE_SYSTEM_VERSION - on unix this is uname -r, for windows it is empty
18 # CMAKE_SYSTEM - ${CMAKE_SYSTEM}-${CMAKE_SYSTEM_VERSION}, for windows: ${CMAKE_SYSTEM}
20 # Expected uname -s output:
28 # GNU/kFreeBSD GNU/kFreeBSD
31 # OFS/1 (Digital Unix) OSF1
32 # SCO OpenServer 5 SCO_SV
33 # SCO UnixWare 7 UnixWare
34 # SCO UnixWare (pre release 7) UNIX_SV
40 # cygwin CYGWIN_NT-5.1
44 # find out on which system cmake runs
46 find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
48 exec_program(uname ARGS -s OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_NAME)
49 exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
50 if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|CYGWIN.*")
51 exec_program(uname ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
53 elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "OpenBSD")
54 exec_program(arch ARGS -s OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
57 exec_program(uname ARGS -p OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
59 if("${val}" GREATER 0)
60 exec_program(uname ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
64 # check the return of the last uname -m or -p
65 if("${val}" GREATER 0)
66 set(CMAKE_HOST_SYSTEM_PROCESSOR "unknown")
68 set(CMAKE_UNAME ${CMAKE_UNAME} CACHE INTERNAL "uname command")
69 # processor may have double quote in the name, and that needs to be removed
70 string(REGEX REPLACE "\"" "" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
71 string(REGEX REPLACE "/" "_" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
75 set (CMAKE_HOST_SYSTEM_NAME "Windows")
76 set (CMAKE_HOST_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
80 # if a toolchain file is used, the user wants to cross compile.
81 # in this case read the toolchain file and keep the CMAKE_HOST_SYSTEM_*
82 # variables around so they can be used in CMakeLists.txt.
83 # In all other cases, the host and target platform are the same.
84 if(CMAKE_TOOLCHAIN_FILE)
85 # at first try to load it as path relative to the directory from which cmake has been run
86 include("${CMAKE_BINARY_DIR}/${CMAKE_TOOLCHAIN_FILE}" OPTIONAL RESULT_VARIABLE _INCLUDED_TOOLCHAIN_FILE)
87 if(NOT _INCLUDED_TOOLCHAIN_FILE)
88 # if the file isn't found there, check the default locations
89 include("${CMAKE_TOOLCHAIN_FILE}" OPTIONAL RESULT_VARIABLE _INCLUDED_TOOLCHAIN_FILE)
92 if(_INCLUDED_TOOLCHAIN_FILE)
93 set(CMAKE_TOOLCHAIN_FILE "${_INCLUDED_TOOLCHAIN_FILE}" CACHE FILEPATH "The CMake toolchain file" FORCE)
95 message(FATAL_ERROR "Could not find toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
96 set(CMAKE_TOOLCHAIN_FILE "NOTFOUND" CACHE FILEPATH "The CMake toolchain file" FORCE)
101 # if CMAKE_SYSTEM_NAME is here already set, either it comes from a toolchain file
102 # or it was set via -DCMAKE_SYSTEM_NAME=...
103 # if that's the case, assume we are crosscompiling
104 if(CMAKE_SYSTEM_NAME)
105 if(NOT DEFINED CMAKE_CROSSCOMPILING)
106 set(CMAKE_CROSSCOMPILING TRUE)
108 set(PRESET_CMAKE_SYSTEM_NAME TRUE)
110 set(CMAKE_SYSTEM_NAME "${CMAKE_HOST_SYSTEM_NAME}")
111 set(CMAKE_SYSTEM_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
112 set(CMAKE_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
113 set(CMAKE_CROSSCOMPILING FALSE)
114 set(PRESET_CMAKE_SYSTEM_NAME FALSE)
118 macro(ADJUST_CMAKE_SYSTEM_VARIABLES _PREFIX)
119 if(NOT ${_PREFIX}_NAME)
120 set(${_PREFIX}_NAME "UnknownOS")
123 # fix for BSD/OS , remove the /
124 if(${_PREFIX}_NAME MATCHES BSD.OS)
125 set(${_PREFIX}_NAME BSDOS)
128 # fix for GNU/kFreeBSD, remove the GNU/
129 if(${_PREFIX}_NAME MATCHES kFreeBSD)
130 set(${_PREFIX}_NAME kFreeBSD)
133 # fix for CYGWIN which has windows version in it
134 if(${_PREFIX}_NAME MATCHES CYGWIN)
135 set(${_PREFIX}_NAME CYGWIN)
138 # set CMAKE_SYSTEM to the CMAKE_SYSTEM_NAME
139 set(${_PREFIX} ${${_PREFIX}_NAME})
140 # if there is a CMAKE_SYSTEM_VERSION then add a -${CMAKE_SYSTEM_VERSION}
141 if(${_PREFIX}_VERSION)
142 set(${_PREFIX} ${${_PREFIX}}-${${_PREFIX}_VERSION})
147 ADJUST_CMAKE_SYSTEM_VARIABLES(CMAKE_SYSTEM)
148 ADJUST_CMAKE_SYSTEM_VARIABLES(CMAKE_HOST_SYSTEM)
150 # this file is also executed from cpack, then we don't need to generate these files
151 # in this case there is no CMAKE_BINARY_DIR
153 # write entry to the log file
154 if(PRESET_CMAKE_SYSTEM_NAME)
155 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
156 "The target system is: ${CMAKE_SYSTEM_NAME} - ${CMAKE_SYSTEM_VERSION} - ${CMAKE_SYSTEM_PROCESSOR}\n")
157 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
158 "The host system is: ${CMAKE_HOST_SYSTEM_NAME} - ${CMAKE_HOST_SYSTEM_VERSION} - ${CMAKE_HOST_SYSTEM_PROCESSOR}\n")
160 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
161 "The system is: ${CMAKE_SYSTEM_NAME} - ${CMAKE_SYSTEM_VERSION} - ${CMAKE_SYSTEM_PROCESSOR}\n")
164 # if a toolchain file is used, it needs to be included in the configured file,
165 # so settings done there are also available if they don't go in the cache and in try_compile()
166 set(INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED)
167 if(DEFINED CMAKE_TOOLCHAIN_FILE)
168 set(INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED "include(\"${CMAKE_TOOLCHAIN_FILE}\")")
171 # configure variables set in this file for fast reload, the template file is defined at the top of this file
172 configure_file(${CMAKE_ROOT}/Modules/CMakeSystem.cmake.in
173 ${CMAKE_PLATFORM_INFO_DIR}/CMakeSystem.cmake