CVS resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Tests / CMakeTests / ToolchainTest.cmake.in
blob90c45d016071284286b726a2b89307f144d1cd8e
1 ############################################################
2 # some preparations so that the CMakeDetermineXXX.cmake files will work in scripted mode
4 # overwrite MARK_AS_ADVANCED(), since this is used in CMakeDetermineCCompiler.cmake
5 # which will complain that it can"t be used in script mode
6 macro(MARK_AS_ADVANCED)
7 endmacro(MARK_AS_ADVANCED)
9 # set this to a place where we are allowed to write
10 set(CMAKE_PLATFORM_ROOT_BIN "${CMAKE_CURRENT_BINARY_DIR}")
12 # don't run the compiler detection
13 set(CMAKE_C_COMPILER_ID_RUN 1)
14 set(CMAKE_CXX_COMPILER_ID_RUN 1)
16 set(MY_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
18 # at first load CMakeDetermineSystem.cmake without toolchain file
19 set(CMAKE_TOOLCHAIN_FILE)
20 include(CMakeDetermineSystem)
22 # check that CMAKE_SYSTEM_XXX and CMAKE_HOST_SYSTEM_xxx are identical
23 if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "${CMAKE_HOST_SYSTEM_NAME}")
24    message(FATAL_ERROR "CMAKE_SYSTEM_NAME and CMAKE_HOST_SYSTEM_NAME not identical: \"${CMAKE_SYSTEM_NAME}\" vs. \"${CMAKE_HOST_SYSTEM_NAME}\"")
25 endif(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "${CMAKE_HOST_SYSTEM_NAME}")
27 if(NOT "${CMAKE_SYSTEM}" STREQUAL "${CMAKE_HOST_SYSTEM}")
28    message(FATAL_ERROR "CMAKE_SYSTEM and CMAKE_HOST_SYSTEM not identical: \"${CMAKE_SYSTEM}\" vs. \"${CMAKE_HOST_SYSTEM}\"")
29 endif(NOT "${CMAKE_SYSTEM}" STREQUAL "${CMAKE_HOST_SYSTEM}")
31 if(NOT "${CMAKE_SYSTEM_VERSION}" STREQUAL "${CMAKE_HOST_SYSTEM_VERSION}")
32    message(FATAL_ERROR "CMAKE_SYSTEM_VERSION and CMAKE_HOST_SYSTEM_VERSION not identical: \"${CMAKE_SYSTEM_VERSION}\" vs. \"${CMAKE_HOST_SYSTEM_VERSION}\"")
33 endif(NOT "${CMAKE_SYSTEM_VERSION}" STREQUAL "${CMAKE_HOST_SYSTEM_VERSION}")
35 if(NOT "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}")
36    message(FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR and CMAKE_HOST_SYSTEM_PROCESSOR not identical: \"${CMAKE_SYSTEM_PROCESSOR}\" vs. \"${CMAKE_HOST_SYSTEM_PROCESSOR}\"")
37 endif(NOT "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}")
39 # save the values so we can compare them to CMAKE_HOST_SYSTEM_XXX in the toolchain case
41 set(NATIVE_SYSTEM           "${CMAKE_SYSTEM}")
42 set(NATIVE_SYSTEM_NAME      "${CMAKE_SYSTEM_NAME}")
43 set(NATIVE_SYSTEM_VERSION   "${CMAKE_SYSTEM_VERSION}")
44 set(NATIVE_SYSTEM_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")
46 # reset them so they will be detected again now
47 set(CMAKE_SYSTEM)
48 set(CMAKE_SYSTEM_NAME)
49 set(CMAKE_SYSTEM_VERSION)
50 set(CMAKE_SYSTEM_PROCESSOR)
51 set(CMAKE_HOST_SYSTEM)
52 set(CMAKE_HOST_SYSTEM_NAME)
53 set(CMAKE_HOST_SYSTEM_VERSION)
54 set(CMAKE_HOST_SYSTEM_PROCESSOR)
57 ############################################################
59 # now define a toolchain file and check that everything is 
60 # detected correctly and nothing predefined is overwritten
62 set(CMAKE_TOOLCHAIN_FILE "${MY_SOURCE_DIR}/DummyToolchain.cmake")
64 include(CMakeDetermineSystem)
65 include(CMakeDetermineCCompiler)
66 include(CMakeDetermineCXXCompiler)
68 #############################################################
70 # check the results from DetermineSystem
72 if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Dumdidum")
73    message(FATAL_ERROR "CMAKE_SYSTEM_NAME overwritten: \"${CMAKE_SYSTEM_NAME}\", was: \"Dumdidum\"")
74 endif(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Dumdidum")
76 if(NOT "${CMAKE_SYSTEM}" STREQUAL "Dumdidum-1.0")
77    message(FATAL_ERROR "CMAKE_SYSTEM wrong: \"${CMAKE_SYSTEM}\", expected: \"Dumdidum-1.0\"")
78 endif(NOT "${CMAKE_SYSTEM}" STREQUAL "Dumdidum-1.0")
79 set(fileOne "${_INCLUDED_TOOLCHAIN_FILE}")
80 set(fileTwo "${MY_SOURCE_DIR}/DummyToolchain.cmake")
81 if(WIN32)
82   string(TOLOWER "${fileOne}" fileOne)
83   string(TOLOWER "${fileTwo}" fileTwo)
84 endif(WIN32)
86 if(NOT "${fileOne}"   STREQUAL "${fileTwo}")
87    message(FATAL_ERROR "Wrong toolchain was loaded: \"${fileOne}\" expected \"${fileTwo}\"")
88 endif(NOT "${fileOne}"   STREQUAL "${fileTwo}")
90 # check that CMAKE_HOST_SYSTEM_XXX and _SYSTEM_xxx detected above are identical
91 if(NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "${NATIVE_SYSTEM_NAME}")
92    message(FATAL_ERROR "CMAKE_HOST_SYSTEM_NAME and NATIVE_SYSTEM_NAME not identical: \"${CMAKE_HOST_SYSTEM_NAME}\" vs. \"${NATIVE_SYSTEM_NAME}\"")
93 endif(NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "${NATIVE_SYSTEM_NAME}")
94 if(NOT "${CMAKE_HOST_SYSTEM}" STREQUAL "${NATIVE_SYSTEM}")
95    message(FATAL_ERROR "CMAKE_HOST_SYSTEM and NATIVE_SYSTEM not identical: \"${CMAKE_HOST_SYSTEM}\" vs. \"${NATIVE_SYSTEM}\"")
96 endif(NOT "${CMAKE_HOST_SYSTEM}" STREQUAL "${NATIVE_SYSTEM}")
97 if(NOT "${CMAKE_HOST_SYSTEM_VERSION}" STREQUAL "${NATIVE_SYSTEM_VERSION}")
98    message(FATAL_ERROR "CMAKE_HOST_SYSTEM_VERSION and NATIVE_SYSTEM_VERSION not identical: \"${CMAKE_HOST_SYSTEM_VERSION}\" vs. \"${NATIVE_SYSTEM_VERSION}\"")
99 endif(NOT "${CMAKE_HOST_SYSTEM_VERSION}" STREQUAL "${NATIVE_SYSTEM_VERSION}")
100 if(NOT "${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "${NATIVE_SYSTEM_PROCESSOR}")
101    message(FATAL_ERROR "CMAKE_HOST_SYSTEM_PROCESSOR and NATIVE_SYSTEM_PROCESSOR not identical: \"${CMAKE_HOST_SYSTEM_PROCESSOR}\" vs. \"${NATIVE_SYSTEM_PROCESSOR}\"")
102 endif(NOT "${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "${NATIVE_SYSTEM_PROCESSOR}")
104 #############################################################
106 # check the results from DetermineCCompiler
108 if(NOT "${_CMAKE_TOOLCHAIN_PREFIX}" STREQUAL "arm-elf-")
109    message(FATAL_ERROR "wrong toolchain prefix detected: \"${_CMAKE_TOOLCHAIN_PREFIX}\", expected: \"arm-elf-\"")
110 endif(NOT "${_CMAKE_TOOLCHAIN_PREFIX}" STREQUAL "arm-elf-")
112 if(NOT "${_CMAKE_USER_C_COMPILER_PATH}" STREQUAL "/opt/foo/bin")
113    message(FATAL_ERROR "wrong C compiler location detected: \"${_CMAKE_USER_C_COMPILER_PATH}\", expected: \"/opt/foo/bin\"")
114 endif(NOT "${_CMAKE_USER_C_COMPILER_PATH}" STREQUAL "/opt/foo/bin")
116 if(NOT "${CMAKE_C_OUTPUT_EXTENSION}" STREQUAL ".foo")
117    message(FATAL_ERROR "C output extension overwritten: \"${CMAKE_C_OUTPUT_EXTENSION}\", was: \".foo\"")
118 endif(NOT "${CMAKE_C_OUTPUT_EXTENSION}" STREQUAL ".foo")
120 #############################################################
122 # check the results from DetermineCXXCompiler
124 if(NOT "${_CMAKE_USER_CXX_COMPILER_PATH}" STREQUAL "/opt/bar/bin")
125    message(FATAL_ERROR "wrong CXX compiler location detected: \"${_CMAKE_USER_CXX_COMPILER_PATH}\", expected: \"/opt/bar/bin\"")
126 endif(NOT "${_CMAKE_USER_CXX_COMPILER_PATH}" STREQUAL "/opt/bar/bin")
128 if(NOT "${CMAKE_CXX_OUTPUT_EXTENSION}" STREQUAL ".bar")
129    message(FATAL_ERROR "C output extension overwritten: \"${CMAKE_CXX_OUTPUT_EXTENSION}\", was: \".bar\"")
130 endif(NOT "${CMAKE_CXX_OUTPUT_EXTENSION}" STREQUAL ".bar")
132 message(STATUS "CMAKE_SYSTEM: \"${CMAKE_SYSTEM}\"")
133 message(STATUS "_CMAKE_TOOLCHAIN_PREFIX: \"${_CMAKE_TOOLCHAIN_PREFIX}\"")
134 message(STATUS "_CMAKE_USER_C_COMPILER_PATH: \"${_CMAKE_USER_C_COMPILER_PATH}\"")
135 message(STATUS "_CMAKE_USER_CXX_COMPILER_PATH: \"${_CMAKE_USER_CXX_COMPILER_PATH}\"")
136 message(STATUS "CMAKE_C_OUTPUT_EXTENSION: \"${CMAKE_C_OUTPUT_EXTENSION}\"")
137 message(STATUS "CMAKE_CXX_OUTPUT_EXTENSION: \"${CMAKE_CXX_OUTPUT_EXTENSION}\"")