2
0
Эх сурвалжийг харах

Pass compiler defines from the ODBC config tool to our build system.
Make FindODBC module to prefer unixODBC over libiodbc when both ODBC driver managers are available.

Yao Wei Tjong 姚伟忠 10 жил өмнө
parent
commit
d39a80b1a9

+ 5 - 3
CMake/Modules/FindODBC.cmake

@@ -25,6 +25,7 @@
 #  ODBC_FOUND
 #  ODBC_INCLUDE_DIRS
 #  ODBC_LIBRARIES
+#  ODBC_DEFINES
 #
 
 if (ODBC_FOUND)
@@ -37,13 +38,14 @@ if (WIN32)
     set (ODBC_FOUND 1)
 else ()
     # On Unix-like host system, use the ODBC config tool
-    find_program (ODBC_CONFIG NAMES iodbc-config odbc_config DOC "ODBC config tool" NO_CMAKE_FIND_ROOT_PATH)
+    find_program (ODBC_CONFIG NAMES odbc_config iodbc-config DOC "ODBC config tool" NO_CMAKE_FIND_ROOT_PATH)
     if (ODBC_CONFIG)
         # Get ODBC compile and link flags and turn them into include dirs and libraries list
         execute_process(COMMAND ${ODBC_CONFIG} --cflags OUTPUT_VARIABLE ODBC_COMPILE_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
         execute_process(COMMAND ${ODBC_CONFIG} --libs OUTPUT_VARIABLE ODBC_LINK_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
         string (REGEX REPLACE " *-I" ";" ODBC_INCLUDE_DIRS "${ODBC_COMPILE_FLAGS}")    # Stringify in case it returns empty string
         string (REGEX REPLACE " *-l" ";" ODBC_LIBRARIES "${ODBC_LINK_FLAGS}")
+        list (GET ODBC_INCLUDE_DIRS 0 ODBC_DEFINES)     # Assume the list of defines always come before the list of include dirs
         list (REMOVE_AT ODBC_INCLUDE_DIRS 0)
         list (REMOVE_AT ODBC_LIBRARIES 0)
         set (ODBC_FOUND 1)
@@ -54,8 +56,8 @@ if (ODBC_FOUND)
     include (FindPackageMessage)
     FIND_PACKAGE_MESSAGE (ODBC "Found ODBC driver manager: ${ODBC_LIBRARIES} ${ODBC_INCLUDE_DIRS}" "[${ODBC_LIBRARIES}][${ODBC_INCLUDE_DIRS}]")
 elseif (ODBC_FIND_REQUIRED)
-    message (FATAL_ERROR "Could not find ODBC driver manager, please install the development package of iODBC or UnixODBC")
+    message (FATAL_ERROR "Could not find ODBC driver manager, please install the development package of unixODBC or libiodbc")
 endif ()
 
-mark_as_advanced (ODBC_INCLUDE_DIRS ODBC_LIBRARIES ODBC_CONFIG)
+mark_as_advanced (ODBC_INCLUDE_DIRS ODBC_LIBRARIES ODBC_DEFINES ODBC_CONFIG)
 

+ 3 - 0
Source/ThirdParty/nanodbc/CMakeLists.txt

@@ -30,6 +30,9 @@ define_source_files (GLOB_CPP_PATTERNS src/*.cpp GLOB_H_PATTERNS src/*.h)
 if (ODBC_INCLUDE_DIRS)
     set (INCLUDE_DIRS ${ODBC_INCLUDE_DIRS})
 endif ()
+if (ODBC_DEFINES)
+    add_definitions (${ODBC_DEFINES})
+endif ()
 
 # Setup target
 setup_library ()

+ 0 - 3
Source/Urho3D/CMakeLists.txt

@@ -182,9 +182,6 @@ if (URHO3D_LUA)
     # This is more practical than patching its header files in many places to make them work with relative path
     list (APPEND INCLUDE_DIRS ${CMAKE_BINARY_DIR}/${DEST_INCLUDE_DIR}/ThirdParty/Lua${JIT})
 endif ()
-if (ODBC_INCLUDE_DIRS)  # URHO3D_DATABASE_ODBC is implied
-    list (APPEND INCLUDE_DIRS ${ODBC_INCLUDE_DIRS})
-endif ()
 
 # Setup library output path
 if (ANDROID)