ToolchainTest.cmake.in 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_VERSION)
  41. set(CMAKE_HOST_SYSTEM_PROCESSOR)
  42. ############################################################
  43. # now define a toolchain file and check that everything is
  44. # detected correctly and nothing predefined is overwritten
  45. set(CMAKE_TOOLCHAIN_FILE "${MY_SOURCE_DIR}/DummyToolchain.cmake")
  46. include(CMakeDetermineSystem)
  47. # make cmake think we are cross compiling for test to work
  48. set(CMAKE_CROSSCOMPILING TRUE)
  49. set(CMAKE_C_COMPILER_ID "GNU")
  50. include(CMakeDetermineCCompiler)
  51. include(CMakeDetermineCXXCompiler)
  52. #############################################################
  53. # check the results from DetermineSystem
  54. if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Dumdidum")
  55. message(FATAL_ERROR "CMAKE_SYSTEM_NAME overwritten: \"${CMAKE_SYSTEM_NAME}\", was: \"Dumdidum\"")
  56. endif()
  57. if(NOT "${CMAKE_SYSTEM}" STREQUAL "Dumdidum-1.0")
  58. message(FATAL_ERROR "CMAKE_SYSTEM wrong: \"${CMAKE_SYSTEM}\", expected: \"Dumdidum-1.0\"")
  59. endif()
  60. set(fileOne "${_INCLUDED_TOOLCHAIN_FILE}")
  61. set(fileTwo "${MY_SOURCE_DIR}/DummyToolchain.cmake")
  62. if(WIN32)
  63. string(TOLOWER "${fileOne}" fileOne)
  64. string(TOLOWER "${fileTwo}" fileTwo)
  65. endif()
  66. if(NOT "${fileOne}" STREQUAL "${fileTwo}")
  67. message(FATAL_ERROR "Wrong toolchain was loaded: \"${fileOne}\" expected \"${fileTwo}\"")
  68. endif()
  69. # check that CMAKE_HOST_SYSTEM_XXX and _SYSTEM_xxx detected above are identical
  70. if(NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "${NATIVE_SYSTEM_NAME}")
  71. message(FATAL_ERROR "CMAKE_HOST_SYSTEM_NAME and NATIVE_SYSTEM_NAME not identical: \"${CMAKE_HOST_SYSTEM_NAME}\" vs. \"${NATIVE_SYSTEM_NAME}\"")
  72. endif()
  73. if(NOT "${CMAKE_HOST_SYSTEM}" STREQUAL "${NATIVE_SYSTEM}")
  74. message(FATAL_ERROR "CMAKE_HOST_SYSTEM and NATIVE_SYSTEM not identical: \"${CMAKE_HOST_SYSTEM}\" vs. \"${NATIVE_SYSTEM}\"")
  75. endif()
  76. if(NOT "${CMAKE_HOST_SYSTEM_VERSION}" STREQUAL "${NATIVE_SYSTEM_VERSION}")
  77. message(FATAL_ERROR "CMAKE_HOST_SYSTEM_VERSION and NATIVE_SYSTEM_VERSION not identical: \"${CMAKE_HOST_SYSTEM_VERSION}\" vs. \"${NATIVE_SYSTEM_VERSION}\"")
  78. endif()
  79. if(NOT "${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "${NATIVE_SYSTEM_PROCESSOR}")
  80. message(FATAL_ERROR "CMAKE_HOST_SYSTEM_PROCESSOR and NATIVE_SYSTEM_PROCESSOR not identical: \"${CMAKE_HOST_SYSTEM_PROCESSOR}\" vs. \"${NATIVE_SYSTEM_PROCESSOR}\"")
  81. endif()
  82. #############################################################
  83. # check the results from DetermineCCompiler
  84. if(NOT "${_CMAKE_TOOLCHAIN_PREFIX}" STREQUAL "arm-elf-")
  85. message(FATAL_ERROR "wrong toolchain prefix detected: \"${_CMAKE_TOOLCHAIN_PREFIX}\", expected: \"arm-elf-\"")
  86. endif()
  87. if(NOT "${_CMAKE_USER_C_COMPILER_PATH}" STREQUAL "/opt/foo/bin")
  88. message(FATAL_ERROR "wrong C compiler location detected: \"${_CMAKE_USER_C_COMPILER_PATH}\", expected: \"/opt/foo/bin\"")
  89. endif()
  90. if(NOT "${CMAKE_C_OUTPUT_EXTENSION}" STREQUAL ".foo")
  91. message(FATAL_ERROR "C output extension overwritten: \"${CMAKE_C_OUTPUT_EXTENSION}\", was: \".foo\"")
  92. endif()
  93. #############################################################
  94. # check the results from DetermineCXXCompiler
  95. if(NOT "${_CMAKE_USER_CXX_COMPILER_PATH}" STREQUAL "/opt/bar/bin")
  96. message(FATAL_ERROR "wrong CXX compiler location detected: \"${_CMAKE_USER_CXX_COMPILER_PATH}\", expected: \"/opt/bar/bin\"")
  97. endif()
  98. if(NOT "${CMAKE_CXX_OUTPUT_EXTENSION}" STREQUAL ".bar")
  99. message(FATAL_ERROR "C output extension overwritten: \"${CMAKE_CXX_OUTPUT_EXTENSION}\", was: \".bar\"")
  100. endif()
  101. message(STATUS "CMAKE_SYSTEM: \"${CMAKE_SYSTEM}\"")
  102. message(STATUS "_CMAKE_TOOLCHAIN_PREFIX: \"${_CMAKE_TOOLCHAIN_PREFIX}\"")
  103. message(STATUS "_CMAKE_USER_C_COMPILER_PATH: \"${_CMAKE_USER_C_COMPILER_PATH}\"")
  104. message(STATUS "_CMAKE_USER_CXX_COMPILER_PATH: \"${_CMAKE_USER_CXX_COMPILER_PATH}\"")
  105. message(STATUS "CMAKE_C_OUTPUT_EXTENSION: \"${CMAKE_C_OUTPUT_EXTENSION}\"")
  106. message(STATUS "CMAKE_CXX_OUTPUT_EXTENSION: \"${CMAKE_CXX_OUTPUT_EXTENSION}\"")