File: CMakeLists.txt

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (1445 lines) | stat: -rw-r--r-- 42,942 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
# Copyright (c) 2006, 2025, Oracle and/or its affiliates.
#
# 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 designed to work 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 either included with
# the program or referenced in the documentation.
#
# 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

INCLUDE_DIRECTORIES(SYSTEM ${BOOST_PATCHES_DIR} ${BOOST_INCLUDE_DIR})

ADD_WSHADOW_WARNING()

# Lots of warnings about -Walloc-size-larger-than= from my_malloc.cc
# but it is basically impossible to trace the actual origin.

IF(FPROFILE_GENERATE OR FPROFILE_USE OR
    CMAKE_COMPILER_FLAG_WITH_LTO OR WITH_LTO)
  IF(MY_COMPILER_IS_GNU AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10)
    # -Walloc-size-larger-than=PTRDIFF_MAX is enabled by default.
    STRING_APPEND(CMAKE_EXE_LINKER_FLAGS " -Wno-alloc-size-larger-than")
    # In functions generated by protobuf:
    STRING_APPEND(CMAKE_EXE_LINKER_FLAGS " -Wno-stringop-overflow")
  ENDIF()
ENDIF()

# Array indexing with pland_idx == int8 gives warnings.
IF(SOLARIS AND MY_COMPILER_IS_GNU_OR_CLANG)
  ADD_COMPILE_OPTIONS("-Wno-char-subscripts")
ENDIF()

SET(CONF_SOURCES
  ${CMAKE_CURRENT_BINARY_DIR}/sql_builtin.cc
)
SET(GEN_SOURCES
  ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.h
  ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
  ${CMAKE_CURRENT_BINARY_DIR}/sql_hints.yy.h
  ${CMAKE_CURRENT_BINARY_DIR}/sql_hints.yy.cc
  ${CMAKE_CURRENT_BINARY_DIR}/lex_hash.h
)
SET(GEN_DIGEST_SOURCES
  ${CMAKE_CURRENT_BINARY_DIR}/lex_token.h
)
SET(GEN_KEYWORD_LIST_SOURCES
  ${CMAKE_CURRENT_BINARY_DIR}/keyword_list.h
)

SET_SOURCE_FILES_PROPERTIES(
  ${GEN_SOURCES}
  ${GEN_DIGEST_SOURCES}
  ${GEN_KEYWORD_LIST_SOURCES}
  ${CONF_SOURCES}
  PROPERTIES GENERATED 1)

# Gen_lex_token
# Make sure sql_yacc.h is generated before compiling gen_lex_token
MYSQL_ADD_EXECUTABLE(gen_lex_token
  gen_lex_token.cc
  DEPENDENCIES GenServerSource
  SKIP_INSTALL
  )

MY_CHECK_CXX_COMPILER_WARNING("-Wmissing-profile" HAS_MISSING_PROFILE)
IF(HAS_MISSING_PROFILE)
  ADD_COMPILE_FLAGS(
    binlog_reader.cc  # In case we did not profile replication.
    gen_lex_token.cc  # This is a compile-time tool.
    COMPILE_FLAGS ${HAS_MISSING_PROFILE})
ENDIF()

ADD_CUSTOM_COMMAND(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lex_token.h
  COMMAND gen_lex_token > lex_token.h
  DEPENDS gen_lex_token
)

# gen_keyword_list
# Make sure sql_yacc.h is generated before compiling gen_keyword_list
MYSQL_ADD_EXECUTABLE(gen_keyword_list
  gen_keyword_list.cc
  DEPENDENCIES GenServerSource
  LINK_LIBRARIES ext::icu
  SKIP_INSTALL
  )

IF(WITH_LTO OR CMAKE_COMPILER_FLAG_WITH_LTO)
  TARGET_COMPILE_OPTIONS(gen_keyword_list PRIVATE "-fno-lto")
ENDIF()

IF(HAS_MISSING_PROFILE)
  ADD_COMPILE_FLAGS(gen_keyword_list.cc COMPILE_FLAGS ${HAS_MISSING_PROFILE})
ENDIF()

ADD_CUSTOM_COMMAND(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/keyword_list.h
  COMMAND gen_keyword_list ${CMAKE_CURRENT_SOURCE_DIR}/sql_yacc.yy > ${CMAKE_CURRENT_BINARY_DIR}/keyword_list.h
  DEPENDS gen_keyword_list
)

ADD_DEFINITIONS(-DMYSQL_SERVER)
ADD_SUBDIRECTORY(server_component)
ADD_SUBDIRECTORY(protobuf)

SET(DD_SOURCES
  dd/collection.cc
  dd/dd_event.cc
  dd/dd_resource_group.cc
  dd/dd_routine.cc
  dd/dd_schema.cc
  dd/dd_table.cc
  dd/dd_tablespace.cc
  dd/dd_trigger.cc
  dd/dd_view.cc
  dd/dd_utility.cc
  dd/properties.cc

  dd/impl/dd.cc
  dd/impl/dictionary_impl.cc
  dd/impl/properties_impl.cc
  dd/impl/system_registry.cc
  dd/impl/transaction_impl.cc
  dd/impl/utils.cc
  dd/impl/sdi.cc
  dd/impl/sdi_api.cc
  dd/impl/sdi_file.cc
  dd/impl/sdi_tablespace.cc
  dd/impl/string_type.cc

  dd/impl/bootstrap/bootstrap_ctx.cc
  dd/impl/bootstrap/bootstrapper.cc

  dd/impl/cache/dictionary_client.cc
  dd/impl/cache/local_multi_map.cc
  dd/impl/cache/multi_map_base.cc
  dd/impl/cache/shared_multi_map.cc
  dd/impl/cache/shared_dictionary_cache.cc
  dd/impl/cache/storage_adapter.cc

  dd/impl/raw/object_keys.cc
  dd/impl/raw/raw_record.cc
  dd/impl/raw/raw_record_set.cc
  dd/impl/raw/raw_table.cc

  dd/impl/system_views/administrable_role_authorizations.cc
  dd/impl/system_views/applicable_roles.cc
  dd/impl/system_views/character_sets.cc
  dd/impl/system_views/check_constraints.cc
  dd/impl/system_views/collations.cc
  dd/impl/system_views/collation_charset_applicability.cc
  dd/impl/system_views/columns.cc
  dd/impl/system_views/columns_extensions.cc
  dd/impl/system_views/column_statistics.cc
  dd/impl/system_views/enabled_roles.cc
  dd/impl/system_views/events.cc
  dd/impl/system_views/files.cc
  dd/impl/system_views/innodb_datafiles.cc
  dd/impl/system_views/innodb_foreign.cc
  dd/impl/system_views/innodb_foreign_cols.cc
  dd/impl/system_views/innodb_fields.cc
  dd/impl/system_views/innodb_tablespaces_brief.cc
  dd/impl/system_views/key_column_usage.cc
  dd/impl/system_views/keywords.cc
  dd/impl/system_views/parameters.cc
  dd/impl/system_views/partitions.cc
  dd/impl/system_views/referential_constraints.cc
  dd/impl/system_views/resource_groups.cc
  dd/impl/system_views/role_column_grants.cc
  dd/impl/system_views/role_routine_grants.cc
  dd/impl/system_views/role_table_grants.cc
  dd/impl/system_views/routines.cc
  dd/impl/system_views/schemata.cc
  dd/impl/system_views/schemata_extensions.cc
  dd/impl/system_views/statistics.cc
  dd/impl/system_views/st_spatial_reference_systems.cc
  dd/impl/system_views/st_units_of_measure.cc
  dd/impl/system_views/st_geometry_columns.cc
  dd/impl/system_views/tables.cc
  dd/impl/system_views/tables_extensions.cc
  dd/impl/system_views/table_constraints.cc
  dd/impl/system_views/table_constraints_extensions.cc
  dd/impl/system_views/tablespaces_extensions.cc
  dd/impl/system_views/triggers.cc
  dd/impl/system_views/view_routine_usage.cc
  dd/impl/system_views/view_table_usage.cc
  dd/impl/system_views/views.cc
  dd/impl/system_views/user_attributes.cc

  dd/impl/tables/character_sets.cc
  dd/impl/tables/check_constraints.cc
  dd/impl/tables/collations.cc
  dd/impl/tables/columns.cc
  dd/impl/tables/column_statistics.cc
  dd/impl/tables/column_type_elements.cc
  dd/impl/tables/dd_properties.cc
  dd/impl/tables/events.cc
  dd/impl/tables/foreign_key_column_usage.cc
  dd/impl/tables/foreign_keys.cc
  dd/impl/tables/index_column_usage.cc
  dd/impl/tables/indexes.cc
  dd/impl/tables/index_partitions.cc
  dd/impl/tables/index_stats.cc
  dd/impl/tables/parameters.cc
  dd/impl/tables/parameter_type_elements.cc
  dd/impl/tables/resource_groups.cc
  dd/impl/tables/routines.cc
  dd/impl/tables/schemata.cc
  dd/impl/tables/spatial_reference_systems.cc
  dd/impl/tables/table_partitions.cc
  dd/impl/tables/table_stats.cc
  dd/impl/tables/table_partition_values.cc
  dd/impl/tables/tables.cc
  dd/impl/tables/tablespace_files.cc
  dd/impl/tables/tablespaces.cc
  dd/impl/tables/triggers.cc
  dd/impl/tables/view_routine_usage.cc
  dd/impl/tables/view_table_usage.cc

  dd/impl/types/index_stat_impl.cc
  dd/impl/types/table_stat_impl.cc
  dd/impl/types/abstract_table_impl.cc
  dd/impl/types/charset_impl.cc
  dd/impl/types/check_constraint_impl.cc
  dd/impl/types/collation_impl.cc
  dd/impl/types/column_impl.cc
  dd/impl/types/column_statistics_impl.cc
  dd/impl/types/column_type_element_impl.cc
  dd/impl/types/entity_object_table_impl.cc
  dd/impl/types/entity_object_impl.cc
  dd/impl/types/event_impl.cc
  dd/impl/types/foreign_key_element_impl.cc
  dd/impl/types/foreign_key_impl.cc
  dd/impl/types/function_impl.cc
  dd/impl/types/index_element_impl.cc
  dd/impl/types/index_impl.cc
  dd/impl/types/object_table_impl.cc
  dd/impl/types/object_table_definition_impl.cc
  dd/impl/types/parameter_impl.cc
  dd/impl/types/parameter_type_element_impl.cc
  dd/impl/types/partition_impl.cc
  dd/impl/types/partition_index_impl.cc
  dd/impl/types/partition_value_impl.cc
  dd/impl/types/procedure_impl.cc
  dd/impl/types/resource_group_impl.cc
  dd/impl/types/routine_impl.cc
  dd/impl/types/schema_impl.cc
  dd/impl/types/spatial_reference_system_impl.cc
  dd/impl/types/table_impl.cc
  dd/impl/types/tablespace_file_impl.cc
  dd/impl/types/tablespace_impl.cc
  dd/impl/types/trigger_impl.cc
  dd/impl/types/view_impl.cc
  dd/impl/types/view_routine_impl.cc
  dd/impl/types/view_table_impl.cc
  dd/impl/types/weak_object_impl.cc

  dd/impl/upgrade/server.cc
  dd/impl/upgrade/dd.cc

  dd/info_schema/metadata.cc
  dd/info_schema/show.cc
  dd/info_schema/show_query_builder.cc
  dd/info_schema/table_stats.cc
  dd/info_schema/tablespace_stats.cc

  dd/performance_schema/init.cc

  dd/ndbinfo_schema/init.cc

  dd/upgrade_57/event.cc
  dd/upgrade_57/global.cc
  dd/upgrade_57/routine.cc
  dd/upgrade_57/schema.cc
  dd/upgrade_57/table.cc
  dd/upgrade_57/upgrade.cc
)

SET(SQL_GIS_SOURCES
  gis/area.cc
  gis/buffer.cc
  gis/covered_by.cc
  gis/crosses.cc
  gis/difference.cc
  gis/difference_functor.cc
  gis/disjoint.cc
  gis/distance.cc
  gis/distance_functor.cc
  gis/distance_sphere.cc
  gis/equals.cc
  gis/frechet_distance.cc
  gis/gc_utils.cc
  gis/geometries.cc
  gis/hausdorff_distance.cc
  gis/intersection.cc
  gis/intersection_functor.cc
  gis/intersects.cc
  gis/is_simple.cc
  gis/is_valid.cc
  gis/length.cc
  gis/line_interpolate.cc
  gis/mbr_utils.cc
  gis/overlaps.cc
  gis/ring_flip_visitor.cc
  gis/rtree_support.cc
  gis/simplify.cc
  gis/so_utils.cc
  gis/srs/srs.cc
  gis/srs/wkt_parser.cc
  gis/st_units_of_measure.cc
  gis/symdifference.cc
  gis/symdifference_functor.cc
  gis/touches.cc
  gis/transform.cc
  gis/union.cc
  gis/union_functor.cc
  gis/within.cc
  gis/wkb.cc
  gis/wkb_size_visitor.cc
  gis/wkb_visitor.cc
  item_geofunc.cc
  item_geofunc_buffer.cc
  item_geofunc_internal.cc
  item_geofunc_relchecks.cc
  options_parser.cc
)

SET(SQL_SHARED_SOURCES
  auth/auth_acls.cc
  auth/auth_common.cc
  auth/dynamic_privileges_impl.cc
  auth/dynamic_privilege_table.cc
  auth/acl_table_user.cc
  auth/sql_authentication.cc
  auth/sql_auth_cache.cc
  auth/sql_authorization.cc
  auth/sql_mfa.cc
  auth/sql_user_table.cc
  auth/sql_user.cc
  auth/partial_revokes.cc
  auth/password.cc
  auth/password_policy_service.cc
  auth/sql_security_ctx.cc
  auth/service_security_context.cc
  auto_thd.cc
  keyring_service.cc
  auth/roles.cc
  auth/role_tables.cc
  auth/sha2_password_common.cc
  auth/sha2_password.cc
  ssl_wrapper_service.cc
  bootstrap.cc
  check_stack.cc
  conn_handler/connection_handler_manager.cc
  clone_handler.cc
  create_field.cc
  current_thd.cc
  dd_sql_view.cc
  dd_sp.cc
  dd_table_share.cc
  debug_sync.cc
  default_values.cc
  derror.cc
  error_handler.cc
  field.cc
  field_conv.cc
  filesort.cc
  filesort_utils.cc
  aggregate_check.cc
  gstream.cc
  handler.cc
  histograms/equi_height.cc
  histograms/equi_height_bucket.cc
  histograms/histogram.cc
  histograms/singleton.cc
  histograms/value_map.cc
  hostname_cache.cc
  init.cc
  log_resource.cc
  item.cc
  item_buff.cc
  item_cmpfunc.cc
  item_create.cc
  item_func.cc
  item_gtid_func.cc
  item_pfs_func.cc
  item_json_func.cc
  item_regexp_func.cc
  item_row.cc
  item_strfunc.cc
  item_subselect.cc
  item_sum.cc
  window.cc
  item_timefunc.cc
  item_xmlfunc.cc
  item_inetfunc.cc
  iterators/basic_row_iterators.cc
  iterators/bka_iterator.cc
  iterators/composite_iterators.cc
  iterators/hash_join_buffer.cc
  iterators/hash_join_chunk.cc
  iterators/hash_join_iterator.cc
  iterators/ref_row_iterators.cc
  iterators/sorting_iterator.cc
  iterators/window_iterators.cc
  join_optimizer/access_path.cc
  join_optimizer/build_interesting_orders.cc
  join_optimizer/common_subexpression_elimination.cc
  join_optimizer/cost_model.cc
  join_optimizer/estimate_selectivity.cc
  join_optimizer/explain_access_path.cc
  join_optimizer/finalize_plan.cc
  join_optimizer/graph_simplification.cc
  join_optimizer/hypergraph.cc
  join_optimizer/interesting_orders.cc
  join_optimizer/join_optimizer.cc
  join_optimizer/make_join_hypergraph.cc
  join_optimizer/online_cycle_finder.cc
  join_optimizer/overflow_bitset.cc
  join_optimizer/print_utils.cc
  join_optimizer/replace_item.cc
  json_diff.cc
  json_schema.cc
  key.cc
  key_spec.cc
  keycaches.cc
  lock.cc
  locked_tables_list.cc
  locking_service.cc
  locks/shared_spin_lock.cc
  log.cc
  mdl.cc
  mdl_context_backup.cc
  migrate_keyring.cc
  my_decimal.cc
  mysqld.cc
  mysqld_thd_manager.cc
  opt_costconstantcache.cc
  opt_costconstants.cc
  opt_costmodel.cc
  opt_explain.cc
  opt_explain_format.cc
  opt_explain_traditional.cc
  opt_explain_json.cc
  opt_hints.cc
  opt_statistics.cc
  opt_sum.cc
  opt_trace.cc
  opt_trace2server.cc
  pack_rows.cc
  parse_file.cc
  parse_tree_handler.cc
  parse_tree_helpers.cc
  parse_tree_hints.cc
  parse_tree_items.cc
  parse_tree_node_base.cc
  parse_tree_nodes.cc
  query_term.cc
  parse_tree_partitions.cc
  parse_tree_window.cc
  select_lex_visitor.cc
  parser_service.cc
  partition_info.cc
  partitioning/partition_handler.cc
  persisted_variable.cc
  protocol_classic.cc
  psi_memory_key.cc
  psi_memory_resource.cc
  query_result.cc
  raii/targeted_stringstream.cc
  range_optimizer/geometry_index_range_scan.cc
  range_optimizer/group_index_skip_scan.cc
  range_optimizer/group_index_skip_scan_plan.cc
  range_optimizer/index_merge.cc
  range_optimizer/index_merge_plan.cc
  range_optimizer/index_range_scan.cc
  range_optimizer/index_range_scan_plan.cc
  range_optimizer/index_skip_scan.cc
  range_optimizer/index_skip_scan_plan.cc
  range_optimizer/partition_pruning.cc
  range_optimizer/range_analysis.cc
  range_optimizer/range_optimizer.cc
  range_optimizer/reverse_index_range_scan.cc
  range_optimizer/rowid_ordered_retrieval.cc
  range_optimizer/rowid_ordered_retrieval_plan.cc
  range_optimizer/tree.cc
  regexp/errors.cc
  regexp/regexp_engine.cc
  regexp/regexp_facade.cc
  resourcegroups/thread_resource_control.cc
  resourcegroups/platform/thread_attrs_api_common.cc
  resourcegroups/resource_group_mgr.cc
  resourcegroups/resource_group_sql_cmd.cc
  rpl_group_replication.cc
  rpl_transaction_ctx.cc
  rpl_transaction_write_set_ctx.cc
  rpl_write_set_handler.cc
  rules_table_service.cc
  rwlock_scoped_lock.cc
  sd_notify.cc
  sdi_utils.cc
  session_tracker.cc
  set_var.cc
  sp.cc
  sp_cache.cc
  sp_head.cc
  sp_instr.cc
  sp_pcontext.cc
  sp_rcontext.cc
  spatial.cc
  string_service.cc
  sql_admin.cc
  sql_alloc_error_handler.cc
  sql_alter.cc
  sql_alter_instance.cc
  sql_backup_lock.cc
  sql_base.cc
  sql_bootstrap.cc
  sql_initialize.cc
  sql_call.cc
  sql_check_constraint.cc
  sql_class.cc
  sql_component.cc
  sql_const_folding.cc
  sql_cmd_ddl_table.cc
  sql_cmd_srs.cc
  sql_connect.cc
  sql_constraint.cc
  sql_cursor.cc
  sql_data_change.cc
  sql_db.cc
  sql_delete.cc
  sql_derived.cc
  sql_digest.cc
  sql_do.cc
  sql_error.cc
  sql_exception_handler.cc
  sql_executor.cc
  sql_get_diagnostics.cc
  sql_gipk.cc
  sql_handler.cc
  sql_help.cc
  sql_import.cc
  sql_insert.cc
  sql_lex.cc
  sql_lex_hash.cc
  sql_lex_hints.cc
  sql_list.cc
  sql_load.cc
  sql_locale.cc
  sql_manager.cc
  sql_optimizer.cc
  sql_parse.cc
  sql_partition.cc
  sql_partition_admin.cc
  sql_planner.cc
  sql_plugin.cc
  sql_plugin_var.cc
  sql_prepare.cc
  sql_profile.cc
  sql_query_rewrite.cc
  sql_reload.cc
  sql_rename.cc
  sql_resolver.cc
  sql_restart_server.cc
  sql_rewrite.cc
  sql_select.cc
  sql_servers.cc
  sql_show.cc
  sql_show_status.cc
  sql_show_processlist.cc
  sql_signal.cc
  sql_state.cc
  sql_table.cc
  sql_tablespace.cc
  sql_test.cc
  sql_thd_internal_api.cc
  sql_thd_api.cc
  sql_time.cc
  sql_timer.cc
  sql_tmp_table.cc
  sql_trigger.cc
  sql_truncate.cc
  sql_udf.cc
  sql_union.cc
  sql_update.cc
  sql_view.cc
  ssl_acceptor_context_iterator.cc
  ssl_acceptor_context_data.cc
  ssl_acceptor_context_operator.cc
  ssl_init_callback.cc
  stateless_allocator.cc
  strfunc.cc
  sys_vars.cc
  sys_vars_resource_mgr.cc
  system_variables.cc
  table.cc
  table_cache.cc
  table_function.cc
  table_trigger_dispatcher.cc
  tc_log.cc
  thr_malloc.cc
  time_zone_common.cc
  transaction.cc
  transaction_info.cc
  trigger.cc
  trigger_creation_ctx.cc
  trigger_chain.cc
  tztime.cc
  uniques.cc
  xa.cc
  xa/recovery.cc
  xa/sql_xa_second_phase.cc
  xa/sql_xa_commit.cc
  xa/sql_xa_end.cc
  xa/sql_xa_prepare.cc
  xa/sql_xa_recover.cc
  xa/sql_xa_rollback.cc
  xa/sql_xa_start.cc
  xa/transaction_cache.cc
  xa/xid_extract.cc
  daemon_proxy_keyring/daemon_proxy_keyring.cc
  )

IF(BUILD_IS_SINGLE_CONFIG)
  GET_PROPERTY(CWD_DEFINITIONS DIRECTORY PROPERTY COMPILE_DEFINITIONS)
  IF(NOT CMAKE_CXX_FLAGS MATCHES "DENABLED_DEBUG_SYNC" AND
      NOT CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER} MATCHES "DENABLED_DEBUG_SYNC" AND
      NOT CWD_DEFINITIONS MATCHES "ENABLED_DEBUG_SYNC")
    # This has ifdef ENABLED_DEBUG_SYNC
    LIST(REMOVE_ITEM SQL_SHARED_SOURCES
      debug_sync.cc
      )
  ENDIF()
ENDIF()

# BISON_TARGET(<Name> <YaccInput> <CodeOutput>
#              [COMPILE_FLAGS <flags>]
#              [DEFINES_FILE <file>]
#              [VERBOSE <file>]
#              )
# FLEX_TARGET(Name FlexInput FlexOutput
#             [COMPILE_FLAGS <string>]
#             [DEFINES_FILE <string>]
#             )
# The Name argument is just an alias.
# Both macros will ADD_CUSTOM_COMMAND, with WORKING_DIRECTORY current src.
IF(WITH_LOCK_ORDER)

  FIND_PACKAGE(BISON REQUIRED)
  FIND_PACKAGE(FLEX REQUIRED)

  BISON_TARGET(debug_lo_parser
    ${CMAKE_CURRENT_SOURCE_DIR}/debug_lo_parser.yy
    ${CMAKE_CURRENT_BINARY_DIR}/debug_lo_parser.cc
    COMPILE_FLAGS "--name-prefix=LOCK_ORDER_ ${BISON_NO_LINE_OPT}"
    DEFINES_FILE ${CMAKE_BINARY_DIR}/sql/debug_lo_parser.h
    )
  FLEX_TARGET(debug_lo_scanner
    ${CMAKE_CURRENT_SOURCE_DIR}/debug_lo_scanner.ll
    ${CMAKE_CURRENT_BINARY_DIR}/debug_lo_scanner.cc
    COMPILE_FLAGS "--prefix=LOCK_ORDER_"
    DEFINES_FILE ${CMAKE_BINARY_DIR}/sql/debug_lo_scanner.h
    )
  MESSAGE(STATUS "BISON outputs ${BISON_debug_lo_parser_OUTPUTS}")
  MESSAGE(STATUS "FLEX outputs ${FLEX_debug_lo_scanner_OUTPUTS}")

  # Some targets, for easier debugging.
  # The new Xcode build system does not support multiple targets that
  # DEPEND on the same outputs.
  IF(NOT APPLE_XCODE)
    ADD_CUSTOM_TARGET(GenBison_lo DEPENDS ${BISON_debug_lo_parser_OUTPUTS})
    ADD_CUSTOM_TARGET(GenFlex_lo DEPENDS ${FLEX_debug_lo_scanner_OUTPUTS})
  ENDIF()

  LIST(APPEND SQL_SHARED_SOURCES
    ${BISON_debug_lo_parser_OUTPUTS}
    ${FLEX_debug_lo_scanner_OUTPUTS}
    debug_lock_order.cc
    )

  # Bison output uses undefined symbols for clang >= v15
  IF(MY_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
    ADD_COMPILE_FLAGS(${CMAKE_BINARY_DIR}/sql/debug_lo_parser.cc
                      COMPILE_FLAGS "-Wno-unused-but-set-variable")
  ENDIF()

  IF(MY_COMPILER_IS_GNU_OR_CLANG)
    ADD_COMPILE_FLAGS(${FLEX_debug_lo_scanner_OUTPUTS}
      COMPILE_FLAGS
      "-Wno-sign-compare"
      "-Wno-unused-parameter"
      )
    ADD_COMPILE_FLAGS(${CMAKE_BINARY_DIR}/sql/debug_lo_parser.cc
      COMPILE_FLAGS
      "-Wno-undef"
      )
  ENDIF()

  # flex annotates some variables as 'register' and that keyword
  # will go away with C++17
  IF(APPLE)
    ADD_COMPILE_FLAGS(${FLEX_debug_lo_scanner_OUTPUTS}
      COMPILE_FLAGS
      "-Wno-deprecated-register"
      )
  ENDIF()
ENDIF()

UNSET(SQL_HEADERS)
IF(CMAKE_GENERATOR STREQUAL "Xcode")
  OPTION(GLOB_RECURSE_SQL_HEADERS "Find header files with GLOB_RECURSE" ON)
ELSE()
  OPTION(GLOB_RECURSE_SQL_HEADERS "Find header files with GLOB_RECURSE" OFF)
ENDIF()
IF(GLOB_RECURSE_SQL_HEADERS)
  # Needed so that IDEs (e.g. Xcode) can see all sources when searching
  # This recursive search finds over 1500 header files, and may actually
  # take a significant amount of time. Hence, do it only upon request.
  # Visual Studio will scan/parse for headers at startup anyways.
  FILE(GLOB_RECURSE SQL_HEADERS
    "${CMAKE_SOURCE_DIR}/include/*.h"
    "${CMAKE_SOURCE_DIR}/sql/*.h"
    "${CMAKE_SOURCE_DIR}/storage/*.h"
    )
ENDIF()

IF(LINUX)
  LIST(APPEND SQL_SHARED_SOURCES
    resourcegroups/platform/thread_attrs_api_linux.cc)
ELSEIF(APPLE)
  LIST(APPEND SQL_SHARED_SOURCES
    resourcegroups/platform/thread_attrs_api_apple.cc)
ELSEIF(FREEBSD)
  LIST(APPEND SQL_SHARED_SOURCES
    resourcegroups/platform/thread_attrs_api_freebsd.cc)
ELSEIF(SOLARIS)
  LIST(APPEND SQL_SHARED_SOURCES
    resourcegroups/platform/thread_attrs_api_solaris.cc)
ELSEIF(WIN32)
  LIST(APPEND SQL_SHARED_SOURCES
    resourcegroups/platform/thread_attrs_api_win.cc)
ENDIF()

SET(SQL_SOURCE
  ${GEN_SOURCES}
  ${GEN_DIGEST_SOURCES}
  ${GEN_KEYWORD_LIST_SOURCES}
  ${CONF_SOURCES}
  ${SQL_SHARED_SOURCES}
  ${SQL_HEADERS}
  ../libmysql/errmsg.cc
  ../sql-common/client.cc
  ../sql-common/client_plugin.cc
  ../sql-common/client_authentication.cc
  ../sql-common/compression.cc
  ../sql-common/get_password.cc
  ../sql-common/my_path_permissions.cc
  ../sql-common/net_ns.cc
  ../sql-common/net_serv.cc
  ../sql-common/sql_string.cc
  ../sql-common/bind_params.cc
  ../sql-common/json_binary.cc
  ../sql-common/json_dom.cc
  ../sql-common/json_error_handler.cc
  ../sql-common/json_path.cc
  ../sql-common/json_syntax_check.cc
  command_service.cc
  conn_handler/channel_info.cc
  conn_handler/connection_handler_per_thread.cc
  conn_handler/connection_handler_one_thread.cc
  conn_handler/socket_connection.cc
  conn_handler/init_net_server_extension.cc
  event_data_objects.cc
  event_db_repository.cc
  event_parse_data.cc
  event_queue.cc
  event_scheduler.cc
  events.cc
  mf_iocache.cc
  protocol_callback.cc
  signal_handler.cc
  sql_audit.cc
  sql_client.cc
  srv_session.cc
  srv_session_info_service.cc
  srv_session_service.cc
  )

IF(NOT HAVE_SETNS)
  LIST(REMOVE_ITEM SQL_SOURCE ../sql-common/net_ns.cc)
ENDIF()

IF(NOT WIN32)
  LIST(APPEND SQL_SOURCE mysqld_daemon.cc)
ENDIF()

IF(WIN32)
  LIST(APPEND SQL_SOURCE
              conn_handler/named_pipe_connection.cc
              conn_handler/shared_memory_connection.cc
              named_pipe.cc
              restart_monitor_win.cc
      )
ENDIF()

# Workaround for Apple Clang bug on ARM.
# When linking mysqld (and executables using server_unittest_library)
# we get linker warnings about
# ld: warning: direct access in function ....
#     to global weak symbol 'typeinfo for .... '
# It turns out we end up with conflicting visibilities for typeinfo symbols:
# e.g. in in singleton.cc.o  vs  histogram.cc.o
# (__DATA,__const) weak external __ZTIN10histograms9SingletonI6StringEE
# (__DATA,__const) weak private external __ZTIN10histograms9SingletonI6StringEE
#
# Setting an explicit visibility here fixes the warnings.
# Note that the LINK_PUBLIC for server_unittest_library
# will make unit tests pick up histogram symbols from libsql_main.a.
IF(APPLE_ARM)
  ADD_COMPILE_FLAGS(
    histograms/equi_height.cc
    histograms/equi_height_bucket.cc
    histograms/histogram.cc
    histograms/singleton.cc
    histograms/value_map.cc
    COMPILE_FLAGS -fvisibility=hidden
    )
ENDIF()


# Fixes "C1128: number of sections exceeded object file format limit" in MSVC
IF(WIN32)
  ADD_COMPILE_FLAGS(
    gis/difference.cc
    gis/difference_functor.cc
    gis/intersection_functor.cc
    gis/symdifference_functor.cc
    gis/touches.cc
    gis/union.cc
    gis/union_functor.cc
    gis/within.cc
    item_geofunc.cc
    item_geofunc_relchecks.cc
    COMPILE_FLAGS "/bigobj")
ENDIF()

# Downgrade -Werror to warning for gcc
IF(MY_COMPILER_IS_GNU)
  MY_CHECK_CXX_COMPILER_WARNING("error=maybe-uninitialized" HAS_WARN_FLAG)
  IF(HAS_WARN_FLAG)
    ADD_COMPILE_FLAGS(
      geometry_rtree.cc
      COMPILE_FLAGS ${HAS_WARN_FLAG}
      )
  ENDIF()
ENDIF()

# Force optimization of (large) MYSQLparse function in MSVC
IF(WIN32 AND NOT WIN32_CLANG)
  ADD_COMPILE_FLAGS(
    ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
    COMPILE_FLAGS "/d2OptimizeHugeFunctions")
ENDIF()

# 'yyexhtaustedlab': unreferenced label
IF(WIN32 AND NOT WIN32_CLANG)
  ADD_COMPILE_FLAGS(${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
                    ${CMAKE_CURRENT_BINARY_DIR}/sql_hints.yy.cc
                    COMPILE_FLAGS "/wd4102")
ENDIF()

# Common for all versions of GCC/Clang
# Bison output uses undefined symbols in #if checks
IF(MY_COMPILER_IS_GNU_OR_CLANG)
  ADD_COMPILE_FLAGS(${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
                    ${CMAKE_CURRENT_BINARY_DIR}/sql_hints.yy.cc
                    COMPILE_FLAGS "-Wno-undef -Wno-unused-label")
  IF(MY_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
    ADD_COMPILE_FLAGS(${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
                      ${CMAKE_CURRENT_BINARY_DIR}/sql_hints.yy.cc
                      COMPILE_FLAGS "-Wno-unused-but-set-variable")
  ENDIF()
  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98753
  IF(MY_COMPILER_IS_GNU AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11)
    ADD_COMPILE_FLAGS(
      ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
      ${CMAKE_CURRENT_BINARY_DIR}/sql_hints.yy.cc
      COMPILE_FLAGS "-Wno-free-nonheap-object")
  ENDIF()
ENDIF()

IF(WIN32)
  # switch statement contains 'default' but no 'case'
  ADD_COMPILE_FLAGS(${CMAKE_CURRENT_BINARY_DIR}/sql_hints.yy.cc
    COMPILE_FLAGS "/wd4065")
  # conversion from 'uint' to 'Item *' of greater size
  ADD_COMPILE_FLAGS(range_optimizer/range_analysis.cc
    COMPILE_FLAGS "/wd4312")
ENDIF()

MY_CHECK_CXX_COMPILER_FLAG("-fno-builtin-memcmp" HAVE_NO_BUILTIN_MEMCMP)
# See comments in filesort_compare-t.cc about __builtin_memcmp
IF(HAVE_NO_BUILTIN_MEMCMP)
  ADD_COMPILE_FLAGS(
    filesort_utils.cc
    COMPILE_FLAGS "-fno-builtin-memcmp"
  )
ENDIF()

ADD_STATIC_LIBRARY(sql_main ${SQL_SOURCE} LINK_LIBRARIES ext::icu ext::xxhash)
ADD_DEPENDENCIES(sql_main GenServerSource)
ADD_DEPENDENCIES(sql_main GenDigestServerSource)
ADD_DEPENDENCIES(sql_main GenBootstrapPriv)
ADD_DEPENDENCIES(sql_main GenSysSchema)
TARGET_LINK_LIBRARIES(sql_main extra::unordered_dense)

TARGET_LINK_LIBRARIES(sql_main ${MYSQLD_STATIC_PLUGIN_LIBS}
  mysql_server_component_services mysys strings vio
  binlogevents_static ${LIBWRAP} ${LIBDL} ${SSL_LIBRARIES}
  extra::rapidjson)

# sql/immutable_string.h uses
# google::protobuf::io::CodedOutputStream::WriteVarint64ToArray
# which may or may not be inlined.
TARGET_LINK_LIBRARIES(sql_main ext::libprotobuf-lite)

ADD_LIBRARY(sql_gis STATIC ${SQL_GIS_SOURCES})
ADD_DEPENDENCIES(sql_gis GenServerSource)
ADD_DEPENDENCIES(sql_gis GenDigestServerSource)
ADD_DEPENDENCIES(sql_gis GenBootstrapPriv)
ADD_DEPENDENCIES(sql_gis GenSysSchema)
ADD_DEPENDENCIES(sql_gis GenError)
TARGET_LINK_LIBRARIES(sql_gis sql_dd sql_main)
SET_TARGET_PROPERTIES(sql_gis PROPERTIES LINK_INTERFACE_MULTIPLICITY 3)

# This typically saves a few hundred megabytes of disk space.
IF(COMPRESS_DEBUG_SECTIONS)
  MY_CHECK_CXX_COMPILER_FLAG("-gz" HAVE_COMPRESS_GZ_OPTION)
  IF(HAVE_COMPRESS_GZ_OPTION)
    TARGET_COMPILE_OPTIONS(sql_gis PRIVATE -gz)
  ENDIF()
ENDIF()
# Exclude sql_gis from PGO on Windows to avoid linker error LNK1248
EXCLUDE_FROM_MSVC_PGO(sql_gis)

ADD_LIBRARY(sql_dd STATIC ${DD_SOURCES})
ADD_DEPENDENCIES(sql_dd GenFixPrivs)
ADD_DEPENDENCIES(sql_dd GenServerSource)
ADD_DEPENDENCIES(sql_dd GenDigestServerSource)
ADD_DEPENDENCIES(sql_dd GenBootstrapPriv)
ADD_DEPENDENCIES(sql_dd GenSysSchema)
ADD_DEPENDENCIES(sql_dd GenError)
ADD_DEPENDENCIES(sql_dd GenKeywordList)
TARGET_LINK_LIBRARIES(sql_dd sql_gis sql_main)
SET_TARGET_PROPERTIES(sql_dd PROPERTIES LINK_INTERFACE_MULTIPLICITY 3)

#
# On Windows platform we compile in the client-side Windows Native Authentication
# plugin which is used by the client connection code included in the server.
#
IF(WIN32)
  ADD_DEFINITIONS(-DAUTHENTICATION_WIN)
  TARGET_LINK_LIBRARIES(sql_main auth_win_client)
  IF(OPENSSL_APPLINK_C)
    MY_ADD_COMPILE_DEFINITIONS(
      ../sql-common/client_authentication.cc
      COMPILE_DEFINITIONS HAVE_OPENSSL_APPLINK_C)
  ENDIF()
ENDIF()

SET(BINLOG_SOURCE
  basic_istream.cc
  basic_ostream.cc
  binlog/global.cc
  binlog/recovery.cc
  binlog/group_commit/bgc_ticket_manager.cc
  binlog/group_commit/bgc_ticket.cc
  binlog/group_commit/atomic_bgc_ticket.cc
  binlog/group_commit/atomic_bgc_ticket_guard.cc
  binlog/monitoring/context.cc
  binlog/decompressing_event_object_istream.cc
  binlog.cc
  binlog_istream.cc
  binlog_ostream.cc
  binlog_reader.cc
  changestreams/misc/replicated_columns_view.cc
  changestreams/misc/replicated_columns_view_with_gipk_on_source.cc
  changestreams/misc/column_filters/column_filter_inbound_func_indexes.cc
  changestreams/misc/column_filters/column_filter_inbound_gipk.cc
  changestreams/misc/column_filters/column_filter_outbound_func_indexes.cc
  log_event.cc
  rpl_commit_stage_manager.cc
  rpl_filter.cc
  rpl_gtid_execution.cc
  rpl_gtid_misc.cc
  rpl_gtid_mode.cc
  rpl_gtid_mutex_cond_array.cc
  rpl_gtid_owned.cc
  rpl_gtid_persist.cc
  rpl_gtid_set.cc
  rpl_gtid_sid_map.cc
  rpl_gtid_specification.cc
  rpl_gtid_state.cc
  rpl_injector.cc
  rpl_log_encryption.cc
  rpl_record.cc
  rpl_table_access.cc
  rpl_trx_tracking.cc
  rpl_utility.cc
  sql_binlog.cc
  stream_cipher.cc
  )
ADD_LIBRARY(binlog STATIC ${BINLOG_SOURCE})
TARGET_LINK_LIBRARIES(binlog binlogevents_static)
TARGET_LINK_LIBRARIES(binlog rpl)

SET (RPL_SOURCE rpl_handler.cc rpl_tblmap.cc rpl_context.cc)
ADD_DEPENDENCIES(binlog GenError)
ADD_LIBRARY(rpl STATIC ${RPL_SOURCE})
TARGET_LINK_LIBRARIES(rpl sql_main)

# library for the replication source
SET (RPL_SOURCE_SRCS rpl_source.cc rpl_binlog_sender.cc binlog_reader.cc)
ADD_DEPENDENCIES(rpl GenError)
ADD_LIBRARY(rpl_source STATIC ${RPL_SOURCE_SRCS})
ADD_DEPENDENCIES(rpl_source GenError)
TARGET_LINK_LIBRARIES(rpl_source binlog sql_main)

SET (RPL_REPLICA_SRCS
  dynamic_ids.cc
  changestreams/apply/commit_order_queue.cc
  changestreams/apply/replication_thread_status.cc
  rpl_applier_reader.cc
  rpl_async_conn_failover.cc
  rpl_async_conn_failover_table_operations.cc
  rpl_async_conn_failover_add_managed_udf.cc
  rpl_async_conn_failover_add_source_udf.cc
  rpl_async_conn_failover_delete_managed_udf.cc
  rpl_async_conn_failover_delete_source_udf.cc
  rpl_async_conn_failover_configuration_propagation.cc
  rpl_async_conn_failover_reset_udf.cc
  rpl_channel_service_interface.cc
  rpl_channel_credentials.cc
  rpl_info.cc
  rpl_info_dummy.cc
  rpl_info_factory.cc
  rpl_info_file.cc
  rpl_info_handler.cc
  rpl_info_table.cc
  rpl_info_table_access.cc
  rpl_info_values.cc
  rpl_io_monitor.cc
  rpl_mi.cc
  rpl_msr.cc
  rpl_mta_submode.cc
  rpl_mysql_connect.cc
  rpl_reporting.cc
  rpl_rli.cc
  rpl_rli_pdb.cc
  rpl_replica.cc
  rpl_replica_commit_order_manager.cc
  rpl_replica_until_options.cc
  rpl_sys_key_access.cc
  rpl_sys_table_access.cc
  rpl_trx_boundary_parser.cc
  udf_service_impl.cc
  udf_service_util.cc
  )
ADD_STATIC_LIBRARY(rpl_replica ${RPL_REPLICA_SRCS}
  DEPENDENCIES GenError
  LINK_LIBRARIES binlog sql_main ${RPL_PROTOBUF_LITE_LIB}
  )

IF(WIN32)
  # Silence warnings about: needs to have dll-interface
  TARGET_COMPILE_OPTIONS(rpl_replica PRIVATE "/wd4251")
  ADD_COMPILE_FLAGS(mysqld.cc COMPILE_FLAGS "/wd4251")
  IF(WIN32_CLANG)
    ADD_COMPILE_FLAGS(mysqld.cc COMPILE_FLAGS " -Wno-microsoft-cast")
  ENDIF()
ENDIF()

# Includes code generated by protobuf, and version 3.12 will generate extra ';'.
MY_CHECK_CXX_COMPILER_WARNING("-Wextra-semi" HAS_WARN_FLAG)
IF(HAS_WARN_FLAG)
  TARGET_COMPILE_OPTIONS(rpl_replica PRIVATE "${HAS_WARN_FLAG}")
  ADD_COMPILE_FLAGS(mysqld.cc COMPILE_FLAGS ${HAS_WARN_FLAG})
ENDIF()

# All these libraries depend on each other.
TARGET_LINK_LIBRARIES(sql_main rpl rpl_source rpl_replica binlog)

IF(WIN32)
  SET(MYSQLD_SOURCE
    main.cc
    enable_win_jemalloc.cc
    nt_servc.cc
    nt_servc.h
    message.rc)
ELSE()
  SET(MYSQLD_SOURCE main.cc)
ENDIF()

MYSQL_ADD_EXECUTABLE(mysqld
  ${MYSQLD_SOURCE} DESTINATION ${INSTALL_SBINDIR} COMPONENT Server
  )
# You may want to redirect output for this one,
# the list of exported symbols is loooong.
ADD_OBJDUMP_TARGET(show_mysqld "$<TARGET_FILE:mysqld>" DEPENDS mysqld)

# We depend on protobuf because of the mysqlx plugin and replication.
IF(UNIX_INSTALL_RPATH_ORIGIN_PRIV_LIBDIR)
  ADD_INSTALL_RPATH_FOR_PROTOBUF(mysqld)
ENDIF()

OPTION(DEBUG_EXTNAME "Build server as mysqld-debug (debug builds only)" OFF)
MARK_AS_ADVANCED(DEBUG_EXTNAME)

IF(DEBUG_EXTNAME)
  SET_TARGET_PROPERTIES(mysqld PROPERTIES DEBUG_OUTPUT_NAME "mysqld-debug")
ENDIF()

# macOS has problems with enabling LTO for shared libs, so we only set it
# as target property for mysqld.
IF(APPLE AND WITH_LTO)
  SET_TARGET_PROPERTIES(mysqld PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
ENDIF()

IF(APPLE)
  # Add CoreServices framework since some dloadable plugins may need it
  FIND_LIBRARY(CORESERVICES NAMES CoreServices)
  IF(CORESERVICES)
    TARGET_LINK_LIBRARIES(mysqld ${CORESERVICES})
  ENDIF()
  IF(APPLE_XCODE)
    MY_ADD_COMPILE_DEFINITIONS(mysqld.cc COMPILE_DEFINITIONS APPLE_XCODE)
  ENDIF()
ENDIF()

IF(WITH_LTO OR CMAKE_COMPILER_FLAG_WITH_LTO)
  # We get ODR violations because of multiple bison parsers.
  MY_CHECK_CXX_COMPILER_WARNING("error=odr" HAS_WARN_FLAG)
  IF(HAS_WARN_FLAG)
    MY_TARGET_LINK_OPTIONS(mysqld "${HAS_WARN_FLAG}")
  ENDIF()
  # We may get errors in boost/geometry/srs/projections/proj/ob_tran.hpp
  # and several other boost files.
  MY_CHECK_CXX_COMPILER_WARNING("error=maybe-uninitialized" HAS_WARN_FLAG)
  IF(HAS_WARN_FLAG)
    MY_TARGET_LINK_OPTIONS(mysqld "${HAS_WARN_FLAG}")
  ENDIF()
  # The linker claims that unmasked_server_id is uninitialized.
  MY_CHECK_CXX_COMPILER_WARNING("error=uninitialized" HAS_WARN_FLAG)
  IF(HAS_WARN_FLAG)
    MY_TARGET_LINK_OPTIONS(mysqld "${HAS_WARN_FLAG}")
  ENDIF()
ENDIF()

GET_TARGET_PROPERTY(mysqld_link_flags mysqld LINK_FLAGS)
IF(NOT mysqld_link_flags)
  SET(mysqld_link_flags)
ENDIF()

IF(UNIX_INSTALL_RPATH_ORIGIN_PRIV_LIBDIR
    OR LINUX_INSTALL_RPATH_ORIGIN
    OR TARGET my_tcmalloc
    )
  # Because of INSTALL_DEBUG_TARGET which does INSTALL(FILES ...)
  IF(UNIX AND NOT APPLE AND CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")
    STRING_APPEND(mysqld_link_flags
      " -Wl,-rpath,'\$ORIGIN/../${INSTALL_PRIV_LIBDIR}'")
    SET_TARGET_PROPERTIES(mysqld
      PROPERTIES LINK_FLAGS "${mysqld_link_flags}")
    MESSAGE(STATUS "LINK_FLAGS for mysqld ${mysqld_link_flags}")
  ENDIF()

  # Insert absolute INSTALL_RPATH before $ORIGIN values.
  # This is done in order to support setuid executables, needed by:
  # https://dev.mysql.com/doc/refman/8.0/en/resource-groups.html

  # Note: for Fedora RPM, this gives ERROR 0008: file '/usr/sbin/mysqld'
  #       contains the $ORIGIN specifier at the wrong position.
  IF(NOT LINUX_RHEL10)
    IF(INSTALL_LAYOUT STREQUAL "DEB" OR INSTALL_LAYOUT STREQUAL "RPM")
      GET_TARGET_PROPERTY(CURRENT_RPATH_mysqld mysqld INSTALL_RPATH)
      LIST(INSERT CURRENT_RPATH_mysqld 0
        "${CMAKE_INSTALL_PREFIX}/${INSTALL_PRIV_LIBDIR}")
      SET_TARGET_PROPERTIES(mysqld
        PROPERTIES INSTALL_RPATH "${CURRENT_RPATH_mysqld}")
    ENDIF()
  ENDIF()
ENDIF()

# Remove profiling data collected during build.
IF(FPROFILE_GENERATE)
  ADD_CUSTOM_COMMAND(TARGET mysqld POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E remove_directory ${FPROFILE_DIR}
    COMMENT "Removing profile data in ${FPROFILE_DIR}"
    )
ENDIF()

IF(MSVC)
  ADD_DEPENDENCIES(sql_main GenError)
  IF(MYSQLD_DEF_FILE)
    # Set module definition file.
    SET_TARGET_PROPERTIES(mysqld
      PROPERTIES LINK_FLAGS
        "${mysqld_link_flags} /DEF:${MYSQLD_DEF_FILE}")
  ELSE()
    # Set module definition file.
    SET_TARGET_PROPERTIES(mysqld
      PROPERTIES LINK_FLAGS
    "${mysqld_link_flags} /DEF:${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/mysqld.def")
  ENDIF()
  SET(_PLATFORM  x64)

  MYSQL_ADD_EXECUTABLE(create_def create_def.cc SKIP_INSTALL)

  # Build mysql_fix_privilege_tables.h
  ADD_CUSTOM_COMMAND(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/mysqld.def
    COMMAND create_def
    "$<TARGET_FILE:binlog>"
    "$<TARGET_FILE:binlogevents_static>"
    "$<TARGET_FILE:mysys>"
    "$<TARGET_FILE:mytime>"
    "$<TARGET_FILE:rpl>"
    "$<TARGET_FILE:rpl_replica>"
    "$<TARGET_FILE:sql_main>"
    "$<TARGET_FILE:strings>"
    "$<TARGET_FILE:vio>"
    > mysqld.def
    WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
    DEPENDS create_def binlog binlogevents_static mysys mytime rpl rpl_replica sql_main strings vio
  )
  MY_ADD_CUSTOM_TARGET(GenMysqldDef ALL
    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/mysqld.def)

  ADD_DEPENDENCIES(sql_main GenError)
  ADD_DEPENDENCIES(mysqld GenMysqldDef)
ENDIF()

SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE)
TARGET_LINK_LIBRARIES(mysqld
  sql_main sql_gis binlog rpl rpl_source rpl_replica sql_dd mysys
  minchassis binlogevents_static ext::icu)

# Add dependency on ldap library, to ensure it is not unloaded
# when we shutdown the authentication plugin.
# For Valgrind, we need it to enable our suppressions.
# For OpenSSL in the 1.0.x series, we need it for clean shutdown.
IF(WITH_VALGRIND)
  SET(LINK_MYSQLD_LDAP_LIBRARY 1)
ENDIF()
IF(WITH_SSL STREQUAL "system" AND
    "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}" VERSION_LESS "1.1")
  SET(LINK_MYSQLD_LDAP_LIBRARY 1)
ENDIF()
IF(WITH_AUTHENTICATION_LDAP AND LINK_MYSQLD_LDAP_LIBRARY)
  TARGET_LINK_LIBRARIES(mysqld ${LDAP_LIBRARY})
ENDIF()

IF(SOLARIS)
  TARGET_LINK_LIBRARIES(mysqld mtmalloc)
ENDIF()

# Remove transitive link dependencies when linking plugins
SET_TARGET_PROPERTIES(mysqld PROPERTIES INTERFACE_LINK_LIBRARIES "")

IF(TARGET copy_jemalloc_dll)
  ADD_DEPENDENCIES(mysqld copy_jemalloc_dll)
ENDIF()

# See DEBUG_EXTNAME above: mysqld may already have name mysqld-debug,
# and the rename is a no-op. If it is called 'mysqld' we rename it.
INSTALL_DEBUG_TARGET(mysqld
  DESTINATION ${INSTALL_SBINDIR}
  RENAME mysqld-debug${CMAKE_EXECUTABLE_SUFFIX}
)

# We have already included cmake/bison.cmake, and done FIND_PACKAGE(BISON)
IF(BISON_FOUND)
  SET(USE_BISON_RESULTS_FROM_MAKE_DIST_DEFAULT OFF)
ELSE()
  SET(USE_BISON_RESULTS_FROM_MAKE_DIST_DEFAULT ON)
ENDIF()

# bison should be REQUIRED, but we have to support source tarball build.
# https://dev.mysql.com/doc/refman/8.0/en/source-installation.html
OPTION(USE_BISON_RESULTS_FROM_MAKE_DIST
  "Use bison results from source distribution tarball"
  ${USE_BISON_RESULTS_FROM_MAKE_DIST_DEFAULT}
  )

IF(USE_BISON_RESULTS_FROM_MAKE_DIST)
  # No bison found, see if generated files are available as sources.
  FOREACH(genfile sql_yacc.h sql_yacc.cc sql_hints.yy.h sql_hints.yy.cc)
    IF(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${genfile}")
      MESSAGE(FATAL_ERROR "Cannot find ${CMAKE_CURRENT_SOURCE_DIR}/${genfile}")
    ENDIF()
    ADD_CUSTOM_COMMAND(
      OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${genfile}
      COMMAND ${CMAKE_COMMAND} -E copy_if_different
        ${CMAKE_CURRENT_SOURCE_DIR}/${genfile}
        ${CMAKE_CURRENT_BINARY_DIR}/${genfile}
      COMMENT "Copying file ${genfile}"
      VERBATIM
      )
  ENDFOREACH()
ELSE()
  BISON_TARGET(mysql_parser
    ${CMAKE_CURRENT_SOURCE_DIR}/sql_yacc.yy
    ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
    COMPILE_FLAGS
    "--name-prefix=MYSQL --yacc ${BISON_FLAGS_WARNINGS} ${BISON_NO_LINE_OPT}"
    DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.h
    )

  BISON_TARGET(hints_parser
    ${CMAKE_CURRENT_SOURCE_DIR}/sql_hints.yy
    ${CMAKE_CURRENT_BINARY_DIR}/sql_hints.yy.cc
    COMPILE_FLAGS
    "--name-prefix=HINT_PARSER_ --yacc ${BISON_FLAGS_WARNINGS} ${BISON_NO_LINE_OPT}"
    DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/sql_hints.yy.h
    )

  MESSAGE(STATUS "BISON outputs ${BISON_mysql_parser_OUTPUTS}")
  MESSAGE(STATUS "BISON outputs ${BISON_hints_parser_OUTPUTS}")

  # Some targets, for easier debugging.
  # The new Xcode build system does not support multiple targets that
  # DEPEND on the same outputs.
  IF(NOT APPLE_XCODE)
    ADD_CUSTOM_TARGET(GenBison_mysql DEPENDS ${BISON_mysql_parser_OUTPUTS})
    ADD_CUSTOM_TARGET(GenBison_hints DEPENDS ${BISON_hints_parser_OUTPUTS})
  ENDIF()

ENDIF()

SET_SOURCE_FILES_PROPERTIES(
  ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
  ${CMAKE_CURRENT_SOURCE_DIR}/sql_digest.cc
  PROPERTIES OBJECT_DEPENDS ${GEN_DIGEST_SOURCES}
)

# Gen_lex_hash
MYSQL_ADD_EXECUTABLE(gen_lex_hash gen_lex_hash.cc SKIP_INSTALL)

IF(HAS_MISSING_PROFILE)
  ADD_COMPILE_FLAGS(
    gen_lex_hash.cc
    COMPILE_FLAGS ${HAS_MISSING_PROFILE})
ENDIF()

ADD_CUSTOM_COMMAND(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lex_hash.h
  COMMAND gen_lex_hash > lex_hash.h
  DEPENDS gen_lex_hash
)

MYSQL_ADD_EXECUTABLE(mysql_tzinfo_to_sql
  time_zone_common.cc
  mysql_tzinfo_to_sql.cc
  DEPENDENCIES GenError
  LINK_LIBRARIES mysys extra::rapidjson
  )
SET_TARGET_PROPERTIES(mysql_tzinfo_to_sql
  PROPERTIES COMPILE_FLAGS "-DDISABLE_PSI_FILE=1 -DABBR_ARE_USED")

MY_ADD_CUSTOM_TARGET(
  GenServerSource
  DEPENDS ${GEN_SOURCES}
)

MY_ADD_CUSTOM_TARGET(
  GenDigestServerSource
  DEPENDS ${GEN_DIGEST_SOURCES}
)

MY_ADD_CUSTOM_TARGET(
  GenKeywordList
  DEPENDS ${GEN_KEYWORD_LIST_SOURCES}
)

ADD_DEPENDENCIES(clang_tidy_prerequisites
  GenBootstrapPriv
  GenDigestServerSource
  GenFixPrivs
  GenKeywordList
  GenServerSource
  GenSysSchema
  )

MYSQL_ADD_PLUGIN(udf_example udf_example.cc
  MODULE_ONLY
  TEST_ONLY
  MODULE_OUTPUT_NAME "udf_example"
  WIN_DEF_FILE "${CMAKE_CURRENT_SOURCE_DIR}/udf_example.def"
  )

MYSQL_ADD_PLUGIN(locking_service locking_service_udf.cc
  MODULE_ONLY
  MODULE_OUTPUT_NAME "locking_service"
  WIN_DEF_FILE "${CMAKE_CURRENT_SOURCE_DIR}/locking_service.def"
  )

FOREACH(tool gtar tar git)
  STRING(TOUPPER ${tool}  TOOL)
  FIND_PROGRAM(${TOOL}_EXECUTABLE ${tool} DOC "path to the executable")
  MARK_AS_ADVANCED(${TOOL}_EXECUTABLE)
ENDFOREACH()

CONFIGURE_FILE(
  ${CMAKE_SOURCE_DIR}/cmake/make_dist.cmake.in
  ${CMAKE_BINARY_DIR}/make_dist.cmake @ONLY)

ADD_CUSTOM_TARGET(dist
  COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/make_dist.cmake
  DEPENDS GenBison_mysql GenBison_hints
  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

ADD_CUSTOM_TARGET(distclean
  COMMAND ${CMAKE_COMMAND} -E echo  WARNING: distclean target is not functional
  COMMAND ${CMAKE_COMMAND} -E echo  Use 'git clean -fdx' instead
  VERBATIM
  )

ADD_CUSTOM_TARGET(show-dist-name
  COMMAND ${CMAKE_COMMAND} -E echo "${CPACK_PACKAGE_FILE_NAME}"
)