create_initial_db.cmake 2.25 KB
Newer Older
1
# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13
# 
# 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
Vicențiu Ciorbaru's avatar
Vicențiu Ciorbaru committed
14
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1335  USA 
15 16

# This script creates initial database for packaging on Windows
Vladislav Vaintroub's avatar
Vladislav Vaintroub committed
17 18 19 20 21 22 23 24
# Force Visual Studio to output to stdout
IF(ENV{VS_UNICODE_OUTPUT})
 SET ($ENV{VS_UNICODE_OUTPUT})
ENDIF()
IF(CMAKE_CFG_INTDIR AND CONFIG)
  #Resolve build configuration variables
  STRING(REPLACE "${CMAKE_CFG_INTDIR}" ${CONFIG} MYSQLD_EXECUTABLE 
    "${MYSQLD_EXECUTABLE}")
25 26 27 28
ENDIF()

# Create bootstrapper SQL script
FILE(WRITE bootstrap.sql "use mysql;\n" )
29
FOREACH(FILENAME mysql_system_tables.sql mysql_system_tables_data.sql mysql_performance_tables.sql)
30
   FILE(STRINGS ${TOP_SRCDIR}/scripts/${FILENAME} CONTENTS)
31 32 33 34 35 36 37
   FOREACH(STR ${CONTENTS})
    IF(NOT STR MATCHES "@current_hostname")
      FILE(APPEND bootstrap.sql "${STR}\n")
    ENDIF()
  ENDFOREACH()
ENDFOREACH()

38 39 40 41
FOREACH(FILENAME ${TOP_SRCDIR}/scripts/fill_help_tables.sql ${TOP_SRCDIR}/scripts/mysql_sys_schema.sql)
  FILE(READ ${FILENAME} CONTENTS)
  FILE(APPEND bootstrap.sql "${CONTENTS}")
ENDFOREACH()
42

Vladislav Vaintroub's avatar
Vladislav Vaintroub committed
43
MAKE_DIRECTORY(mysql)
44 45 46 47

SET(BOOTSTRAP_COMMAND 
  ${MYSQLD_EXECUTABLE} 
  --no-defaults 
48
  --console
49
  --bootstrap
50 51 52 53 54
  --datadir=.
)

GET_FILENAME_COMPONENT(CWD . ABSOLUTE)
EXECUTE_PROCESS(
55
  COMMAND "${CMAKE_COMMAND}" -E echo Executing ${BOOTSTRAP_COMMAND}
56 57
)
EXECUTE_PROCESS (
58
  COMMAND "${CMAKE_COMMAND}" -E
59
  echo input file bootstrap.sql, current directory ${CWD}
60 61
)
EXECUTE_PROCESS (  
62 63 64
  COMMAND ${BOOTSTRAP_COMMAND}
  INPUT_FILE bootstrap.sql
  OUTPUT_VARIABLE OUT
65 66 67 68 69 70 71
  ERROR_VARIABLE ERR
  RESULT_VARIABLE RESULT
 )

IF(NOT RESULT EQUAL 0)
  MESSAGE(FATAL_ERROR "Could not create initial database \n ${OUT} \n ${ERR}")
ENDIF()