STYLE: Nightly Version update
[cmake.git] / Modules / CheckTypeSize.cmake
blobc9a71f0c974eb334019cc1c0d72fd4a0af50b95d
2 # Check if the type exists and determine size of type.  if the type
3 # exists, the size will be stored to the variable.
5 # CHECK_TYPE_SIZE - macro which checks the size of type
6 # VARIABLE - variable to store size if the type exists.
7 # HAVE_${VARIABLE} - does the variable exists or not
10 MACRO(CHECK_TYPE_SIZE TYPE VARIABLE)
11   SET(CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS 1)
12   IF("HAVE_${VARIABLE}" MATCHES "^HAVE_${VARIABLE}$")
13     SET(MACRO_CHECK_TYPE_SIZE_FLAGS 
14       "-DCHECK_TYPE_SIZE_TYPE=\"${TYPE}\" ${CMAKE_REQUIRED_FLAGS}")
15     FOREACH(def HAVE_SYS_TYPES_H HAVE_STDINT_H HAVE_STDDEF_H)
16       IF("${def}")
17         SET(MACRO_CHECK_TYPE_SIZE_FLAGS 
18           "${MACRO_CHECK_TYPE_SIZE_FLAGS} -D${def}")
19       ENDIF("${def}")
20     ENDFOREACH(def)
21     SET(CHECK_TYPE_SIZE_PREMAIN)
22     FOREACH(def ${CMAKE_EXTRA_INCLUDE_FILES})
23       SET(CHECK_TYPE_SIZE_PREMAIN "${CHECK_TYPE_SIZE_PREMAIN}#include \"${def}\"\n")
24     ENDFOREACH(def)
25     CONFIGURE_FILE("${CMAKE_ROOT}/Modules/CheckTypeSize.c.in"
26       "${CMAKE_BINARY_DIR}/CMakeTmp/CheckTypeSize.c" IMMEDIATE @ONLY)
27     FILE(READ "${CMAKE_BINARY_DIR}/CMakeTmp/CheckTypeSize.c"
28       CHECK_TYPE_SIZE_FILE_CONTENT)
29     MESSAGE(STATUS "Check size of ${TYPE}")
30     IF(CMAKE_REQUIRED_LIBRARIES)
31       SET(CHECK_TYPE_SIZE_ADD_LIBRARIES 
32         "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
33     ENDIF(CMAKE_REQUIRED_LIBRARIES)
34     TRY_RUN(${VARIABLE} HAVE_${VARIABLE}
35       ${CMAKE_BINARY_DIR}
36       "${CMAKE_BINARY_DIR}/CMakeTmp/CheckTypeSize.c"
37       CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_TYPE_SIZE_FLAGS}
38       "${CHECK_TYPE_SIZE_ADD_LIBRARIES}"
39       OUTPUT_VARIABLE OUTPUT)
40     IF(HAVE_${VARIABLE})
41       MESSAGE(STATUS "Check size of ${TYPE} - done")
42       FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log 
43         "Determining size of ${TYPE} passed with the following output:\n${OUTPUT}\n\n")
44     ELSE(HAVE_${VARIABLE})
45       MESSAGE(STATUS "Check size of ${TYPE} - failed")
46       FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeError.log 
47         "Determining size of ${TYPE} failed with the following output:\n${OUTPUT}\nCheckTypeSize.c:\n${CHECK_TYPE_SIZE_FILE_CONTENT}\n\n")
48     ENDIF(HAVE_${VARIABLE})
49   ENDIF("HAVE_${VARIABLE}" MATCHES "^HAVE_${VARIABLE}$")
50   SET(CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS )
51 ENDMACRO(CHECK_TYPE_SIZE)