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