1# Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License, version 2.0,
5# as published by the Free Software Foundation.
6#
7# This program is also distributed with certain software (including
8# but not limited to OpenSSL) that is licensed under separate terms,
9# as designated in a particular file or component or in included license
10# documentation.  The authors of MySQL hereby grant you an additional
11# permission to link the program and your derivative works with the
12# separately licensed software that they have included with MySQL.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License, version 2.0, for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
23# This script creates initial database for packaging on Windows
24SET(CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@")
25SET(CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@")
26SET(MYSQLD_EXECUTABLE "@MYSQLD_EXECUTABLE@")
27SET(CMAKE_CFG_INTDIR "@CMAKE_CFG_INTDIR@")
28
29SET(WITH_SSL_PATH "@WITH_SSL_PATH@")
30SET(CRYPTO_LIBRARY "@CRYPTO_LIBRARY@")
31SET(OPENSSL_LIBRARY "@OPENSSL_LIBRARY@")
32
33SET(WIN32 "@WIN32@")
34
35# Force Visual Studio to output to stdout
36IF(ENV{VS_UNICODE_OUTPUT})
37 SET ($ENV{VS_UNICODE_OUTPUT})
38ENDIF()
39IF(CMAKE_CFG_INTDIR AND CONFIG)
40  #Resolve build configuration variables
41  STRING(REPLACE "${CMAKE_CFG_INTDIR}" ${CONFIG} MYSQLD_EXECUTABLE
42    "${MYSQLD_EXECUTABLE}")
43ENDIF()
44
45# Create bootstrapper SQL script
46FILE(WRITE bootstrap.sql "use mysql;\n" )
47FOREACH(FILENAME mysql_system_tables.sql mysql_system_tables_data.sql)
48   FILE(STRINGS ${CMAKE_SOURCE_DIR}/scripts/${FILENAME} CONTENTS)
49   FOREACH(STR ${CONTENTS})
50    IF(NOT STR MATCHES "@current_hostname")
51      FILE(APPEND bootstrap.sql "${STR}\n")
52    ENDIF()
53  ENDFOREACH()
54ENDFOREACH()
55FILE(READ ${CMAKE_SOURCE_DIR}/scripts/fill_help_tables.sql CONTENTS)
56FILE(APPEND bootstrap.sql "${CONTENTS}")
57
58
59FILE(REMOVE_RECURSE mysql performance_schema)
60FILE(REMOVE ibdata1 ib_logfile0 ib_logfile1)
61
62MAKE_DIRECTORY(mysql)
63IF(WIN32)
64  SET(CONSOLE --console)
65ENDIF()
66
67SET(BOOTSTRAP_COMMAND
68  ${MYSQLD_EXECUTABLE}
69  --no-defaults
70  ${CONSOLE}
71  --bootstrap
72  --lc-messages-dir=${CMAKE_CURRENT_BINARY_DIR}/share
73  --basedir=.
74  --datadir=.
75  --default-storage-engine=MyISAM
76  --default-tmp-storage-engine=MyISAM
77  --loose-skip-ndbcluster
78  --max_allowed_packet=8M
79  --net_buffer_length=16K
80)
81
82GET_FILENAME_COMPONENT(CWD . ABSOLUTE)
83
84IF(WITH_SSL_PATH AND HAVE_CRYPTO_DLL AND HAVE_OPENSSL_DLL)
85  GET_FILENAME_COMPONENT(MYSQLD_DIR "${MYSQLD_EXECUTABLE}" PATH)
86  GET_FILENAME_COMPONENT(CRYPTO_NAME "${CRYPTO_LIBRARY}" NAME_WE)
87  GET_FILENAME_COMPONENT(OPENSSL_NAME "${OPENSSL_LIBRARY}" NAME_WE)
88  CONFIGURE_FILE("${WITH_SSL_PATH}/bin/${CRYPTO_NAME}.dll"
89                 "${MYSQLD_DIR}/${CRYPTO_NAME}.dll" COPYONLY)
90  CONFIGURE_FILE("${WITH_SSL_PATH}/bin/${OPENSSL_NAME}.dll"
91                 "${MYSQLD_DIR}/${OPENSSL_NAME}.dll" COPYONLY)
92ENDIF()
93
94EXECUTE_PROCESS(
95  COMMAND "@CMAKE_COMMAND@" -E echo Executing ${BOOTSTRAP_COMMAND}
96)
97EXECUTE_PROCESS (
98  COMMAND "@CMAKE_COMMAND@" -E
99  echo input file bootstrap.sql, current directory ${CWD}
100)
101EXECUTE_PROCESS (
102  COMMAND ${BOOTSTRAP_COMMAND}
103  INPUT_FILE bootstrap.sql
104  OUTPUT_VARIABLE OUT
105  ERROR_VARIABLE ERR
106  RESULT_VARIABLE RESULT
107 )
108
109IF(NOT RESULT EQUAL 0)
110  MESSAGE(FATAL_ERROR "Could not create initial database \n ${OUT} \n ${ERR}")
111ENDIF()
112
113EXECUTE_PROCESS (
114  COMMAND "@CMAKE_COMMAND@" -E touch ${CMAKE_CURRENT_BINARY_DIR}/initdb.dep
115)
116