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)
17 SET(MACRO_CHECK_TYPE_SIZE_FLAGS
18 "${MACRO_CHECK_TYPE_SIZE_FLAGS} -D${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")
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}
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)
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)