CMakeDetermineSystem.cmake 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # This module is used by the Makefile generator to determin the following variables:
  2. # CMAKE_SYSTEM_NAME - on unix this is uname -s, for windows it is Windows
  3. # CMAKE_SYSTEM_VERSION - on unix this is uname -r, for windows it is empty
  4. # CMAKE_SYSTEM - ${CMAKE_SYSTEM}-${CMAKE_SYSTEM_VERSION}, for windows: ${CMAKE_SYSTEM}
  5. #
  6. # Expected uname -s output:
  7. #
  8. # AIX AIX
  9. # BSD/OS BSD/OS
  10. # FreeBSD FreeBSD
  11. # HP-UX HP-UX
  12. # IRIX IRIX
  13. # Linux Linux
  14. # NetBSD NetBSD
  15. # OpenBSD OpenBSD
  16. # OFS/1 (Digital Unix) OSF1
  17. # SCO OpenServer 5 SCO_SV
  18. # SCO UnixWare 7 UnixWare
  19. # SCO UnixWare (pre release 7) UNIX_SV
  20. # SCO XENIX Xenix
  21. # Solaris SunOS
  22. # SunOS SunOS
  23. # Tru64 Tru64
  24. # Ultrix ULTRIX
  25. # cygwin CYGWIN_NT-5.1
  26. # MacOSX Darwin
  27. #set the source file which will be configured to become CMakeSystem.cmake
  28. SET(_CMAKE_SYSTEM_TEMPLATE_FILE ${CMAKE_ROOT}/Modules/CMakeSystem.cmake.in )
  29. IF(CMAKE_TOOLCHAIN_FILE)
  30. # at first try to load it as path relative to the directory from which cmake has been run
  31. INCLUDE("${CMAKE_BINARY_DIR}/${CMAKE_TOOLCHAIN_FILE}" OPTIONAL RESULT_VARIABLE _INCLUDED_TOOLCHAIN_FILE)
  32. IF(NOT _INCLUDED_TOOLCHAIN_FILE)
  33. # if the file isn't found there, check the default locations
  34. INCLUDE("${CMAKE_TOOLCHAIN_FILE}" OPTIONAL RESULT_VARIABLE _INCLUDED_TOOLCHAIN_FILE)
  35. ENDIF(NOT _INCLUDED_TOOLCHAIN_FILE)
  36. IF(_INCLUDED_TOOLCHAIN_FILE)
  37. SET(CMAKE_TOOLCHAIN_FILE "${_INCLUDED_TOOLCHAIN_FILE}")
  38. ELSE(_INCLUDED_TOOLCHAIN_FILE)
  39. MESSAGE(FATAL_ERROR "Could not find toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
  40. ENDIF(_INCLUDED_TOOLCHAIN_FILE)
  41. # use a different source file for CMakeSystem.cmake, since it has to hold a bit more information
  42. SET(_CMAKE_SYSTEM_TEMPLATE_FILE ${CMAKE_ROOT}/Modules/CMakeSystemWithToolchainFile.cmake.in )
  43. IF(NOT DEFINED CMAKE_CROSSCOMPILING)
  44. SET(CMAKE_CROSSCOMPILING TRUE)
  45. ENDIF(NOT DEFINED CMAKE_CROSSCOMPILING)
  46. ENDIF(CMAKE_TOOLCHAIN_FILE)
  47. IF(NOT CMAKE_SYSTEM_NAME)
  48. IF(UNIX)
  49. FIND_PROGRAM(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
  50. IF(CMAKE_UNAME)
  51. EXEC_PROGRAM(uname ARGS -s OUTPUT_VARIABLE CMAKE_SYSTEM_NAME)
  52. EXEC_PROGRAM(uname ARGS -r OUTPUT_VARIABLE CMAKE_SYSTEM_VERSION)
  53. IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
  54. EXEC_PROGRAM(uname ARGS -m OUTPUT_VARIABLE CMAKE_SYSTEM_PROCESSOR
  55. RETURN_VALUE val)
  56. ELSE(CMAKE_SYSTEM_NAME MATCHES "Linux")
  57. EXEC_PROGRAM(uname ARGS -p OUTPUT_VARIABLE CMAKE_SYSTEM_PROCESSOR
  58. RETURN_VALUE val)
  59. IF("${val}" GREATER 0)
  60. EXEC_PROGRAM(uname ARGS -m OUTPUT_VARIABLE CMAKE_SYSTEM_PROCESSOR
  61. RETURN_VALUE val)
  62. ENDIF("${val}" GREATER 0)
  63. ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
  64. # check the return of the last uname -m or -p
  65. IF("${val}" GREATER 0)
  66. SET(CMAKE_SYSTEM_PROCESSOR "unknown")
  67. ENDIF("${val}" GREATER 0)
  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_SYSTEM_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")
  71. STRING(REGEX REPLACE "/" "_" CMAKE_SYSTEM_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")
  72. ENDIF(CMAKE_UNAME)
  73. ELSE(UNIX)
  74. IF(WIN32)
  75. SET (CMAKE_SYSTEM_NAME "Windows")
  76. SET (CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
  77. ENDIF(WIN32)
  78. ENDIF(UNIX)
  79. ENDIF(NOT CMAKE_SYSTEM_NAME)
  80. IF(NOT CMAKE_SYSTEM_NAME)
  81. SET(CMAKE_SYSTEM_NAME "UnknownOS")
  82. ENDIF(NOT CMAKE_SYSTEM_NAME)
  83. # fix for BSD/OS , remove the /
  84. IF(CMAKE_SYSTEM_NAME MATCHES BSD.OS)
  85. SET(CMAKE_SYSTEM_NAME BSDOS)
  86. ENDIF(CMAKE_SYSTEM_NAME MATCHES BSD.OS)
  87. # fix for CYGWIN which has windows version in it
  88. IF(CMAKE_SYSTEM_NAME MATCHES CYGWIN)
  89. SET(CMAKE_SYSTEM_NAME CYGWIN)
  90. ENDIF(CMAKE_SYSTEM_NAME MATCHES CYGWIN)
  91. # set CMAKE_SYSTEM to the CMAKE_SYSTEM_NAME
  92. SET(CMAKE_SYSTEM ${CMAKE_SYSTEM_NAME})
  93. # if there is a CMAKE_SYSTEM_VERSION then add a -${CMAKE_SYSTEM_VERSION}
  94. IF(CMAKE_SYSTEM_VERSION)
  95. SET(CMAKE_SYSTEM ${CMAKE_SYSTEM}-${CMAKE_SYSTEM_VERSION})
  96. ENDIF(CMAKE_SYSTEM_VERSION)
  97. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  98. "The system is: ${CMAKE_SYSTEM_NAME} - ${CMAKE_SYSTEM_VERSION} - ${CMAKE_SYSTEM_PROCESSOR}\n")
  99. # configure variables set in this file for fast reload, the template file is defined at the top of this file
  100. CONFIGURE_FILE(${_CMAKE_SYSTEM_TEMPLATE_FILE}
  101. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake
  102. IMMEDIATE @ONLY)