forked from FreeTDS/freetds
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
450 lines (394 loc) · 14.3 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
project(FreeTDS)
cmake_minimum_required(VERSION 2.6)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
cmake_policy(SET CMP0005 NEW)
endif(COMMAND cmake_policy)
set(PACKAGE freetds)
unset(VERSION)
if(EXISTS "${CMAKE_SOURCE_DIR}/configure")
file(STRINGS "${CMAKE_SOURCE_DIR}/configure" VER LIMIT_COUNT 1 REGEX "^[ ]*VERSION[ ]*=.*0")
if(VER MATCHES "VERSION[ ]*=[ ]*'?([^' ]+)")
set(VERSION ${CMAKE_MATCH_1})
endif()
else()
file(STRINGS "${CMAKE_SOURCE_DIR}/configure.ac" VER LIMIT_COUNT 1 REGEX "^AC_INIT\\(FreeTDS,[ ]*0[.].*\\)$")
if(VER MATCHES "AC_INIT\\(FreeTDS,[ ]*(.+)\\)$")
set(VERSION ${CMAKE_MATCH_1})
endif()
endif()
if(DEFINED VERSION)
# versions to test
# set(VERSION "0.92.dev.esyscmd(printf $(date +\"%Y%m%d\"))")
# set(VERSION "0.92.dev.esyscmd(printf $(date +\"%y%m%d\"))") # FAIL
# set(VERSION "0.95rc1")
# set(VERSION "0.95")
# set(VERSION "0.95.1")
string(TIMESTAMP DATE "%Y%m%d")
string(REPLACE ".esyscmd(printf $(date +\"%Y%m%d\"))" ".${DATE}" VERSION ${VERSION})
string(REGEX REPLACE "^([0-9]+\\.[0-9]+)(rc|RC)" "\\1.dev." VER "${VERSION}")
string(REPLACE ".dev." ".9999." VER ${VER})
if(VER MATCHES "[^0-9.]" OR VER MATCHES "\\.\\.")
message(FATAL_ERROR "wrong VERSION format (${VERSION}) --> (${VER})")
endif()
if("${VER}.0" MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)")
set(MAJOR ${CMAKE_MATCH_1})
set(MINOR ${CMAKE_MATCH_2})
set(SUBVERSION ${CMAKE_MATCH_3})
if(SUBVERSION STREQUAL "9999")
math(EXPR MINOR "${MINOR} - 1")
endif()
else()
message(FATAL_ERROR "wrong VERSION format (${VERSION}) --> (${VER})")
endif()
# message(FATAL_ERROR "DEBUG ${MAJOR} ${MINOR} ${SUBVERSION}")
else()
message(FATAL_ERROR "VERSION not found or wrong format")
endif()
# get build number from date
# use same formula used in configure.ac
unset(BUILD_NUMBER)
string(TIMESTAMP BUILD_NUMBER "( %Y - 2000 ) * 366 + 1%j - 1000")
math(EXPR BUILD_NUMBER "${BUILD_NUMBER}")
set(FREETDS_TOPDIR ${CMAKE_CURRENT_LIST_DIR})
enable_testing()
set(CMAKE_CTEST_COMMAND ctest)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
# TODO depends on configure
add_definitions(-D_REENTRANT -D_THREAD_SAFE)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckTypeSize)
include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckStructHasMember)
include(CheckPrototypeDefinition)
find_package(Perl)
macro(config_write str)
file(APPEND "${CMAKE_BINARY_DIR}/include/config.h.in" "${str}")
endmacro()
file(WRITE "${CMAKE_BINARY_DIR}/include/config.h.in" "/* Automatic generated by cmake */\n\n")
foreach(fn
arpa/inet.h
com_err.h
dirent.h
errno.h
getopt.h
inttypes.h
langinfo.h
libgen.h
limits.h
locale.h
malloc.h
netdb.h
netinet/in.h
netinet/tcp.h
paths.h
poll.h
roken.h
signal.h
sql.h
sqlext.h
stddef.h
stdlib.h
stdint.h
string.h
strings.h
sys/eventfd.h
sys/ioctl.h
sys/param.h
sys/resource.h
sys/select.h
sys/socket.h
sys/stat.h
sys/time.h
sys/types.h
sys/wait.h
unistd.h
wchar.h
windows.h)
string(REGEX REPLACE "[/.]" "_" var "${fn}")
string(TOUPPER "HAVE_${var}" var)
CHECK_INCLUDE_FILE(${fn} ${var})
config_write("/* Define to 1 if you have the <${fn}> header file. */\n")
config_write("#cmakedefine ${var} 1\n\n")
endforeach(fn)
find_package(OpenSSL)
if(OPENSSL_FOUND)
config_write("#define HAVE_OPENSSL 1\n\n")
include_directories(${OPENSSL_INCLUDE_DIR})
endif(OPENSSL_FOUND)
set(CMAKE_THREAD_PREFER_PTHREAD ON)
find_package(Threads REQUIRED)
if(HAVE_WINDOWS_H)
if(NOT HAVE_SQL_H)
unset(HAVE_SQL_H CACHE)
CHECK_INCLUDE_FILES("windows.h;sql.h" HAVE_SQL_H)
endif()
if(HAVE_SQL_H AND NOT HAVE_SQLEXT_H)
unset(HAVE_SQLEXT_H CACHE)
CHECK_INCLUDE_FILES("windows.h;sql.h;sqlext.h" HAVE_SQLEXT_H)
endif()
if(NOT HAVE_ODBCSS_H)
unset(HAVE_ODBCSS_H CACHE)
CHECK_INCLUDE_FILES("windows.h;sqltypes.h;odbcss.h" HAVE_ODBCSS_H)
endif()
endif(HAVE_WINDOWS_H)
# find types
macro(ADD_HEADER VAR FN)
if(${VAR})
set(CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES} ${FN})
endif()
endmacro(ADD_HEADER)
add_header(HAVE_WCHAR_H wchar.h)
add_header(HAVE_WINDOWS_H windows.h)
add_header(HAVE_SQL_H sql.h)
add_header(HAVE_SQLEXT_H sqlext.h)
foreach(fn char double float int short long "long double" "long long" "SQLWCHAR" "void *" wchar_t __int64
SQLLEN SQLROWOFFSET SQLROWSETSIZE SQLSETPOSIROW)
string(REGEX REPLACE "[/. ]" "_" var "${fn}")
string(REPLACE "*" "P" var "${var}")
string(TOUPPER "HAVE_${var}" have)
string(TOUPPER "SIZEOF_${var}" var)
CHECK_TYPE_SIZE(${fn} ${var})
if(HAVE_${var})
set(${have} 1 CACHE INTERNAL "Have type ${fn}")
else()
set(${var} 0)
endif()
config_write("#define ${var} \\@${var}\\@\n\n")
endforeach(fn)
foreach(fn SQLLEN SQLROWOFFSET SQLROWSETSIZE SQLSETPOSIROW)
config_write("/* Define to 1 if you have type <${fn}>. */\n#cmakedefine HAVE_${fn} 1\n\n")
endforeach(fn)
check_prototype_definition(SQLColAttribute
"SQLRETURN SQL_API SQLColAttribute (SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber, SQLUSMALLINT FieldIdentifier,
SQLPOINTER CharacterAttribute, SQLSMALLINT BufferLength,
SQLSMALLINT *StringLength, SQLLEN * NumericAttribute)"
SQL_SUCCESS
"${CMAKE_EXTRA_INCLUDE_FILES}"
TDS_SQLCOLATTRIBUTE_SQLLEN)
config_write("/* Define to 1 if last argument of SQLColAttribute it's SQLLEN * */\n#cmakedefine TDS_SQLCOLATTRIBUTE_SQLLEN 1\n\n")
check_prototype_definition(SQLParamOptions
"SQLRETURN SQL_API SQLParamOptions(SQLHSTMT hstmt, SQLULEN crow, SQLULEN *pirow)"
SQL_SUCCESS
"${CMAKE_EXTRA_INCLUDE_FILES}"
TDS_SQLPARAMOPTIONS_SQLLEN)
config_write("/* Define to 1 if SQLParamOptions accept SQLULEN as arguments */\n#cmakedefine TDS_SQLPARAMOPTIONS_SQLLEN 1\n\n")
set(CMAKE_EXTRA_INCLUDE_FILES)
macro(SELECT_TYPE VAR SIZE TYPES ERROR)
set(${VAR} "")
foreach(t ${TYPES})
string(REGEX REPLACE "[/. ]" "_" var "${t}")
string(REPLACE "*" "P" var "${var}")
string(TOUPPER "SIZEOF_${var}" var)
if(${${var}} EQUAL ${SIZE})
set(${VAR} ${t})
break()
endif()
endforeach(t)
if(${VAR} STREQUAL "")
message(FATAL_ERROR ${ERROR})
endif()
endmacro(SELECT_TYPE)
SELECT_TYPE(tds_sysdep_int16_type 2 "short;int" "No 16-bit int found.")
SELECT_TYPE(tds_sysdep_int32_type 4 "short;int;long" "No 32-bit int found.")
SELECT_TYPE(tds_sysdep_int64_type 8 "long;long long;__int64" "No 64-bit int found.")
SELECT_TYPE(tds_sysdep_real32_type 4 "float;double" "No 32-bit real found.")
SELECT_TYPE(tds_sysdep_real64_type 8 "float;double;long double" "No 64-bit real found.")
SELECT_TYPE(tds_sysdep_intptr_type ${SIZEOF_VOID_P} "short;int;long;__int64" "No intptr type found.")
# find functions
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
set(FUNCS asprintf vasprintf strtok_r readpassphrase
strlcpy strlcat basename getopt strsep
vsnprintf _vsnprintf snprintf _snprintf _vscprintf gettimeofday
nl_langinfo locale_charset setenv putenv
getuid getpwuid getpwuid_r fstat alarm fork
gethrtime localtime_r setitimer
_fseeki64 _ftelli64 setrlimit
inet_ntoa_r getipnodebyaddr getipnodebyname
getaddrinfo inet_ntop gethostname poll socketpair
clock_gettime fseeko pthread_cond_timedwait pthread_cond_timedwait_relative_np
pthread_condattr_setclock _lock_file _unlock_file usleep nanosleep
readdir_r eventfd daemon)
macro(CHECK_FUNCTION_EXISTS_DEFINE func)
string(TOUPPER "HAVE_${func}" var)
check_function_exists(${func} ${var})
config_write("/* Define to 1 if you have function <${func}>. */\n")
config_write("#cmakedefine ${var} 1\n\n")
endmacro()
# TODO
set(HAVE_GETADDRINFO 1 CACHE INTERNAL "")
foreach(func ${FUNCS})
check_function_exists_define(${func})
endforeach(func)
macro(CHECK_STDIO_FUNCTION_EXISTS FUNCTION)
string(TOUPPER "HAVE_${FUNCTION}" VARIABLE)
string(TOUPPER "CHECK_${FUNCTION}" CHECK)
if (NOT ${VARIABLE})
set(MACRO_CHECK_FUNCTION_DEFINITIONS
"-D${CHECK}=1 ${CMAKE_REQUIRED_FLAGS}")
message(STATUS "Looking for ${FUNCTION}")
try_compile(${VARIABLE}
${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/misc/cmake_checks.c
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
OUTPUT_VARIABLE OUTPUT)
if(${VARIABLE})
set(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}")
message(STATUS "Looking for ${FUNCTION} - found")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if the function ${FUNCTION} exists passed with the following output:\n"
"${OUTPUT}\n\n")
else()
message(STATUS "Looking for ${FUNCTION} - not found")
set(${VARIABLE} "" CACHE INTERNAL "Have function ${FUNCTION}")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if the function ${FUNCTION} exists failed with the following output:\n"
"${OUTPUT}\n\n")
endif()
endif()
endmacro()
foreach(func asprintf vasprintf vsnprintf _vsnprintf snprintf _snprintf _vscprintf)
check_stdio_function_exists(${func})
endforeach(func)
set(CMAKE_REQUIRED_LIBRARIES)
check_struct_has_member("struct tm" "tm_zone" "time.h" HAVE_STRUCT_TM_TM_ZONE)
config_write("#cmakedefine HAVE_STRUCT_TM_TM_ZONE 1\n\n")
macro(SEARCH_LIBRARY FUNC HAVE VAR LIBS)
foreach(lib ${LIBS})
if(NOT ${HAVE})
unset(${HAVE} CACHE)
check_library_exists(${lib} ${FUNC} "" ${HAVE})
if(${HAVE})
unset(${VAR} CACHE)
set(${VAR} ${lib} CACHE INTERNAL "")
endif()
endif()
endforeach(lib)
endmacro(SEARCH_LIBRARY)
check_library_exists(readline readline "" HAVE_READLINE)
if(HAVE_READLINE)
config_write("#cmakedefine HAVE_READLINE 1\n\n")
search_library(tgetent HAVE_TGETENT lib_READLINE "readline;ncurses;curses;termcap")
set(lib_READLINE readline ${lib_READLINE})
endif(HAVE_READLINE)
config_write("#cmakedefine HAVE_SQLGETPRIVATEPROFILESTRING 1\n\n")
if(WIN32)
set(lib_ODBCINST odbccp32)
check_library_exists(legacy_stdio_definitions _vsnwprintf_s "" LEGACY_STDIO)
if(LEGACY_STDIO)
set(lib_ODBCINST ${lib_ODBCINST} legacy_stdio_definitions)
endif(LEGACY_STDIO)
else()
search_library(SQLGetPrivateProfileString HAVE_SQLGETPRIVATEPROFILESTRING lib_ODBCINST "odbcinst;iodbcinst")
endif()
# flags
set(ENABLE_ODBC_WIDE ON CACHE BOOL "Enable ODBC wide character support")
set(ENABLE_EXTRA_CHECKS OFF CACHE BOOL "Enable internal extra checks, do not use in production")
set(ENABLE_KRB5 OFF CACHE BOOL "Enable Kerberos support")
set(ENABLE_ODBC_MARS OFF CACHE BOOL "Enable MARS")
foreach(flag ODBC_WIDE EXTRA_CHECKS KRB5 ODBC_MARS)
config_write("#cmakedefine ENABLE_${flag} 1\n\n")
endforeach(flag)
config_write("#define VERSION \"\\@VERSION\\@\"\n\n")
config_write("#define FREETDS_TOPDIR \"${FREETDS_TOPDIR}\"\n\n")
# TODO make it configure option
config_write("#define TDS70 1\n\n")
config_write("#ifdef _MSC_VER
# define inline __inline
# define _CRT_SECURE_NO_WARNINGS 1
#endif\n\n")
if(WIN32)
config_write("/* Define to 1 if you want to use SSPI for Win32 */\n#define HAVE_SSPI 1\n\n")
config_write("/* define to format string used for 64bit integers */\n#define TDS_I64_PREFIX \"I64\"\n\n")
config_write("/* Define to 1 if you have the SQLGetPrivateProfileString function. */\n#define HAVE_SQLGETPRIVATEPROFILESTRING 1\n\n")
else(WIN32)
# this section make just work on Linux, many definition are not checked
config_write("#define HAVE_FUNC_GETPWUID_R_5 1\n\n")
config_write("#define HAVE_FUNC_LOCALTIME_R_TM 1\n\n")
config_write("/* define to format string used for 64bit integers */\n#define TDS_I64_PREFIX \"ll\"\n\n")
config_write("#define UNIXODBC 1\n\n#define _GNU_SOURCE 1\n\n")
if(NOT OPENSSL_FOUND)
include(FindGnuTLS)
if(GNUTLS_FOUND)
config_write("#define HAVE_GNUTLS 1\n")
set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
check_function_exists_define(gnutls_certificate_set_verify_function)
check_function_exists_define(gnutls_record_disable_padding)
check_function_exists_define(gnutls_rnd)
set(CMAKE_REQUIRED_LIBRARIES)
pkg_check_modules(NETTLEDEP gnutls)
if (";${NETTLEDEP_STATIC_LIBRARIES};" MATCHES ";nettle;")
set(lib_GNUTLS ${GNUTLS_LIBRARIES})
config_write("#define GNUTLS_USE_NETTLE 1\n\n")
pkg_check_modules(NETTLE nettle)
if(NETTLE_FOUND)
set(lib_GNUTLS ${GNUTLS_LIBRARIES} ${NETTLE_LIBRARIES})
config_write("#define HAVE_NETTLE 1\n\n")
if (";${NETTLEDEP_STATIC_LIBRARIES};" MATCHES ";hogweed;")
set(lib_GNUTLS ${lib_GNUTLS} hogweed)
endif()
if (";${NETTLEDEP_STATIC_LIBRARIES};" MATCHES ";gmp;")
set(lib_GNUTLS ${lib_GNUTLS} gmp)
config_write("#define HAVE_GMP 1\n\n")
endif()
endif(NETTLE_FOUND)
else()
set(lib_GNUTLS ${GNUTLS_LIBRARIES} gcrypt tasn1)
endif()
endif(GNUTLS_FOUND)
endif(NOT OPENSSL_FOUND)
if(NOT HAVE_CLOCK_GETTIME AND NOT HAVE_GETHRTIME)
search_library(clock_gettime HAVE_CLOCK_GETTIME lib_RT "rt;posix4")
config_write("#cmakedefine HAVE_CLOCK_GETTIME 1\n\n")
endif(NOT HAVE_CLOCK_GETTIME AND NOT HAVE_GETHRTIME)
if(CMAKE_USE_PTHREADS_INIT)
config_write("#define HAVE_PTHREAD 1\n\n")
config_write("#define TDS_HAVE_PTHREAD_MUTEX 1\n\n")
endif(CMAKE_USE_PTHREADS_INIT)
config_write("
#define TIME_WITH_SYS_TIME 1
//#define _ALL_SOURCE 1
#define __EXTENSIONS__ 1
// readline
#define HAVE_RL_INHIBIT_COMPLETION 1
#define HAVE_RL_ON_NEW_LINE 1
#define HAVE_RL_RESET_LINE_STATE 1
// iconv
#define HAVE_ICONV 1
#define ICONV_CONST
")
endif(WIN32)
set(lib_BASE ${lib_RT} ${CMAKE_THREAD_LIBS_INIT})
if(EXISTS "${CMAKE_SOURCE_DIR}/iconv/lib/iconv.lib")
set(lib_BASE ${lib_BASE} ${CMAKE_THREAD_LIBS_INIT} "${CMAKE_SOURCE_DIR}/iconv/lib/iconv.lib")
config_write("#define HAVE_ICONV 1\n\n")
config_write("#define ICONV_CONST \n\n")
endif()
if(WIN32)
set(lib_NETWORK ws2_32)
else(WIN32)
# TODO check libraries
set(lib_NETWORK gssapi_krb5)
endif(WIN32)
if(OPENSSL_FOUND)
set(lib_NETWORK ${lib_NETWORK} ${OPENSSL_LIBRARIES})
elseif(GNUTLS_FOUND)
set(lib_NETWORK ${lib_NETWORK} ${lib_GNUTLS})
endif(OPENSSL_FOUND)
include_directories(${CMAKE_BINARY_DIR}/include include win32 iconv/include)
add_subdirectory(src/replacements)
add_subdirectory(src/tds)
add_subdirectory(src/ctlib)
add_subdirectory(src/dblib)
add_subdirectory(src/odbc)
add_subdirectory(src/apps)
configure_file(${CMAKE_BINARY_DIR}/include/config.h.in ${CMAKE_BINARY_DIR}/include/config.h)
configure_file(${CMAKE_SOURCE_DIR}/include/tds_sysdep_public.h.in ${CMAKE_BINARY_DIR}/include/tds_sysdep_public.h)
configure_file(${CMAKE_SOURCE_DIR}/include/freetds/version.h.in ${CMAKE_BINARY_DIR}/include/freetds/version.h)
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/configure")
configure_file(${CMAKE_SOURCE_DIR}/src/odbc/version.rc.in ${CMAKE_SOURCE_DIR}/src/odbc/version.rc)
endif(NOT EXISTS "${CMAKE_SOURCE_DIR}/configure")