comparison Resources/CMake/UnixOdbcConfiguration.cmake @ 329:b5fb8b77ce4d

initial commit of ODBC framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 10 Aug 2021 20:08:53 +0200
parents
children 75ff5ce4a995
comparison
equal deleted inserted replaced
328:6a49c495c940 329:b5fb8b77ce4d
1 # Orthanc - A Lightweight, RESTful DICOM Store
2 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
3 # Department, University Hospital of Liege, Belgium
4 # Copyright (C) 2017-2021 Osimis S.A., Belgium
5 #
6 # This program is free software: you can redistribute it and/or
7 # modify it under the terms of the GNU Affero General Public License
8 # as published by the Free Software Foundation, either version 3 of
9 # the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Affero General Public License for more details.
15 #
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19
20 if (STATIC_BUILD OR NOT USE_SYSTEM_UNIX_ODBC)
21 include(CheckFunctionExists)
22 include(CheckTypeSize)
23
24 set(VERSION "2.3.9") # Used in "config.h.in"
25 set(UNIX_ODBC_SOURCES_DIR ${CMAKE_BINARY_DIR}/unixODBC-${VERSION})
26 set(UNIX_ODBC_MD5 "06f76e034bb41df5233554abe961a16f")
27 set(UNIX_ODBC_URL "http://orthanc.osimis.io/ThirdPartyDownloads/unixODBC-${VERSION}.tar.gz")
28
29 DownloadPackage(${UNIX_ODBC_MD5} ${UNIX_ODBC_URL} "${UNIX_ODBC_SOURCES_DIR}")
30
31 if (STATIC_BUILD OR NOT USE_SYSTEM_LTDL)
32 add_definitions(
33 -DLT_OBJDIR=".libs/"
34 -DLTDL # Necessary for LT_SCOPE to be properly defined
35 #-DLT_DEBUG_LOADERS # Get debug messages
36 )
37
38 include_directories(
39 ${UNIX_ODBC_SOURCES_DIR}/libltdl
40 ${UNIX_ODBC_SOURCES_DIR}/libltdl/libltdl/
41 )
42
43 list(APPEND LTDL_SOURCES
44 ${UNIX_ODBC_SOURCES_DIR}/libltdl/loaders/dlopen.c
45 ${UNIX_ODBC_SOURCES_DIR}/libltdl/loaders/preopen.c
46 ${UNIX_ODBC_SOURCES_DIR}/libltdl/lt__alloc.c
47 ${UNIX_ODBC_SOURCES_DIR}/libltdl/lt__strl.c
48 ${UNIX_ODBC_SOURCES_DIR}/libltdl/lt_dlloader.c
49 ${UNIX_ODBC_SOURCES_DIR}/libltdl/lt_error.c
50 ${UNIX_ODBC_SOURCES_DIR}/libltdl/ltdl.c
51 ${UNIX_ODBC_SOURCES_DIR}/libltdl/slist.c
52 )
53 else()
54 check_include_file("libltdl/lt_dlloader.h" HAVE_LT_DLLOADER_H)
55 if (NOT HAVE_LT_DLLOADER_H)
56 message(FATAL_ERROR "Please install the libltdl-dev package")
57 endif()
58
59 link_libraries(ltdl)
60 endif()
61
62
63 include_directories(
64 ${CMAKE_CURRENT_BINARY_DIR}/AUTOGENERATED
65 ${UNIX_ODBC_SOURCES_DIR}/include
66 ${UNIX_ODBC_SOURCES_DIR}/DriverManager
67 )
68
69 file(GLOB UNIX_ODBC_SOURCES
70 ${UNIX_ODBC_SOURCES_DIR}/cur/*.c
71 ${UNIX_ODBC_SOURCES_DIR}/DriverManager/*.c
72 ${UNIX_ODBC_SOURCES_DIR}/odbcinst/*.c
73 ${UNIX_ODBC_SOURCES_DIR}/ini/*.c
74 ${UNIX_ODBC_SOURCES_DIR}/log/*.c
75 ${UNIX_ODBC_SOURCES_DIR}/lst/*.c
76 )
77
78 list(REMOVE_ITEM UNIX_ODBC_SOURCES
79 ${UNIX_ODBC_SOURCES_DIR}/cur/SQLConnect.c
80 ${UNIX_ODBC_SOURCES_DIR}/cur/SQLGetDiagRec.c
81 )
82
83
84 set(ASCII_ENCODING "auto-search")
85 set(SYSTEM_FILE_PATH "/etc")
86 set(DEFLIB_PATH "/usr/lib")
87 set(ENABLE_DRIVER_ICONV ON) # Enables support for encodings
88
89 set(STDC_HEADERS 1)
90 set(UNIXODBC ON)
91 set(UNIXODBC_SOURCE ON) # This makes "intptr_t" to be defined
92 set(ICONV_CONST ON)
93 set(STRICT_ODBC_ERROR ON)
94
95 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
96 set(PLATFORM64 1)
97 endif()
98
99 list(GET CMAKE_FIND_LIBRARY_SUFFIXES 0 SHLIBEXT)
100
101 check_include_file("alloca.h" HAVE_ALLOCA_H)
102 check_include_file("argz.h" HAVE_ARGZ_H)
103 check_include_file("crypt.h" HAVE_CRYPT_H)
104 check_include_file("dirent.h" HAVE_DIRENT_H)
105 check_include_file("dlfcn.h" HAVE_DLFCN_H)
106 check_include_file("inttypes.h" HAVE_INTTYPES_H)
107 check_include_file("langinfo.h" HAVE_LANGINFO_H)
108 check_include_file("crypt.h" HAVE_CRYPT_H)
109 check_include_file("limits.h" HAVE_LIMITS_H)
110 check_include_file("locale.h" HAVE_LOCALE_H)
111 check_include_file("malloc.h" HAVE_MALLOC_H)
112 check_include_file("memory.h" HAVE_MEMORY_H)
113 check_include_file("pwd.h" HAVE_PWD_H)
114 check_include_file("stdarg.h" HAVE_STDARG_H)
115 check_include_file("stdlib.h" HAVE_STDLIB_H)
116 check_include_file("string.h" HAVE_STRING_H)
117 check_include_file("strings.h" HAVE_STRINGS_H)
118 check_include_file("time.h" HAVE_TIME_H)
119 check_include_file("sys/sem.h" HAVE_SYS_SEM_H)
120 check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
121 check_include_file("sys/time.h" HAVE_SYS_TIME_H)
122 check_include_file("sys/timeb.h" HAVE_SYS_TIMEB_H)
123 check_include_file("unistd.h" HAVE_UNISTD_H)
124 check_include_file("readline/readline.h" HAVE_READLINE_H)
125 check_include_file("readline/history.h" HAVE_READLINE_HISTORY_H)
126
127 check_symbol_exists(alloca "alloca.h" HAVE_ALLOCA)
128 check_symbol_exists(argz_add "argz.h" HAVE_ARGZ_ADD)
129 check_symbol_exists(argz_append "argz.h" HAVE_ARGZ_APPEND)
130 check_symbol_exists(argz_count "argz.h" HAVE_ARGZ_COUNT)
131 check_symbol_exists(argz_create_sep "argz.h" HAVE_ARGZ_CREATE_SEP)
132 check_symbol_exists(argz_insert "argz.h" HAVE_ARGZ_INSERT)
133 check_symbol_exists(argz_next "argz.h" HAVE_ARGZ_NEXT)
134 check_symbol_exists(argz_stringify "argz.h" HAVE_ARGZ_STRINGIFY)
135
136 check_function_exists(atoll HAVE_ATOLL)
137 check_function_exists(closedir HAVE_CLOSEDIR)
138 check_function_exists(endpwent HAVE_ENDPWENT)
139
140 if (HAVE_ARGZ_H)
141 set(HAVE_WORKING_ARGZ 1)
142 endif()
143
144 find_package(Threads)
145 if (Threads_FOUND)
146 set(HAVE_LIBPTHREAD 1)
147 endif ()
148
149 set(CMAKE_REQUIRED_LIBRARIES)
150 if (HAVE_DLFCN_H)
151 list(APPEND CMAKE_REQUIRED_LIBRARIES "dl")
152 endif()
153 if (HAVE_CRYPT_H)
154 list(APPEND CMAKE_REQUIRED_LIBRARIES "crypt")
155 endif()
156 if (HAVE_READLINE_H)
157 list(APPEND CMAKE_REQUIRED_LIBRARIES "readline")
158 endif()
159 if (HAVE_LT_DLLOADER_H)
160 set(HAVE_LIBDLLOADER 0) # to improve
161 set(HAVE_LTDL 1) # to improve
162 endif()
163
164 check_function_exists(dlerror HAVE_DLERROR)
165 check_function_exists(dlloader_init HAVE_LIBDLLOADER)
166 check_function_exists(dlopen HAVE_LIBDL)
167 check_function_exists(encrypt HAVE_LIBCRYPT)
168 check_function_exists(ftime HAVE_FTIME)
169 check_function_exists(getpwuid HAVE_GETPWUID)
170 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
171 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
172 check_function_exists(getuid HAVE_GETUID)
173 check_function_exists(iconv HAVE_ICONV)
174 check_function_exists(localtime_r HAVE_LOCALTIME_R)
175 check_function_exists(opendir HAVE_OPENDIR)
176 check_function_exists(putenv HAVE_PUTENV)
177 check_function_exists(readdir HAVE_READDIR)
178 check_function_exists(readline HAVE_READLINE)
179 check_function_exists(setenv HAVE_SETENV)
180 check_function_exists(setlocale HAVE_SETLOCALE)
181 check_function_exists(socket HAVE_SOCKET)
182 check_function_exists(strcasecmp HAVE_STRCASECMP)
183 check_function_exists(strchr HAVE_STRCHR)
184 check_function_exists(strdup HAVE_STRDUP)
185 check_function_exists(strncasecmp HAVE_STRNCASECMP)
186 check_function_exists(strstr HAVE_STRSTR)
187 check_function_exists(strtol HAVE_STRTOL)
188 check_function_exists(strtoll HAVE_STRTOLL)
189 check_function_exists(time HAVE_TIME)
190 check_function_exists(vprintf HAVE_VPRINTF)
191 check_function_exists(vsnprintf HAVE_VSNPRINTF)
192
193 set(CMAKE_EXTRA_INCLUDE_FILES)
194 if (HAVE_ARGZ_H)
195 list(APPEND CMAKE_EXTRA_INCLUDE_FILES "argz.h")
196 endif()
197
198 check_type_size("long" SIZEOF_LONG)
199 check_type_size("long int" SIZEOF_LONG_INT)
200
201 check_type_size("error_t" HAVE_ERROR_T)
202 if (DEFINED HAVE_ERROR_T)
203 set(HAVE_ERROR_T 1)
204 endif()
205
206 check_type_size("long long" HAVE_LONG_LONG)
207 if (DEFINED HAVE_LONG_LONG)
208 set(HAVE_LONG_LONG 1)
209 endif()
210
211 check_type_size("nl_langinfo" HAVE_LANGINFO_CODESET)
212 if (DEFINED HAVE_LANGINFO_CODESET)
213 set(HAVE_LANGINFO_CODESET 1) # to improve
214 set(HAVE_NL_LANGINFO 1)
215 endif()
216
217 check_type_size("ptrdiff_t" HAVE_PTRDIFF_T)
218 if (DEFINED HAVE_PTRDIFF_T)
219 set(HAVE_PTRDIFF_T 1)
220 endif()
221
222 configure_file(
223 ${CMAKE_CURRENT_LIST_DIR}/../Odbc/config.h.in
224 ${CMAKE_CURRENT_BINARY_DIR}/AUTOGENERATED/config.h
225 )
226
227 configure_file(
228 ${CMAKE_CURRENT_LIST_DIR}/../Odbc/config.h.in
229 ${CMAKE_CURRENT_BINARY_DIR}/AUTOGENERATED/unixodbc_conf.h
230 )
231
232 add_definitions(
233 -DHAVE_CONFIG_H=1
234 )
235
236 else()
237 check_include_file("sqlext.h" HAVE_UNIX_ODBC_H)
238 if (NOT HAVE_UNIX_ODBC_H)
239 message(FATAL_ERROR "Please install the unixodbc-dev package")
240 endif()
241
242 check_include_file("libltdl/lt_dlloader.h" HAVE_LT_DLLOADER_H)
243 if (NOT HAVE_LT_DLLOADER_H)
244 message(FATAL_ERROR "Please install the libltdl-dev package")
245 endif()
246
247 link_libraries(odbc ltdl)
248 endif()