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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
# Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
#
# 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
# Build comp_sql - used for embedding SQL in C or C++ programs
IF(NOT CMAKE_CROSSCOMPILING)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
ADD_EXECUTABLE(comp_sql comp_sql.c)
TARGET_LINK_LIBRARIES(comp_sql)
ENDIF()
# Build mysql_fix_privilege_tables.sql (concatenate 3 sql scripts)
IF(NOT WIN32 OR CMAKE_CROSSCOMPILING)
FIND_PROGRAM(CAT_EXECUTABLE cat DOC "path to the executable")
MARK_AS_ADVANCED(CAT_EXECUTABLE)
ENDIF()
IF(CAT_EXECUTABLE)
SET(CAT_COMMAND COMMAND
${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_SOURCE_DIR}
${CAT_EXECUTABLE} mysql_system_tables.sql mysql_system_tables_fix.sql mysql_performance_tables.sql >
${CMAKE_CURRENT_BINARY_DIR}/mysql_fix_privilege_tables.sql
)
ELSEIF(WIN32)
FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/mysql_fix_privilege_tables.sql
native_outfile )
SET(CAT_COMMAND
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_SOURCE_DIR}
cmd /c copy /b mysql_system_tables.sql + mysql_system_tables_fix.sql + mysql_performance_tables.sql
${native_outfile} )
ELSE()
MESSAGE(FATAL_ERROR "Cannot concatenate files")
ENDIF()
# Build mysql_fix_privilege_tables.c
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mysql_fix_privilege_tables_sql.c
${CAT_COMMAND}
COMMAND comp_sql
mysql_fix_privilege_tables
mysql_fix_privilege_tables.sql
mysql_fix_privilege_tables_sql.c
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS comp_sql
${CMAKE_CURRENT_SOURCE_DIR}/mysql_system_tables.sql
${CMAKE_CURRENT_SOURCE_DIR}/mysql_system_tables_fix.sql
${CMAKE_CURRENT_SOURCE_DIR}/mysql_performance_tables.sql
)
# Add target for the above to be built
ADD_CUSTOM_TARGET(GenFixPrivs
ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/mysql_fix_privilege_tables_sql.c
)
IF(UNIX)
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/make_binary_distribution
"cd ${CMAKE_BINARY_DIR} && '${CMAKE_CPACK_COMMAND}' -G TGZ --config CPackConfig.cmake\n" )
EXECUTE_PROCESS(
COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/make_binary_distribution
)
ENDIF()
INSTALL(FILES
${CMAKE_CURRENT_SOURCE_DIR}/mysql_system_tables.sql
${CMAKE_CURRENT_SOURCE_DIR}/mysql_system_tables_data.sql
${CMAKE_CURRENT_SOURCE_DIR}/mysql_performance_tables.sql
${CMAKE_CURRENT_SOURCE_DIR}/fill_help_tables.sql
${CMAKE_CURRENT_SOURCE_DIR}/mysql_test_data_timezone.sql
${FIX_PRIVILEGES_SQL}
DESTINATION ${INSTALL_MYSQLSHAREDIR} COMPONENT Server
)
# TCMalloc hacks
IF(MALLOC_LIB)
MESSAGE("Using tcmalloc '${MALLOC_LIB}'")
INSTALL(FILES ${MALLOC_LIB} DESTINATION ${INSTALL_LIBDIR} OPTIONAL)
ENDIF()
IF(CMAKE_GENERATOR MATCHES "Makefiles")
FOREACH(ARCH ${CMAKE_OSX_ARCHITECTURES})
SET(CFLAGS "${CFLAGS} -arch ${ARCH}")
SET(CXXFLAGS "${CXXFLAGS} -arch ${ARCH}")
ENDFOREACH()
ENDIF()
IF(UNIX)
# FIND_PROC and CHECK_PID are used by mysqld_safe
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
SET (FIND_PROC
"ps wwwp $PID | grep -v mysqld_safe | grep -- $MYSQLD > /dev/null")
ENDIF()
IF(NOT FIND_PROC AND CMAKE_SYSTEM_NAME MATCHES "SunOS")
SET (FIND_PROC
"ps -p $PID | grep -v mysqld_safe | grep -- $MYSQLD > /dev/null")
ENDIF()
IF(NOT FIND_PROC)
# BSD style
EXECUTE_PROCESS(COMMAND ps -uaxww OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE result)
IF(result MATCHES 0)
SET( FIND_PROC
"ps -uaxww | grep -v mysqld_safe | grep -- $MYSQLD | grep $PID > /dev/null")
ENDIF()
ENDIF()
IF(NOT FIND_PROC)
# SysV style
EXECUTE_PROCESS(COMMAND ps -ef OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE result)
IF(result MATCHES 0)
SET( FIND_PROC "ps -ef | grep -v mysqld_safe | grep -- $MYSQLD | grep $PID > /dev/null")
ENDIF()
ENDIF()
EXECUTE_PROCESS(COMMAND sh -c "kill -0 $$" OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE result)
IF(result MATCHES 0)
SET(CHECK_PID "kill -0 $PID > /dev/null 2> /dev/null")
ELSE()
SET(CHECK_PID "kill -s SIGCONT $PID > /dev/null 2> /dev/null")
ENDIF()
SET(HOSTNAME "hostname")
SET(MYSQLD_USER "mysql")
# Required for mysqlbug until autotools are deprecated, once done remove these
# and expand default cmake variables
SET(CC ${CMAKE_C_COMPILER})
SET(CXX ${CMAKE_CXX_COMPILER})
SET(SAVE_CC ${CMAKE_C_COMPILER})
SET(SAVE_CXX ${CMAKE_CXX_COMPILER})
SET(SAVE_CFLAGS ${CFLAGS})
SET(SAVE_CXXFLAGS ${CXXFLAGS})
# XXX no cmake equivalent for this, just make one up
SET(CONFIGURE_LINE "Built using CMake")
# Also required for mysqlbug, autoconf only supports --version so for now we
# just explicitly require GNU
IF(CMAKE_COMPILER_IS_GNUCC)
EXECUTE_PROCESS(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1} --version
COMMAND sed 1q
OUTPUT_VARIABLE CC_VERSION)
ELSE()
SET(CC_VERSION "")
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX)
EXECUTE_PROCESS(
COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} --version
COMMAND sed 1q
OUTPUT_VARIABLE CXX_VERSION)
ELSE()
SET(CXX_VERSION "")
ENDIF()
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mysqlbug.sh
${CMAKE_CURRENT_BINARY_DIR}/mysqlbug ESCAPE_QUOTES @ONLY)
EXECUTE_PROCESS(
COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/mysqlbug
)
INSTALL_SCRIPT(${CMAKE_CURRENT_BINARY_DIR}/mysqlbug
DESTINATION ${INSTALL_BINDIR}
COMPONENT Server
)
ENDIF(UNIX)
# Really ugly, one script, "mysql_install_db", needs prefix set to ".",
# i.e. makes access relative the current directory. This matches
# the documentation, so better not change this.
IF(INSTALL_LAYOUT MATCHES "STANDALONE")
SET(prefix ".")
ELSE()
SET(prefix "${CMAKE_INSTALL_PREFIX}")
ENDIF()
SET(bindir ${prefix}/${INSTALL_BINDIR})
SET(sbindir ${prefix}/${INSTALL_SBINDIR})
SET(scriptdir ${prefix}/${INSTALL_BINDIR})
SET(libexecdir ${prefix}/${INSTALL_SBINDIR})
SET(pkgdatadir ${prefix}/${INSTALL_MYSQLSHAREDIR})
IF(INSTALL_LAYOUT MATCHES "STANDALONE")
SET(localstatedir ${prefix}/data)
ELSE()
SET(localstatedir ${MYSQL_DATADIR})
ENDIF()
IF(UNIX)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mysql_install_db.sh
${CMAKE_CURRENT_BINARY_DIR}/mysql_install_db ESCAPE_QUOTES @ONLY)
SET(DEST ${INSTALL_SCRIPTDIR})
SET(EXT)
EXECUTE_PROCESS(
COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/mysql_install_db
)
INSTALL_SCRIPT(
"${CMAKE_CURRENT_BINARY_DIR}/mysql_install_db"
DESTINATION ${DEST}
COMPONENT Server
)
ENDIF()
SET(prefix "${CMAKE_INSTALL_PREFIX}")
IF(INSTALL_SYSCONFDIR)
SET(sysconfdir ${DEFAULT_SYSCONFDIR})
ELSE()
SET(sysconfdir "/etc")
ENDIF()
SET(bindir ${prefix}/${INSTALL_BINDIR})
SET(libexecdir ${prefix}/${INSTALL_SBINDIR})
SET(scriptdir ${prefix}/${INSTALL_BINDIR})
SET(datadir ${prefix}/${INSTALL_MYSQLSHAREDIR})
SET(pkgdatadir ${prefix}/${INSTALL_MYSQLSHAREDIR})
SET(libsubdir ${INSTALL_LIBDIR})
SET(pkgincludedir ${prefix}/${INSTALL_INCLUDEDIR})
SET(pkglibdir ${prefix}/${INSTALL_LIBDIR})
SET(pkgplugindir ${prefix}/${INSTALL_PLUGINDIR})
SET(localstatedir ${MYSQL_DATADIR})
SET(RPATH_OPTION "")
IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
SET(RPATH_OPTION "-R$pkglibdir")
ENDIF()
# some scripts use @TARGET_LINUX@
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
SET(TARGET_LINUX "true")
ELSE()
SET(TARGET_LINUX "false")
ENDIF()
# Use cmake variables to inspect dependencies for
# mysqlclient library (add -l stuff)
SET(CLIENT_LIBS "")
SET(LIBS "")
# Avoid compatibility warning about lists with empty elements
IF(POLICY CMP0011)
CMAKE_POLICY(SET CMP0011 NEW)
ENDIF()
IF(POLICY CMP0007)
CMAKE_POLICY(SET CMP0007 OLD)
ENDIF()
# Extract dependencies using CMake's internal ${target}_LIB_DEPENDS variable
# returned string in ${var} is can be passed to linker's command line
MACRO(EXTRACT_LINK_LIBRARIES target var)
IF(${target}_LIB_DEPENDS)
LIST(REMOVE_ITEM ${target}_LIB_DEPENDS "")
LIST(REMOVE_DUPLICATES ${target}_LIB_DEPENDS)
FOREACH(lib ${${target}_LIB_DEPENDS})
# Filter out "general", it is not a library, just CMake hint
# Also, remove duplicates
IF(NOT lib STREQUAL "general" AND NOT ${var} MATCHES "-l${lib} ")
IF (lib MATCHES "^\\-l")
SET(${var} "${${var}} ${lib} ")
ELSEIF(lib MATCHES "^/")
IF (lib MATCHES "\\.(a|so([0-9.]*)|lib|dll|dylib)$")
# Full path, convert to just filename, strip "lib" prefix and extension
GET_FILENAME_COMPONENT(lib "${lib}" NAME_WE)
STRING(REGEX REPLACE "^lib" "" lib "${lib}")
SET(${var} "${${var}}-l${lib} " )
ENDIF()
ELSE()
SET(${var} "${${var}}-l${lib} " )
ENDIF()
ENDIF()
ENDFOREACH()
ENDIF()
IF(MSVC)
STRING(REPLACE "-l" "" ${var} "${${var}}")
ENDIF()
ENDMACRO()
EXTRACT_LINK_LIBRARIES(mysqlclient CLIENT_LIBS)
EXTRACT_LINK_LIBRARIES(mysqlserver LIBS)
# mysql_config evaluates ${LIBDL}, we want to avoid it
# as our CLIENT_LIBS and LIBS are already correct
SET(LIBDL)
SET(NON_THREADED_LIBS ${CLIENT_LIBS})
SET(mysql_config_COMPONENT COMPONENT Development)
SET(msql2mysql_COMPONENT COMPONENT Client)
SET(mysqlaccess_COMPONENT COMPONENT Client)
SET(mysql_find_rows_COMPONENT COMPONENT Client)
SET(mytop_COMPONENT Mytop)
IF(WIN32)
# On Windows, some .sh and some .pl.in files are configured
# The resulting files will have .pl extension (those are perl scripts)
# Input files with pl.in extension
SET(PLIN_FILES mysql_config mysql_secure_installation)
# Input files with .sh extension
SET(SH_FILES mysql_convert_table_format mysqld_multi mysqldumpslow
mysqlhotcopy)
FOREACH(file ${PLIN_FILES})
IF(NOT ${file}_COMPONENT)
SET(${file}_COMPONENT Server_Scripts)
ENDIF()
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${file}.pl.in
${CMAKE_CURRENT_BINARY_DIR}/${file}.pl ESCAPE_QUOTES @ONLY)
INSTALL_SCRIPT(${CMAKE_CURRENT_BINARY_DIR}/${file}.pl COMPONENT ${${file}_COMPONENT})
ENDFOREACH()
FOREACH(file ${SH_FILES})
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${file}.sh
${CMAKE_CURRENT_BINARY_DIR}/${file}.pl ESCAPE_QUOTES @ONLY)
INSTALL_SCRIPT(${CMAKE_CURRENT_BINARY_DIR}/${file}.pl COMPONENT Server_Scripts)
ENDFOREACH()
ELSE()
IF(WITH_WSREP)
SET(WSREP_BINARIES
wsrep_sst_common
wsrep_sst_mysqldump
wsrep_sst_rsync
wsrep_sst_xtrabackup
wsrep_sst_xtrabackup-v2
)
ENDIF()
# Configure this one, for testing, but do not install it.
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mysql_config.pl.in
${CMAKE_CURRENT_BINARY_DIR}/mysql_config.pl ESCAPE_QUOTES @ONLY)
# On Unix, most of the files end up in the bin directory
SET(BIN_SCRIPTS
msql2mysql
mysql_config
mysql_fix_extensions
mysql_setpermission
mysql_secure_installation
mysql_zap
mysqlaccess
mysql_convert_table_format
mysql_find_rows
mytop
mysqlhotcopy
mysqldumpslow
mysqld_multi
mysqld_safe
${WSREP_BINARIES}
)
FOREACH(file ${BIN_SCRIPTS})
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.sh)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${file}.sh
${CMAKE_CURRENT_BINARY_DIR}/${file} ESCAPE_QUOTES @ONLY)
ELSEIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file})
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${file}
${CMAKE_CURRENT_BINARY_DIR}/${file} COPYONLY)
ELSE()
MESSAGE(FATAL_ERROR "Can not find ${file}.sh or ${file} in "
"${CMAKE_CURRENT_SOURCE_DIR}" )
ENDIF()
EXECUTE_PROCESS(COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/${file})
IF(NOT ${file}_COMPONENT)
SET(${file}_COMPONENT Server)
ENDIF()
INSTALL_SCRIPT(
${CMAKE_CURRENT_BINARY_DIR}/${file}
DESTINATION ${INSTALL_BINDIR}
COMPONENT ${${file}_COMPONENT}
)
ENDFOREACH()
ENDIF()
# Install libgcc as mylibgcc.a
IF(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_FLAGS MATCHES "-static")
EXECUTE_PROCESS (
COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}
${CMAKE_CXX_FLAGS} --print-libgcc
OUTPUT_VARIABLE LIBGCC_LOCATION
RESULT_VARIABLE RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
IF(${RESULT} EQUAL 0 AND EXISTS ${LIBGCC_LOCATION})
INSTALL(FILES "${LIBGCC_LOCATION}" DESTINATION ${INSTALL_LIBDIR}
COMPONENT Development)
ENDIF()
ENDIF()
|