FindODBC.cmake 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #[==[
  2. Provides the following variables:
  3. * `ODBC_INCLUDE_DIRS`: Include directories necessary to use ODBC.
  4. * `ODBC_LIBRARIES`: Libraries necessary to use ODBC.
  5. * A `ODBC::ODBC` imported target.
  6. #]==]
  7. # No .pc files are shipped with ODBC on Windows.
  8. set(_ODBC_use_pkgconfig 0)
  9. if (NOT WIN32)
  10. find_package(PkgConfig)
  11. if (PkgConfig_FOUND)
  12. set(_ODBC_use_pkgconfig 1)
  13. endif ()
  14. endif ()
  15. if (_ODBC_use_pkgconfig)
  16. pkg_check_modules(_iodbc "libiodbc" QUIET IMPORTED_TARGET)
  17. unset(_odbc_target)
  18. if (NOT _iodbc_FOUND)
  19. pkg_check_modules(_unixodbc "odbc" QUIET IMPORTED_TARGET)
  20. if (_unixodbc_FOUND)
  21. set(_odbc_target "_unixodbc")
  22. endif ()
  23. else ()
  24. set(_odbc_target "_iodbc")
  25. endif ()
  26. set(ODBC_FOUND 0)
  27. if (_odbc_target)
  28. set(ODBC_FOUND 1)
  29. set(ODBC_INCLUDE_DIRS ${${_odbc_target}_INCLUDE_DIRS})
  30. set(ODBC_LIBRARIES ${${_odbc_target}_LINK_LIBRARIES})
  31. if (NOT TARGET ODBC::ODBC)
  32. add_library(ODBC::ODBC INTERFACE IMPORTED)
  33. target_link_libraries(ODBC::ODBC
  34. INTERFACE "PkgConfig::${_odbc_target}")
  35. endif ()
  36. endif ()
  37. unset(_odbc_target)
  38. else ()
  39. find_path(ODBC_INCLUDE_DIR
  40. NAMES sql.h
  41. PATHS
  42. "C:/Program Files/ODBC"
  43. "C:/ODBC"
  44. PATH_SUFFIXES include include/odbc
  45. DOC "Location of sql.h")
  46. mark_as_advanced(ODBC_INCLUDE_DIR)
  47. find_library(ODBC_LIBRARY
  48. NAMES odbc iodbc unixodbc odbc32
  49. PATHS
  50. "C:/Program Files/ODBC"
  51. "C:/ODBC"
  52. PATH_SUFFIXES lib lib/debug
  53. DOC "Location of the ODBC library")
  54. mark_as_advanced(ODBC_LIBRARY)
  55. include(FindPackageHandleStandardArgs)
  56. find_package_handle_standard_args(ODBC
  57. REQUIRED_VARS ODBC_INCLUDE_DIR ODBC_LIBRARY)
  58. if (ODBC_FOUND)
  59. set(ODBC_INCLUDE_DIRS "${ODBC_INCLUDE_DIR}")
  60. set(ODBC_LIBRARIES "${ODBC_LIBRARY}")
  61. if (NOT TARGET ODBC::ODBC)
  62. add_library(ODBC::ODBC UNKNOWN IMPORTED)
  63. set_target_properties(ODBC::ODBC PROPERTIES
  64. IMPORTED_LOCATION "${ODBC_LIBRARY}"
  65. INTERFACE_INCLUDE_DIRECTORIES "${ODBC_INCLUDE_DIR}")
  66. endif ()
  67. endif ()
  68. endif ()
  69. unset(_ODBC_use_pkgconfig)