-
Notifications
You must be signed in to change notification settings - Fork 158
/
CMakeLists.txt
306 lines (262 loc) · 8.81 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
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)
file(STRINGS "configure" VERSION LIMIT_COUNT 1 REGEX "^[ ]*VERSION[ ]*=.*0")
if(VERSION MATCHES "VERSION[ ]*=[ ]*'?([^' ]+)")
set(VERSION ${CMAKE_MATCH_1})
string(REGEX REPLACE "^dev[.]" "" VER "${VERSION}")
if("${VER}.0" MATCHES "^([0-9]+)[.]([0-9]+)[.]([^.]*)")
set(MAJOR ${CMAKE_MATCH_1})
set(MINOR ${CMAKE_MATCH_2})
set(SUBVERSION ${CMAKE_MATCH_3})
if(SUBVERSION STREQUAL "dev")
math(EXPR MINOR "${MINOR} - 1")
set(SUBVERSION 9999)
endif()
else()
message(FATAL_ERROR "wrong VERSION format (${VERSION})")
endif()
else()
message(FATAL_ERROR "VERSION not found or wrong format")
endif()
# get build number from date
unset(BUILD_NUMBER)
execute_process(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE BUILD_NUMBER)
if(BUILD_NUMBER STREQUAL "")
execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE BUILD_NUMBER)
endif()
if(BUILD_NUMBER MATCHES "(..)/(..)/..(..).*")
math(EXPR BUILD_NUMBER "${CMAKE_MATCH_3} * 372 + ${CMAKE_MATCH_2} * 31 + ${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "Unable to compute current date --${BUILD_NUMBER}--")
endif()
set(FREETDS_TOPDIR ${CMAKE_CURRENT_LIST_DIR})
enable_testing()
# TODO depends on configure
add_definitions(-D_REENTRANT -D_THREAD_SAFE)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckTypeSize)
include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckStructHasMember)
macro(config_write str)
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/include/config.h.in" "${str}")
endmacro()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/config.h.in" "/* Automatic generated by cmake */\n\n")
foreach(fn
arpa/inet.h
com_err.h
errno.h
inttypes.h
langinfo.h
libgen.h
limits.h
locale.h
netdb.h
netinet/in.h
netinet/tcp.h
odbcss.h
paths.h
poll.h
readpassphrase.h
roken.h
signal.h
sql.h
sqlext.h
stddef.h
stdlib.h
stdint.h
string.h
strings.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)
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)
foreach(fn char double float int short long "long double" "long long" "SQLWCHAR" "void *" wchar_t __int64)
string(REGEX REPLACE "[/. ]" "_" var "${fn}")
string(REPLACE "*" "P" var "${var}")
string(TOUPPER "SIZEOF_${var}" var)
CHECK_TYPE_SIZE(${fn} ${var})
if(NOT HAVE_${var})
set(${var} 0)
endif()
config_write("#define ${var} \\@${var}\\@\n\n")
endforeach(fn)
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.")
# find functions
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
set(FUNCS _atoi64 asprintf vasprintf atoll 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)
foreach(func ${FUNCS})
string(TOUPPER "HAVE_${func}" var)
check_function_exists(${func} ${var})
set(HAVE_GETADDRINFO 1 CACHE INTERNAL "")
config_write("/* Define to 1 if you have function <${func}>. */\n")
config_write("#cmakedefine ${var} 1\n\n")
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)
# 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")
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")
include(FindGnuTLS)
if(GNUTLS_FOUND)
config_write("#define HAVE_GNUTLS 1\n#define HAVE_GNUTLS_RECORD_DISABLE_PADDING 1\n")
set(lib_GNUTLS ${GNUTLS_LIBRARIES})
endif(GNUTLS_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
// odbc
#define HAVE_SQLLEN 1
#define HAVE_SQLSETPOSIROW 1
#define TDS_SQLCOLATTRIBUTE_SQLLEN 1
#define TDS_SQLPARAMOPTIONS_SQLLEN 1
// iconv
#define HAVE_ICONV 1
#define ICONV_CONST
")
endif(WIN32)
set(lib_BASE ${lib_RT} ${CMAKE_THREAD_LIBS_INIT})
if(WIN32)
set(lib_NETWORK ws2_32)
else(WIN32)
# TODO check libraries
set(lib_NETWORK ${GNUTLS_LIBRARIES} gssapi_krb5)
endif(WIN32)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include include win32)
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_CURRENT_BINARY_DIR}/include/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/config.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/tds_sysdep_public.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/tds_sysdep_public.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/freetds/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/freetds/version.h)