@@ -60,7 +60,7 @@ if(EXT_ODBC AND EXT_PDO_ODBC AND NOT EXT_ODBC_TYPE STREQUAL EXT_PDO_ODBC_TYPE)
6060  )
6161endif ()
6262
63- # Some ODBC drivers require setting ODBC_LIBRARY manually to find package . 
63+ # Some ODBC drivers require setting ODBC_LIBRARY manually to be found . 
6464if (
6565  EXT_ODBC
6666  AND  NOT  EXT_ODBC_TYPE MATCHES  "auto|unixODBC|iODBC" 
@@ -120,12 +120,6 @@ target_sources(
120120
121121target_compile_definitions (php_odbc PRIVATE  ZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
122122
123- # TODO: Can this be fixed better? 
124- get_target_property (extension_type php_odbc TYPE )
125- if (NOT  extension_type MATCHES  "^(MODULE|SHARED)_LIBRARY$" )
126-   target_link_libraries (php_odbc PRIVATE  PHP::main)
127- endif ()
128- 
129123if (NOT  EXT_ODBC_TYPE STREQUAL  "auto" )
130124  set (ODBC_USE_DRIVER "${EXT_ODBC_TYPE} " )
131125endif ()
@@ -137,48 +131,65 @@ set_package_properties(
137131    PURPOSE "Necessary to enable the odbc extension." 
138132)
139133
140- if (ODBC_DRIVER AND  EXT_ODBC_TYPE STREQUAL  "auto" )
141-   set (EXT_ODBC_TYPE "${ODBC_DRIVER} " )
134+ target_link_libraries (php_odbc PRIVATE  ODBC::ODBC)
135+ 
136+ # Sanity checks. 
137+ if (EXT_ODBC_TYPE STREQUAL  "ibm-db2"  AND  TARGET  ODBC::ODBC)
138+   cmake_push_check_state(RESET)
139+     set (CMAKE_REQUIRED_LIBRARIES ODBC::ODBC)
140+     check_include_file(sqlcli1.h HAVE_SQLCLI1_H)
141+     check_library_exists(ODBC::ODBC ""  SQLExecute HAVE_SQLEXECUTE)
142+   cmake_pop_check_state()
143+   if (NOT  HAVE_SQLCLI1_H)
144+     message (FATAL_ERROR "Required <sqlcli1.h> header file not found" )
145+   endif ()
146+   if (NOT  HAVE_SQLEXECUTE)
147+     message (
148+       FATAL_ERROR
149+       "ODBC build test failed. SQLExecute not found. The DB2 environment " 
150+       "needs to be sourced. Run the command line:\n " 
151+       "  . $IBM_DB2/db2profile" 
152+     )
153+   endif ()
142154endif ()
143155
144- target_link_libraries (php_odbc PRIVATE  ODBC::ODBC)
156+ ################################################################################ 
157+ # Set variables for main/build-defs.h and config.h file. 
158+ ################################################################################ 
159+ 
160+ # Set PHP_ODBC_TYPE for configuration header value. 
161+ if (ODBC_DRIVER STREQUAL  "Windows" )
162+   set (PHP_ODBC_TYPE "Win32" )
163+ elseif (
164+   (ODBC_DRIVER STREQUAL  "iODBC"  AND  EXT_ODBC_TYPE STREQUAL  "auto" )
165+   OR  EXT_ODBC_TYPE STREQUAL  "iODBC" 
166+ )
167+   # To match the native build system string: 
168+   set (PHP_ODBC_TYPE "iodbc" )
169+ elseif (ODBC_DRIVER AND  EXT_ODBC_TYPE STREQUAL  "auto" )
170+   set (PHP_ODBC_TYPE "${ODBC_DRIVER} " )
171+ elseif (EXT_ODBC_TYPE STREQUAL  "custom" )
172+   # To match the native build system string: 
173+   set (PHP_ODBC_TYPE custom-odbc)
174+ else ()
175+   set (PHP_ODBC_TYPE "${EXT_ODBC_TYPE} " )
176+ endif ()
145177
146- if (EXT_ODBC_TYPE  STREQUAL  "adabas" )
178+ if (PHP_ODBC_TYPE  STREQUAL  "adabas" )
147179  set (HAVE_ADABAS 1)
148- elseif (EXT_ODBC_TYPE  STREQUAL  "dbmaker" )
180+ elseif (PHP_ODBC_TYPE  STREQUAL  "dbmaker" )
149181  set (HAVE_DBMAKER 1)
150- elseif (EXT_ODBC_TYPE  MATCHES  "^(empress|empress-bcs)$" )
182+ elseif (PHP_ODBC_TYPE  MATCHES  "^(empress|empress-bcs)$" )
151183  set (HAVE_EMPRESS 1)
152- elseif (EXT_ODBC_TYPE  STREQUAL  "esoob" )
184+ elseif (PHP_ODBC_TYPE  STREQUAL  "esoob" )
153185  set (HAVE_ESOOB 1)
154- 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 ()
186+ elseif (PHP_ODBC_TYPE STREQUAL  "ibm-db2" )
174187  set (HAVE_IBMDB2 1)
175- elseif (EXT_ODBC_TYPE  STREQUAL  "iODBC " )
188+ elseif (PHP_ODBC_TYPE  STREQUAL  "iodbc " )
176189  set (HAVE_IODBC 1)
177-   # To match the native build system string: 
178-   set (EXT_ODBC_TYPE iodbc)
179- elseif (EXT_ODBC_TYPE STREQUAL  "sapdb" )
190+ elseif (PHP_ODBC_TYPE STREQUAL  "sapdb" )
180191  set (HAVE_SAPDB 1)
181- elseif (EXT_ODBC_TYPE  STREQUAL  "solid" )
192+ elseif (PHP_ODBC_TYPE  STREQUAL  "solid" )
182193  # Set based on the Solid version: 
183194  if (ODBC_LIBRARY MATCHES  "23\. (a|so)$" )
184195    set (HAVE_SOLID 1)
@@ -195,21 +206,16 @@ elseif(EXT_ODBC_TYPE STREQUAL "solid")
195206  elseif (CMAKE_SYSTEM_NAME  STREQUAL  "FreeBSD" )
196207    set (SS_FBX 1)
197208  endif ()
198- elseif (EXT_ODBC_TYPE  STREQUAL  "unixODBC" )
209+ elseif (PHP_ODBC_TYPE  STREQUAL  "unixODBC" )
199210  set (HAVE_UNIXODBC 1)
200- elseif (EXT_ODBC_TYPE  STREQUAL  "custom" )
211+ elseif (PHP_ODBC_TYPE  STREQUAL  "custom-odbc " )
201212  set (HAVE_CODBC 1)
202-   # To match the native build system string: 
203-   set (EXT_ODBC_TYPE custom-odbc)
204213endif ()
205214
206215if (NOT  EXT_ODBC_TYPE MATCHES  "^(dbmaker|solid)$" )
207216  set (HAVE_SQLDATASOURCES 1)
208217endif ()
209218
210- ################################################################################ 
211- # Set ODBC_* variables for main/build-defs.h file. 
212- ################################################################################ 
213219if (TARGET  ODBC::ODBC)
214220  block(PROPAGATE PHP_ODBC_BUILD_DEFINITIONS_CODE)
215221    get_target_property (definitions  ODBC::ODBC INTERFACE_COMPILE_DEFINITIONS )
@@ -249,11 +255,10 @@ if(TARGET ODBC::ODBC)
249255    set (PHP_ODBC_CFLAGS "${cflags} "  CACHE  INTERNAL  "ODBC CFLAGS" )
250256    set (PHP_ODBC_LFLAGS "${ldflags} "  CACHE  INTERNAL  "ODBC linker flags" )
251257    set (PHP_ODBC_LIBS "${libs} "  CACHE  INTERNAL  "ODBC libraries" )
252-     set (PHP_ODBC_TYPE "${EXT_ODBC_TYPE } "  CACHE  INTERNAL  "ODBC type" )
258+     set (PHP_ODBC_TYPE "${PHP_ODBC_TYPE } "  CACHE  INTERNAL  "ODBC type" )
253259
254260    if (
255-       NOT  CMAKE_SYSTEM_NAME  STREQUAL  "Windows" 
256-       AND  NOT  PHP_SOURCE_DIR
261+       NOT  ODBC_DRIVER STREQUAL  "Windows" 
257262      AND  NOT  EXISTS  ${PHP_SOURCE_DIR} /main/build -defs.h.in
258263    )
259264      set (
0 commit comments