FindODBC.cmake 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #
  2. # Copyright (c) 2008-2020 the Urho3D project.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. #
  22. # Find ODBC driver manager
  23. #
  24. # ODBC_FOUND
  25. # ODBC_INCLUDE_DIRS
  26. # ODBC_LIBRARIES
  27. # ODBC_DEFINES
  28. # ODBC_VERSION
  29. #
  30. if (WIN32)
  31. set (ODBC_INCLUDE_DIRS " ") # The headers should be available in the default include search path
  32. set (ODBC_LIBRARIES odbc32 odbccp32 ws2_32) # This should be also the case for MinGW cross-compiler toolchain
  33. set (ODBC_DEFINES)
  34. set (ODBC_VERSION 3) # Assume it is 3
  35. else ()
  36. # On Unix-like host system, use the ODBC config tool
  37. find_program (ODBC_CONFIG NAMES odbc_config iodbc-config DOC "ODBC config tool" NO_CMAKE_FIND_ROOT_PATH)
  38. if (ODBC_CONFIG AND NOT ODBC_INCLUDE_DIRS AND NOT ODBC_LIBRARIES) # Only do this once
  39. # Get ODBC compile and link flags and turn them into include dirs and libraries list
  40. execute_process (COMMAND ${ODBC_CONFIG} --cflags OUTPUT_VARIABLE ODBC_COMPILE_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
  41. execute_process (COMMAND ${ODBC_CONFIG} --libs OUTPUT_VARIABLE ODBC_LINK_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
  42. string (REGEX REPLACE " *-I" ";" ODBC_INCLUDE_DIRS "${ODBC_COMPILE_FLAGS}") # Stringify in case it returns empty string
  43. string (REGEX REPLACE " *-l" ";" ODBC_LIBRARIES "${ODBC_LINK_FLAGS}")
  44. list (GET ODBC_INCLUDE_DIRS 0 ODBC_DEFINES) # Assume the list of defines always come before the list of include dirs
  45. list (REMOVE_AT ODBC_INCLUDE_DIRS 0)
  46. list (REMOVE_AT ODBC_LIBRARIES 0)
  47. set (ODBC_INCLUDE_DIRS ${ODBC_INCLUDE_DIRS} CACHE PATH "ODBC include directory")
  48. set (ODBC_LIBRARIES ${ODBC_LIBRARIES} CACHE STRING "ODBC library")
  49. set (ODBC_DEFINES ${ODBC_DEFINES} CACHE STRING "ODBC defines")
  50. # Get ODBC version
  51. execute_process (COMMAND ${ODBC_CONFIG} --odbcversion OUTPUT_VARIABLE ODBC_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
  52. set (ODBC_VERSION ${ODBC_VERSION} CACHE INTERNAL "ODBC version")
  53. endif ()
  54. endif ()
  55. include (FindPackageHandleStandardArgs)
  56. find_package_handle_standard_args (ODBC REQUIRED_VARS ODBC_LIBRARIES ODBC_INCLUDE_DIRS VERSION_VAR ODBC_VERSION FAIL_MESSAGE "Could NOT find ODBC driver manager, please install the development package for unixODBC or libiodbc")
  57. mark_as_advanced (ODBC_INCLUDE_DIRS ODBC_LIBRARIES ODBC_DEFINES ODBC_CONFIG)