2 # This module is used by the Makefile generator to determin the following variables:
3 # CMAKE_SYSTEM_NAME - on unix this is uname -s, for windows it is Windows
4 # CMAKE_SYSTEM_VERSION - on unix this is uname -r, for windows it is empty
5 # CMAKE_SYSTEM - ${CMAKE_SYSTEM}-${CMAKE_SYSTEM_VERSION}, for windows: ${CMAKE_SYSTEM}
7 # Expected uname -s output:
17 # OFS/1 (Digital Unix) OSF1
18 # SCO OpenServer 5 SCO_SV
19 # SCO UnixWare 7 UnixWare
20 # SCO UnixWare (pre release 7) UNIX_SV
26 # cygwin CYGWIN_NT-5.1
30 # find out on which system cmake runs
32 FIND_PROGRAM(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
34 EXEC_PROGRAM(uname ARGS -s OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_NAME)
35 EXEC_PROGRAM(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
36 IF(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
37 EXEC_PROGRAM(uname ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
39 ELSE(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
40 EXEC_PROGRAM(uname ARGS -p OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
42 IF("${val}" GREATER 0)
43 EXEC_PROGRAM(uname ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
45 ENDIF("${val}" GREATER 0)
46 ENDIF(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
47 # check the return of the last uname -m or -p
48 IF("${val}" GREATER 0)
49 SET(CMAKE_HOST_SYSTEM_PROCESSOR "unknown")
50 ENDIF("${val}" GREATER 0)
51 SET(CMAKE_UNAME ${CMAKE_UNAME} CACHE INTERNAL "uname command")
52 # processor may have double quote in the name, and that needs to be removed
53 STRING(REGEX REPLACE "\"" "" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
54 STRING(REGEX REPLACE "/" "_" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
58 SET (CMAKE_HOST_SYSTEM_NAME "Windows")
59 SET (CMAKE_HOST_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
60 ENDIF(CMAKE_HOST_WIN32)
61 ENDIF(CMAKE_HOST_UNIX)
63 # if a toolchain file is used, the user wants to cross compile.
64 # in this case read the toolchain file and keep the CMAKE_HOST_SYSTEM_*
65 # variables around so they can be used in CMakeLists.txt.
66 # In all other cases, the host and target platform are the same.
67 IF(CMAKE_TOOLCHAIN_FILE)
68 # at first try to load it as path relative to the directory from which cmake has been run
69 INCLUDE("${CMAKE_BINARY_DIR}/${CMAKE_TOOLCHAIN_FILE}" OPTIONAL RESULT_VARIABLE _INCLUDED_TOOLCHAIN_FILE)
70 IF(NOT _INCLUDED_TOOLCHAIN_FILE)
71 # if the file isn't found there, check the default locations
72 INCLUDE("${CMAKE_TOOLCHAIN_FILE}" OPTIONAL RESULT_VARIABLE _INCLUDED_TOOLCHAIN_FILE)
73 ENDIF(NOT _INCLUDED_TOOLCHAIN_FILE)
75 IF(_INCLUDED_TOOLCHAIN_FILE)
76 SET(CMAKE_TOOLCHAIN_FILE "${_INCLUDED_TOOLCHAIN_FILE}" CACHE FILEPATH "The CMake toolchain file" FORCE)
77 ELSE(_INCLUDED_TOOLCHAIN_FILE)
78 MESSAGE(FATAL_ERROR "Could not find toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
79 SET(CMAKE_TOOLCHAIN_FILE "NOTFOUND" CACHE FILEPATH "The CMake toolchain file" FORCE)
80 ENDIF(_INCLUDED_TOOLCHAIN_FILE)
81 ENDIF(CMAKE_TOOLCHAIN_FILE)
84 # if CMAKE_SYSTEM_NAME is here already set, either it comes from a toolchain file
85 # or it was set via -DCMAKE_SYSTEM_NAME=...
86 # if that's the case, assume we are crosscompiling
88 IF(NOT DEFINED CMAKE_CROSSCOMPILING)
89 SET(CMAKE_CROSSCOMPILING TRUE)
90 ENDIF(NOT DEFINED CMAKE_CROSSCOMPILING)
91 SET(PRESET_CMAKE_SYSTEM_NAME TRUE)
92 ELSE(CMAKE_SYSTEM_NAME)
93 SET(CMAKE_SYSTEM_NAME "${CMAKE_HOST_SYSTEM_NAME}")
94 SET(CMAKE_SYSTEM_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
95 SET(CMAKE_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
96 SET(CMAKE_CROSSCOMPILING FALSE)
97 SET(PRESET_CMAKE_SYSTEM_NAME FALSE)
98 ENDIF(CMAKE_SYSTEM_NAME)
101 MACRO(ADJUST_CMAKE_SYSTEM_VARIABLES _PREFIX)
102 IF(NOT ${_PREFIX}_NAME)
103 SET(${_PREFIX}_NAME "UnknownOS")
104 ENDIF(NOT ${_PREFIX}_NAME)
106 # fix for BSD/OS , remove the /
107 IF(${_PREFIX}_NAME MATCHES BSD.OS)
108 SET(${_PREFIX}_NAME BSDOS)
109 ENDIF(${_PREFIX}_NAME MATCHES BSD.OS)
111 # fix for CYGWIN which has windows version in it
112 IF(${_PREFIX}_NAME MATCHES CYGWIN)
113 SET(${_PREFIX}_NAME CYGWIN)
114 ENDIF(${_PREFIX}_NAME MATCHES CYGWIN)
116 # set CMAKE_SYSTEM to the CMAKE_SYSTEM_NAME
117 SET(${_PREFIX} ${${_PREFIX}_NAME})
118 # if there is a CMAKE_SYSTEM_VERSION then add a -${CMAKE_SYSTEM_VERSION}
119 IF(${_PREFIX}_VERSION)
120 SET(${_PREFIX} ${${_PREFIX}}-${${_PREFIX}_VERSION})
121 ENDIF(${_PREFIX}_VERSION)
123 ENDMACRO(ADJUST_CMAKE_SYSTEM_VARIABLES _PREFIX)
125 ADJUST_CMAKE_SYSTEM_VARIABLES(CMAKE_SYSTEM)
126 ADJUST_CMAKE_SYSTEM_VARIABLES(CMAKE_HOST_SYSTEM)
128 # this file is also executed from cpack, then we don't need to generate these files
129 # in this case there is no CMAKE_BINARY_DIR
131 # write entry to the log file
132 IF(PRESET_CMAKE_SYSTEM_NAME)
133 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
134 "The target system is: ${CMAKE_SYSTEM_NAME} - ${CMAKE_SYSTEM_VERSION} - ${CMAKE_SYSTEM_PROCESSOR}\n")
135 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
136 "The host system is: ${CMAKE_HOST_SYSTEM_NAME} - ${CMAKE_HOST_SYSTEM_VERSION} - ${CMAKE_HOST_SYSTEM_PROCESSOR}\n")
137 ELSE(PRESET_CMAKE_SYSTEM_NAME)
138 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
139 "The system is: ${CMAKE_SYSTEM_NAME} - ${CMAKE_SYSTEM_VERSION} - ${CMAKE_SYSTEM_PROCESSOR}\n")
140 ENDIF(PRESET_CMAKE_SYSTEM_NAME)
142 # if a toolchain file is used, it needs to be included in the configured file,
143 # so settings done there are also available if they don't go in the cache and in TRY_COMPILE()
144 SET(INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED)
145 IF(DEFINED CMAKE_TOOLCHAIN_FILE)
146 SET(INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED "INCLUDE(\"${CMAKE_TOOLCHAIN_FILE}\")")
147 ENDIF(DEFINED CMAKE_TOOLCHAIN_FILE)
149 # configure variables set in this file for fast reload, the template file is defined at the top of this file
150 CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeSystem.cmake.in
151 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake
154 ENDIF(CMAKE_BINARY_DIR)