summaryrefslogtreecommitdiffstats
path: root/Modules/TestBigEndian.cmake
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2007-08-10 17:14:00 (GMT)
committerAlexander Neundorf <neundorf@kde.org>2007-08-10 17:14:00 (GMT)
commit578841cce53d476afdb646ed7db29f3752ac9786 (patch)
tree3697ad9bf2b8c52bb0e8cd15a9f95f41f6379fbb /Modules/TestBigEndian.cmake
parentc6092b7e5e9a421d317969eb3230ccdb7acc0065 (diff)
downloadCMake-578841cce53d476afdb646ed7db29f3752ac9786.zip
CMake-578841cce53d476afdb646ed7db29f3752ac9786.tar.gz
CMake-578841cce53d476afdb646ed7db29f3752ac9786.tar.bz2
STYLE: remove unused CheckTypeSize.c.in
ENH: change test for endianess from TRY_RUN() to TRY_COMPILE() by testing the binary image of a 16bit integer array, tested on Linux x86, Intel Mac and Sun (big endian) Alex
Diffstat (limited to 'Modules/TestBigEndian.cmake')
-rw-r--r--Modules/TestBigEndian.cmake108
1 files changed, 78 insertions, 30 deletions
diff --git a/Modules/TestBigEndian.cmake b/Modules/TestBigEndian.cmake
index 2d1853c..bf91fb7 100644
--- a/Modules/TestBigEndian.cmake
+++ b/Modules/TestBigEndian.cmake
@@ -5,37 +5,85 @@
#
MACRO(TEST_BIG_ENDIAN VARIABLE)
- SET(CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS 1)
- IF(NOT DEFINED ${VARIABLE})
IF("HAVE_${VARIABLE}" MATCHES "^HAVE_${VARIABLE}$")
- TRY_RUN(${VARIABLE} HAVE_${VARIABLE}
- ${CMAKE_BINARY_DIR}
- ${CMAKE_ROOT}/Modules/TestBigEndian.c
- COMPILE_OUTPUT_VARIABLE OUTPUT)
- IF("${VARIABLE}" STREQUAL "FAILED_TO_RUN")
- MESSAGE(SEND_ERROR "TestBigEndian Failed to run with output: ${OUTPUT}")
- ENDIF("${VARIABLE}" STREQUAL "FAILED_TO_RUN")
MESSAGE(STATUS "Check if the system is big endian")
- IF(HAVE_${VARIABLE})
- FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
- "Determining the endianes of the system passed. The system is ")
- IF(${VARIABLE})
- FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
- "big endian")
- MESSAGE(STATUS "Check if the system is big endian - big endian")
- ELSE(${VARIABLE})
- FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
- "little endian")
- MESSAGE(STATUS "Check if the system is big endian - little endian")
- ENDIF(${VARIABLE})
- FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
- "Test produced following output:\n${OUTPUT}\n\n")
- ELSE(HAVE_${VARIABLE})
- FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
- "Determining the endianes of the system failed with the following output:\n${OUTPUT}\n\n")
- MESSAGE("Check if the system is big endian - failed")
- ENDIF(HAVE_${VARIABLE})
+ MESSAGE(STATUS "Searching 16 bit integer")
+
+ INCLUDE(CheckTypeSize)
+
+ CHECK_TYPE_SIZE("unsigned short" CMAKE_SIZEOF_UNSIGNED_SHORT)
+ IF(CMAKE_SIZEOF_UNSIGNED_SHORT EQUAL 2)
+ MESSAGE(STATUS "Using unsigned short")
+ SET(CMAKE_16BIT_TYPE "unsigned short")
+ ELSE(CMAKE_SIZEOF_UNSIGNED_SHORT EQUAL 2)
+ CHECK_TYPE_SIZE("unsigned int" CMAKE_SIZEOF_UNSIGNED_INT)
+ IF(CMAKE_SIZEOF_UNSIGNED_INT)
+ MESSAGE(STATUS "Using unsigned int")
+ SET(CMAKE_16BIT_TYPE "unsigned int")
+
+ ELSE(CMAKE_SIZEOF_UNSIGNED_INT)
+
+ CHECK_TYPE_SIZE("unsigned long" CMAKE_SIZEOF_UNSIGNED_LONG)
+ IF(CMAKE_SIZEOF_UNSIGNED_LONG)
+ MESSAGE(STATUS "Using unsigned long")
+ SET(CMAKE_16BIT_TYPE "unsigned long")
+ ELSE(CMAKE_SIZEOF_UNSIGNED_LONG)
+ MESSAGE(FATAL_ERROR "no suitable type found")
+ ENDIF(CMAKE_SIZEOF_UNSIGNED_LONG)
+
+ ENDIF(CMAKE_SIZEOF_UNSIGNED_INT)
+
+ ENDIF(CMAKE_SIZEOF_UNSIGNED_SHORT EQUAL 2)
+
+
+ CONFIGURE_FILE("${CMAKE_ROOT}/Modules/TestEndianess.c.in"
+ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c"
+ IMMEDIATE @ONLY)
+
+ FILE(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c"
+ TEST_ENDIANESS_FILE_CONTENT)
+
+ TRY_COMPILE(HAVE_${VARIABLE}
+ "${CMAKE_BINARY_DIR}"
+ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c"
+ OUTPUT_VARIABLE OUTPUT
+ COPY_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin" )
+
+ IF(HAVE_${VARIABLE})
+
+ FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin"
+ CMAKE_TEST_ENDIANESS_STRINGS_LE LIMIT_COUNT 1 REGEX "THIS IS LITTLE ENDIAN")
+
+ FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin"
+ CMAKE_TEST_ENDIANESS_STRINGS_BE LIMIT_COUNT 1 REGEX "THIS IS BIG ENDIAN")
+
+ IF(CMAKE_TEST_ENDIANESS_STRINGS_LE)
+ SET(${VARIABLE} 0 CACHE INTERNAL "Result of TEST_BIG_ENDIAN" FORCE)
+ MESSAGE(STATUS "Check if the system is big endian - little endian")
+ ENDIF(CMAKE_TEST_ENDIANESS_STRINGS_LE)
+
+ IF(CMAKE_TEST_ENDIANESS_STRINGS_BE)
+ SET(${VARIABLE} 1 CACHE INTERNAL "Result of TEST_BIG_ENDIAN" FORCE)
+ MESSAGE(STATUS "Check if the system is big endian - big endian")
+ ENDIF(CMAKE_TEST_ENDIANESS_STRINGS_BE)
+
+ IF(CMAKE_TEST_ENDIANESS_STRINGS_BE AND CMAKE_TEST_ENDIANESS_STRINGS_LE)
+ MESSAGE(SEND_ERROR "TEST_BIG_ENDIAN found different results, consider setting CMAKE_OSX_ARCHITECTURES or CMAKE_TRY_COMPILE_OSX_ARCHITECTURES to one or no architecture !")
+ ENDIF(CMAKE_TEST_ENDIANESS_STRINGS_BE AND CMAKE_TEST_ENDIANESS_STRINGS_LE)
+ IF(NOT CMAKE_TEST_ENDIANESS_STRINGS_BE AND NOT CMAKE_TEST_ENDIANESS_STRINGS_LE)
+ MESSAGE(SEND_ERROR "TEST_BIG_ENDIAN found no !")
+ ENDIF(NOT CMAKE_TEST_ENDIANESS_STRINGS_BE AND NOT CMAKE_TEST_ENDIANESS_STRINGS_LE)
+
+ FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the system is big endian passed with the following output:\n${OUTPUT}\nTestEndianess.c:\n${TEST_ENDIANESS_FILE_CONTENT}\n\n")
+
+ ELSE(HAVE_${VARIABLE})
+ MESSAGE(STATUS "Check if the system is big endian - failed")
+ FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if the system is big endian failed with the following output:\n${OUTPUT}\nTestEndianess.c:\n${TEST_ENDIANESS_FILE_CONTENT}\n\n")
+ SET(${VARIABLE})
+ ENDIF(HAVE_${VARIABLE})
ENDIF("HAVE_${VARIABLE}" MATCHES "^HAVE_${VARIABLE}$")
- ENDIF(NOT DEFINED ${VARIABLE})
- SET(CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS)
ENDMACRO(TEST_BIG_ENDIAN)
+
+