-
Notifications
You must be signed in to change notification settings - Fork 1
/
MySQLConfig.cmake
95 lines (74 loc) · 2.66 KB
/
MySQLConfig.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
# - Try to find the MySQL client library
# based upon GpgmeConfig.
# Once done this will define
#
# MYSQL_FOUND - system has MySQL
# MYSQL_INCLUDE_DIR - the MySQL include directory
# MYSQL_LIBRARY - Link these to use MySQL
# MYSQL_LIBRARY_DIR - Link directories
if ( MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY AND MYSQL_LIBRARY_DIR )
# Already in cache
set(MYSQL_FOUND TRUE)
else()
execute_process(COMMAND mysql_config --libs RESULT_VARIABLE RET OUTPUT_VARIABLE str_libs OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT ${RET} EQUAL 0)
return()
endif()
execute_process(COMMAND mysql_config --cflags RESULT_VARIABLE RET OUTPUT_VARIABLE str_includes OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT ${RET} EQUAL 0)
return()
endif()
string(FIND ${str_libs} " " pos)
if(${pos} EQUAL -1)
string(LENGTH ${str_libs} pos)
endif()
while(${pos} GREATER 0)
math(EXPR length "${pos} - 1")
math(EXPR next "${pos} + 1")
string(LENGTH ${str_libs} strlength)
math(EXPR strlength "${strlength} - 1")
string(SUBSTRING ${str_libs} 1 1 prefix)
if (length GREATER strlength OR length EQUAL strlength)
string(SUBSTRING ${str_libs} 2 -1 value)
set(pos -1)
else()
string(SUBSTRING ${str_libs} 2 ${length} value)
string(SUBSTRING ${str_libs} ${next} -1 str_libs)
string(FIND ${str_libs} " " pos)
endif()
string(STRIP ${value} value)
if (${prefix} STREQUAL "L")
list(APPEND MYSQL_LIBRARY_DIR ${value})
elseif(${prefix} STREQUAL "l")
list(APPEND MYSQL_LIBRARY ${value})
endif()
endwhile()
string(FIND ${str_includes} " " pos)
if(${pos} EQUAL -1)
string(LENGTH ${str_includes} pos)
endif()
while(${pos} GREATER 0)
math(EXPR length "${pos} - 1")
math(EXPR next "${pos} + 1")
string(LENGTH ${str_includes} strlength)
math(EXPR strlength "${strlength} - 1")
string(SUBSTRING ${str_includes} 1 1 prefix)
if (length GREATER strlength OR length EQUAL strlength)
string(SUBSTRING ${str_includes} 2 -1 value)
set(pos -1)
else()
string(SUBSTRING ${str_includes} 2 ${length} value)
string(SUBSTRING ${str_includes} ${next} -1 str_includes)
string(FIND ${str_includes} " " pos)
endif()
string(STRIP ${value} value)
if (${prefix} STREQUAL "I")
list(APPEND MYSQL_INCLUDE_DIR ${value})
endif()
endwhile()
mark_as_advanced(
MYSQL_LIBRARY
MYSQL_INCLUDE_DIR
MYSQL_LIBRARY_DIR
)
endif()