1# Copyright (c) 2009, 2012, 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 as published by 5# the Free Software Foundation; version 2 of the License. 6# 7# This program is distributed in the hope that it will be useful, 8# but WITHOUT ANY WARRANTY; without even the implied warranty of 9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10# GNU General Public License for more details. 11# 12# You should have received a copy of the GNU General Public License 13# along with this program; if not, write to the Free Software 14# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 15 16# This script creates initial database for packaging on Windows 17SET(CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@") 18SET(CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@") 19SET(MYSQLD_EXECUTABLE "@MYSQLD_EXECUTABLE@") 20SET(CMAKE_CFG_INTDIR "@CMAKE_CFG_INTDIR@") 21SET(WIN32 "@WIN32@") 22# Force Visual Studio to output to stdout 23IF(ENV{VS_UNICODE_OUTPUT}) 24 SET ($ENV{VS_UNICODE_OUTPUT}) 25ENDIF() 26IF(CMAKE_CFG_INTDIR AND CONFIG) 27 #Resolve build configuration variables 28 STRING(REPLACE "${CMAKE_CFG_INTDIR}" ${CONFIG} MYSQLD_EXECUTABLE 29 "${MYSQLD_EXECUTABLE}") 30ENDIF() 31 32# Create bootstrapper SQL script 33FILE(WRITE bootstrap.sql "use mysql;\n" ) 34FOREACH(FILENAME mysql_system_tables.sql mysql_system_tables_data.sql) 35 FILE(STRINGS ${CMAKE_SOURCE_DIR}/scripts/${FILENAME} CONTENTS) 36 FOREACH(STR ${CONTENTS}) 37 IF(NOT STR MATCHES "@current_hostname") 38 FILE(APPEND bootstrap.sql "${STR}\n") 39 ENDIF() 40 ENDFOREACH() 41ENDFOREACH() 42FILE(READ ${CMAKE_SOURCE_DIR}/scripts/fill_help_tables.sql CONTENTS) 43FILE(APPEND bootstrap.sql ${CONTENTS}) 44 45 46FILE(REMOVE_RECURSE mysql) 47MAKE_DIRECTORY(mysql) 48IF(WIN32) 49 SET(CONSOLE --console) 50ENDIF() 51 52SET(BOOTSTRAP_COMMAND 53 ${MYSQLD_EXECUTABLE} 54 --no-defaults 55 ${CONSOLE} 56 --bootstrap 57 --lc-messages-dir=${CMAKE_CURRENT_BINARY_DIR}/share 58 --basedir=. 59 --datadir=. 60 --default-storage-engine=MyISAM 61 --loose-skip-innodb 62 --loose-skip-ndbcluster 63 --max_allowed_packet=8M 64 --net_buffer_length=16K 65) 66 67GET_FILENAME_COMPONENT(CWD . ABSOLUTE) 68EXECUTE_PROCESS( 69 COMMAND "@CMAKE_COMMAND@" -E echo Executing ${BOOTSTRAP_COMMAND} 70) 71EXECUTE_PROCESS ( 72 COMMAND "@CMAKE_COMMAND@" -E 73 echo input file bootstrap.sql, current directory ${CWD} 74) 75EXECUTE_PROCESS ( 76 COMMAND ${BOOTSTRAP_COMMAND} 77 INPUT_FILE bootstrap.sql 78 OUTPUT_VARIABLE OUT 79 ERROR_VARIABLE ERR 80 RESULT_VARIABLE RESULT 81 ) 82 83IF(NOT RESULT EQUAL 0) 84 MESSAGE(FATAL_ERROR "Could not create initial database \n ${OUT} \n ${ERR}") 85ENDIF() 86 87EXECUTE_PROCESS ( 88 COMMAND "@CMAKE_COMMAND@" -E touch ${CMAKE_CURRENT_BINARY_DIR}/initdb.dep 89) 90