forked from mysql/mysql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1277 lines (1139 loc) · 44.4 KB
/
CMakeLists.txt
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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# 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, version 2.0, 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
IF(WIN32)
# CMake 3.8.0 is needed for Visual Studio 2017 and x64 toolset.
CMAKE_MINIMUM_REQUIRED(VERSION 3.8.0)
ELSEIF(APPLE)
# Version 3.9.2 in needed because INCLUDE_DIRECTORIES(SYSTEM ...) wasn't
# handled properly by the cmake Xcode generator.
CMAKE_MINIMUM_REQUIRED(VERSION 3.9.2)
ELSEIF(UNIX)
# CMake 3.4.0 is needed for Solaris due to CMake bug 15673.
# Cannot use CMAKE_SYSTEM_NAME until after PROJECT(), use uname directly.
FIND_PROGRAM(MY_UNAME uname /bin /usr/bin /usr/local/bin /sbin)
IF(MY_UNAME)
EXEC_PROGRAM(uname ARGS -s OUTPUT_VARIABLE MY_HOST_SYSTEM_NAME)
IF(MY_HOST_SYSTEM_NAME MATCHES "SunOS")
CMAKE_MINIMUM_REQUIRED(VERSION 3.4.0)
ENDIF()
ENDIF()
ENDIF()
# 2.8.12 as minimum unless higher is checked above.
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
# Explicitly set CMP0018 and CMP0022 = NEW since newer versions of
# CMake has OLD as default even if OLD is deprecated.
# See cmake --help-policy CMP0018 / CMP0022
CMAKE_POLICY(SET CMP0018 NEW)
CMAKE_POLICY(SET CMP0022 NEW)
# Disallow use of the LOCATION property for build targets.
IF(POLICY CMP0026)
CMAKE_POLICY(SET CMP0026 NEW)
ENDIF()
# In CMake 3.12 and above, the
#
# * ``check_include_file`` macro in the ``CheckIncludeFile`` module, the
# * ``check_include_file_cxx`` macro in the
# ``CheckIncludeFileCXX`` module, and the
# * ``check_include_files`` macro in the ``CheckIncludeFiles`` module
#
# now prefer to link the check executable to the libraries listed in the
# ``CMAKE_REQUIRED_LIBRARIES`` variable.
IF(POLICY CMP0075)
CMAKE_POLICY(SET CMP0075 OLD)
ENDIF()
MESSAGE(STATUS "Running cmake version ${CMAKE_VERSION}")
# Will set GIT_EXECUTABLE and GIT_FOUND
FIND_PACKAGE(Git)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
# First, decide about build type (debug or release)
# If cmake is invoked with -DCMAKE_BUILD_TYPE,
# respect user wishes and do not (re)define CMAKE_BUILD_TYPE. If WITH_DEBUG
# is given, set CMAKE_BUILD_TYPE = Debug. Otherwise, use Relwithdebinfo.
IF(DEFINED CMAKE_BUILD_TYPE)
SET(HAVE_CMAKE_BUILD_TYPE TRUE)
ENDIF()
OPTION(WITH_DEBUG "Use dbug/safemutex" OFF)
# Use a default manufacturer if no manufacturer was identified.
SET(MANUFACTURER_DOCSTRING
"Set the entity that appears as the manufacturer of packages that support a manufacturer field.")
IF(NOT DEFINED MANUFACTURER)
SET(MANUFACTURER "Built from Source" CACHE STRING ${MANUFACTURER_DOCSTRING})
MARK_AS_ADVANCED(MANUFACTURER)
ENDIF()
# MAX_INDEXES - Set the maximum number of indexes per table, default 64U
IF (NOT MAX_INDEXES)
SET(MAX_INDEXES 64U)
ELSEIF(MAX_INDEXES MATCHES "^[0-9]+[Uu]?$")
# MAX_INDEXES should be unsigned, so add the U suffix if it's missing.
STRING(REGEX REPLACE "^([0-9]+).*$" "\\1U" MAX_INDEXES "${MAX_INDEXES}")
MESSAGE(STATUS "Configuring with MAX_INDEXES = ${MAX_INDEXES}")
ELSE()
MESSAGE(FATAL_ERROR "MAX_INDEXES should be an unsigned integer.")
ENDIF(NOT MAX_INDEXES)
IF(MAX_INDEXES GREATER 255)
MESSAGE(FATAL_ERROR "MAX_INDEXES values greater than 255 is not supported!")
ELSEIF(MAX_INDEXES LESS 64)
# Per documentation, ignore values less than 64 and use the default instead.
MESSAGE(WARNING "MAX_INDEXES option ignored because it is less than 64.")
SET(MAX_INDEXES 64U)
ENDIF()
# We choose to provide WITH_DEBUG as alias to standard CMAKE_BUILD_TYPE=Debug
# which turns out to be not trivial, as this involves synchronization
# between CMAKE_BUILD_TYPE and WITH_DEBUG. Besides, we have to deal with cases
# where WITH_DEBUG is reset from ON to OFF and here we need to reset
# CMAKE_BUILD_TYPE to either none or default RelWithDebInfo
SET(BUILDTYPE_DOCSTRING
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or
CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel")
IF(WITH_DEBUG)
SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING ${BUILDTYPE_DOCSTRING} FORCE)
SET(OLD_WITH_DEBUG 1 CACHE INTERNAL "" FORCE)
ELSEIF(NOT HAVE_CMAKE_BUILD_TYPE OR OLD_WITH_DEBUG)
IF(CMAKE_BUILD_TYPE MATCHES "Debug" OR NOT HAVE_CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
${BUILDTYPE_DOCSTRING} FORCE)
ENDIF()
SET(OLD_WITH_DEBUG 0 CACHE INTERNAL "" FORCE)
ENDIF()
IF(CMAKE_GENERATOR MATCHES "Visual Studio [1-9][0-9].*" AND
CMAKE_GENERATOR_TOOLSET STREQUAL "")
# Switch to 64 bit toolset on Windows (32 bit is default).
# This is recommended as the 32 bit linker will run into address space issues
# and not exit for long time.
SET(CMAKE_GENERATOR_TOOLSET "host=x64")
ENDIF()
# On Linux el6/el7 the default gcc is too old, see if devtoolset is installed.
# Same with SLES 12, look for gcc 7 there.
# We need to look for gcc before calling PROJECT below.
OPTION(FORCE_UNSUPPORTED_COMPILER "Disable compiler version checks" OFF)
MARK_AS_ADVANCED(WITHOUT_SERVER DISABLE_SHARED FORCE_UNSUPPORTED_COMPILER)
IF(CMAKE_HOST_UNIX AND NOT FORCE_UNSUPPORTED_COMPILER
AND NOT CMAKE_C_COMPILER AND NOT CMAKE_CXX_COMPILER)
# Cannot INCLUDE(CMakeDetermineSystem) prior to PROJECT initialization below.
SET (ENV_CC "$ENV{CC}")
SET (ENV_CXX "$ENV{CXX}")
IF (ENV_CC STREQUAL "" AND ENV_CXX STREQUAL "")
IF(MY_UNAME)
EXEC_PROGRAM(uname ARGS -r OUTPUT_VARIABLE MY_HOST_SYSTEM_VERSION)
IF(MY_HOST_SYSTEM_NAME MATCHES "Linux" AND
MY_HOST_SYSTEM_VERSION MATCHES "\\.el[67](uek)?\\.")
MESSAGE(STATUS
"This is ${MY_HOST_SYSTEM_NAME} version ${MY_HOST_SYSTEM_VERSION}")
MESSAGE(STATUS "We probably need some devtoolset compiler")
FIND_PROGRAM(ALTERNATIVE_GCC gcc
NO_DEFAULT_PATH
PATHS "/opt/rh/devtoolset-7/root/usr/bin")
FIND_PROGRAM(ALTERNATIVE_GPP g++
NO_DEFAULT_PATH
PATHS "/opt/rh/devtoolset-7/root/usr/bin")
FIND_PROGRAM(ALTERNATIVE_ENABLE enable
NO_DEFAULT_PATH
PATHS "/opt/rh/devtoolset-7/")
IF(ALTERNATIVE_GCC AND ALTERNATIVE_GPP)
SET(CMAKE_C_COMPILER ${ALTERNATIVE_GCC})
SET(CMAKE_CXX_COMPILER ${ALTERNATIVE_GPP})
MESSAGE(STATUS "Using ${ALTERNATIVE_GCC}")
MESSAGE(STATUS "Using ${ALTERNATIVE_GPP}")
ELSE()
MESSAGE(WARNING "Could not find devtoolset gcc")
ENDIF()
ELSEIF(MY_HOST_SYSTEM_NAME MATCHES "Linux" AND
EXISTS "/etc/os-release")
FILE(READ "/etc/os-release" MY_OS_RELEASE)
IF (MY_OS_RELEASE MATCHES "SUSE Linux Enterprise Server 12")
MESSAGE(STATUS "We need to look for a newer GCC on SLES 12")
FIND_PROGRAM(ALTERNATIVE_GCC gcc-7
NO_DEFAULT_PATH
PATHS "/usr/bin")
FIND_PROGRAM(ALTERNATIVE_GPP g++-7
NO_DEFAULT_PATH
PATHS "/usr/bin")
IF (ALTERNATIVE_GCC AND ALTERNATIVE_GPP)
SET(CMAKE_C_COMPILER ${ALTERNATIVE_GCC})
SET(CMAKE_CXX_COMPILER ${ALTERNATIVE_GPP})
MESSAGE(STATUS "Using ${ALTERNATIVE_GCC}")
MESSAGE(STATUS "Using ${ALTERNATIVE_GPP}")
# Use the new ABI so that std::string can be used with allocators
# that are not default-constructible (e.g. Memroot_allocator)
ADD_DEFINITIONS(-D_GLIBCXX_USE_CXX11_ABI=1)
ELSE()
MESSAGE(WARNING "Could not find newer gcc")
ENDIF()
ENDIF()
ENDIF()
ENDIF()
ENDIF()
ENDIF()
# Optionally set project name, e.g.
# foo.xcodeproj (mac) or foo.sln (windows)
SET(MYSQL_PROJECT_NAME_DOCSTRING "MySQL project name")
IF(DEFINED MYSQL_PROJECT_NAME)
SET(MYSQL_PROJECT_NAME ${MYSQL_PROJECT_NAME} CACHE STRING
${MYSQL_PROJECT_NAME_DOCSTRING} FORCE)
ELSE()
SET(MYSQL_PROJECT_NAME "MySQL" CACHE STRING
${MYSQL_PROJECT_NAME_DOCSTRING} FORCE)
MARK_AS_ADVANCED(MYSQL_PROJECT_NAME)
ENDIF()
# Remember if WITH_NDBCLUSTER was specified by user
IF(DEFINED WITH_NDBCLUSTER)
SET(HAVE_WITH_NDBCLUSTER 1)
ENDIF()
OPTION(WITH_NDBCLUSTER "Build MySQL Cluster" OFF)
OPTION(WITH_NDBCLUSTER_STORAGE_ENGINE
"Legacy and deprecated alias for WITH_NDBCLUSTER" OFF)
OPTION(WITH_PLUGIN_NDBCLUSTER
"Legacy and deprecated alias for WITH_NDBCLUSTER" OFF)
MARK_AS_ADVANCED(WITH_NDBCLUSTER_STORAGE_ENGINE WITH_PLUGIN_NDBCLUSTER)
IF(NOT HAVE_WITH_NDBCLUSTER)
# Unless user has used WITH_NDBCLUSTER also look at
# some of the legacy variables
IF(WITH_PLUGIN_NDBCLUSTER)
MESSAGE(WARNING "WITH_PLUGIN_NDBCLUSTER is deprecated and will be "
"removed in a future release. Please use WITH_NDBCLUSTER instead.")
SET(WITH_NDBCLUSTER ON)
ENDIF()
IF(WITH_NDBCLUSTER_STORAGE_ENGINE)
MESSAGE(WARNING "WITH_NDBCLUSTER_STORAGE_ENGINE is deprecated and "
"will be removed in a future release. Please use WITH_NDBCLUSTER "
"instead.")
SET(WITH_NDBCLUSTER ON)
ENDIF()
ENDIF()
IF(WITH_NDBCLUSTER)
MESSAGE(STATUS "Building MySQL Cluster")
ENDIF()
INCLUDE(mysql_version)
IF(POLICY CMP0048)
CMAKE_POLICY(SET CMP0048 NEW)
PROJECT(${MYSQL_PROJECT_NAME}
VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION})
ELSE()
PROJECT(${MYSQL_PROJECT_NAME})
ENDIF()
GET_FILENAME_COMPONENT(REALPATH_CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR} REALPATH)
GET_FILENAME_COMPONENT(REALPATH_CMAKE_BINARY_DIR ${CMAKE_BINARY_DIR} REALPATH)
MESSAGE(STATUS "Source directory ${REALPATH_CMAKE_SOURCE_DIR}")
MESSAGE(STATUS "Binary directory ${REALPATH_CMAKE_BINARY_DIR}")
# IN PB2 we have a few configurations which are built in-source (e.g. doxygen).
IF(DEFINED ENV{PB2WORKDIR})
OPTION(FORCE_INSOURCE_BUILD "Allow in-source build" ON)
ELSE()
OPTION(FORCE_INSOURCE_BUILD "Allow in-source build" OFF)
ENDIF()
# https://gitlab.kitware.com/cmake/community/wikis/FAQ
# cmake-does-not-generate-a-make-distclean-target-why
# Why disallow in-source build?
# Basically because 'make clean' or 'make distclean' do not work.
# So if you do a 'git pull' you may end up with a developer sandbox
# that no longer works as expected (CMakeCache.txt and other
# generated/configured files may contain data which is no longer valid)
IF(${REALPATH_CMAKE_SOURCE_DIR} STREQUAL ${REALPATH_CMAKE_BINARY_DIR})
IF(FORCE_INSOURCE_BUILD)
MESSAGE(WARNING "This is an in-source build")
ELSE()
MESSAGE(FATAL_ERROR
"Please do not build in-source. "
"Out-of source builds are highly recommended: "
"you can have multiple builds for the same source, "
"and there is an easy way to do cleanup, "
"simply remove the build directory "
"(note that 'make clean' or 'make distclean' does *not* work) "
"\nYou *can* force in-source build by invoking cmake with -DFORCE_INSOURCE_BUILD=1")
ENDIF()
ENDIF()
MACRO(REPORT_CXX_FLAGS)
MESSAGE(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
FOREACH(BUILD_TYPE "" _DEBUG _RELWITHDEBINFO _RELEASE _MINSIZEREL)
SET(flag "CMAKE_CXX_FLAGS${BUILD_TYPE}")
MESSAGE(STATUS "${flag}: ${${flag}}")
ENDFOREACH()
ENDMACRO()
# STRING(APPEND ...) from cmake VERSION 3.4
MACRO(STRING_APPEND STRING_VAR INPUT)
SET(${STRING_VAR} "${${STRING_VAR}}${INPUT}")
ENDMACRO()
MACRO(STRING_PREPEND STRING_VAR INPUT)
SET(${STRING_VAR} "${INPUT}${${STRING_VAR}}")
ENDMACRO()
# Write content to file, using CONFIGURE_FILE
# The advantage compared to FILE(WRITE) is that timestamp
# does not change if file already has the same content
SET(MYSQL_CMAKE_SCRIPT_DIR "${CMAKE_SOURCE_DIR}/cmake")
MACRO(CONFIGURE_FILE_CONTENT content file)
SET(CMAKE_CONFIGURABLE_FILE_CONTENT
"${content}\n")
CONFIGURE_FILE(
${MYSQL_CMAKE_SCRIPT_DIR}/configurable_file_content.in
${file}
@ONLY)
ENDMACRO()
SET(BUILD_IS_SINGLE_CONFIG TRUE)
MESSAGE(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
IF(CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR STREQUAL "Xcode")
SET(BUILD_IS_SINGLE_CONFIG FALSE)
ENDIF()
# Maintainer mode is default on only for debug builds using GCC/G++
IF(CMAKE_BUILD_TYPE MATCHES "Debug" OR WITH_DEBUG)
IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX)
SET(MYSQL_MAINTAINER_MODE ON CACHE BOOL
"MySQL maintainer-specific development environment")
ENDIF()
ENDIF()
OPTION(WITH_DEFAULT_COMPILER_OPTIONS
"Use flags from cmake/build_configurations/compiler_options.cmake"
ON)
OPTION(WITH_DEFAULT_FEATURE_SET
"Use feature set in cmake/build_configurations/feature_set.cmake"
ON)
IF(BUILD_CONFIG)
INCLUDE(
${CMAKE_SOURCE_DIR}/cmake/build_configurations/${BUILD_CONFIG}.cmake)
ENDIF()
OPTION(INSTALL_STATIC_LIBRARIES "Install static libraries" ON)
#cmake on 64bit windows/mac/solaris doesn't set CMAKE_SYSTEM_PROCESSOR correctly
SET(MYSQL_MACHINE_TYPE ${CMAKE_SYSTEM_PROCESSOR})
# Include the platform-specific file. To allow exceptions, this code
# looks for files in order of how specific they are. If there is, for
# example, a generic Linux.cmake and a version-specific
# Linux-2.6.28-11-generic, it will pick Linux-2.6.28-11-generic and
# include it. It is then up to the file writer to include the generic
# version if necessary.
FOREACH(_base
${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_VERSION}-${CMAKE_SYSTEM_PROCESSOR}
${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_VERSION}
${CMAKE_SYSTEM_NAME})
SET(_file ${CMAKE_SOURCE_DIR}/cmake/os/${_base}.cmake)
IF(EXISTS ${_file})
INCLUDE(${_file})
BREAK()
ENDIF()
ENDFOREACH()
IF(UNIX)
OPTION(WITH_INNODB_MEMCACHED "" OFF)
OPTION(ENABLE_MEMCACHED_SASL "Enable SASL on InnoDB Memcached" OFF)
OPTION(ENABLE_MEMCACHED_SASL_PWDB "Enable SASL on InnoDB Memcached" OFF)
ELSE()
OPTION(WITH_INNODB_MEMCACHED "" OFF)
ENDIF()
# Following autotools tradition, add preprocessor definitions
# specified in environment variable CPPFLAGS
IF(DEFINED ENV{CPPFLAGS})
ADD_DEFINITIONS($ENV{CPPFLAGS})
ENDIF()
INCLUDE(CheckTypeSize)
CHECK_TYPE_SIZE("void *" SIZEOF_VOIDP)
MESSAGE(STATUS "SIZEOF_VOIDP ${SIZEOF_VOIDP}")
# On some platforms, cmake may think that CMAKE_SIZEOF_VOID_P == 4
# even if we have configured for 64bit build....
SET(CMAKE_SIZEOF_VOID_P ${SIZEOF_VOIDP})
IF(WITH_DEFAULT_COMPILER_OPTIONS)
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/build_configurations/compiler_options.cmake)
ENDIF()
IF(WITH_DEFAULT_FEATURE_SET)
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/build_configurations/feature_set.cmake)
ENDIF()
INCLUDE(CMakePushCheckState)
# Add macros
INCLUDE(character_sets)
INCLUDE(cpu_info)
INCLUDE(zlib)
INCLUDE(lz4)
INCLUDE(lzma)
INCLUDE(re2)
INCLUDE(icu)
INCLUDE(libevent)
INCLUDE(ssl)
INCLUDE(sasl)
INCLUDE(readline)
INCLUDE(protobuf)
INCLUDE(package_name)
INCLUDE(libutils)
INCLUDE(plugin)
INCLUDE(component)
INCLUDE(install_macros)
INCLUDE(install_layout)
INCLUDE(mysql_add_executable)
INCLUDE(mysqlgcs)
INCLUDE(curl)
INCLUDE(rapidjson)
OPTION(DISABLE_SHARED
"Don't build shared libraries, compile code as position-dependent" OFF)
IF(DISABLE_SHARED)
MESSAGE("Dynamic plugins are disabled.")
ENDIF()
OPTION(ENABLED_PROFILING "Enable profiling" ON)
OPTION(WITHOUT_SERVER OFF)
IF(UNIX)
OPTION(WITH_VALGRIND "Valgrind instrumentation" OFF)
ENDIF()
IF(WIN32)
OPTION(WITH_MSCRT_DEBUG "MS Visual Studio Debug CRT instrumentation" OFF)
ENDIF()
IF(NOT WITHOUT_SERVER)
OPTION (WITH_UNIT_TESTS "Compile MySQL with unit tests" ON)
ENDIF()
OPTION(WITH_AUTHENTICATION_LDAP
"Report error if the LDAP authentication plugin cannot be built." OFF)
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
# We need some extra FAIL_REGEX patterns
# Note that CHECK_C_SOURCE_COMPILES is a misnomer, it will also link.
MACRO (MY_CHECK_C_COMPILER_FLAG FLAG RESULT)
SET(SAVE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${FLAG}")
CHECK_C_SOURCE_COMPILES("int main(void) { return 0; }" ${RESULT}
FAIL_REGEX "unknown argument ignored"
FAIL_REGEX "argument unused during compilation"
FAIL_REGEX "unsupported .*option"
FAIL_REGEX "unknown .*option"
FAIL_REGEX "unrecognized .*option"
FAIL_REGEX "ignoring unknown option"
FAIL_REGEX "[Ww]arning: [Oo]ption"
FAIL_REGEX "error: visibility"
FAIL_REGEX "warning: visibility"
)
SET(CMAKE_REQUIRED_FLAGS "${SAVE_CMAKE_REQUIRED_FLAGS}")
ENDMACRO()
MACRO (MY_CHECK_CXX_COMPILER_FLAG FLAG RESULT)
SET(SAVE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${FLAG}")
CHECK_CXX_SOURCE_COMPILES("int main(void) { return 0; }" ${RESULT}
FAIL_REGEX "unknown argument ignored"
FAIL_REGEX "argument unused during compilation"
FAIL_REGEX "unsupported .*option"
FAIL_REGEX "unknown .*option"
FAIL_REGEX "unrecognized .*option"
FAIL_REGEX "ignoring unknown option"
FAIL_REGEX "[Ww]arning: [Oo]ption"
FAIL_REGEX "error: visibility"
FAIL_REGEX "warning: visibility"
)
SET(CMAKE_REQUIRED_FLAGS "${SAVE_CMAKE_REQUIRED_FLAGS}")
ENDMACRO()
MACRO(MY_SANITIZER_CHECK SAN_OPT ADD_OPTIMIZATION RESULT)
MY_CHECK_C_COMPILER_FLAG("${SAN_OPT}" C_RESULT)
MY_CHECK_CXX_COMPILER_FLAG("${SAN_OPT}" CXX_RESULT)
IF(C_RESULT AND CXX_RESULT)
STRING_APPEND(CMAKE_C_FLAGS " ${SAN_OPT}")
STRING_APPEND(CMAKE_CXX_FLAGS " ${SAN_OPT}")
# We switch on basic optimization also for debug builds.
# We disable inlining for stack trace readability.
# With optimization we may get some warnings, so we switch off -Werror
IF(${ADD_OPTIMIZATION})
STRING_APPEND(CMAKE_C_FLAGS " -O1 -fno-inline")
STRING_APPEND(CMAKE_CXX_FLAGS " -O1 -fno-inline")
IF(NOT SANITIZE_MAINTAINER_MODE)
SET(MYSQL_MAINTAINER_MODE OFF CACHE BOOL
"MySQL maintainer-specific development environment" FORCE)
ENDIF()
ENDIF()
SET(${RESULT} 1)
ELSE()
SET(${RESULT} 0)
ENDIF()
ENDMACRO()
OPTION(WITH_ASAN "Enable address sanitizer" OFF)
IF(WITH_ASAN)
IF(WIN32_CLANG)
# NOTE: We do _not_ modify CMAKE_C_FLAGS / CMAKE_CXX_FLAGS to add
# -fsanitize=address here yet; Clang (at least of 5.0.0) requires /MT,
# but CMake adds /MDd to all feature checks almost no matter what we do.
# For the same reason, we have to enable it unconditionalyl without
# doing a feature test; we know it's working. Modifying the flags happens
# below, near the end.
SET(HAVE_ASAN 1)
# Get the path to the ASAN support libraries.
GET_FILENAME_COMPONENT(ASAN_LIB_DIR ${CMAKE_CXX_COMPILER} DIRECTORY)
SET(ASAN_LIB_DIR "${ASAN_LIB_DIR}/../lib/clang/${CMAKE_CXX_COMPILER_VERSION}/lib/windows")
GET_FILENAME_COMPONENT(ASAN_LIB_DIR ${ASAN_LIB_DIR} REALPATH)
ELSE()
MY_SANITIZER_CHECK("-fsanitize=address" TRUE WITH_ASAN_OK)
IF(WITH_ASAN_OK)
OPTION(WITH_ASAN_SCOPE "Enable -fsanitize-address-use-after-scope" ON)
SET(HAVE_ASAN 1)
# This works with clang, but not gcc it seems.
MY_CHECK_CXX_COMPILER_FLAG(
"-fsanitize=address -fsanitize-address-use-after-scope"
HAVE_SANITIZE_SCOPE)
IF(WITH_ASAN_SCOPE AND HAVE_SANITIZE_SCOPE)
STRING_APPEND(CMAKE_C_FLAGS " -fsanitize-address-use-after-scope")
STRING_APPEND(CMAKE_CXX_FLAGS " -fsanitize-address-use-after-scope")
ENDIF()
ELSE()
MESSAGE(FATAL_ERROR "Do not know how to enable address sanitizer")
ENDIF()
ENDIF()
ENDIF()
OPTION(WITH_MSAN "Enable memory sanitizer" OFF)
IF(WITH_MSAN)
MY_SANITIZER_CHECK("-fsanitize=memory -fsanitize-memory-track-origins"
TRUE WITH_MSAN_OK)
IF(NOT WITH_MSAN_OK)
MESSAGE(FATAL_ERROR "Do not know how to enable memory sanitizer")
ELSE()
MESSAGE(WARNING "Memory sanitizer support is currently experimental.")
ENDIF()
ENDIF()
OPTION(WITH_UBSAN "Enable undefined behavior sanitizer" OFF)
IF(WITH_UBSAN)
MY_SANITIZER_CHECK("-fsanitize=undefined" TRUE WITH_UBSAN_OK)
IF(NOT WITH_UBSAN_OK)
MESSAGE(FATAL_ERROR
"Do not know how to enable undefined behavior sanitizer")
ELSE()
SET(HAVE_UBSAN 1)
ENDIF()
ENDIF()
OPTION(WITH_TSAN "Enable thread sanitizer" OFF)
IF(WITH_TSAN)
MY_SANITIZER_CHECK("-fsanitize=thread" TRUE WITH_TSAN_OK)
IF(NOT WITH_TSAN_OK)
MESSAGE(FATAL_ERROR "Do not know how to enable thread sanitizer")
ELSE()
MESSAGE(WARNING "Thread sanitizer support is currently experimental.")
SET(HAVE_TSAN 1)
ENDIF()
ENDIF()
IF(WITH_ASAN AND WITH_MSAN)
MESSAGE(FATAL_ERROR
"Cannot use AddressSanitizer and MemorySanitizer together")
ENDIF()
# Older versions of ccache must be disabled: export CCACHE_DISABLE=1
# See http://www.cmake.org/Wiki/CTest/Coverage
OPTION(ENABLE_GCOV "Enable gcov (debug, Linux builds only)" OFF)
IF (ENABLE_GCOV AND NOT WIN32 AND NOT APPLE)
STRING_APPEND(CMAKE_C_FLAGS " -fprofile-arcs -ftest-coverage -DHAVE_GCOV")
STRING_APPEND(CMAKE_CXX_FLAGS " -fprofile-arcs -ftest-coverage -DHAVE_GCOV")
STRING_APPEND(CMAKE_EXE_LINKER_FLAGS " -fprofile-arcs -ftest-coverage -lgcov")
ENDIF()
OPTION(ENABLE_GPROF "Enable gprof (optimized, Linux builds only)" OFF)
IF (ENABLE_GPROF AND NOT WIN32 AND NOT APPLE)
STRING_APPEND(CMAKE_C_FLAGS " -pg")
STRING_APPEND(CMAKE_CXX_FLAGS " -pg")
STRING_APPEND(CMAKE_EXE_LINKER_FLAGS " -pg")
ENDIF()
# Use gold if available and not explicitly disabled.
IF(WIN32)
# Feature tests are expensive on Windows, and we only support MSVC,
# which does not use gold. Thus, default to off to save the test.
OPTION(USE_LD_GOLD "Use GNU gold linker" OFF)
ELSE()
OPTION(USE_LD_GOLD "Use GNU gold linker" ON)
ENDIF()
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
OPTION(LINK_RANDOMIZE "Randomize the order of all symbols in the binary" OFF)
SET(LINK_RANDOMIZE_SEED "mysql"
CACHE STRING "Seed to use for link randomization")
ELSE()
SET(LINK_RANDOMIZE OFF)
ENDIF()
IF (USE_LD_GOLD)
# These tests will give a false negative on some Clang versions,
# since there is no easy way in CMake to check for a linker flag
# without reimplementing CheckCXXSourceCompiles, and
# CheckCXXSourceCompiles tends to compile and link in two steps
# (which causes warning output about unused flags, which we interpret
# as the flag not existing).
MY_CHECK_C_COMPILER_FLAG("-fuse-ld=gold" C_LD_GOLD_RESULT)
MY_CHECK_CXX_COMPILER_FLAG("-fuse-ld=gold" CXX_LD_GOLD_RESULT)
IF (C_LD_GOLD_RESULT AND CXX_LD_GOLD_RESULT AND NOT SOLARIS)
SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -fuse-ld=gold")
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -fuse-ld=gold")
# Seemingly --gc-sections causes problems with randomization, so only
# turn it on if we are not making a randomized build.
IF (NOT LINK_RANDOMIZE)
SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--gc-sections")
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,--gc-sections")
ENDIF()
ENDIF()
ENDIF()
IF(LINK_RANDOMIZE)
STRING_APPEND(CMAKE_C_FLAGS " -ffunction-sections -fdata-sections")
STRING_APPEND(CMAKE_CXX_FLAGS " -ffunction-sections -fdata-sections")
SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--sort-section=name")
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,--sort-section=name")
SET(CMAKE_CXX_ARCHIVE_CREATE "sh -c '${CMAKE_SOURCE_DIR}/scripts/randomize-order.pl ${LINK_RANDOMIZE_SEED} <OBJECTS> && <CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>'")
SET(CMAKE_CXX_ARCHIVE_CREATE_APPEND "sh -c '${CMAKE_SOURCE_DIR}/scripts/randomize-order.pl ${LINK_RANDOMIZE_SEED} <OBJECTS> && <CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>'")
SET(CMAKE_C_ARCHIVE_CREATE ${CMAKE_CXX_ARCHIVE_CREATE})
SET(CMAKE_C_ARCHIVE_CREATE_APPEND ${CMAKE_CXX_ARCHIVE_CREATE_APPEND})
ENDIF()
IF(LINUX)
# May be set to ON in cmake/build_configurations/mysql_release.cmake
IF(DEFINED REPRODUCIBLE_BUILD)
SET(REPRODUCIBLE_BUILD_DEFAULT ${REPRODUCIBLE_BUILD})
ELSE()
SET(REPRODUCIBLE_BUILD_DEFAULT OFF)
ENDIF()
OPTION(REPRODUCIBLE_BUILD "Take extra pains to make build result independent of build location and time" ${REPRODUCIBLE_BUILD_DEFAULT})
ENDIF()
IF(REPRODUCIBLE_BUILD)
SET(DEBUG_PREFIX_FLAGS
"-fdebug-prefix-map=${CMAKE_SOURCE_DIR}/=./ -fdebug-prefix-map=${CMAKE_CURRENT_BINARY_DIR}=./obj")
# See if -fdebug-prefix= commands are included in the debug output,
# making the build unreproducible with switches recorded.
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69821.
EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -g3 -x c -S -fdebug-prefix-map=foo=bar -o - -
INPUT_FILE /dev/null OUTPUT_VARIABLE DEBUG_PREFIX_MAP_RESULT)
IF(DEBUG_PREFIX_MAP_RESULT MATCHES "foo=bar")
SET(DEBUG_PREFIX_FLAGS "${DEBUG_PREFIX_FLAGS} -gno-record-gcc-switches")
ENDIF()
STRING_APPEND(CMAKE_C_FLAGS " ${DEBUG_PREFIX_FLAGS}")
STRING_APPEND(CMAKE_CXX_FLAGS " ${DEBUG_PREFIX_FLAGS}")
SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--build-id=none")
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--build-id=none")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE
"${CMAKE_SOURCE_DIR}/scripts/invoke-with-relative-paths.pl")
ENDIF()
OPTION(ENABLED_LOCAL_INFILE
"If we should enable LOAD DATA LOCAL by default" OFF)
MARK_AS_ADVANCED(ENABLED_LOCAL_INFILE)
#
# Options related to client-side protocol tracing
#
OPTION(WITH_CLIENT_PROTOCOL_TRACING
"Support for client-side protocol tracing plugins" ON)
OPTION(WITH_TEST_TRACE_PLUGIN
"Have a built-in test protocol trace plugin in libmysql (requires WITH_CLIENT_PROTOCOL_TRACING option)" OFF)
# Sanity checks for protocol tracing options
IF(WITH_TEST_TRACE_PLUGIN AND NOT WITH_CLIENT_PROTOCOL_TRACING)
MESSAGE("WARNING: Test trace plugin was selected but client protocol tracing infrastructure is not enabled - ignoring")
SET(WITH_TEST_TRACE_PLUGIN 0)
ENDIF()
IF(WITH_TEST_TRACE_PLUGIN AND NOT CMAKE_BUILD_TYPE MATCHES "Debug")
MESSAGE(SEND_ERROR
"Test trace plugin was selected but it can be included only in debug binaries.
Set WITH_TEST_TRACE_PLUGIN to OFF or WITH_DEBUG to ON.")
ENDIF()
# Set DBUG_OFF for non-debug project types.
FOREACH(BUILD_TYPE RELEASE RELWITHDEBINFO MINSIZEREL)
FOREACH(LANG C CXX)
STRING_PREPEND(CMAKE_${LANG}_FLAGS_${BUILD_TYPE} "-DDBUG_OFF ")
ENDFOREACH()
ENDFOREACH()
IF(NOT CMAKE_BUILD_TYPE
AND NOT CMAKE_GENERATOR MATCHES "Visual Studio"
AND NOT CMAKE_GENERATOR MATCHES "Xcode")
# This is the case of no CMAKE_BUILD_TYPE choosen, typical for VS and Xcode
# or if custom C flags are set. In VS and Xcode for non-Debug configurations
# DBUG_OFF is already correctly set.
ADD_DEFINITIONS(-DDBUG_OFF)
ENDIF()
# Add safemutex for debug configurations
# Enable debug sync for debug builds.
FOREACH(LANG C CXX)
STRING_PREPEND(CMAKE_${LANG}_FLAGS_DEBUG "-DENABLED_DEBUG_SYNC ")
STRING_PREPEND(CMAKE_${LANG}_FLAGS_DEBUG "-DSAFE_MUTEX ")
ENDFOREACH()
# Set commonly used variables
IF(WIN32)
SET(DEFAULT_MYSQL_HOME "C:/Program Files/MySQL/MySQL Server ${MYSQL_BASE_VERSION}" )
SET(SHAREDIR share)
ELSE()
SET(DEFAULT_MYSQL_HOME ${CMAKE_INSTALL_PREFIX})
SET(SHAREDIR ${DEFAULT_MYSQL_HOME}/${INSTALL_MYSQLSHAREDIR})
ENDIF()
SET(DEFAULT_BASEDIR "${DEFAULT_MYSQL_HOME}")
IF(INSTALL_MYSQLDATADIR MATCHES "^/.*")
SET(MYSQL_DATADIR ${INSTALL_MYSQLDATADIR} CACHE PATH "default MySQL data directory")
ELSE()
SET(MYSQL_DATADIR "${DEFAULT_MYSQL_HOME}/${INSTALL_MYSQLDATADIR}" CACHE PATH "default MySQL data directory")
ENDIF()
IF(INSTALL_MYSQLKEYRINGDIR MATCHES "^/.*")
SET(MYSQL_KEYRINGDIR ${INSTALL_MYSQLKEYRINGDIR} CACHE PATH "default MySQL keyring directory")
ELSE()
SET(MYSQL_KEYRINGDIR "${DEFAULT_MYSQL_HOME}/${INSTALL_MYSQLKEYRINGDIR}" CACHE PATH "default MySQL keyring directory")
ENDIF()
SET(DEFAULT_CHARSET_HOME "${DEFAULT_MYSQL_HOME}")
SET(PLUGINDIR "${DEFAULT_MYSQL_HOME}/${INSTALL_PLUGINDIR}")
IF(SYSCONFDIR)
SET(DEFAULT_SYSCONFDIR "${SYSCONFDIR}")
ENDIF()
IF(WIN32) # P_tmpdir is not defined on Windows as of VS2015.
SET(TMPDIR "" # So we use empty path as default. In practice TMP/TEMP is used
CACHE PATH
"PATH to MySQL TMP dir")
ELSE()
SET(TMPDIR "P_tmpdir"
CACHE PATH
"PATH to MySQL TMP dir. Defaults to the P_tmpdir macro in <stdio.h>")
ENDIF()
IF(TMPDIR STREQUAL "P_tmpdir")
# Do not quote it, to refer to the P_tmpdir macro.
SET(DEFAULT_TMPDIR "P_tmpdir")
ELSE()
# Quote it, to make it a const char string.
SET(DEFAULT_TMPDIR "\"${TMPDIR}\"")
ENDIF()
INCLUDE(cmake/boost.cmake)
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
OPTION(WITH_SYSTEMD "Enable installation of systemd support files" OFF)
IF (WITH_SYSTEMD)
INCLUDE(cmake/systemd.cmake)
ENDIF()
ELSE()
IF (WITH_SYSTEMD)
MESSAGE(FATAL_ERROR "Installation of systemd support files not supported")
ENDIF()
ENDIF()
# Run platform tests
INCLUDE(configure.cmake)
# Common defines and includes
ADD_DEFINITIONS(-DHAVE_CONFIG_H)
ADD_DEFINITIONS(-DHAVE_OPENSSL) # TODO: remove #ifdef from C++ code
ADD_DEFINITIONS(-D__STDC_LIMIT_MACROS) # Enable C99 limit macros
ADD_DEFINITIONS(-D__STDC_FORMAT_MACROS) # Enable C99 printf format macros
ADD_DEFINITIONS(-D_USE_MATH_DEFINES) # Get access to M_PI, M_E, etc. in math.h
OPTION(ENABLE_EXPERIMENT_SYSVARS "Expose ussually hidden system variables to allow experiments" OFF)
IF(ENABLE_EXPERIMENT_SYSVARS)
ADD_DEFINITIONS(-DENABLE_EXPERIMENT_SYSVARS)
ENDIF()
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/libbinlogevents/include
${CMAKE_SOURCE_DIR}/libbinlogevents/export)
SET(WITH_SYSTEM_LIBS_DEFAULT OFF)
OPTION(WITH_LTO
"Enable the link-time optimizer. Currently works for gcc7/gcc8 only." OFF)
IF(WITH_LTO)
MY_CHECK_CXX_COMPILER_FLAG("-flto" CXX_LTO_RESULT)
IF(NOT CXX_LTO_RESULT)
MESSAGE(FATAL_ERROR "Compiler does not support -flto")
ENDIF()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
# Test for parallel linking.
SET(NUM_PROCESSING_UNITS 4)
MY_CHECK_CXX_COMPILER_FLAG(
"-flto=${NUM_PROCESSING_UNITS}" CXX_LTO_PARALLEL_RESULT)
IF(CXX_LTO_PARALLEL_RESULT)
FIND_PROGRAM(NPROC_EXECUTABLE nproc)
IF(NPROC_EXECUTABLE)
EXECUTE_PROCESS(COMMAND ${NPROC_EXECUTABLE}
OUTPUT_VARIABLE NPROC_NUM
RESULT_VARIABLE NPROC_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE)
IF(NOT NPROC_RESULT)
SET(NUM_PROCESSING_UNITS ${NPROC_NUM})
ENDIF()
ENDIF()
SET(CMAKE_CXX_LINK_FLAGS
"${CMAKE_CXX_LINK_FLAGS} -flto=${NUM_PROCESSING_UNITS}")
SET(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -flto=${NUM_PROCESSING_UNITS}")
ELSE()
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -flto")
SET(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -flto")
ENDIF()
# On some platforms (Fedora) we *must* use gcc-ar / gcc-ranlib
# to get the right plugins for supporting -flto output from gcc.
IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX)
IF(ALTERNATIVE_ENABLE)
GET_FILENAME_COMPONENT(ALTERNATIVE_ENABLE_DIR ${ALTERNATIVE_ENABLE} PATH)
SET(DEVTOOLSET_ROOT "${ALTERNATIVE_ENABLE_DIR}/root")
FIND_PROGRAM(GCC_AR_EXECUTABLE gcc-ar
NO_DEFAULT_PATH
PATHS "${DEVTOOLSET_ROOT}/usr/bin")
FIND_PROGRAM(GCC_RANLIB_EXECUTABLE gcc-ranlib
NO_DEFAULT_PATH
PATHS "${DEVTOOLSET_ROOT}/usr/bin")
ELSEIF(ALTERNATIVE_GCC)
STRING(REGEX MATCH "^([0-9])" ALTERNATIVE_GCC_MAJ_VER ${CMAKE_C_COMPILER_VERSION})
GET_FILENAME_COMPONENT(ALTERNATIVE_GCC_DIR ${ALTERNATIVE_GCC} PATH)
FIND_PROGRAM(GCC_AR_EXECUTABLE gcc-ar-${ALTERNATIVE_GCC_MAJ_VER}
NO_DEFAULT_PATH
PATHS "${ALTERNATIVE_GCC_DIR}")
FIND_PROGRAM(GCC_RANLIB_EXECUTABLE gcc-ranlib-${ALTERNATIVE_GCC_MAJ_VER}
NO_DEFAULT_PATH
PATHS "${ALTERNATIVE_GCC_DIR}")
ELSE()
FIND_PROGRAM(GCC_AR_EXECUTABLE gcc-ar)
FIND_PROGRAM(GCC_RANLIB_EXECUTABLE gcc-ranlib)
ENDIF()
IF(GCC_AR_EXECUTABLE AND GCC_RANLIB_EXECUTABLE)
SET(CMAKE_AR ${GCC_AR_EXECUTABLE})
SET(CMAKE_RANLIB ${GCC_RANLIB_EXECUTABLE})
ENDIF()
ENDIF()
# We must use -DWITH_PROTOBUF=system.
# There are also bugs exposed by LTO in the bundled ICU and editline sources.
SET(WITH_SYSTEM_LIBS_DEFAULT ON)
ENDIF()
# Explicit list of all -DWITH_XXX=system possibilities
# *except* boost, which requires one specific version to be downloaded
SET(SYSTEM_LIBRARIES
CURL
EDITLINE
ICU
LIBEVENT
LZ4
# LZMA use bundled by default here
PROTOBUF
RAPIDJSON
RE2
SSL
ZLIB
)
OPTION(WITH_SYSTEM_LIBS
"Use -DWITH_XXX=system for ${SYSTEM_LIBRARIES}" ${WITH_SYSTEM_LIBS_DEFAULT})
GET_CMAKE_PROPERTY(CACHE_VARS CACHE_VARIABLES)
UNSET(COMMAND_LINE_VARS)
FOREACH(CACHE_VAR ${CACHE_VARS})
GET_PROPERTY(CACHE_VAR_HELPSTRING CACHE ${CACHE_VAR} PROPERTY HELPSTRING)
IF(CACHE_VAR_HELPSTRING STREQUAL
"No help, variable specified on the command line."
)
LIST(APPEND COMMAND_LINE_VARS ${CACHE_VAR})
ENDIF()
ENDFOREACH()
# Default to "system" for all SYSTEM_LIBRARIES
IF(WITH_SYSTEM_LIBS)
FOREACH(SYSTEM_LIB ${SYSTEM_LIBRARIES})
LIST(FIND COMMAND_LINE_VARS WITH_${SYSTEM_LIB} FOUNDIT)
IF(FOUNDIT LESS 0)
SET(WITH_${SYSTEM_LIB} "system")
SET(WITH_${SYSTEM_LIB} "system" CACHE STRING
"Use system rather than bundled" FORCE)
MESSAGE(STATUS "Adding -DWITH_${SYSTEM_LIB}=${WITH_${SYSTEM_LIB}}")
ELSE()
MESSAGE(STATUS
"Found WITH_${SYSTEM_LIB}=${WITH_${SYSTEM_LIB}} on command line")
ENDIF()
ENDFOREACH()
# Don't redo the system analysis on subsequent runs of cmake
UNSET(WITH_SYSTEM_LIBS)
UNSET(WITH_SYSTEM_LIBS CACHE)
ENDIF()
# Add bundled or system zlib.
MYSQL_CHECK_ZLIB_WITH_COMPRESS()
IF(BUILD_BUNDLED_ZLIB)
INCLUDE_DIRECTORIES(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/extra/zlib ${CMAKE_CURRENT_BINARY_DIR}/extra/zlib)
ENDIF()
# Add bundled wolfssl/wolfcrypt or system openssl.
MYSQL_CHECK_SSL()
MYSQL_CHECK_SSL_DLLS()
# Add system/bundled editline.
MYSQL_CHECK_EDITLINE()
# Add libevent
MYSQL_CHECK_LIBEVENT()
# Add lz4 library
MYSQL_CHECK_LZ4()
# Add lzma library
MYSQL_CHECK_LZMA()
# Add re2 library
MYSQL_CHECK_RE2()
# Add icu library
MYSQL_CHECK_ICU()
# Add SASL library
MYSQL_CHECK_SASL()
# Add protoc and libprotobuf
IF(NOT WITHOUT_SERVER)
MYSQL_CHECK_PROTOBUF()
ENDIF()
# Try and set CURL_LIBRARY
MYSQL_CHECK_CURL()
# Add RapidJSON library.
MYSQL_CHECK_RAPIDJSON()
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
# Check for pthread_setname_np
CHECK_C_SOURCE_COMPILES("
#include <pthread.h>
int main(int ac, char **av)
{
const char *thread_name= 0;
int ret = pthread_setname_np(pthread_self(), thread_name);
return ret;
}"
HAVE_PTHREAD_SETNAME_NP)
ENDIF()
IF (BUILD_BUNDLED_LZMA)
ADD_SUBDIRECTORY(extra/lzma)
ENDIF()
IF (BUILD_BUNDLED_RE2)
ADD_SUBDIRECTORY(extra/re2)
ENDIF()
#
# Setup maintainer mode options by the end. Platform checks are
# not run with the warning options as to not perturb fragile checks
# (i.e. do not make warnings into errors).
#
# Why don't these flags affect the entire build?
# Because things may already have been included with ADD_SUBDIRECTORY
#
OPTION(MYSQL_MAINTAINER_MODE
"MySQL maintainer-specific development environment" OFF)
INCLUDE(maintainer)
IF(WITH_UNIT_TESTS)