Skip to content

Commit bede678

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
2 parents 150f08b + bf13397 commit bede678

File tree

4 files changed

+125
-54
lines changed

4 files changed

+125
-54
lines changed

cmake/cmake/modules/FindODBC.cmake

Lines changed: 94 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,51 @@ Modifications from upstream:
1111
1212
* `ODBC_DRIVER`
1313
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.
1517
1618
* `ODBC_VERSION`
1719
1820
Version of the found ODBC library if it was retrieved from config utilities.
1921
2022
* Additional cache variables:
2123
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.
2539
2640
* Additional hints:
2741
2842
* `ODBC_USE_DRIVER`
2943
3044
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.
3250
3351
* Added pkg-config integration.
3452
3553
* 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.
3855
3956
* Added package meta-data for FeatureSummary.
57+
58+
* Fixed finding ODBC on Windows and MinGW.
4059
#]=============================================================================]
4160

4261
include(FeatureSummary)
@@ -59,15 +78,54 @@ mark_as_advanced(
5978
ODBC_LINK_OPTIONS
6079
)
6180

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")
64122
# List names of ODBC libraries on Windows
65123
if(NOT MINGW)
66-
set(ODBC_LIBRARY odbc32.lib)
124+
set(_odbc_lib_names odbc32.lib)
67125
else()
68-
set(ODBC_LIBRARY libodbc32.a)
126+
set(_odbc_lib_names libodbc32.a)
69127
endif()
70-
set(_odbc_lib_names odbc32;)
128+
list(APPEND _odbc_lib_names odbc32)
71129

72130
# List additional libraries required to use ODBC library
73131
if(MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
@@ -77,23 +135,7 @@ if(WIN32)
77135
endif()
78136
endif()
79137

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)
97139
# unixODBC and iODBC accept unified command line options
98140
execute_process(COMMAND ${ODBC_CONFIG} --cflags
99141
OUTPUT_VARIABLE _cflags OUTPUT_STRIP_TRAILING_WHITESPACE)
@@ -128,25 +170,11 @@ if(UNIX AND ODBC_CONFIG)
128170
unset(_libs)
129171
endif()
130172

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-
145173
### Try unixODBC or iODBC in include/lib filesystems ##########################
146174
if(UNIX AND NOT ODBC_CONFIG)
147-
if(ODBC_USE_DRIVER MATCHES "^(unixODBC|unixodbc|UNIXODBC)$")
175+
if(ODBC_USE_DRIVER STREQUAL "unixODBC")
148176
set(_odbc_lib_names odbc;unixodbc;)
149-
elseif(ODBC_USE_DRIVER MATCHES "^(iODBC|iodbc|IODBC)$")
177+
elseif(ODBC_USE_DRIVER STREQUAL "iODBC")
150178
set(_odbc_lib_names iodbc;)
151179
else()
152180
# List names of both ODBC libraries, unixODBC and iODBC
@@ -160,7 +188,7 @@ find_path(ODBC_INCLUDE_DIR
160188
PATHS ${_odbc_include_paths}
161189
HINTS ${PC_ODBC_INCLUDE_DIRS})
162190

163-
if(NOT ODBC_INCLUDE_DIR AND WIN32)
191+
if(NOT ODBC_INCLUDE_DIR AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
164192
set(ODBC_INCLUDE_DIR "")
165193
endif()
166194

@@ -184,6 +212,17 @@ if(NOT ODBC_LIBRARY)
184212
endforeach()
185213
endif()
186214

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+
187226
# Unset internal lists as no longer used
188227
unset(_odbc_include_paths)
189228
unset(_odbc_lib_paths)
@@ -213,15 +252,15 @@ block(PROPAGATE ODBC_VERSION)
213252
OUTPUT_STRIP_TRAILING_WHITESPACE
214253
ERROR_QUIET
215254
)
216-
if(_odbc_version MATCHES "[0-9]+\.[0-9.]*")
255+
if(_odbc_version MATCHES "[0-9]+\.[0-9.]+")
217256
set(ODBC_VERSION ${_odbc_version})
218257
endif()
219258
endif()
220259
endblock()
221260

222261
### Set result variables ######################################################
223262
set(_odbc_required_vars ODBC_LIBRARY)
224-
if(NOT WIN32)
263+
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
225264
list(APPEND _odbc_required_vars ODBC_INCLUDE_DIR)
226265
endif()
227266

@@ -262,6 +301,10 @@ if(ODBC_FOUND)
262301
add_library(ODBC::ODBC INTERFACE IMPORTED)
263302
set_target_properties(ODBC::ODBC PROPERTIES
264303
IMPORTED_LIBNAME "${ODBC_LIBRARY}")
304+
305+
if(EXISTS "${ODBC_LIBRARY_DIR}")
306+
target_link_directories(ODBC::ODBC INTERFACE "${ODBC_LIBRARY_DIR}")
307+
endif()
265308
endif()
266309
set_target_properties(ODBC::ODBC PROPERTIES
267310
INTERFACE_INCLUDE_DIRECTORIES "${ODBC_INCLUDE_DIR}")
@@ -305,7 +348,9 @@ if(ODBC_FOUND)
305348
elseif(PC_ODBC_MODULE_NAME STREQUAL "odbc")
306349
set(ODBC_DRIVER "unixODBC")
307350
endif()
308-
elseif(WIN32)
351+
elseif(MINGW)
352+
set(ODBC_DRIVER "unixODBC")
353+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
309354
set(ODBC_DRIVER "Windows")
310355
endif()
311356

cmake/cmake/modules/PHP/Set.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ php_set(
132132
```
133133

134134
```sh
135-
cmake -S <source-dir> -B <build-dir> -D VAR=overridden
135+
cmake -B <build-dir> -D VAR=overridden
136136
```
137137

138138
Output:
@@ -157,7 +157,7 @@ php_set(
157157
```
158158

159159
```sh
160-
cmake -S <source-dir> -B <build-dir> -D VAR=unixodbc
160+
cmake -B <build-dir> -D VAR=unixodbc
161161
```
162162

163163
Will output `VAR=unixODBC` and not `VAR=unixodbc`.

cmake/ext/odbc/CMakeLists.txt

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ project(
33
LANGUAGES C
44
)
55

6+
include(CheckIncludeFile)
7+
include(CheckLibraryExists)
68
include(CMakeDependentOption)
9+
include(CMakePushCheckState)
710
include(FeatureSummary)
811
include(PHP/Set)
912

@@ -74,8 +77,9 @@ endif()
7477
php_set(
7578
EXT_ODBC_VERSION
7679
TYPE STRING
77-
IF EXT_ODBC
80+
IF [[EXT_ODBC AND NOT EXT_ODBC_TYPE MATCHES "^(unixODBC|dbmaker)$"]]
7881
VALUE "0x0350"
82+
ELSE_VALUE "0x0350"
7983
DOC
8084
"Hex number to force support for the ODBC specification version. Default: "
8185
"0x0350. Set to special value 0 (zero) or empty to not define explicit "
@@ -148,9 +152,30 @@ elseif(EXT_ODBC_TYPE MATCHES "^(empress|empress-bcs)$")
148152
elseif(EXT_ODBC_TYPE STREQUAL "esoob")
149153
set(HAVE_ESOOB 1)
150154
elseif(EXT_ODBC_TYPE STREQUAL "ibm-db2")
155+
# Sanity check.
156+
if(TARGET ODBC::ODBC)
157+
cmake_push_check_state(RESET)
158+
set(CMAKE_REQUIRED_LIBRARIES ODBC::ODBC)
159+
check_include_file(sqlcli1.h HAVE_SQLCLI1_H)
160+
check_library_exists(ODBC::ODBC "" SQLExecute HAVE_SQLEXECUTE)
161+
cmake_pop_check_state()
162+
if(NOT HAVE_SQLCLI1_H)
163+
message(FATAL_ERROR "Required <sqlcli1.h> header file not found")
164+
endif()
165+
if(NOT HAVE_SQLEXECUTE)
166+
message(
167+
FATAL_ERROR
168+
"ODBC build test failed. SQLExecute not found. The DB2 environment "
169+
"needs to be sourced. Run the command line:\n"
170+
" . $IBM_DB2/db2profile"
171+
)
172+
endif()
173+
endif()
151174
set(HAVE_IBMDB2 1)
152175
elseif(EXT_ODBC_TYPE STREQUAL "iODBC")
153176
set(HAVE_IODBC 1)
177+
# To match the native build system string:
178+
set(EXT_ODBC_TYPE iodbc)
154179
elseif(EXT_ODBC_TYPE STREQUAL "sapdb")
155180
set(HAVE_SAPDB 1)
156181
elseif(EXT_ODBC_TYPE STREQUAL "solid")
@@ -173,8 +198,9 @@ elseif(EXT_ODBC_TYPE STREQUAL "solid")
173198
elseif(EXT_ODBC_TYPE STREQUAL "unixODBC")
174199
set(HAVE_UNIXODBC 1)
175200
elseif(EXT_ODBC_TYPE STREQUAL "custom")
176-
set(EXT_ODBC_TYPE custom-odbc)
177201
set(HAVE_CODBC 1)
202+
# To match the native build system string:
203+
set(EXT_ODBC_TYPE custom-odbc)
178204
endif()
179205

180206
if(NOT EXT_ODBC_TYPE MATCHES "^(dbmaker|solid)$")

cmake/ext/pdo_odbc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ if(TARGET ODBC::ODBC)
159159
message(
160160
FATAL_ERROR
161161
"The ODBC library does not appear to be ODBC 3 compatible (the ODBC 3.0 "
162-
"function SQLAllocHandle not found. Consider using iODBC or unixODBC "
162+
"function SQLAllocHandle not found). Consider using iODBC or unixODBC "
163163
"instead, and load libraries as a driver in that environment. It will "
164164
"emulate the functions required for PDO support."
165165
)

0 commit comments

Comments
 (0)