@@ -11,32 +11,51 @@ Modifications from upstream:
11
11
12
12
* `ODBC_DRIVER`
13
13
14
- Name of the found driver, if any. For example, `unixODBC`, `iODBC`.
14
+ Name of the found driver, if any. For example, `unixODBC`, `iODBC`. On
15
+ Windows in MinGW environment it is set to `unixODBC`, and to `Windows` for
16
+ the rest of the Windows system.
15
17
16
18
* `ODBC_VERSION`
17
19
18
20
Version of the found ODBC library if it was retrieved from config utilities.
19
21
20
22
* Additional cache variables:
21
23
22
- * `ODBC_COMPILE_DEFINITIONS` - a `;`-list of compile definitions.
23
- * `ODBC_COMPILE_OPTIONS` - a `;`-list of compile options.
24
- * `ODBC_LINK_OPTIONS` - a `;`-list of linker options.
24
+ * `ODBC_COMPILE_DEFINITIONS`
25
+
26
+ A `;`-list of compile definitions.
27
+
28
+ * `ODBC_COMPILE_OPTIONS`
29
+
30
+ A `;`-list of compile options.
31
+
32
+ * `ODBC_LINK_OPTIONS`
33
+
34
+ A `;`-list of linker options.
35
+
36
+ * `ODBC_LIBRARY_DIR`
37
+
38
+ The path to the ODBC library directory that contains the ODBC library.
25
39
26
40
* Additional hints:
27
41
28
42
* `ODBC_USE_DRIVER`
29
43
30
44
Set to `unixODBC` or `iODBC` to limit searching for specific ODBC driver
31
- instead of any driver.
45
+ instead of any driver. On Windows, the searched driver will be the core ODBC
46
+ Windows implementation only. On Windows in MinGW environment, there is at
47
+ the time of writing `unixODBC` implementation available in the default
48
+ MinGW installation and as a standalone package. The driver name is
49
+ case-insensitive and if supported it will be adjusted to the expected case.
32
50
33
51
* Added pkg-config integration.
34
52
35
53
* Fixed limitation where the upstream module can't (yet) select which specific
36
- ODBC driver to use. Except on Windows, where the driver searching is the same
37
- as upstream.
54
+ ODBC driver to use.
38
55
39
56
* Added package meta-data for FeatureSummary.
57
+
58
+ * Fixed finding ODBC on Windows and MinGW.
40
59
#]=============================================================================]
41
60
42
61
include (FeatureSummary )
@@ -59,15 +78,54 @@ mark_as_advanced(
59
78
ODBC_LINK_OPTIONS
60
79
)
61
80
62
- ### Try Windows Kits ##########################################################
63
- if (WIN32 )
81
+ # Adjust ODBC driver string case sensitivity.
82
+ if (ODBC_USE_DRIVER )
83
+ string (TOLOWER "${ODBC_USE_DRIVER} " _odbc_use_driver )
84
+ if (_odbc_use_driver STREQUAL "unixodbc" )
85
+ set (ODBC_USE_DRIVER "unixODBC" )
86
+ elseif (_odbc_use_driver STREQUAL "iodbc" )
87
+ set (ODBC_USE_DRIVER "iODBC" )
88
+ endif ()
89
+ unset (_odbc_use_driver )
90
+ endif ()
91
+
92
+ ### Try unixODBC or iODBC config program ######################################
93
+ if (ODBC_USE_DRIVER STREQUAL "unixODBC" )
94
+ set (_odbc_config_names odbc_config )
95
+ elseif (ODBC_USE_DRIVER STREQUAL "iODBC" )
96
+ set (_odbc_config_names iodbc-config )
97
+ else ()
98
+ set (_odbc_config_names odbc_config iodbc-config )
99
+ endif ()
100
+
101
+ find_program (ODBC_CONFIG
102
+ NAMES ${_odbc_config_names}
103
+ DOC "Path to unixODBC or iODBC config program" )
104
+ mark_as_advanced (ODBC_CONFIG )
105
+
106
+ ### Try pkg-config ############################################################
107
+ if (NOT ODBC_CONFIG )
108
+ find_package (PkgConfig QUIET )
109
+ if (PKG_CONFIG_FOUND )
110
+ if (ODBC_USE_DRIVER STREQUAL "unixODBC" )
111
+ pkg_check_modules (PC_ODBC QUIET odbc )
112
+ elseif (ODBC_USE_DRIVER STREQUAL "iODBC" )
113
+ pkg_check_modules (PC_ODBC QUIET libiodbc )
114
+ else ()
115
+ pkg_search_module (PC_ODBC QUIET odbc libiodbc )
116
+ endif ()
117
+ endif ()
118
+ endif ()
119
+
120
+ ### Try Windows ###############################################################
121
+ if (NOT ODBC_CONFIG AND NOT PC_ODBC_FOUND AND CMAKE_SYSTEM_NAME STREQUAL "Windows" )
64
122
# List names of ODBC libraries on Windows
65
123
if (NOT MINGW )
66
- set (ODBC_LIBRARY odbc32.lib )
124
+ set (_odbc_lib_names odbc32.lib )
67
125
else ()
68
- set (ODBC_LIBRARY libodbc32.a )
126
+ set (_odbc_lib_names libodbc32.a )
69
127
endif ()
70
- set ( _odbc_lib_names odbc32; )
128
+ list ( APPEND _odbc_lib_names odbc32 )
71
129
72
130
# List additional libraries required to use ODBC library
73
131
if (MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Intel" )
@@ -77,23 +135,7 @@ if(WIN32)
77
135
endif ()
78
136
endif ()
79
137
80
- ### Try unixODBC or iODBC config program ######################################
81
- if (UNIX )
82
- if (ODBC_USE_DRIVER MATCHES "^(unixODBC|unixodbc|UNIXODBC)$" )
83
- set (_odbc_config_names odbc_config )
84
- elseif (ODBC_USE_DRIVER MATCHES "^(iODBC|iodbc|IODBC)$" )
85
- set (_odbc_config_names iodbc-config )
86
- else ()
87
- set (_odbc_config_names odbc_config iodbc-config )
88
- endif ()
89
-
90
- find_program (ODBC_CONFIG
91
- NAMES ${_odbc_config_names}
92
- DOC "Path to unixODBC or iODBC config program" )
93
- mark_as_advanced (ODBC_CONFIG )
94
- endif ()
95
-
96
- if (UNIX AND ODBC_CONFIG )
138
+ if (ODBC_CONFIG )
97
139
# unixODBC and iODBC accept unified command line options
98
140
execute_process (COMMAND ${ODBC_CONFIG} --cflags
99
141
OUTPUT_VARIABLE _cflags OUTPUT_STRIP_TRAILING_WHITESPACE )
@@ -128,25 +170,11 @@ if(UNIX AND ODBC_CONFIG)
128
170
unset (_libs )
129
171
endif ()
130
172
131
- ### Try pkg-config ############################################################
132
- if (NOT ODBC_CONFIG )
133
- find_package (PkgConfig QUIET )
134
- if (PKG_CONFIG_FOUND )
135
- if (ODBC_USE_DRIVER MATCHES "^(unixODBC|unixodbc|UNIXODBC)$" )
136
- pkg_check_modules (PC_ODBC QUIET odbc )
137
- elseif (ODBC_USE_DRIVER MATCHES "^(iODBC|iodbc|IODBC)$" )
138
- pkg_check_modules (PC_ODBC QUIET libiodbc )
139
- else ()
140
- pkg_search_module (PC_ODBC QUIET odbc libiodbc )
141
- endif ()
142
- endif ()
143
- endif ()
144
-
145
173
### Try unixODBC or iODBC in include/lib filesystems ##########################
146
174
if (UNIX AND NOT ODBC_CONFIG )
147
- if (ODBC_USE_DRIVER MATCHES "^( unixODBC|unixodbc|UNIXODBC)$ " )
175
+ if (ODBC_USE_DRIVER STREQUAL " unixODBC" )
148
176
set (_odbc_lib_names odbc;unixodbc; )
149
- elseif (ODBC_USE_DRIVER MATCHES "^( iODBC|iodbc|IODBC)$ " )
177
+ elseif (ODBC_USE_DRIVER STREQUAL " iODBC" )
150
178
set (_odbc_lib_names iodbc; )
151
179
else ()
152
180
# List names of both ODBC libraries, unixODBC and iODBC
@@ -160,7 +188,7 @@ find_path(ODBC_INCLUDE_DIR
160
188
PATHS ${_odbc_include_paths}
161
189
HINTS ${PC_ODBC_INCLUDE_DIRS} )
162
190
163
- if (NOT ODBC_INCLUDE_DIR AND WIN32 )
191
+ if (NOT ODBC_INCLUDE_DIR AND CMAKE_SYSTEM_NAME STREQUAL "Windows" )
164
192
set (ODBC_INCLUDE_DIR "" )
165
193
endif ()
166
194
@@ -184,6 +212,17 @@ if(NOT ODBC_LIBRARY)
184
212
endforeach ()
185
213
endif ()
186
214
215
+ # Find library directory when ODBC_LIBRARY is set as a library name. For
216
+ # example, when looking for ODBC with ODBC_ROOT or CMAKE_PREFIX_PATH set.
217
+ if (NOT ODBC_LIBRARY_DIR AND ODBC_LIBRARY AND NOT IS_ABSOLUTE "${ODBC_LIBRARY} " )
218
+ find_library (ODBC_LIBRARY_DIR ${ODBC_LIBRARY} PATH_SUFFIXES odbc )
219
+ if (ODBC_LIBRARY_DIR )
220
+ cmake_path (GET ODBC_LIBRARY_DIR PARENT_PATH _parent )
221
+ set_property (CACHE ODBC_LIBRARY_DIR PROPERTY VALUE ${_parent} )
222
+ unset (_parent )
223
+ endif ()
224
+ endif ()
225
+
187
226
# Unset internal lists as no longer used
188
227
unset (_odbc_include_paths )
189
228
unset (_odbc_lib_paths )
@@ -213,15 +252,15 @@ block(PROPAGATE ODBC_VERSION)
213
252
OUTPUT_STRIP_TRAILING_WHITESPACE
214
253
ERROR_QUIET
215
254
)
216
- if (_odbc_version MATCHES "[0-9]+\. [0-9.]* " )
255
+ if (_odbc_version MATCHES "[0-9]+\. [0-9.]+ " )
217
256
set (ODBC_VERSION ${_odbc_version} )
218
257
endif ()
219
258
endif ()
220
259
endblock ()
221
260
222
261
### Set result variables ######################################################
223
262
set (_odbc_required_vars ODBC_LIBRARY )
224
- if (NOT WIN32 )
263
+ if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" )
225
264
list (APPEND _odbc_required_vars ODBC_INCLUDE_DIR )
226
265
endif ()
227
266
@@ -262,6 +301,10 @@ if(ODBC_FOUND)
262
301
add_library (ODBC::ODBC INTERFACE IMPORTED )
263
302
set_target_properties (ODBC::ODBC PROPERTIES
264
303
IMPORTED_LIBNAME "${ODBC_LIBRARY} " )
304
+
305
+ if (EXISTS "${ODBC_LIBRARY_DIR} " )
306
+ target_link_directories (ODBC::ODBC INTERFACE "${ODBC_LIBRARY_DIR} " )
307
+ endif ()
265
308
endif ()
266
309
set_target_properties (ODBC::ODBC PROPERTIES
267
310
INTERFACE_INCLUDE_DIRECTORIES "${ODBC_INCLUDE_DIR} " )
@@ -305,7 +348,9 @@ if(ODBC_FOUND)
305
348
elseif (PC_ODBC_MODULE_NAME STREQUAL "odbc" )
306
349
set (ODBC_DRIVER "unixODBC" )
307
350
endif ()
308
- elseif (WIN32 )
351
+ elseif (MINGW )
352
+ set (ODBC_DRIVER "unixODBC" )
353
+ elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
309
354
set (ODBC_DRIVER "Windows" )
310
355
endif ()
311
356
0 commit comments