FindODBC.cmake 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #
  2. # Copyright (c) 2008-2015 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 (ODBC_FOUND)
  31. return ()
  32. endif ()
  33. if (WIN32)
  34. set (ODBC_INCLUDE_DIRS) # The headers should be available in the default include search path
  35. set (ODBC_LIBRARIES odbc32) # This should be also the case for MinGW cross-compiler toolchain
  36. set (ODBC_DEFINES)
  37. set (ODBC_VERSION 3) # Assume it is 3
  38. set (ODBC_FOUND 1)
  39. else ()
  40. # On Unix-like host system, use the ODBC config tool
  41. find_program (ODBC_CONFIG NAMES odbc_config iodbc-config DOC "ODBC config tool" NO_CMAKE_FIND_ROOT_PATH)
  42. if (ODBC_CONFIG)
  43. # Get ODBC compile and link flags and turn them into include dirs and libraries list
  44. execute_process (COMMAND ${ODBC_CONFIG} --cflags OUTPUT_VARIABLE ODBC_COMPILE_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
  45. execute_process (COMMAND ${ODBC_CONFIG} --libs OUTPUT_VARIABLE ODBC_LINK_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
  46. string (REGEX REPLACE " *-I" ";" ODBC_INCLUDE_DIRS "${ODBC_COMPILE_FLAGS}") # Stringify in case it returns empty string
  47. string (REGEX REPLACE " *-l" ";" ODBC_LIBRARIES "${ODBC_LINK_FLAGS}")
  48. list (GET ODBC_INCLUDE_DIRS 0 ODBC_DEFINES) # Assume the list of defines always come before the list of include dirs
  49. list (REMOVE_AT ODBC_INCLUDE_DIRS 0)
  50. list (REMOVE_AT ODBC_LIBRARIES 0)
  51. # Get ODBC version
  52. execute_process (COMMAND ${ODBC_CONFIG} --odbcversion OUTPUT_VARIABLE ODBC_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
  53. set (ODBC_FOUND 1)
  54. endif ()
  55. endif ()
  56. if (ODBC_FOUND)
  57. include (FindPackageMessage)
  58. FIND_PACKAGE_MESSAGE (ODBC "Found ODBC driver manager: ${ODBC_LIBRARIES} ${ODBC_INCLUDE_DIRS}" "[${ODBC_LIBRARIES}][${ODBC_INCLUDE_DIRS}]")
  59. elseif (ODBC_FIND_REQUIRED)
  60. message (FATAL_ERROR "Could not find ODBC driver manager, please install the development package of unixODBC or libiodbc")
  61. endif ()
  62. mark_as_advanced (ODBC_INCLUDE_DIRS ODBC_LIBRARIES ODBC_DEFINES ODBC_VERSION ODBC_CONFIG)