summaryrefslogtreecommitdiffstats
path: root/libmariadb/CMakeLists.txt
blob: 206e4e0322e13b178aa2a8b7245dc9b0b3942856 (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
# CMakeLists.txt

# This is the LGPL libmariadb project.

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR)
INCLUDE(CheckFunctionExists)
IF(COMMAND CMAKE_POLICY)
  SET(NEW_POLICIES CMP0003 CMP0022 CMP0023 CMP0057 CMP0077 CMP0069 CMP0075)
  FOREACH(TYPE OLD NEW)
    FOREACH(P ${${TYPE}_POLICIES})
      IF(POLICY ${P})
        CMAKE_POLICY(SET ${P} ${TYPE})
      ENDIF()
    ENDFOREACH()
  ENDFOREACH()
ENDIF()


PROJECT(mariadb-connector-c C)

# Is C/C built as subproject?
get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY)

# do not inherit include directories from the parent project
SET_PROPERTY(DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
FOREACH(V WITH_MYSQLCOMPAT WITH_MSI WITH_SIGNCODE WITH_RTC WITH_UNIT_TESTS
    WITH_DYNCOL WITH_EXTERNAL_ZLIB WITH_CURL WITH_SQLITE WITH_SSL WITH_ICONV
    DEFAULT_CHARSET INSTALL_LAYOUT WITH_TEST_SRCPKG)
  SET(${V} ${${OPT}${V}})
ENDFOREACH()

# SET(PACKAGE_STATUS_SUFFIX "rc1")

SET(CC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
SET(CC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

SET(CPACK_PACKAGE_VERSION_MAJOR 3)
SET(CPACK_PACKAGE_VERSION_MINOR 3)
SET(CPACK_PACKAGE_VERSION_PATCH 8)
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
MATH(EXPR MARIADB_PACKAGE_VERSION_ID "${CPACK_PACKAGE_VERSION_MAJOR} * 10000 +
                            ${CPACK_PACKAGE_VERSION_MINOR} * 100   +
                            ${CPACK_PACKAGE_VERSION_PATCH}")

MACRO(ADD_OPTION _name _text _default)
  IF(NOT DEFINED ${_name})
    OPTION(${OPT}${_name} "${_text}" "${_default}")
  ELSE()
    OPTION(${OPT}${_name} "${_text}" "${${_name}}")
  ENDIF()
ENDMACRO()

### Options ###
IF(NOT WIN32)
  ADD_OPTION(WITH_MYSQLCOMPAT "creates libmysql* symbolic links" OFF)
ELSE()
  ADD_OPTION(WITH_MSI "Build MSI installation package" OFF)
  ADD_OPTION(WITH_SIGNCODE "digitally sign files" OFF)
  ADD_OPTION(WITH_RTC "enables run time checks for debug builds" OFF)
  ADD_OPTION(WITH_ICONV "enables character set conversion" OFF)
ENDIF()

ADD_OPTION(WITH_UNIT_TESTS "build test suite" ON)
ADD_OPTION(WITH_DYNCOL "Enables support of dynamic columns" ON)
ADD_OPTION(WITH_EXTERNAL_ZLIB "Enables use of external zlib" OFF)
ADD_OPTION(WITH_CURL "Enables use of curl" ON)
ADD_OPTION(WITH_SSL "Enables use of TLS/SSL library" ON)
###############

INCLUDE(${CC_SOURCE_DIR}/cmake/misc.cmake)
INCLUDE(FindCURL)

IF(WITH_SIGNCODE)
  IF(WIN32 AND NOT SIGN_OPTIONS)
    SET(SIGN_OPTIONS /tr http://timestamp.digicert.com /td sha256 /fd sha256 /a)
  ELSE()
    SEPARATE_ARGUMENTS(SIGN_OPTIONS)
  ENDIF()
  MARK_AS_ADVANCED(SIGN_OPTIONS)
ENDIF()

SET(MARIADB_CONNECTOR_C_COPYRIGHT "2013-2017 MariaDB Corporation Ab")

IF(WITH_RTC)
  SET(RTC_OPTIONS "/RTC1 /RTCc")
ENDIF()

INCLUDE(${CC_SOURCE_DIR}/cmake/plugins.cmake)


IF(WIN32)
  FILE(REMOVE ${CC_BINARY_DIR}/win/packaging/plugin.conf)
  INCLUDE(${CC_SOURCE_DIR}/cmake/version_info.cmake)
ENDIF()

IF(NOT IS_SUBPROJECT)
IF(MSVC)
  # Speedup system tests
  INCLUDE(${CC_SOURCE_DIR}/cmake/WindowsCache.cmake)
  ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN -DNOGDI)
  IF (MSVC)
    SET(CONFIG_TYPES "DEBUG" "RELEASE" "RELWITHDEBINFO")
    FOREACH(BUILD_TYPE ${CONFIG_TYPES})
      FOREACH(COMPILER CXX C)
        SET(COMPILER_FLAGS "${CMAKE_${COMPILER}_FLAGS_${BUILD_TYPE}}")
        IF (NOT COMPILER_FLAGS STREQUAL "")
          IF(NOT WITH_ASAN)
            STRING(REPLACE "/MD" "/MT" COMPILER_FLAGS ${COMPILER_FLAGS})
            IF (BUILD_TYPE STREQUAL "DEBUG")
              SET(COMPILER_FLAGS "${COMPILER_FLAGS} ${RTC_OPTIONS}")
            ENDIF()
          ENDIF()
          STRING(REPLACE "/Zi" "/Z7" COMPILER_FLAGS ${COMPILER_FLAGS})
          MESSAGE (STATUS "CMAKE_${COMPILER}_FLAGS_${BUILD_TYPE}= ${COMPILER_FLAGS}")
          SET(CMAKE_${COMPILER}_FLAGS_${BUILD_TYPE} ${COMPILER_FLAGS})
        ENDIF()
      ENDFOREACH()
    ENDFOREACH()
  ENDIF()
ENDIF()
ELSE()
  # MDEV-16383
  IF(WITH_EMBEDDED_SERVER)
    ADD_DEFINITIONS(-DHAVE_EMBEDDED)
  ENDIF()
ENDIF(NOT IS_SUBPROJECT)

# Disable dbug information for release builds
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DDBUG_OFF")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DDBUG_OFF")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DDBUG_OFF")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DDBUG_OFF")

IF(CMAKE_COMPILER_IS_GNUCC)
  INCLUDE(CheckCCompilerFlag)
  SET(GCC_FLAGS -Wunused -Wlogical-op -Wno-uninitialized  -Wall -Wextra -Wformat-security -Wno-init-self -Wwrite-strings -Wshift-count-overflow -Wdeclaration-after-statement -Wno-undef -Wno-unknown-pragmas -Wno-stringop-truncation)
  FOREACH(GCC_FLAG ${GCC_FLAGS})
    CHECK_C_COMPILER_FLAG("${GCC_FLAG}" HAS_${GCC_FLAG}_FLAG)
    IF(${HAS_${GCC_FLAG}_FLAG})
      SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_FLAG}")
    ENDIF()
  ENDFOREACH()
ENDIF()

# If the build type isn't specified, set to Relwithdebinfo as default.
IF(NOT CMAKE_BUILD_TYPE)
  SET(CMAKE_BUILD_TYPE "RelWithDebInfo")
ENDIF()

# various defines for generating include/mysql_version.h
INCLUDE(FindGit)
IF(GIT_EXECUTABLE AND EXISTS ${CC_SOURCE_DIR}/.git)
  EXECUTE_PROCESS(
    COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
      WORKING_DIRECTORY ${CC_SOURCE_DIR}
       OUTPUT_VARIABLE OUT RESULT_VARIABLE RES)
   IF(RES EQUAL 0)
    STRING(REGEX REPLACE "\n$" "" CC_SOURCE_REVISION "${OUT}")
  ENDIF()
ENDIF()
SET(PROTOCOL_VERSION 10) # we adapted new password option from PHP's mysqlnd !

# if C/C is build as subproject inside MariaDB server tree we will
# use the version defined by server
IF(MAJOR_VERSION)
  SET(MARIADB_CLIENT_VERSION_MAJOR ${MAJOR_VERSION})
  SET(MARIADB_CLIENT_VERSION_MINOR ${MINOR_VERSION})
  SET(MARIADB_CLIENT_VERSION_PATCH ${PATCH_VERSION})
  SET(MARIADB_CLIENT_VERSION_EXTRA ${EXTRA_VERSION})
ELSE()
  SET(MARIADB_CLIENT_VERSION_MAJOR "10")
  SET(MARIADB_CLIENT_VERSION_MINOR "8")
  SET(MARIADB_CLIENT_VERSION_PATCH "8")
  SET(MARIADB_CLIENT_VERSION_EXTRA "")
ENDIF()

IF(WIN32)
 # version in resource files need to be consistent
 # with server's , so that MSI minor upgrade work.
 # if this is not a subproject build, C/C version is used.
  FOREACH(v MAJOR MINOR PATCH TINY)
    IF(DEFINED ${v}_VERSION)
      SET(${v}_FILE_VERSION "${${v}_VERSION}")
    ELSEIF(DEFINED CPACK_PACKAGE_VERSION_${v})
      SET(${v}_FILE_VERSION "${CPACK_PACKAGE_VERSION_${v}}")
    ELSE()
      SET(${v}_FILE_VERSION "0")
    ENDIF()
    IF(NOT ${v}_FILE_VERSION MATCHES "^[0-9]+$")
      MESSAGE(FATAL_ERROR
        "${v}_FILE_VERSION is not numeric - '${${v}_FILE_VERSION}'")
    ENDIF()
  ENDFOREACH()
ENDIF()

SET(MARIADB_CLIENT_VERSION "${MARIADB_CLIENT_VERSION_MAJOR}.${MARIADB_CLIENT_VERSION_MINOR}.${MARIADB_CLIENT_VERSION_PATCH}${MARIADB_CLIENT_VERSION_EXTRA}")
SET(MARIADB_BASE_VERSION "mariadb-${MARIADB_CLIENT_VERSION_MAJOR}.${MARIADB_CLIENT_VERSION_MINOR}")
MATH(EXPR MARIADB_VERSION_ID "${MARIADB_CLIENT_VERSION_MAJOR} * 10000 +
                              ${MARIADB_CLIENT_VERSION_MINOR} * 100   +
                              ${MARIADB_CLIENT_VERSION_PATCH}")

IF (NOT MARIADB_PORT)
  SET(MARIADB_PORT 3306)
ENDIF ()
IF(NOT MARIADB_UNIX_ADDR)
  SET(MARIADB_UNIX_ADDR "/tmp/mysql.sock")
ENDIF()

INCLUDE("${CC_SOURCE_DIR}/cmake/install.cmake")
IF(NOT PLUGINDIR)
  SET(PLUGINDIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_PLUGINDIR}")
ENDIF()

# todo: we don't character sets in share - all is compiled in
SET(SHAREDIR "share")
SET(DEFAULT_CHARSET_HOME "${CMAKE_INSTALL_PREFIX}")

INCLUDE(${CC_SOURCE_DIR}/cmake/SearchLibrary.cmake)

# Compression plugins: ZSTD, ZLIB

INCLUDE(${CC_SOURCE_DIR}/cmake/FindZStd.cmake)

IF(WITH_EXTERNAL_ZLIB)
  IF(NOT ZLIB_FOUND)
    FIND_PACKAGE(ZLIB REQUIRED)
  ENDIF()
  SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${ZLIB_LIBRARIES})
ELSE()
  SET(ZLIB_INCLUDE_DIR "${CC_SOURCE_DIR}/external/zlib")
  ADD_SUBDIRECTORY("${CC_SOURCE_DIR}/external/zlib")
ENDIF()
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})

IF(NOT WIN32)
  INCLUDE(TestBigEndian)
  TEST_BIG_ENDIAN(HAVE_BIGENDIAN)
ENDIF()

# check for various include files
INCLUDE(${CC_SOURCE_DIR}/cmake/check_include_files.cmake)
# check for various functions
INCLUDE(${CC_SOURCE_DIR}/cmake/check_functions.cmake)
# check for various types
INCLUDE(${CC_SOURCE_DIR}/cmake/check_types.cmake)

IF(UNIX)
  SEARCH_LIBRARY(LIBM floor m)
  SEARCH_LIBRARY(LIBPTHREAD pthread_getspecific "pthread;pthreads")
  SEARCH_LIBRARY(LIBNSL gethostbyname_r "nsl_r;nsl")
  SEARCH_LIBRARY(LIBSOCKET setsockopt socket)
  FIND_PACKAGE(Threads)
  SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBNSL} ${LIBBIND} ${LIBICONV} ${ZLIB_LIBRARY} 
      ${LIBSOCKET} ${CMAKE_DL_LIBS} ${LIBM} ${LIBPTHREAD})
  SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${LIBNSL} ${LIBBIND} ${LIBICONV} 
    ${LIBSOCKET} ${CMAKE_DL_LIBS} ${LIBM} ${LIBPTHREAD})
  #remove possible dups from required libraries
  LIST(LENGTH CMAKE_REQUIRED_LIBRARIES rllength)
  IF(${rllength} GREATER 0)
    LIST(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES)
  ENDIF()
ENDIF()


IF(CMAKE_HAVE_PTHREAD_H)
  SET(CMAKE_REQUIRED_INCLUDES pthread.h)
ENDIF()

IF(DBUG_OFF)
  ADD_DEFINITIONS(-DDBUG_OFF=1)
ENDIF()

ADD_DEFINITIONS(-DMARIADB_SYSTEM_TYPE="${CMAKE_SYSTEM_NAME}")
ADD_DEFINITIONS(-DMARIADB_MACHINE_TYPE="${CMAKE_SYSTEM_PROCESSOR}")

IF(WIN32)
  SET(HAVE_THREADS 1)
  ADD_DEFINITIONS(-DHAVE_DLOPEN)
  ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
ELSEIF()
  SET(HAVE_THREADS ${CMAKE_USE_PTHREADS})
ENDIF()

IF(NOT DEFAULT_CHARSET)
  SET(DEFAULT_CHARSET "utf8mb4")
ENDIF()


# convert SSL options to uppercase
IF(WITH_SSL)
  STRING(TOUPPER ${WITH_SSL} WITH_SSL)
ENDIF()
IF(WITH_SSL STREQUAL "ON")
  IF(WIN32)
    SET(WITH_SSL "SCHANNEL")
  ELSE()
    SET(WITH_SSL "OPENSSL")
  ENDIF()
ENDIF()

IF(NOT WITH_SSL STREQUAL "OFF")
  IF(WITH_SSL STREQUAL "OPENSSL")
    IF (NOT OPENSSL_FOUND)
      FIND_PACKAGE(OpenSSL)
    ENDIF()
    IF(OPENSSL_FOUND)
      ADD_DEFINITIONS(-DHAVE_OPENSSL -DHAVE_TLS)
      SET(SSL_SOURCES "${CC_SOURCE_DIR}/libmariadb/secure/openssl.c")
      SET(SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
      IF(WIN32)
        CHECK_INCLUDE_FILES (${OPENSSL_INCLUDE_DIR}/openssl/applink.c HAVE_OPENSSL_APPLINK_C)
      ENDIF()
      INCLUDE_DIRECTORIES(BEFORE ${OPENSSL_INCLUDE_DIR})


      TRY_RUN(LIBRESSL_RESULT HAVE_LIBRESSL
              ${CMAKE_BINARY_DIR}
              ${CC_SOURCE_DIR}/cmake/libressl_version.c
              COMPILE_DEFINITIONS "-I${OPENSSL_INCLUDE_DIR}"
              RUN_OUTPUT_VARIABLE LIBRESSL_VERSION)
      IF(HAVE_LIBRESSL)
        ADD_DEFINITIONS(-DHAVE_LIBRESSL)
        SET(TLS_LIBRARY_VERSION ${LIBRESSL_VERSION})
      ELSE()
        SET(TLS_LIBRARY_VERSION "OpenSSL ${OPENSSL_VERSION}")
      ENDIF()
    ELSE()
      MESSAGE1(TLS_LIBRARY_VERSION "OpenSSL/LibreSSL not found")
    ENDIF()
  ENDIF()
  IF(WITH_SSL STREQUAL "GNUTLS")
    FIND_PACKAGE(GnuTLS "3.3.24" REQUIRED)
    IF(GNUTLS_FOUND)
      ADD_DEFINITIONS(-DHAVE_GNUTLS -DHAVE_TLS)
      SET(SSL_SOURCES "${CC_SOURCE_DIR}/libmariadb/secure/gnutls.c")
      SET(SSL_LIBRARIES ${GNUTLS_LIBRARY})
      SET(TLS_LIBRARY_VERSION "GnuTLS ${GNUTLS_VERSION_STRING}")
      INCLUDE_DIRECTORIES(${GNUTLS_INCLUDE_DIR})
    ELSE()
      MESSAGE(FATAL_ERROR "GnuTLS not found")
    ENDIF()
  ENDIF()
  IF(WIN32)
    IF(WITH_SSL STREQUAL "SCHANNEL")
      ADD_DEFINITIONS(-DHAVE_SCHANNEL -DHAVE_TLS)
      SET(SSL_SOURCES "${CC_SOURCE_DIR}/libmariadb/secure/schannel.c"
                      "${CC_SOURCE_DIR}/libmariadb/secure/ma_schannel.c"
                      "${CC_SOURCE_DIR}/libmariadb/secure/schannel_certs.c")
      INCLUDE_DIRECTORIES("${CC_SOURCE_DIR}/plugins/pvio/")
      SET(SSL_LIBRARIES secur32)
      SET(TLS_LIBRARY_VERSION "Schannel ${CMAKE_SYSTEM_VERSION}")
    ENDIF()
  ENDIF()
  MESSAGE1(TLS_LIBRARY_VERSION "TLS library/version: ${TLS_LIBRARY_VERSION}")

  MARK_AS_ADVANCED(SSL_SOURCES)
ENDIF()

SET(ENABLED_LOCAL_INFILE "AUTO" CACHE STRING "If we should should enable LOAD DATA LOCAL by default (OFF/ON/AUTO)")
MARK_AS_ADVANCED(ENABLED_LOCAL_INFILE)
IF (ENABLED_LOCAL_INFILE MATCHES "^(0|FALSE)$")
  SET(ENABLED_LOCAL_INFILE OFF)
ELSEIF(ENABLED_LOCAL_INFILE MATCHES "^(1|TRUE)$")
  SET(ENABLED_LOCAL_INFILE ON)
ELSEIF (NOT ENABLED_LOCAL_INFILE MATCHES "^(ON|OFF|AUTO)$")
  MESSAGE(FATAL_ERROR "ENABLED_LOCAL_INFILE must be one of OFF, ON, AUTO")
ENDIF()

IF(WITH_ICONV)
  IF(NOT WIN32)
    INCLUDE(${CC_SOURCE_DIR}/cmake/FindIconv.cmake)
  ENDIF()
ENDIF()

CONFIGURE_FILE(${CC_SOURCE_DIR}/include/ma_config.h.in
               ${CC_BINARY_DIR}/include/ma_config.h)
CONFIGURE_FILE(${CC_SOURCE_DIR}/include/ma_config.h.in
               ${CC_BINARY_DIR}/include/config.h)
CONFIGURE_FILE(${CC_SOURCE_DIR}/include/mariadb_version.h.in
               ${CC_BINARY_DIR}/include/mariadb_version.h)

INCLUDE_DIRECTORIES(${CC_BINARY_DIR}/include)

IF(WIN32)
  SET(SYSTEM_LIBS ws2_32 advapi32 kernel32 shlwapi crypt32 ${LIBZ})
ELSE()
  SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${LIBPTHREAD} ${CMAKE_DL_LIBS} ${LIBM})
  IF(ICONV_EXTERNAL)
    SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${ICONV_LIBRARIES})
  ENDIF()
ENDIF()
IF(WITH_SSL)
  SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${SSL_LIBRARIES})
ENDIF()
MESSAGE1(SYSTEM_LIBS "SYSTEM_LIBS ${SYSTEM_LIBS}")
MARK_AS_ADVANCED(SYSTEM_LIBS)

IF(NOT IS_SUBPROJECT)
IF ((NOT WIN32) AND (CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU"))
  SET(WARNING_AS_ERROR "-Werror")
ELSEIF(CMAKE_C_COMPILER_ID MATCHES "MSVC")
  SET(WARNING_AS_ERROR "/WX")
ENDIF()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_AS_ERROR}")
ENDIF()


IF(NOT REMOTEIO_PLUGIN_TYPE MATCHES "OFF")
  IF(CURL_FOUND)
    INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
    IF(REMOTEIO_PLUGIN_TYPE MATCHES "STATIC")
      SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${CURL_LIBRARIES})
    ENDIF()
    ADD_DEFINITIONS("-DHAVE_REMOTEIO=1")
  ENDIF()
ENDIF()
IF(NOT WIN32)
  IF(NOT AUTH_GSSAPI_PLUGIN_TYPE MATCHES "OFF")
    INCLUDE(${CC_SOURCE_DIR}/cmake/FindGSSAPI.cmake)
    IF(GSSAPI_FOUND)
      INCLUDE_DIRECTORIES(${GSSAPI_INCS})
      IF(AUTH_GSSAPI_PLUGIN_TYPE MATCHES "STATIC")
        SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${GSSAPI_LIBS})
      ENDIF()
    ENDIF()
  ENDIF()
ENDIF()
INCLUDE(${CC_SOURCE_DIR}/plugins/CMakeLists.txt)
ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(libmariadb)
IF((NOT WIN32) OR CYGWIN)
  ADD_SUBDIRECTORY(mariadb_config)
ENDIF()

IF(IS_DIRECTORY ${CC_SOURCE_DIR}/unittest)
  IF(WITH_UNIT_TESTS)
    ADD_SUBDIRECTORY(unittest/mytap)
    ADD_SUBDIRECTORY(unittest/libmariadb)
  ENDIF()
ENDIF()

IF(CLIENT_DOCS)
  INSTALL(DIRECTORY ${CLIENT_DOCS}
          DESTINATION ${DOCS_INSTALL_DIR_${INSTALL_LAYOUT}}
          COMPONENT SharedLibraries)
ENDIF()

IF(UNIX)
  ADD_SUBDIRECTORY(man)
ENDIF()

IF(WIN32 AND WITH_MSI AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
  ADD_SUBDIRECTORY(win/packaging)
ENDIF()
MESSAGE1(SYSTEM_PROCESSOR "SYSTEM processor: ${CMAKE_SYSTEM_PROCESSOR}")
SET(CPACK_PACKAGE_VENDOR "MariaDB Corporation Ab")
SET(CPACK_PACKAGE_DESCRIPTION "MariaDB Connector/C. A library for connecting to MariaDB and MySQL servers")
SET(CPACK_PACKAGE_NAME "mariadb_connector_c")
STRING(TOLOWER ${CMAKE_SYSTEM_NAME} system_name)
SET(CPACK_RESOURCE_FILE_LICENSE "${CC_SOURCE_DIR}/COPYING.LIB")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CC_SOURCE_DIR}/README")
INCLUDE(cmake/ConnectorName.cmake)
IF(NOT PACKAGE_STATUS_SUFFIX)
  SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-src")
  IF(PACKAGE_PLATFORM_SUFFIX)
    SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_PLATFORM_SUFFIX}")
  ELSE()
    SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}")
  ENDIF()
ELSE()
  SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-src")
  IF(PACKAGE_PLATFORM_SUFFIX)
    SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-${PACKAGE_PLATFORM_SUFFIX}")
  ELSE()
    SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}")
  ENDIF()
ENDIF()
# Build source packages
IF(GIT_BUILD_SRCPKG)
  # get branch name
  EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} show-branch OUTPUT_VARIABLE git_branch)
  STRING(REGEX MATCH "\\[([^]]+)\\]" git_branch ${git_branch})
  STRING(REGEX REPLACE "\\[|\\]" "" GIT_BRANCH ${git_branch})
  MESSAGE1(GIT_BRANCH "${GIT_BRANCH}")
  IF(WIN32)
    EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} archive ${GIT_BRANCH} --format=zip --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.zip)
  ELSE()
    EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} archive ${GIT_BRANCH} --format=zip --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.zip)
    EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} archive ${GIT_BRANCH} --format=tar --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar)
    EXECUTE_PROCESS(COMMAND gzip -9 -f ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar)
  ENDIF()
ENDIF()

SET(CPACK_SOURCE_IGNORE_FILES
\\\\.git/
\\\\.gitignore
\\\\.gitattributes
CMakeCache\\\\.txt
cmake_dist\\\\.cmake
CPackConfig\\\\.cmake
mariadb_config\\\\.c$
\\\\.build/
html/
unittest
/cmake_install.cmake
/CTestTestfile.cmake
/CPackSourceConfig.cmake
/CMakeFiles/
/version_resources/
/_CPack_Packages/
\\\\.gz$
\\\\.zip$
mariadb_config/mariadb_config$
/CMakeFiles/
/version_resources/
/_CPack_Packages/
Makefile$
include/my_config\\\\.h$
)

IF(WITH_TEST_SRCPKG)
  SET(PACKAGE_FILE ${CC_SOURCE_DIR}/package.name)
  FILE(REMOVE ${PACKAGE_FILE})
  FILE(WRITE ${PACKAGE_FILE} ${CPACK_SOURCE_PACKAGE_FILE_NAME})
ENDIF()

IF(WIN32)
  SET(CPACK_GENERATOR "ZIP")
  SET(CPACK_SOURCE_GENERATOR "ZIP")
ELSE()
  SET(CPACK_GENERATOR "TGZ")
  SET(CPACK_SOURCE_GENERATOR "TGZ")
ENDIF()
INCLUDE(CPack)

IF(WITH_EXTERNAL_ZLIB)
  SET(zlib_status ${WITH_EXTERNAL_ZLIB})
ELSE()
  SET(zlib_status "yes (using bundled zlib)")
ENDIF()

MESSAGE1(STATUS "MariaDB Connector/c configuration:
-- Static PLUGINS ${PLUGINS_STATIC}
-- Dynamic PLUGINS ${PLUGINS_DYNAMIC}
-- CPack generation: ${CPACK_GENERATOR}
-- SSL support: ${WITH_SSL} Libs: ${SSL_LIBRARIES}
-- Zlib support: ${zlib_status}
-- ZStd support: ${ZSTD_FOUND}
-- Installation layout: ${INSTALL_LAYOUT}
-- Include files will be installed in ${INSTALL_INCLUDEDIR}
-- Libraries will be installed in ${INSTALL_LIBDIR}
-- Binaries will be installed in ${INSTALL_BINDIR}
-- Documentation included from ${CLIENT_DOCS}
-- Required: ${CMAKE_REQUIRED_LIBRARIES}")