ToolchainTest.cmake.in 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. ############################################################
  2. # some preparations so that the CMakeDetermineXXX.cmake files will work in scripted mode
  3. # overwrite mark_as_advanced(), since this is used in CMakeDetermineCCompiler.cmake
  4. # which will complain that it can"t be used in script mode
  5. macro(MARK_AS_ADVANCED)
  6. endmacro()
  7. # set this to a place where we are allowed to write
  8. set(CMAKE_PLATFORM_INFO_DIR "${CMAKE_CURRENT_BINARY_DIR}")
  9. # don't run the compiler detection
  10. set(CMAKE_C_COMPILER_ID_RUN 1)
  11. set(CMAKE_CXX_COMPILER_ID_RUN 1)
  12. set(MY_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
  13. # at first load CMakeDetermineSystem.cmake without toolchain file
  14. set(CMAKE_TOOLCHAIN_FILE)
  15. include(CMakeDetermineSystem)
  16. # check that CMAKE_SYSTEM_XXX and CMAKE_HOST_SYSTEM_xxx are identical
  17. if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "${CMAKE_HOST_SYSTEM_NAME}")
  18. message(FATAL_ERROR "CMAKE_SYSTEM_NAME and CMAKE_HOST_SYSTEM_NAME not identical: \"${CMAKE_SYSTEM_NAME}\" vs. \"${CMAKE_HOST_SYSTEM_NAME}\"")
  19. endif()
  20. if(NOT "${CMAKE_SYSTEM}" STREQUAL "${CMAKE_HOST_SYSTEM}")
  21. message(FATAL_ERROR "CMAKE_SYSTEM and CMAKE_HOST_SYSTEM not identical: \"${CMAKE_SYSTEM}\" vs. \"${CMAKE_HOST_SYSTEM}\"")
  22. endif()
  23. if(NOT "${CMAKE_SYSTEM_VERSION}" STREQUAL "${CMAKE_HOST_SYSTEM_VERSION}")
  24. message(FATAL_ERROR "CMAKE_SYSTEM_VERSION and CMAKE_HOST_SYSTEM_VERSION not identical: \"${CMAKE_SYSTEM_VERSION}\" vs. \"${CMAKE_HOST_SYSTEM_VERSION}\"")
  25. endif()
  26. if(NOT "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}")
  27. message(FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR and CMAKE_HOST_SYSTEM_PROCESSOR not identical: \"${CMAKE_SYSTEM_PROCESSOR}\" vs. \"${CMAKE_HOST_SYSTEM_PROCESSOR}\"")
  28. endif()
  29. # save the values so we can compare them to CMAKE_HOST_SYSTEM_XXX in the toolchain case
  30. set(NATIVE_SYSTEM "${CMAKE_SYSTEM}")
  31. set(NATIVE_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
  32. set(NATIVE_SYSTEM_VERSION "${CMAKE_SYSTEM_VERSION}")
  33. set(NATIVE_SYSTEM_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")
  34. # reset them so they will be detected again now
  35. set(CMAKE_SYSTEM)
  36. set(CMAKE_SYSTEM_NAME)
  37. set(CMAKE_SYSTEM_VERSION)
  38. set(CMAKE_SYSTEM_PROCESSOR)
  39. set(CMAKE_HOST_SYSTEM)
  40. set(CMAKE_HOST_SYSTEM_NAME)
  41. set(CMAKE_HOST_SYSTEM_VERSION)
  42. set(CMAKE_HOST_SYSTEM_PROCESSOR)
  43. ############################################################
  44. # now define a toolchain file and check that everything is
  45. # detected correctly and nothing predefined is overwritten
  46. set(CMAKE_TOOLCHAIN_FILE "${MY_SOURCE_DIR}/DummyToolchain.cmake")
  47. include(CMakeDetermineSystem)
  48. # make cmake think we are cross compiling for test to work
  49. set(CMAKE_CROSSCOMPILING TRUE)
  50. set(CMAKE_C_COMPILER_ID "GNU")
  51. include(CMakeDetermineCCompiler)
  52. include(CMakeDetermineCXXCompiler)
  53. #############################################################
  54. # check the results from DetermineSystem
  55. if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Dumdidum")
  56. message(FATAL_ERROR "CMAKE_SYSTEM_NAME overwritten: \"${CMAKE_SYSTEM_NAME}\", was: \"Dumdidum\"")
  57. endif()
  58. if(NOT "${CMAKE_SYSTEM}" STREQUAL "Dumdidum-1.0")
  59. message(FATAL_ERROR "CMAKE_SYSTEM wrong: \"${CMAKE_SYSTEM}\", expected: \"Dumdidum-1.0\"")
  60. endif()
  61. set(fileOne "${_INCLUDED_TOOLCHAIN_FILE}")
  62. set(fileTwo "${MY_SOURCE_DIR}/DummyToolchain.cmake")
  63. if(WIN32)
  64. string(TOLOWER "${fileOne}" fileOne)
  65. string(TOLOWER "${fileTwo}" fileTwo)
  66. endif()
  67. if(NOT "${fileOne}" STREQUAL "${fileTwo}")
  68. message(FATAL_ERROR "Wrong toolchain was loaded: \"${fileOne}\" expected \"${fileTwo}\"")
  69. endif()
  70. # check that CMAKE_HOST_SYSTEM_XXX and _SYSTEM_xxx detected above are identical
  71. if(NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "${NATIVE_SYSTEM_NAME}")
  72. message(FATAL_ERROR "CMAKE_HOST_SYSTEM_NAME and NATIVE_SYSTEM_NAME not identical: \"${CMAKE_HOST_SYSTEM_NAME}\" vs. \"${NATIVE_SYSTEM_NAME}\"")
  73. endif()
  74. if(NOT "${CMAKE_HOST_SYSTEM}" STREQUAL "${NATIVE_SYSTEM}")
  75. message(FATAL_ERROR "CMAKE_HOST_SYSTEM and NATIVE_SYSTEM not identical: \"${CMAKE_HOST_SYSTEM}\" vs. \"${NATIVE_SYSTEM}\"")
  76. endif()
  77. if(NOT "${CMAKE_HOST_SYSTEM_VERSION}" STREQUAL "${NATIVE_SYSTEM_VERSION}")
  78. message(FATAL_ERROR "CMAKE_HOST_SYSTEM_VERSION and NATIVE_SYSTEM_VERSION not identical: \"${CMAKE_HOST_SYSTEM_VERSION}\" vs. \"${NATIVE_SYSTEM_VERSION}\"")
  79. endif()
  80. if(NOT "${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "${NATIVE_SYSTEM_PROCESSOR}")
  81. message(FATAL_ERROR "CMAKE_HOST_SYSTEM_PROCESSOR and NATIVE_SYSTEM_PROCESSOR not identical: \"${CMAKE_HOST_SYSTEM_PROCESSOR}\" vs. \"${NATIVE_SYSTEM_PROCESSOR}\"")
  82. endif()
  83. #############################################################
  84. # check the results from DetermineCCompiler
  85. if(NOT "${_CMAKE_TOOLCHAIN_PREFIX}" STREQUAL "arm-elf-")
  86. message(FATAL_ERROR "wrong toolchain prefix detected: \"${_CMAKE_TOOLCHAIN_PREFIX}\", expected: \"arm-elf-\"")
  87. endif()
  88. if(NOT "${_CMAKE_USER_C_COMPILER_PATH}" STREQUAL "/opt/foo/bin")
  89. message(FATAL_ERROR "wrong C compiler location detected: \"${_CMAKE_USER_C_COMPILER_PATH}\", expected: \"/opt/foo/bin\"")
  90. endif()
  91. if(NOT "${CMAKE_C_OUTPUT_EXTENSION}" STREQUAL ".foo")
  92. message(FATAL_ERROR "C output extension overwritten: \"${CMAKE_C_OUTPUT_EXTENSION}\", was: \".foo\"")
  93. endif()
  94. #############################################################
  95. # check the results from DetermineCXXCompiler
  96. if(NOT "${_CMAKE_USER_CXX_COMPILER_PATH}" STREQUAL "/opt/bar/bin")
  97. message(FATAL_ERROR "wrong CXX compiler location detected: \"${_CMAKE_USER_CXX_COMPILER_PATH}\", expected: \"/opt/bar/bin\"")
  98. endif()
  99. if(NOT "${CMAKE_CXX_OUTPUT_EXTENSION}" STREQUAL ".bar")
  100. message(FATAL_ERROR "C output extension overwritten: \"${CMAKE_CXX_OUTPUT_EXTENSION}\", was: \".bar\"")
  101. endif()
  102. message(STATUS "CMAKE_SYSTEM: \"${CMAKE_SYSTEM}\"")
  103. message(STATUS "_CMAKE_TOOLCHAIN_PREFIX: \"${_CMAKE_TOOLCHAIN_PREFIX}\"")
  104. message(STATUS "_CMAKE_USER_C_COMPILER_PATH: \"${_CMAKE_USER_C_COMPILER_PATH}\"")
  105. message(STATUS "_CMAKE_USER_CXX_COMPILER_PATH: \"${_CMAKE_USER_CXX_COMPILER_PATH}\"")
  106. message(STATUS "CMAKE_C_OUTPUT_EXTENSION: \"${CMAKE_C_OUTPUT_EXTENSION}\"")
  107. message(STATUS "CMAKE_CXX_OUTPUT_EXTENSION: \"${CMAKE_CXX_OUTPUT_EXTENSION}\"")