FindMysql.cmake 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  2. #
  3. # The MySQL Connector/C++ is licensed under the terms of the GPLv2
  4. # <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
  5. # MySQL Connectors. There are special exceptions to the terms and
  6. # conditions of the GPLv2 as it is applied to this software, see the
  7. # FLOSS License Exception
  8. # <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published
  12. # by the Free Software Foundation; version 2 of the License.
  13. #
  14. # This program is distributed in the hope that it will be useful, but
  15. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  17. # for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. #=============================================================================
  23. # Copyright 2015 Sphinx Technologies, Inc.
  24. # Copyright 2017-2026, Manticore Software LTD (https://manticoresearch.com)
  25. #
  26. # Distributed under the OSI-approved BSD License (the "License");
  27. # see accompanying file Copyright.txt for details.
  28. #
  29. # This software is distributed WITHOUT ANY WARRANTY; without even the
  30. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  31. # See the License for more information.
  32. # The module uses these variables:
  33. # MYSQL_ROOT_DIR path to the MySQL bundle (where mysql is installed)
  34. # MYSQL_USE_STATIC_LIBS look and link with static library
  35. #
  36. # On exit the module will set these variables:
  37. #
  38. # Mysql_FOUND - if library was found
  39. #
  40. # Mysql::Mysql - imported target to link with.
  41. #
  42. #=============================================================================
  43. # (To distribute this file outside of CMake, substitute the full
  44. # License text for the above reference.)
  45. ##########################################################################
  46. function ( _MYSQL_CONFIG VAR _opt )
  47. EXECUTE_PROCESS ( COMMAND ${MYSQL_CONFIG_EXECUTABLE} ${_opt} OUTPUT_VARIABLE _mysql_config_output )
  48. STRING ( REGEX REPLACE "[\r\n]$" "" _mysql_config_output "${_mysql_config_output}" )
  49. SET ( ${VAR} ${_mysql_config_output} PARENT_SCOPE )
  50. endfunction ()
  51. function ( _find_library VAR _names _suffixes )
  52. if (NOT ${VAR})
  53. set ( CMAKE_FIND_LIBRARY_SUFFIXES ${_suffixes} )
  54. find_library ( ${VAR} NAMES ${_names}
  55. HINTS
  56. ${MYSQL_LIB_HINT}
  57. PATHS
  58. ${MYSQL_ROOT_DIR}/lib
  59. ${MYSQL_ROOT_DIR}/lib/mysql
  60. $ENV{MYSQL_ROOT_DIR}/lib
  61. $ENV{MYSQL_ROOT_DIR}/lib/mysql
  62. /usr/lib/mysql
  63. /usr/local/lib/mysql
  64. /usr/local/mysql/lib
  65. /usr/local/mysql/lib/mysql
  66. /opt/mysql/mysql/lib
  67. /opt/mysql/mysql/lib/mysql
  68. /opt/mysql-client/lib
  69. ENV MYSQL_DIR
  70. PATH_SUFFIXES
  71. /libmysql_r/.libs
  72. /lib
  73. /lib/mysql
  74. )
  75. endif ()
  76. SET ( ${VAR} ${${VAR}} PARENT_SCOPE )
  77. endfunction ()
  78. if (NOT MYSQL_CONFIG_EXECUTABLE)
  79. if (EXISTS "$ENV{MYSQL_DIR}/bin/mysql_config")
  80. SET ( MYSQL_CONFIG_EXECUTABLE "$ENV{MYSQL_DIR}/bin/mysql_config" )
  81. else ()
  82. set ( MYSQL_CONFIG_PREFER_PATH "$ENV{MYSQL_HOME}/bin" CACHE FILEPATH "preferred path to MySQL (mysql_config)" )
  83. FIND_PROGRAM ( MYSQL_CONFIG_EXECUTABLE
  84. NAMES mysql_config
  85. DOC "full path of mysql_config"
  86. PATHS ${MYSQL_CONFIG_PREFER_PATH}
  87. /usr/bin
  88. /usr/local/bin
  89. /opt/local/lib/mysql55/bin
  90. /opt/mysql/bin
  91. /opt/mysql/mysql/bin
  92. /usr/local/mysql/bin
  93. /usr/pkg/bin
  94. /usr/local/opt/mysql-client/bin
  95. ${MYSQL_ROOT_DIR}/bin
  96. )
  97. endif ()
  98. mark_as_advanced ( MYSQL_CONFIG_EXECUTABLE )
  99. endif ()
  100. if (MYSQL_CONFIG_EXECUTABLE)
  101. _MYSQL_CONFIG ( MYSQL_INCLUDE_HINT "--variable=pkgincludedir" )
  102. _MYSQL_CONFIG ( MYSQL_LIB_HINT "--variable=pkglibdir" )
  103. mark_as_advanced ( MYSQL_INCLUDE_HINT MYSQL_LIB_HINT )
  104. endif ()
  105. #-------------- FIND MYSQL_INCLUDE_DIR ------------------
  106. if (NOT MYSQL_INCLUDE_DIR)
  107. find_path ( MYSQL_INCLUDE_DIR mysql.h
  108. ${MYSQL_INCLUDE_HINT}
  109. ${WITH_MYSQL_INCLUDES}
  110. ${MYSQL_ROOT_DIR}/include
  111. ${MYSQL_ROOT_DIR}/include/mysql
  112. $ENV{MYSQL_ROOT_DIR}/include
  113. $ENV{MYSQL_ROOT_DIR}/include/mysql
  114. $ENV{MYSQL_INCLUDE_DIR}
  115. $ENV{MYSQL_DIR}/include
  116. /usr/include/mysql
  117. /usr/local/include/mysql
  118. /opt/mysql/mysql/include
  119. /opt/mysql/mysql/include/mysql
  120. /usr/local/mysql/include
  121. /usr/local/mysql/include/mysql
  122. /opt/mysql-client/include/mysql
  123. $ENV{ProgramFiles}/MySQL/*/include
  124. $ENV{SystemDrive}/MySQL/*/include
  125. )
  126. endif ()
  127. #----------------- FIND MYSQL_LIBRARY -------------------
  128. if (MYSQL_USE_STATIC_LIBS)
  129. _find_library ( MYSQL_LIBRARY mysqlclient ".a;.lib" )
  130. mark_as_advanced ( MYSQL_INCLUDE_DIR MYSQL_LIBRARY )
  131. include ( FindPackageHandleStandardArgs )
  132. find_package_handle_standard_args ( Mysql REQUIRED_VARS MYSQL_LIBRARY MYSQL_LIBRARY )
  133. if (Mysql_FOUND AND NOT TARGET Mysql::Mysql)
  134. add_library ( Mysql::Mysql STATIC IMPORTED )
  135. set_target_properties ( Mysql::Mysql PROPERTIES
  136. INTERFACE_INCLUDE_DIRECTORIES "${MYSQL_INCLUDE_DIR}"
  137. IMPORTED_LOCATION "${MYSQL_LIBRARY}"
  138. )
  139. endif ()
  140. else ()
  141. _find_library ( MYSQL_LIBRARY mysqlclient ".so;.dylib;.dll" )
  142. mark_as_advanced ( MYSQL_INCLUDE_DIR MYSQL_LIBRARY )
  143. include ( FindPackageHandleStandardArgs )
  144. find_package_handle_standard_args ( Mysql REQUIRED_VARS MYSQL_INCLUDE_DIR MYSQL_LIBRARY )
  145. if (Mysql_FOUND AND NOT TARGET Mysql::Mysql)
  146. add_library ( Mysql::Mysql SHARED IMPORTED )
  147. set_target_properties ( Mysql::Mysql PROPERTIES
  148. INTERFACE_INCLUDE_DIRECTORIES "${MYSQL_INCLUDE_DIR}"
  149. IMPORTED_LOCATION "${MYSQL_LIBRARY}"
  150. )
  151. endif ()
  152. endif ()