comparison extern/jansson/CMakeLists.txt @ 0:8991989c4708

Initial import
author David Demelier <markand@malikania.fr>
date Tue, 22 Mar 2016 18:26:05 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8991989c4708
1 #
2 # This is a modified version for irccd.
3 # -------------------------------------------------------------------
4 #
5 # - installation stuff has been removed,
6 # - documentation process has been removed.
7 # - style has been adapted to match our conventions.
8 # - comments and unneeded stuff have been removed.
9 #
10
11 project (jansson C)
12
13 option(USE_URANDOM "Use /dev/urandom to seed the hash function." ON)
14 option(USE_WINDOWS_CRYPTOAPI "Use CryptGenRandom to seed the hash function." ON)
15
16 # for CheckFunctionKeywords
17 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
18
19 include(CheckCSourceCompiles)
20 include(CheckFunctionExists)
21 include(CheckFunctionKeywords)
22 include(CheckIncludeFiles)
23 include(CheckTypeSize)
24
25 if (MSVC)
26 # Turn off Microsofts "security" warnings.
27 add_definitions( "/W3 /D_CRT_SECURE_NO_WARNINGS /wd4005 /wd4996 /nologo" )
28
29 if (STATIC_CRT)
30 set(CMAKE_C_FLAGS_RELEASE "/MT")
31 set(CMAKE_C_FLAGS_DEBUG "/MTd")
32 endif()
33 endif()
34
35 if (NOT WIN32 AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX))
36 add_definitions("-fPIC")
37 endif()
38
39 check_include_files(endian.h HAVE_ENDIAN_H)
40 check_include_files(fcntl.h HAVE_FCNTL_H)
41 check_include_files(sched.h HAVE_SCHED_H)
42 check_include_files(unistd.h HAVE_UNISTD_H)
43 check_include_files(sys/param.h HAVE_SYS_PARAM_H)
44 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
45 check_include_files(sys/time.h HAVE_SYS_TIME_H)
46 check_include_files(sys/time.h HAVE_SYS_TYPES_H)
47
48 check_function_exists(close HAVE_CLOSE)
49 check_function_exists(getpid HAVE_GETPID)
50 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
51 check_function_exists(open HAVE_OPEN)
52 check_function_exists(read HAVE_READ)
53 check_function_exists(sched_yield HAVE_SCHED_YIELD)
54
55 # Check for the int-type includes
56 check_include_files(stdint.h HAVE_STDINT_H)
57
58 # Check our 64 bit integer sizes
59 check_type_size(__int64 __INT64)
60 check_type_size(int64_t INT64_T)
61 check_type_size("long long" LONG_LONG_INT)
62
63 # Check our 32 bit integer sizes
64 check_type_size(int32_t INT32_T)
65 check_type_size(__int32 __INT32)
66 check_type_size("long" LONG_INT)
67 check_type_size("int" INT)
68
69 if (HAVE_INT32_T)
70 set(JSON_INT32 int32_t)
71 elseif (HAVE___INT32)
72 set(JSON_INT32 __int32)
73 elseif (HAVE_LONG_INT AND (${LONG_INT} EQUAL 4))
74 set(JSON_INT32 long)
75 elseif (HAVE_INT AND (${INT} EQUAL 4))
76 set(JSON_INT32 int)
77 else ()
78 message (FATAL_ERROR "Could not detect a valid 32-bit integer type")
79 endif ()
80
81 check_type_size("unsigned long" UNSIGNED_LONG_INT)
82 check_type_size("unsigned int" UNSIGNED_INT)
83 check_type_size("unsigned short" UNSIGNED_SHORT)
84 check_type_size(uint32_t UINT32_T)
85 check_type_size(__uint32 __UINT32)
86
87 if (HAVE_UINT32_T)
88 set(JSON_UINT32 uint32_t)
89 elseif (HAVE___UINT32)
90 set(JSON_UINT32 __uint32)
91 elseif (HAVE_UNSIGNED_LONG_INT AND (${UNSIGNED_LONG_INT} EQUAL 4))
92 set(JSON_UINT32 "unsigned long")
93 elseif (HAVE_UNSIGNED_INT AND (${UNSIGNED_INT} EQUAL 4))
94 set(JSON_UINT32 "unsigned int")
95 else ()
96 message(FATAL_ERROR "Could not detect a valid unsigned 32-bit integer type")
97 endif ()
98
99 check_type_size(uint16_t UINT16_T)
100 check_type_size(__uint16 __UINT16)
101
102 if (HAVE_UINT16_T)
103 set(JSON_UINT16 uint16_t)
104 elseif (HAVE___UINT16)
105 set(JSON_UINT16 __uint16)
106 elseif (HAVE_UNSIGNED_INT AND (${UNSIGNED_INT} EQUAL 2))
107 set(JSON_UINT16 "unsigned int")
108 elseif (HAVE_UNSIGNED_SHORT AND (${UNSIGNED_SHORT} EQUAL 2))
109 set(JSON_UINT16 "unsigned short")
110 else ()
111 message(FATAL_ERROR "Could not detect a valid unsigned 16-bit integer type")
112 endif ()
113
114 check_type_size(uint8_t UINT8_T)
115 check_type_size(__uint8 __UINT8)
116
117 if (HAVE_UINT8_T)
118 set(JSON_UINT8 uint8_t)
119 elseif (HAVE___UINT8)
120 set(JSON_UINT8 __uint8)
121 else ()
122 set(JSON_UINT8 "unsigned char")
123 endif ()
124
125 # Check for ssize_t and SSIZE_T existance.
126 check_type_size(ssize_t SSIZE_T)
127 check_type_size(SSIZE_T UPPERCASE_SSIZE_T)
128
129 if(NOT HAVE_SSIZE_T)
130 if(HAVE_UPPERCASE_SSIZE_T)
131 set(JSON_SSIZE SSIZE_T)
132 else()
133 set(JSON_SSIZE int)
134 endif()
135 endif()
136
137 set(CMAKE_EXTRA_INCLUDE_FILES "")
138
139 # Check for all the variants of strtoll
140 check_function_exists(strtoll HAVE_STRTOLL)
141 check_function_exists(strtoq HAVE_STRTOQ)
142 check_function_exists(_strtoi64 HAVE__STRTOI64)
143
144 # Figure out what variant we should use
145 if (HAVE_STRTOLL)
146 set(JSON_STRTOINT strtoll)
147 elseif (HAVE_STRTOQ)
148 set(JSON_STRTOINT strtoq)
149 elseif (HAVE__STRTOI64)
150 set(JSON_STRTOINT _strtoi64)
151 else ()
152 # fallback to strtol (32 bit)
153 # this will set all the required variables
154 set (JSON_STRTOINT strtol)
155 set (JSON_INT_T long)
156 set (JSON_INTEGER_FORMAT "\"ld\"")
157 endif ()
158
159 # if we haven't defined JSON_INT_T, then we have a 64 bit conversion function.
160 # detect what to use for the 64 bit type.
161 # Note: I will prefer long long if I can get it, as that is what the automake system aimed for.
162 if (NOT DEFINED JSON_INT_T)
163 if (HAVE_LONG_LONG_INT AND (${LONG_LONG_INT} EQUAL 8))
164 set(JSON_INT_T "long long")
165 elseif (HAVE_INT64_T)
166 set(JSON_INT_T int64_t)
167 elseif (HAVE___INT64)
168 set(JSON_INT_T __int64)
169 else ()
170 message(FATAL_ERROR "Could not detect 64 bit type, although I detected the strtoll equivalent")
171 endif ()
172
173 # Apparently, Borland BCC and MSVC wants I64d,
174 # Borland BCC could also accept LD
175 # and gcc wants ldd,
176 # I am not sure what cygwin will want, so I will assume I64d
177
178 if (WIN32) # matches both msvc and cygwin
179 set(JSON_INTEGER_FORMAT "\"I64d\"")
180 else ()
181 set(JSON_INTEGER_FORMAT "\"lld\"")
182 endif ()
183 endif ()
184
185
186 # If locale.h and localeconv() are available, define to 1, otherwise to 0.
187 check_include_files (locale.h HAVE_LOCALE_H)
188 check_function_exists (localeconv HAVE_LOCALECONV)
189
190 if (HAVE_LOCALECONV AND HAVE_LOCALE_H)
191 set(JSON_HAVE_LOCALECONV 1)
192 else ()
193 set(JSON_HAVE_LOCALECONV 0)
194 endif()
195
196 # check if we have setlocale
197 check_function_exists(setlocale HAVE_SETLOCALE)
198
199 # Check what the inline keyword is.
200 # Note that the original JSON_INLINE was always set to just 'inline', so this goes further.
201 check_function_keywords("inline")
202 check_function_keywords("__inline")
203 check_function_keywords("__inline__")
204
205 if (HAVE_INLINE)
206 set(JSON_INLINE inline)
207 elseif (HAVE___INLINE)
208 set(JSON_INLINE __inline)
209 elseif (HAVE___INLINE__)
210 set(JSON_INLINE __inline__)
211 else()
212 # no inline on this platform
213 set (JSON_INLINE)
214 endif()
215
216 # Find our snprintf
217 check_function_exists (snprintf HAVE_SNPRINTF)
218 check_function_exists (_snprintf HAVE__SNPRINTF)
219
220 if (HAVE_SNPRINTF)
221 set(JSON_SNPRINTF snprintf)
222 elseif (HAVE__SNPRINTF)
223 set(JSON_SNPRINTF _snprintf)
224 endif ()
225
226 check_c_source_compiles ("int main() { unsigned long val; __sync_bool_compare_and_swap(&val, 0, 1); return 0; } " HAVE_SYNC_BUILTINS)
227 check_c_source_compiles ("int main() { char l; unsigned long v; __atomic_test_and_set(&l, __ATOMIC_RELAXED); __atomic_store_n(&v, 1, __ATOMIC_RELEASE); __atomic_load_n(&v, __ATOMIC_ACQUIRE); return 0; }" HAVE_ATOMIC_BUILTINS)
228
229 # configure the public config file
230 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/jansson_config.h.cmake
231 ${CMAKE_CURRENT_BINARY_DIR}/include/jansson_config.h)
232
233 # Copy the jansson.h file to the public include folder
234 file (COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson.h
235 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/)
236
237 add_definitions(-DJANSSON_USING_CMAKE)
238
239 # configure the private config file
240 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/jansson_private_config.h.cmake
241 ${CMAKE_CURRENT_BINARY_DIR}/private_include/jansson_private_config.h)
242
243 # and tell the source code to include it
244 add_definitions(-DHAVE_CONFIG_H)
245
246 include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
247 include_directories(${CMAKE_CURRENT_BINARY_DIR}/private_include)
248
249 # Add the lib sources.
250 file(GLOB JANSSON_SRC src/*.c)
251
252 set(
253 JANSSON_HDR_PRIVATE
254 ${CMAKE_CURRENT_SOURCE_DIR}/src/hashtable.h
255 ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson_private.h
256 ${CMAKE_CURRENT_SOURCE_DIR}/src/strbuffer.h
257 ${CMAKE_CURRENT_SOURCE_DIR}/src/utf.h
258 ${CMAKE_CURRENT_BINARY_DIR}/private_include/jansson_private_config.h
259 )
260
261 set(
262 JANSSON_HDR_PUBLIC
263 ${CMAKE_CURRENT_BINARY_DIR}/include/jansson_config.h
264 ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson.h
265 )
266
267 malikania_create_library(
268 TARGET extern-jansson
269 SOURCES
270 ${JANSSON_SRC}
271 ${JANSSON_HDR_PRIVATE}
272 ${JANSSON_HDR_PUBLIC}
273 PUBLIC_INCLUDES
274 ${jansson_SOURCE_DIR}/src
275 ${jansson_BINARY_DIR}/include
276 )