Imported Upstream version 1.1.5
[platform/upstream/cmocka.git] / ConfigureChecks.cmake
1 include(CheckIncludeFile)
2 include(CheckSymbolExists)
3 include(CheckFunctionExists)
4 include(CheckLibraryExists)
5 include(CheckTypeSize)
6 include(CheckCXXSourceCompiles)
7 include(CheckStructHasMember)
8 include(TestBigEndian)
9
10 set(PACKAGE ${PROJECT_NAME})
11 set(VERSION ${PROJECT_VERSION})
12 set(DATADIR ${DATA_INSTALL_DIR})
13 set(LIBDIR ${CMAKE_INSTALL_LIBDIR})
14 set(PLUGINDIR "${PLUGIN_INSTALL_DIR}-${LIBRARY_SOVERSION}")
15 set(SYSCONFDIR ${SYSCONF_INSTALL_DIR})
16
17 set(BINARYDIR ${CMAKE_BINARY_DIR})
18 set(SOURCEDIR ${CMAKE_SOURCE_DIR})
19
20 function(COMPILER_DUMPVERSION _OUTPUT_VERSION)
21     # Remove whitespaces from the argument.
22     # This is needed for CC="ccache gcc" cmake ..
23     string(REPLACE " " "" _C_COMPILER_ARG "${CMAKE_C_COMPILER_ARG1}")
24
25     execute_process(
26         COMMAND
27             ${CMAKE_C_COMPILER} ${_C_COMPILER_ARG} -dumpversion
28         OUTPUT_VARIABLE _COMPILER_VERSION
29     )
30
31     string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
32         _COMPILER_VERSION ${_COMPILER_VERSION})
33
34     set(${_OUTPUT_VERSION} ${_COMPILER_VERSION} PARENT_SCOPE)
35 endfunction()
36
37 if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
38     compiler_dumpversion(GNUCC_VERSION)
39     if (NOT GNUCC_VERSION EQUAL 34)
40         check_c_compiler_flag("-fvisibility=hidden" WITH_VISIBILITY_HIDDEN)
41     endif (NOT GNUCC_VERSION EQUAL 34)
42 endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
43
44 # DEFINITIONS
45 if (SOLARIS)
46     add_definitions(-D__EXTENSIONS__)
47 endif (SOLARIS)
48
49 # HEADER FILES
50 check_include_file(assert.h HAVE_ASSERT_H)
51 check_include_file(inttypes.h HAVE_INTTYPES_H)
52 check_include_file(io.h HAVE_IO_H)
53 check_include_file(malloc.h HAVE_MALLOC_H)
54 check_include_file(memory.h HAVE_MEMORY_H)
55 check_include_file(setjmp.h HAVE_SETJMP_H)
56 check_include_file(signal.h HAVE_SIGNAL_H)
57 check_include_file(stdarg.h HAVE_STDARG_H)
58 check_include_file(stddef.h HAVE_STDDEF_H)
59 check_include_file(stdint.h HAVE_STDINT_H)
60 check_include_file(stdio.h HAVE_STDIO_H)
61 check_include_file(stdlib.h HAVE_STDLIB_H)
62 check_include_file(string.h HAVE_STRING_H)
63 check_include_file(strings.h HAVE_STRINGS_H)
64 check_include_file(sys/stat.h HAVE_SYS_STAT_H)
65 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
66 check_include_file(time.h HAVE_TIME_H)
67 check_include_file(unistd.h HAVE_UNISTD_H)
68
69 if (HAVE_TIME_H)
70     check_struct_has_member("struct timespec" tv_sec "time.h" HAVE_STRUCT_TIMESPEC)
71 endif (HAVE_TIME_H)
72
73 # FUNCTIONS
74 check_function_exists(calloc HAVE_CALLOC)
75 check_function_exists(exit HAVE_EXIT)
76 check_function_exists(fprintf HAVE_FPRINTF)
77 check_function_exists(free HAVE_FREE)
78 check_function_exists(longjmp HAVE_LONGJMP)
79 check_function_exists(siglongjmp HAVE_SIGLONGJMP)
80 check_function_exists(malloc HAVE_MALLOC)
81 check_function_exists(memcpy HAVE_MEMCPY)
82 check_function_exists(memset HAVE_MEMSET)
83 check_function_exists(printf HAVE_PRINTF)
84 check_function_exists(setjmp HAVE_SETJMP)
85 check_function_exists(signal HAVE_SIGNAL)
86 check_function_exists(strsignal HAVE_STRSIGNAL)
87 check_function_exists(strcmp HAVE_STRCMP)
88 check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
89
90 if (WIN32)
91     check_function_exists(_vsnprintf_s HAVE__VSNPRINTF_S)
92     check_function_exists(_vsnprintf HAVE__VSNPRINTF)
93     check_function_exists(_snprintf HAVE__SNPRINTF)
94     check_function_exists(_snprintf_s HAVE__SNPRINTF_S)
95     check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF)
96     check_symbol_exists(vsnprintf stdio.h HAVE_VSNPRINTF)
97 else (WIN32)
98     check_function_exists(sprintf HAVE_SNPRINTF)
99     check_function_exists(vsnprintf HAVE_VSNPRINTF)
100 endif (WIN32)
101
102 find_library(RT_LIBRARY rt)
103 if (RT_LIBRARY AND NOT LINUX AND NOT ANDROID)
104     set(CMOCKA_REQUIRED_LIBRARIES ${RT_LIBRARY} CACHE INTERNAL "cmocka required system libraries")
105 endif ()
106
107 # OPTIONS
108 check_c_source_compiles("
109 __thread int tls;
110
111 int main(void) {
112     return 0;
113 }" HAVE_GCC_THREAD_LOCAL_STORAGE)
114
115 if (WIN32)
116 check_c_source_compiles("
117 __declspec(thread) int tls;
118
119 int main(void) {
120     return 0;
121 }" HAVE_MSVC_THREAD_LOCAL_STORAGE)
122 endif(WIN32)
123
124 if (HAVE_TIME_H AND HAVE_STRUCT_TIMESPEC AND HAVE_CLOCK_GETTIME)
125     if (RT_LIBRARY)
126         set(CMAKE_REQUIRED_LIBRARIES ${RT_LIBRARY})
127     endif()
128
129     check_c_source_compiles("
130 #include <time.h>
131
132 int main(void) {
133     struct timespec ts;
134
135     clock_gettime(CLOCK_REALTIME, &ts);
136
137     return 0;
138 }" HAVE_CLOCK_REALTIME)
139
140     # reset cmake requirements
141     set(CMAKE_REQUIRED_INCLUDES)
142     set(CMAKE_REQUIRED_LIBRARIES)
143 endif ()
144
145 # ENDIAN
146 if (NOT WIN32)
147     set(WORDS_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
148     test_big_endian(WORDS_BIGENDIAN)
149 endif (NOT WIN32)