ENH: for universal binaries return the endianess based on the processor

Alex
This commit is contained in:
Alexander Neundorf 2007-08-13 11:04:19 -04:00
parent 54f0a2f0a0
commit 263bb4e172
1 changed files with 18 additions and 8 deletions

View File

@ -42,7 +42,7 @@ MACRO(TEST_BIG_ENDIAN VARIABLE)
FILE(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c" FILE(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c"
TEST_ENDIANESS_FILE_CONTENT) TEST_ENDIANESS_FILE_CONTENT)
TRY_COMPILE(HAVE_${VARIABLE} TRY_COMPILE(HAVE_${VARIABLE}
"${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c" "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c"
@ -53,23 +53,33 @@ MACRO(TEST_BIG_ENDIAN VARIABLE)
FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin" FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin"
CMAKE_TEST_ENDIANESS_STRINGS_LE LIMIT_COUNT 1 REGEX "THIS IS LITTLE ENDIAN") CMAKE_TEST_ENDIANESS_STRINGS_LE LIMIT_COUNT 1 REGEX "THIS IS LITTLE ENDIAN")
FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin" FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin"
CMAKE_TEST_ENDIANESS_STRINGS_BE LIMIT_COUNT 1 REGEX "THIS IS BIG ENDIAN") CMAKE_TEST_ENDIANESS_STRINGS_BE LIMIT_COUNT 1 REGEX "THIS IS BIG ENDIAN")
# on mac, if there are universal binaries built both will be true
# return the result depending on the machine on which cmake runs
IF(CMAKE_TEST_ENDIANESS_STRINGS_BE AND CMAKE_TEST_ENDIANESS_STRINGS_LE)
IF(CMAKE_SYSTEM_PROCESSOR MATCHES powerpc)
SET(CMAKE_TEST_ENDIANESS_STRINGS_BE TRUE)
SET(CMAKE_TEST_ENDIANESS_STRINGS_LE FALSE)
ELSE(CMAKE_SYSTEM_PROCESSOR MATCHES powerpc)
SET(CMAKE_TEST_ENDIANESS_STRINGS_BE FALSE)
SET(CMAKE_TEST_ENDIANESS_STRINGS_LE TRUE)
ENDIF(CMAKE_SYSTEM_PROCESSOR MATCHES powerpc)
MESSAGE(STATUS "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(CMAKE_TEST_ENDIANESS_STRINGS_LE) IF(CMAKE_TEST_ENDIANESS_STRINGS_LE)
SET(${VARIABLE} 0 CACHE INTERNAL "Result of TEST_BIG_ENDIAN" FORCE) SET(${VARIABLE} 0 CACHE INTERNAL "Result of TEST_BIG_ENDIAN" FORCE)
MESSAGE(STATUS "Check if the system is big endian - little endian") MESSAGE(STATUS "Check if the system is big endian - little endian")
ENDIF(CMAKE_TEST_ENDIANESS_STRINGS_LE) ENDIF(CMAKE_TEST_ENDIANESS_STRINGS_LE)
IF(CMAKE_TEST_ENDIANESS_STRINGS_BE) IF(CMAKE_TEST_ENDIANESS_STRINGS_BE)
SET(${VARIABLE} 1 CACHE INTERNAL "Result of TEST_BIG_ENDIAN" FORCE) SET(${VARIABLE} 1 CACHE INTERNAL "Result of TEST_BIG_ENDIAN" FORCE)
MESSAGE(STATUS "Check if the system is big endian - big endian") MESSAGE(STATUS "Check if the system is big endian - big endian")
ENDIF(CMAKE_TEST_ENDIANESS_STRINGS_BE) ENDIF(CMAKE_TEST_ENDIANESS_STRINGS_BE)
IF(CMAKE_TEST_ENDIANESS_STRINGS_BE AND CMAKE_TEST_ENDIANESS_STRINGS_LE)
MESSAGE(STATUS "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) IF(NOT CMAKE_TEST_ENDIANESS_STRINGS_BE AND NOT CMAKE_TEST_ENDIANESS_STRINGS_LE)
MESSAGE(SEND_ERROR "TEST_BIG_ENDIAN found no result!") MESSAGE(SEND_ERROR "TEST_BIG_ENDIAN found no result!")
ENDIF(NOT CMAKE_TEST_ENDIANESS_STRINGS_BE AND NOT CMAKE_TEST_ENDIANESS_STRINGS_LE) ENDIF(NOT CMAKE_TEST_ENDIANESS_STRINGS_BE AND NOT CMAKE_TEST_ENDIANESS_STRINGS_LE)