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
This commit is contained in:
Alexander Neundorf 2007-08-10 13:14:00 -04:00
parent c6092b7e5e
commit 578841cce5
5 changed files with 99 additions and 82 deletions

View File

@ -1,34 +0,0 @@
#cmakedefine CHECK_TYPE_SIZE_TYPE @CHECK_TYPE_SIZE_TYPE@
#ifdef CHECK_TYPE_SIZE_TYPE
@CHECK_TYPE_SIZE_PREINCLUDE@
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif /* HAVE_STDINT_H */
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif /* HAVE_STDDEF_H */
@CHECK_TYPE_SIZE_PREMAIN@
#ifdef __CLASSIC_C__
int main(){
int ac;
char*av[];
#else
int main(int ac, char*av[]){
#endif
if(ac > 1000){return *av[0];}
return sizeof(CHECK_TYPE_SIZE_TYPE);
}
#else /* CHECK_TYPE_SIZE_TYPE */
# error "CHECK_TYPE_SIZE_TYPE has to specify the type"
#endif /* CHECK_TYPE_SIZE_TYPE */

View File

@ -78,7 +78,7 @@ MACRO(CHECK_TYPE_SIZE TYPE VARIABLE)
ELSE(HAVE_${VARIABLE})
MESSAGE(STATUS "Check size of ${TYPE} - failed")
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining size of ${TYPE} failed with the following output:\n${OUTPUT}\nCheckTypeSize.c:\n${CHECK_TYPE_SIZE_FILE_CONTENT}\n\n")
"Determining size of ${TYPE} failed with the following output:\n${OUTPUT}\nCheckTypeSizeC.c:\n${CHECK_TYPE_SIZE_FILE_CONTENT}\n\n")
SET(${VARIABLE})
ENDIF(HAVE_${VARIABLE})
SET(${VARIABLE} "${${VARIABLE}}" CACHE INTERNAL "Result of CHECK_TYPE_SIZE" FORCE)

View File

@ -1,17 +0,0 @@
#ifdef __CLASSIC_C__
int main(){
int ac;
char*av[];
#else
int main(int ac, char*av[]){
#endif
/* Are we little or big endian? From Harbison&Steele. */
union
{
long l;
char c[sizeof (long)];
} u;
u.l = 1;
if(ac > 1000){return *av[0];}
return (u.c[sizeof (long) - 1] == 1)?1:0;
}

View File

@ -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})
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
"big endian")
MESSAGE(STATUS "Check if the system is big endian - big endian")
ELSE(${VARIABLE})
"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
"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})
"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)

View File

@ -0,0 +1,20 @@
/* A 16 bit integer is required. */
typedef @CMAKE_16BIT_TYPE@ cmakeint16;
/* On a little endian machine, these 16bit ints will give "THIS IS LITTLE ENDIAN."
On a big endian machine the characters will be exchanged pairwise. */
const cmakeint16 info_little[] = {0x4854, 0x5349, 0x4920, 0x2053, 0x494c, 0x5454, 0x454c, 0x4520, 0x444e, 0x4149, 0x2e4e, 0x0000};
/* on a big endian machine, these 16bit ints will give "THIS IS BIG ENDIAN."
On a little endian machine the characters will be exchanged pairwise. */
const cmakeint16 info_big[] = {0x5448, 0x4953, 0x2049, 0x5320, 0x4249, 0x4720, 0x454e, 0x4449, 0x414e, 0x2e2e, 0x0000};
#ifdef __CLASSIC_C__
int main(){
int ac;
char*av[];
#else
int main(int ac, char*av[]){
#endif
return (&info_little[0] != &info_big[0]);
}