summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 7b95163873cd771ef21008dbc442f18e517f42ca (plain)
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
# Copyright (C) 2006-2009 MySQL AB & Monty Program Ab
# 
# 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

CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR)
IF(COMMAND cmake_policy)
  cmake_policy(SET CMP0005 NEW)
ENDIF(COMMAND cmake_policy)

PROJECT(MySql)

# This reads user configuration, generated by configure.js.
INCLUDE(win/configure.data OPTIONAL)

MACRO(MYSQL_GET_CONFIG_VALUE keyword var)
 IF(NOT ${var})
   IF (EXISTS ${CMAKE_SOURCE_DIR}/configure.in)
     FILE (STRINGS  ${CMAKE_SOURCE_DIR}/configure.in str  REGEX  "^[ ]*${keyword}=")
    IF(str)
      STRING(REPLACE "${keyword}=" "" str ${str})
      STRING(REGEX REPLACE  "[ ].*" ""  str ${str})
      SET(${var} ${str} CACHE INTERNAL "Config variable")
    ENDIF()
   ENDIF()
 ENDIF()
ENDMACRO()


# Read mysql version for configure script

MACRO(GET_MYSQL_VERSION)
  IF(NOT VERSION_STRING)
    IF(EXISTS ${CMAKE_SOURCE_DIR}/configure.in)
      FILE(STRINGS  ${CMAKE_SOURCE_DIR}/configure.in  str REGEX "AM_INIT_AUTOMAKE")
      STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+[-][^ \\)]+" VERSION_STRING "${str}")
      IF(NOT VERSION_STRING)
        STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" VERSION_STRING "${str}")
        IF(NOT VERSION_STRING)
          FILE(STRINGS  configure.in  str REGEX "AC_INIT\\(")
          STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+[-][a-zA-Z0-9]+" VERSION_STRING "${str}")
          IF(NOT VERSION_STRING)
            STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" VERSION_STRING "${str}")
          ENDIF()
        ENDIF()
      ENDIF()
    ENDIF()
  ENDIF()
  
  IF(NOT VERSION_STRING)
    MESSAGE(FATAL_ERROR 
  "VERSION_STRING cannot be parsed, please specify -DVERSION_STRING=major.minor.patch-extra"
  "when calling cmake")
  ENDIF()
  
  SET(VERSION ${VERSION_STRING})
  STRING(REPLACE "-" "_" MYSQL_U_SCORE_VERSION "${VERSION_STRING}")
  
  # Remove trailing (non-numeric) part of the version string
  STRING(REGEX REPLACE "[^\\.0-9].*" "" VERSION_STRING ${VERSION_STRING})
 
  STRING(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" MAJOR_VERSION "${VERSION_STRING}")
  STRING(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" MINOR_VERSION "${VERSION_STRING}")
  STRING(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" PATCH "${VERSION_STRING}")
  SET(MYSQL_BASE_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}" CACHE INTERNAL "MySQL Base version")
  SET(MYSQL_NO_DASH_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH}")
  MATH(EXPR MYSQL_VERSION_ID "10000*${MAJOR_VERSION} + 100*${MINOR_VERSION} + ${PATCH}")
  MARK_AS_ADVANCED(VERSION MYSQL_VERSION_ID MYSQL_BASE_VERSION)
  SET(CPACK_PACKAGE_VERSION_MAJOR ${MAJOR_VERSION})
  SET(CPACK_PACKAGE_VERSION_MINOR ${MINOR_VERSION})
  SET(CPACK_PACKAGE_VERSION_PATCH ${PATCH})
ENDMACRO()

# Get mysql version and other interesting variables
GET_MYSQL_VERSION()

MYSQL_GET_CONFIG_VALUE("PROTOCOL_VERSION" PROTOCOL_VERSION)
MYSQL_GET_CONFIG_VALUE("DOT_FRM_VERSION" DOT_FRM_VERSION)
MYSQL_GET_CONFIG_VALUE("MYSQL_TCP_PORT_DEFAULT" MYSQL_TCP_PORT_DEFAULT)
MYSQL_GET_CONFIG_VALUE("MYSQL_UNIX_ADDR_DEFAULT" MYSQL_UNIX_ADDR_DEFAULT)
MYSQL_GET_CONFIG_VALUE("SHARED_LIB_MAJOR_VERSION" SHARED_LIB_MAJOR_VERSION)
IF(NOT MYSQL_TCP_PORT_DEFAULT)
 SET(MYSQL_TCP_PORT_DEFAULT "3306")
ENDIF()
IF(NOT MYSQL_TCP_PORT)
  SET(MYSQL_TCP_PORT ${MYSQL_TCP_PORT_DEFAULT})
  SET(MYSQL_TCP_PORT_DEFAULT "0")
ELSEIF(MYSQL_TCP_PORT EQUAL MYSQL_TCP_PORT_DEFAULT)
  SET(MYSQL_TCP_PORT_DEFAULT "0")
ENDIF()


IF(NOT MYSQL_UNIX_ADDR)
  SET(MYSQL_UNIX_ADDR "/tmp/mysql.sock")
ENDIF()
IF(NOT COMPILATION_COMMENT)
  SET(COMPILATION_COMMENT "Source distribution")
ENDIF()

SET(WITH_EXAMPLE_STORAGE_ENGINE TRUE)
SET(WITH_FEDERATEDX_STORAGE_ENGINE TRUE)
SET(WITH_PARTITION_STORAGE_ENGINE TRUE)
SET(WITH_MARIA_STORAGE_ENGINE TRUE)
SET(WITH_PBXT_STORAGE_ENGINE TRUE)
SET(WITH_XTRADB_STORAGE_ENGINE TRUE)

# Hardcode support for CSV storage engine
SET(WITH_CSV_STORAGE_ENGINE TRUE)

CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/include/mysql_version.h.in
               ${CMAKE_SOURCE_DIR}/include/mysql_version.h @ONLY)

# Set standard options
ADD_DEFINITIONS(-DHAVE_YASSL)
ADD_DEFINITIONS(-DCMAKE_CONFIGD)
ADD_DEFINITIONS(-DDEFAULT_MYSQL_HOME="c:/Program Files/MySQL/MySQL Server ${MYSQL_BASE_VERSION}/")
ADD_DEFINITIONS(-DDEFAULT_BASEDIR="c:/Program Files/MySQL/")
ADD_DEFINITIONS(-DMYSQL_DATADIR="c:/Program Files/MySQL/MySQL Server ${MYSQL_BASE_VERSION}/data")
ADD_DEFINITIONS(-DDEFAULT_CHARSET_HOME="c:/Program Files/MySQL/MySQL Server ${MYSQL_BASE_VERSION}/")
ADD_DEFINITIONS(-DPACKAGE=mysql)
ADD_DEFINITIONS(-DSHAREDIR="share")

# Set debug options
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DFORCE_INIT_OF_VARS")

SET(localstatedir "C:\\\\mysql\\\\data\\\\")
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/support-files/my-huge.cnf.sh
               ${CMAKE_SOURCE_DIR}/support-files/my-huge.ini @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/support-files/my-innodb-heavy-4G.cnf.sh
               ${CMAKE_SOURCE_DIR}/support-files/my-innodb-heavy-4G.ini @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/support-files/my-large.cnf.sh
               ${CMAKE_SOURCE_DIR}/support-files/my-large.ini @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/support-files/my-medium.cnf.sh
               ${CMAKE_SOURCE_DIR}/support-files/my-medium.ini @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/support-files/my-small.cnf.sh
               ${CMAKE_SOURCE_DIR}/support-files/my-small.ini @ONLY)


ADD_DEFINITIONS(-D__NT__)

IF(CYBOZU)
  ADD_DEFINITIONS(-DCYBOZU)
  ADD_DEFINITIONS(-DHAVE_UTF8_GENERAL_CS)
ENDIF(CYBOZU)

IF(EXTRA_DEBUG)
  ADD_DEFINITIONS(-D EXTRA_DEBUG)
ENDIF(EXTRA_DEBUG)

SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFE_MUTEX")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFE_MUTEX")

OPTION (WITH_DEBUG_FULL "Enable malloc debug library (only debug builds)" OFF)
IF(WITH_DEBUG_FULL)
  SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC")
  SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC")
ENDIF()

IF(ENABLED_DEBUG_SYNC)
  ADD_DEFINITIONS(-D ENABLED_DEBUG_SYNC)
ENDIF(ENABLED_DEBUG_SYNC)
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DENABLED_DEBUG_SYNC")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DENABLED_DEBUG_SYNC")

# in some places we use DBUG_OFF
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DDBUG_OFF")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DDBUG_OFF")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DDBUG_OFF")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DDBUG_OFF")

#TODO: update the code and remove the disabled warnings
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4800 /wd4805")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4800 /wd4805")

# Disable warnings in Visual Studio 8 and above
IF(MSVC AND NOT CMAKE_GENERATOR MATCHES "Visual Studio 7")
    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4996")
    SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /wd4996")
    SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /wd4996")
    SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /wd4996")
    SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /wd4996")
    SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /wd4996")
ENDIF(MSVC AND NOT CMAKE_GENERATOR MATCHES "Visual Studio 7")

IF(CMAKE_GENERATOR MATCHES "Visual Studio 7")
    # VS2003 has a bug that prevents linking mysqld with module definition file 
    # (/DEF option for linker). Linker would incorrectly complain about multiply 
    # defined symbols. Workaround is to disable dynamic plugins, so /DEF is not
    # used.
    MESSAGE("Warning: Building MySQL with Visual Studio 2003.NET is no more supported.")
    MESSAGE("Please use a newer version of Visual Studio.")
    SET(WITHOUT_DYNAMIC_PLUGINS TRUE)
ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio 7")

# Settings for Visual Studio 7 and above.  
IF(MSVC)
    # replace /MDd with /MTd
    STRING(REPLACE "/MD"  "/MT"  CMAKE_C_FLAGS_RELEASE          ${CMAKE_C_FLAGS_RELEASE})
    STRING(REPLACE "/MD"  "/MT"  CMAKE_C_FLAGS_RELWITHDEBINFO   ${CMAKE_C_FLAGS_RELWITHDEBINFO})
    STRING(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG            ${CMAKE_C_FLAGS_DEBUG})
    STRING(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG_INIT       ${CMAKE_C_FLAGS_DEBUG_INIT})

    STRING(REPLACE "/MD"  "/MT"  CMAKE_CXX_FLAGS_RELEASE        ${CMAKE_CXX_FLAGS_RELEASE})
    STRING(REPLACE "/MD"  "/MT"  CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
    STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG          ${CMAKE_CXX_FLAGS_DEBUG})
    STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG_INIT     ${CMAKE_CXX_FLAGS_DEBUG_INIT})

    # generate map files, set stack size (see bug#20815)
    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:1048576")

    # remove support for Exception handling
    STRING(REPLACE "/GX"   "" CMAKE_CXX_FLAGS            ${CMAKE_CXX_FLAGS})
    STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS            ${CMAKE_CXX_FLAGS})
    STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS_INIT       ${CMAKE_CXX_FLAGS_INIT})
    STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS_DEBUG_INIT ${CMAKE_CXX_FLAGS_DEBUG_INIT})
    
    # Mark 32 bit executables large address aware so they can 
    # use > 2GB address space
    IF(CMAKE_SIZEOF_VOID_P MATCHES 4)
      SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
    ENDIF(CMAKE_SIZEOF_VOID_P MATCHES 4)
    
    # Disable automatic manifest generation.
    STRING(REPLACE "/MANIFEST" "/MANIFEST:NO" CMAKE_EXE_LINKER_FLAGS 
    	   ${CMAKE_EXE_LINKER_FLAGS})
    # Explicitly disable it since it is the default for newer versions of VS
    STRING(REGEX MATCH "MANIFEST:NO" tmp_manifest ${CMAKE_EXE_LINKER_FLAGS})
    IF(NOT tmp_manifest)
        SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
    ENDIF(NOT tmp_manifest)
ENDIF(MSVC)

IF(WIN32)
  ADD_DEFINITIONS("-D_WINDOWS -D__WIN__ -D_CRT_SECURE_NO_DEPRECATE")
  ADD_DEFINITIONS("-D_WIN32_WINNT=0x0501")
ENDIF(WIN32)

# default to x86 platform.  We'll check for X64 in a bit
SET (PLATFORM X86)

# This definition is necessary to work around a bug with Intellisense described
# here: http://tinyurl.com/2cb428.  Syntax highlighting is important for proper
# debugger functionality.
IF(CMAKE_SIZEOF_VOID_P MATCHES 8)
    MESSAGE(STATUS "Detected 64-bit platform.")
    ADD_DEFINITIONS("-D_WIN64")
    SET (PLATFORM X64)
ENDIF(CMAKE_SIZEOF_VOID_P MATCHES 8)

IF(EMBED_MANIFESTS)
    # Search for the tools (mt, makecat, signtool) necessary for embedding
    # manifests and signing executables with the MySQL AB authenticode cert.
    #
    # CMake will first search it's defaults (CMAKE_FRAMEWORK_PATH, 
    # CMAKE_APPBUNDLE_PATH, CMAKE_PROGRAM_PATH and the system PATH) followed 
    # by the listed paths which are the current possible defaults and should be
    # updated when necessary.  
    # 
    # The custom manifests are designed to be compatible with all mt versions.
    # The MySQL AB Authenticode certificate is available only internally.  
    # Others should store a single signing certificate in a local cryptographic
    # service provider and alter the signtool command as necessary.
    FIND_PROGRAM(HAVE_MANIFEST_TOOL NAMES mt
                 PATHS
                 "$ENV{PROGRAMFILES}/Microsoft Visual Studio 8/VC/bin"
                 "$ENV{PROGRAMFILES}/Microsoft Visual Studio 8/Common7/Tools/Bin"
                 "$ENV{PROGRAMFILES}/Microsoft Visual Studio 8/SDK/v2.0/Bin")
    FIND_PROGRAM(HAVE_CATALOG_TOOL NAMES makecat
                 PATHS
                 "$ENV{PROGRAMFILES}/Microsoft Visual Studio 8/Common7/Tools/Bin")
    FIND_PROGRAM(HAVE_SIGN_TOOL NAMES signtool
                 PATHS
                 "$ENV{PROGRAMFILES}/Microsoft Visual Studio 8/Common7/Tools/Bin"
                 "$ENV{PROGRAMFILES}/Microsoft Visual Studio 8/SDK/v2.0/Bin")

    IF(HAVE_MANIFEST_TOOL)
        MESSAGE(STATUS "Found Mainfest Tool.")
    ELSE(HAVE_MANIFEST_TOOL)
        MESSAGE(FATAL_ERROR "Manifest tool, mt.exe, can't be found.")
    ENDIF(HAVE_MANIFEST_TOOL)
    IF(HAVE_CATALOG_TOOL)
        MESSAGE(STATUS "Found Catalog Tool.")
    ELSE(HAVE_CATALOG_TOOL)
        MESSAGE(FATAL_ERROR "Catalog tool, makecat.exe, can't be found.")
    ENDIF(HAVE_CATALOG_TOOL)
    IF(HAVE_SIGN_TOOL)
        MESSAGE(STATUS "Found Sign Tool. Embedding custom manifests and signing executables.")
    ELSE(HAVE_SIGN_TOOL)
        MESSAGE(FATAL_ERROR "Sign tool, signtool.exe, can't be found.")
    ENDIF(HAVE_SIGN_TOOL)

    # Set the processor architecture.
    IF(CMAKE_GENERATOR MATCHES "Visual Studio 8 2005 Win64")
    	SET(PROCESSOR_ARCH "amd64") 
    ELSE(CMAKE_GENERATOR MATCHES "Visual Studio 8 2005 Win64")
    	SET(PROCESSOR_ARCH "X86")
    ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio 8 2005 Win64")
ENDIF(EMBED_MANIFESTS)

# Figure out what engines to build and how (statically or dynamically),
# add preprocessor defines for storage engines.
IF(WITHOUT_DYNAMIC_PLUGINS)
  MESSAGE("Dynamic plugins are disabled.")
ENDIF(WITHOUT_DYNAMIC_PLUGINS)

FILE(GLOB STORAGE_SUBDIRS storage/* plugin/*)
FOREACH(SUBDIR ${STORAGE_SUBDIRS})
  IF (EXISTS ${SUBDIR}/CMakeLists.txt)
    # Check  MYSQL_STORAGE_ENGINE macro is present
    FILE(STRINGS ${SUBDIR}/CMakeLists.txt HAVE_STORAGE_ENGINE REGEX "MYSQL_(STORAGE_ENGINE|PLUGIN)")
    IF(HAVE_STORAGE_ENGINE)
      # Extract name of engine from HAVE_STORAGE_ENGINE
      STRING(REGEX REPLACE ".*MYSQL_(STORAGE_ENGINE|PLUGIN)\\((.*\)\\).*"
           "\\2" ENGINE_NAME ${HAVE_STORAGE_ENGINE})
      STRING(TOUPPER ${ENGINE_NAME} ENGINE)
      STRING(TOLOWER ${ENGINE_NAME} ENGINE_LOWER) 
    
      SET(ENGINE_BUILD_TYPE "DYNAMIC")
      # Read plug.in to find out if a plugin is mandatory and whether it supports
      # build as shared library (dynamic).
      IF(EXISTS ${SUBDIR}/plug.in)
        FILE(READ ${SUBDIR}/plug.in PLUGIN_FILE_CONTENT)
        IF (PLUGIN_FILE_CONTENT MATCHES "MYSQL_PLUGIN_DYNAMIC\\(${ENGINE_LOWER}")
          STRING (REGEX REPLACE
                  ".*MYSQL_PLUGIN_DYNAMIC\\(${ENGINE_LOWER},[ \\t]*\\[?([a-zA-Z0-9_]+/)*([a-zA-Z0-9_]+).*"
                  "\\2" MYSQL_PLUGIN_DYNAMIC  ${PLUGIN_FILE_CONTENT})
        ELSE (PLUGIN_FILE_CONTENT MATCHES "MYSQL_PLUGIN_DYNAMIC\\(${ENGINE_LOWER}")
          SET (MYSQL_PLUGIN_DYNAMIC "")
        ENDIF(PLUGIN_FILE_CONTENT MATCHES "MYSQL_PLUGIN_DYNAMIC\\(${ENGINE_LOWER}")
        IF (PLUGIN_FILE_CONTENT MATCHES "MYSQL_PLUGIN_STATIC\\(${ENGINE_LOWER}")
          STRING (REGEX REPLACE
            ".*MYSQL_PLUGIN_STATIC\\(${ENGINE_LOWER},[ \\t]*\\[?([a-zA-Z0-9_]+/)*([a-zA-Z0-9_]+).*"
                  "\\2"
                  MYSQL_PLUGIN_STATIC  ${PLUGIN_FILE_CONTENT})
        ELSE (PLUGIN_FILE_CONTENT MATCHES "MYSQL_PLUGIN_STATIC\\(${ENGINE_LOWER}")
          SET (MYSQL_PLUGIN_STATIC "")
        ENDIF(PLUGIN_FILE_CONTENT MATCHES "MYSQL_PLUGIN_STATIC\\(${ENGINE_LOWER}")
        STRING (REGEX MATCH  "MYSQL_PLUGIN_MANDATORY"  MYSQL_PLUGIN_MANDATORY  ${PLUGIN_FILE_CONTENT})
        
        IF(MYSQL_PLUGIN_MANDATORY)
          SET(WITH_${ENGINE}_STORAGE_ENGINE TRUE)
        ENDIF(MYSQL_PLUGIN_MANDATORY)

        IF (WITH_${ENGINE}_STORAGE_ENGINE AND MYSQL_PLUGIN_STATIC)
          SET(ENGINE_BUILD_TYPE "STATIC")
        ELSEIF(NOT WITHOUT_${ENGINE}_STORAGE_ENGINE AND MYSQL_PLUGIN_DYNAMIC AND NOT WITHOUT_DYNAMIC_PLUGINS)
          SET(ENGINE_BUILD_TYPE "DYNAMIC")
        ELSE(WITH_${ENGINE}_STORAGE_ENGINE AND MYSQL_PLUGIN_STATIC)
          SET(ENGINE_BUILD_TYPE "NONE")
        ENDIF(WITH_${ENGINE}_STORAGE_ENGINE AND MYSQL_PLUGIN_STATIC)

        IF (ENGINE_BUILD_TYPE STREQUAL "STATIC") 
          SET (mysql_plugin_defs  "${mysql_plugin_defs},builtin_${ENGINE_LOWER}_plugin")
          SET (MYSQLD_STATIC_ENGINE_LIBS ${MYSQLD_STATIC_ENGINE_LIBS} ${MYSQL_PLUGIN_STATIC})
          SET (MYSQLD_STATIC_ENGINES ${MYSQLD_STATIC_ENGINES} ${ENGINE})
          SET (STORAGE_ENGINE_DEFS "${STORAGE_ENGINE_DEFS} -DWITH_${ENGINE}_STORAGE_ENGINE")
          SET (WITH_${ENGINE}_STORAGE_ENGINE TRUE)
	  SET (${ENGINE}_DIR ${SUBDIR})
        ENDIF (ENGINE_BUILD_TYPE STREQUAL "STATIC")
      ENDIF(EXISTS ${SUBDIR}/plug.in)

      IF(NOT ENGINE_BUILD_TYPE STREQUAL "NONE")
        SET (${ENGINE}_LIB ${MYSQL_PLUGIN_${ENGINE_BUILD_TYPE}})
        LIST(APPEND  ${ENGINE_BUILD_TYPE}_ENGINE_DIRECTORIES  ${SUBDIR})
      ENDIF(NOT ENGINE_BUILD_TYPE STREQUAL "NONE")
      
    ENDIF(HAVE_STORAGE_ENGINE)
  ENDIF(EXISTS ${SUBDIR}/CMakeLists.txt)
ENDFOREACH(SUBDIR ${STORAGE_SUBDIRS})

# Special handling for partition(not really pluggable)
IF(NOT WITHOUT_PARTITION_STORAGE_ENGINE)
  SET (STORAGE_ENGINE_DEFS "${STORAGE_ENGINE_DEFS} -DWITH_PARTITION_STORAGE_ENGINE")
  SET (mysql_plugin_defs  "${mysql_plugin_defs},builtin_partition_plugin")
ENDIF(NOT WITHOUT_PARTITION_STORAGE_ENGINE)

# Special handling for tmp tables with the maria engine
IF(WITH_MARIA_STORAGE_ENGINE)
  ADD_DEFINITIONS(-DWITH_MARIA_STORAGE_ENGINE)
  IF(WITH_MARIA_TMP_TABLES)
    ADD_DEFINITIONS(-DUSE_MARIA_FOR_TMP_TABLES)
  ENDIF(WITH_MARIA_TMP_TABLES)
ENDIF(WITH_MARIA_STORAGE_ENGINE)

ADD_DEFINITIONS(${STORAGE_ENGINE_DEFS}) 

# Now write out our mysql_plugin_defs struct
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc.in 
               ${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc @ONLY)

# Add subdirectories for storage engines
SET (ENGINE_BUILD_TYPE "STATIC")
FOREACH(DIR ${STATIC_ENGINE_DIRECTORIES})
  ADD_SUBDIRECTORY(${DIR})
ENDFOREACH(DIR ${STATIC_ENGINE_DIRECTORIES})

SET (ENGINE_BUILD_TYPE "DYNAMIC")
FOREACH(DIR ${DYNAMIC_ENGINE_DIRECTORIES})
  ADD_SUBDIRECTORY(${DIR})
ENDFOREACH(DIR ${DYNAMIC_ENGINE_DIRECTORIES})


# FIXME "debug" only needed if build type is "Debug", but
# CMAKE_BUILD_TYPE is not set during configure time.
ADD_SUBDIRECTORY(vio)
ADD_SUBDIRECTORY(dbug)
ADD_SUBDIRECTORY(strings)
ADD_SUBDIRECTORY(regex)
ADD_SUBDIRECTORY(mysys)
ADD_SUBDIRECTORY(scripts)
ADD_SUBDIRECTORY(zlib)
ADD_SUBDIRECTORY(extra/yassl)
ADD_SUBDIRECTORY(extra/yassl/taocrypt)
ADD_SUBDIRECTORY(extra/libevent)
ADD_SUBDIRECTORY(extra)
ADD_SUBDIRECTORY(client)
ADD_SUBDIRECTORY(sql)
ADD_SUBDIRECTORY(server-tools/instance-manager)
ADD_SUBDIRECTORY(libmysql)
ADD_SUBDIRECTORY(tests)
ADD_SUBDIRECTORY(unittest/mytap)
ADD_SUBDIRECTORY(unittest/mysys)
IF(WITH_EMBEDDED_SERVER) 
  ADD_SUBDIRECTORY(libmysqld)
  ADD_SUBDIRECTORY(libmysqld/examples)
ENDIF(WITH_EMBEDDED_SERVER)
ADD_SUBDIRECTORY(mysql-test/lib/My/SafeProcess)

# Set up the installer
SET(CPACK_PACKAGE_NAME "MariaDB")
STRING(REPLACE "-MariaDB" "" CPACK_PACKAGE_VERSION ${VERSION})
SET(CPACK_PACKAGE_VENDOR "Monty Program AB http://www.montyprogram.com")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MariaDB")
SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/COPYING)
SET(CPACK_GENERATOR NSIS)

# Use our own NSIS template
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/win/cmake" ${CMAKE_MODULE_PATH})

# Installer components and grouping
SET(CPACK_COMPONENT_GROUP_SERVER_DESCRIPTION "The files necessary for running the MariaDB server.")
SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION "Files used in development on the MariaDB server.")
SET(CPACK_ALL_INSTALL_TYPES Normal Development)
SET(CPACK_COMPONENT_RUNTIME_DISPLAY_NAME "MariaDB server")
SET(CPACK_COMPONENT_RUNTIME_DESCRIPTION "The server itself. You want to install this one.")
SET(CPACK_COMPONENT_RUNTIME_GROUP "Server")
SET(CPACK_COMPONENT_RUNTIME_INSTALL_TYPES Normal Development)
SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "Development headers")
SET(CPACK_COMPONENT_HEADERS_DESCRIPTION "Header files for development on MariaDB.")
SET(CPACK_COMPONENT_HEADERS_DEPENDS runtime)
SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Development)
SET(CPACK_COMPONENT_EMBEDDED_DISPLAY_NAME "Embedded")
SET(CPACK_COMPONENT_EMBEDDED_DESCRIPTION "Files for embedding MariaDB in other projects.")
SET(CPACK_COMPONENT_EMBEDDED_DEPENDS headers)
SET(CPACK_COMPONENT_EMBEDDED_GROUP "Development")
SET(CPACK_COMPONENT_EMBEDDED_INSTALL_TYPES Development)
SET(CPACK_COMPONENT_SCRIPTS_DISPLAY_NAME "Server scripts")
SET(CPACK_COMPONENT_SCRIPTS_DESCRIPTION "SQL and Perl scripts to control and modify the server. You need a perl installation for some of these to work.")
SET(CPACK_COMPONENT_SCRIPTS_DEPENDS runtime)
SET(CPACK_COMPONENT_SCRIPTS_GROUP "Server")
SET(CPACK_COMPONENT_SCRIPTS_INSTALL_TYPES Normal Development)
SET(CPACK_COMPONENT_MYSQLTEST_DISPLAY_NAME "MariaDB test suite")
SET(CPACK_COMPONENT_MYSQLTEST_DESCRIPTION "The MariaDB regression test suite.")
SET(CPACK_COMPONENT_MYSQLTEST_DEPENDS runtime)
SET(CPACK_COMPONENT_MYSQLTEST_GROUP "Testing")
SET(CPACK_COMPONENT_MYSQLTEST_INSTALL_TYPES Normal Development)
SET(CPACK_COMPONENT_SQLBENCH_DISPLAY_NAME "SQL Bench")
SET(CPACK_COMPONENT_SQLBENCH_DESCRIPTION "The MariaDB benchmark suite.")
SET(CPACK_COMPONENT_SQLBENCH_DEPENDS runtime)
SET(CPACK_COMPONENT_SQLBENCH_GROUP "Testing")
SET(CPACK_COMPONENT_SQLBENCH_INSTALL_TYPES Normal Development)

# Add files to the installer
INSTALL(FILES COPYING EXCEPTIONS-CLIENT DESTINATION .)
INSTALL(FILES support-files/my-huge.ini support-files/my-innodb-heavy-4G.ini DESTINATION .)
INSTALL(FILES support-files/my-large.ini support-files/my-medium.ini DESTINATION .)
INSTALL(FILES support-files/my-small.ini DESTINATION .)
INSTALL(FILES Docs/INSTALL-BINARY DESTINATION Docs)
INSTALL(FILES COPYING DESTINATION Docs)
FILE(GLOB headerfiles "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
INSTALL(FILES ${headerfiles} DESTINATION include COMPONENT headers)
INSTALL(FILES include/mysql/plugin.h DESTINATION include/mysql COMPONENT headers)
INSTALL(FILES libmysql/libmysql.def DESTINATION include COMPONENT headers)

# Handle the database files
FILE(GLOB datafiles "${CMAKE_CURRENT_SOURCE_DIR}/win/data/mysql/*")
INSTALL(FILES ${datafiles} DESTINATION data/clean/mysql)
INSTALL(FILES win/data/maria_log.00000001 win/data/maria_log_control DESTINATION data/clean)
INSTALL(DIRECTORY win/data/test DESTINATION data/clean)
SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}
  IfFileExists '$INSTDIR\\\\data\\\\mysql\\\\db.frm' 0 CopyDatabaseFiles
    MessageBox MB_OK 'There are already database files present in the data directory. Clean database files are not written to the directory'
    GoTo EndCopyDatabaseFiles
  CopyDatabaseFiles:
    CopyFiles '$INSTDIR\\\\data\\\\clean\\\\*' '$INSTDIR\\\\data'
  EndCopyDatabaseFiles:")
SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}
  MessageBox MB_OK 'This will not delete the database files in $INSTDIR\\\\data'")

# Files in the share dir
INSTALL(FILES sql/share/errmsg.txt DESTINATION share COMPONENT runtime)
FILE(GLOB charsets sql/share/charsets/*)
INSTALL(FILES ${charsets} DESTINATION share/charsets COMPONENT runtime)
FILE(GLOB share_dirs sql/share/*/errmsg.sys)
FOREACH(ERRMSGFILE ${share_dirs})
  STRING(REPLACE "//" "/" ERRMSGFILE ${ERRMSGFILE}) # Work around a cmake bug
  FILE(RELATIVE_PATH DIRNAME ${PROJECT_SOURCE_DIR}/sql/share ${ERRMSGFILE})
  STRING(REPLACE "/errmsg.sys" "" DIRNAME ${DIRNAME})
  INSTALL(FILES ${ERRMSGFILE} DESTINATION share/${DIRNAME} COMPONENT runtime)
ENDFOREACH(ERRMSGFILE ${share_dirs})

# MTR files
FILE(GLOB_RECURSE testfiles mysql-test/*)
FOREACH(testfile ${testfiles})
    FILE(RELATIVE_PATH dirname ${PROJECT_SOURCE_DIR} ${testfile})
    GET_FILENAME_COMPONENT(dirname ${dirname} PATH)
	GET_FILENAME_COMPONENT(filename ${testfile} NAME)
	GET_FILENAME_COMPONENT(ext ${testfile} EXT)
	SET(ok "yes")
	IF (NOT "x_${ext}" STREQUAL "x_")
		# Test if this is one of the extensions we don't want to install
		STRING(TOLOWER ${ext} ext)
		IF(${ext} STREQUAL ".dir" OR ${ext} STREQUAL ".vcproj" OR ${ext} STREQUAL ".user" OR ${ext} STREQUAL ".ilk"
				OR ${ext} STREQUAL ".idb" OR ${ext} STREQUAL ".map" OR ${ext} STREQUAL ".gcov"
				OR ${ext} STREQUAL ".supp" OR ${ext} STREQUAL ".am" OR ${ext} STREQUAL ".stress")
			SET(ok "no")
		ENDIF()
	ENDIF(NOT "x_${ext}" STREQUAL "x_")
	IF (${ok} STREQUAL "yes")
		# Message("Dir: ${dirname}. File: ${filename}. Ext: ${ext}")
		INSTALL(FILES ${testfile} DESTINATION ${dirname} COMPONENT mysqltest)
	ENDIF(${ok} STREQUAL "yes")
ENDFOREACH(testfile ${testfiles})

# SQL Bench
FILE(GLOB_RECURSE benchfiles sql-bench/*)
FOREACH(testfile ${testfiles})
    FILE(RELATIVE_PATH dirname ${PROJECT_SOURCE_DIR} ${testfile})
    GET_FILENAME_COMPONENT(dirname ${dirname} PATH)
	GET_FILENAME_COMPONENT(filename ${testfile} NAME)
	IF(NOT ${dirname} STREQUAL "sql-bench" OR ${filename} STREQUAL "README")
		INSTALL(FILES ${testfile} DESTINATION ${dirname} COMPONENT sqlbench)
	ENDIF()
ENDFOREACH(testfile ${testfiles})

INCLUDE(InstallRequiredSystemLibraries)

# This must always be the last line
INCLUDE(CPack)