選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

133 行
4.4KB

  1. # - Try to find MySQL / MySQL Embedded library
  2. # Find the MySQL includes and client library
  3. # This module defines
  4. # MYSQL_INCLUDE_DIR, where to find mysql.h
  5. # MYSQL_LIBRARIES, the libraries needed to use MySQL.
  6. # MYSQL_LIB_DIR, path to the MYSQL_LIBRARIES
  7. # MYSQL_EMBEDDED_LIBRARIES, the libraries needed to use MySQL Embedded.
  8. # MYSQL_EMBEDDED_LIB_DIR, path to the MYSQL_EMBEDDED_LIBRARIES
  9. # MYSQL_FOUND, If false, do not try to use MySQL.
  10. # MYSQL_EMBEDDED_FOUND, If false, do not try to use MySQL Embedded.
  11. # Copyright (c) 2006-2008, Jarosław Staniek <staniek@kde.org>
  12. #
  13. # Redistribution and use is allowed according to the terms of the BSD license.
  14. # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
  15. include(CheckCXXSourceCompiles)
  16. if(WIN32)
  17. find_path(MYSQL_INCLUDE_DIR mysql.h
  18. PATHS
  19. $ENV{MYSQL_INCLUDE_DIR}
  20. $ENV{MYSQL_DIR}/include
  21. $ENV{ProgramFiles}/MySQL/*/include
  22. $ENV{SystemDrive}/MySQL/*/include
  23. $ENV{ProgramW6432}/MySQL/*/include
  24. )
  25. else(WIN32)
  26. #在Mac OS下, mysql.h的文件可能不是在mysql目录下
  27. #可能存在/usr/local/mysql/include/mysql.h
  28. find_path(MYSQL_INCLUDE_DIR mysql.h
  29. PATHS
  30. $ENV{MYSQL_INCLUDE_DIR}
  31. $ENV{MYSQL_DIR}/include
  32. /usr/local/mysql/include
  33. /usr/local/mysql/include/mysql
  34. /opt/mysql/mysql/include
  35. PATH_SUFFIXES
  36. mysql
  37. )
  38. endif(WIN32)
  39. if(WIN32)
  40. if (${CMAKE_BUILD_TYPE})
  41. string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_TOLOWER)
  42. endif()
  43. # path suffix for debug/release mode
  44. # binary_dist: mysql binary distribution
  45. # build_dist: custom build
  46. if(CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug")
  47. set(binary_dist debug)
  48. set(build_dist Debug)
  49. else(CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug")
  50. ADD_DEFINITIONS(-DDBUG_OFF)
  51. set(binary_dist opt)
  52. set(build_dist Release)
  53. endif(CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug")
  54. # find_library(MYSQL_LIBRARIES NAMES mysqlclient
  55. set(MYSQL_LIB_PATHS
  56. $ENV{MYSQL_DIR}/lib/${binary_dist}
  57. $ENV{MYSQL_DIR}/libmysql/${build_dist}
  58. $ENV{MYSQL_DIR}/client/${build_dist}
  59. $ENV{ProgramFiles}/MySQL/*/lib/${binary_dist}
  60. $ENV{SystemDrive}/MySQL/*/lib/${binary_dist}
  61. $ENV{MYSQL_DIR}/lib/opt
  62. $ENV{MYSQL_DIR}/client/release
  63. $ENV{ProgramFiles}/MySQL/*/lib/opt
  64. $ENV{ProgramFiles}/MySQL/*/lib/
  65. $ENV{SystemDrive}/MySQL/*/lib/opt
  66. $ENV{ProgramW6432}/MySQL/*/lib
  67. )
  68. find_library(MYSQL_LIBRARIES NAMES libmysql
  69. PATHS
  70. ${MYSQL_LIB_PATHS}
  71. )
  72. else(WIN32)
  73. # find_library(MYSQL_LIBRARIES NAMES mysqlclient
  74. set(MYSQL_LIB_PATHS
  75. $ENV{MYSQL_DIR}/libmysql_r/.libs
  76. $ENV{MYSQL_DIR}/lib
  77. $ENV{MYSQL_DIR}/lib/mysql
  78. /usr/local/mysql/lib
  79. /opt/mysql/mysql/lib
  80. $ENV{MYSQL_DIR}/libmysql_r/.libs
  81. $ENV{MYSQL_DIR}/lib
  82. $ENV{MYSQL_DIR}/lib/mysql
  83. /usr/local/mysql/lib
  84. /opt/mysql/mysql/lib
  85. PATH_SUFFIXES
  86. mysql
  87. )
  88. find_library(MYSQL_LIBRARIES NAMES mysqlclient
  89. PATHS
  90. ${MYSQL_LIB_PATHS}
  91. )
  92. endif(WIN32)
  93. find_library(MYSQL_EMBEDDED_LIBRARIES NAMES mysqld
  94. PATHS
  95. ${MYSQL_LIB_PATHS}
  96. )
  97. if(MYSQL_LIBRARIES)
  98. get_filename_component(MYSQL_LIB_DIR ${MYSQL_LIBRARIES} PATH)
  99. endif(MYSQL_LIBRARIES)
  100. if(MYSQL_EMBEDDED_LIBRARIES)
  101. get_filename_component(MYSQL_EMBEDDED_LIB_DIR ${MYSQL_EMBEDDED_LIBRARIES} PATH)
  102. endif(MYSQL_EMBEDDED_LIBRARIES)
  103. set( CMAKE_REQUIRED_INCLUDES ${MYSQL_INCLUDE_DIR} )
  104. set( CMAKE_REQUIRED_LIBRARIES ${MYSQL_EMBEDDED_LIBRARIES} )
  105. check_cxx_source_compiles( "#include <mysql.h>\nint main() { int i = MYSQL_OPT_USE_EMBEDDED_CONNECTION; }" HAVE_MYSQL_OPT_EMBEDDED_CONNECTION )
  106. if(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
  107. set(MYSQL_FOUND TRUE)
  108. message(STATUS "Found MySQL: ${MYSQL_INCLUDE_DIR}, ${MYSQL_LIBRARIES}")
  109. else(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
  110. set(MYSQL_FOUND FALSE)
  111. message(STATUS "MySQL not found.")
  112. endif(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
  113. if(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)
  114. set(MYSQL_EMBEDDED_FOUND TRUE)
  115. message(STATUS "Found MySQL Embedded: ${MYSQL_INCLUDE_DIR}, ${MYSQL_EMBEDDED_LIBRARIES}")
  116. else(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)
  117. set(MYSQL_EMBEDDED_FOUND FALSE)
  118. message(STATUS "MySQL Embedded not found.")
  119. endif(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)
  120. mark_as_advanced(MYSQL_INCLUDE_DIR MYSQL_LIBRARIES MYSQL_EMBEDDED_LIBRARIES)