-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
1189 lines (917 loc) · 36.9 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
# Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Copyright (c) 2007, 2024, 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
##########################################################################
PROJECT(MySQL_Connector_ODBC)
CMAKE_MINIMUM_REQUIRED(VERSION 3.2 FATAL_ERROR)
if(COMMAND cmake_policy)
cmake_policy(VERSION 3.0)
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0003 NEW)
cmake_policy(SET CMP0022 NEW)
# cmake_policy(SET CMP0026 OLD)
endif(COMMAND cmake_policy)
#------- compatibility with older cmake versions ------
#message("CMAKE_VERSION: ${CMAKE_VERSION}")
if(CMAKE_VERSION VERSION_LESS "3.0")
SET(BUILDTYPE_DOCSTRING
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or
CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel")
#
# If cmake is invoked with -DCMAKE_BUILD_TYPE,
# respect user wishes and do not (re)define CMAKE_BUILD_TYPE. Otherwise,
# use Relwithdebinfo.
#
#IF(NOT DEFINED CMAKE_BUILD_TYPE)
# SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING
# ${BUILDTYPE_DOCSTRING} FORCE)
#ENDIF()
macro(add_compile_options)
add_definitions(${ARGV})
endmacro()
else()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()
#-----------------------------------------------------
include(TestBigEndian)
test_big_endian(BIG_ENDIAN)
message(STATUS "BIG_ENDIAN: ${BIG_ENDIAN}")
if (BIG_ENDIAN)
add_definitions(-DIS_BIG_ENDIAN)
endif()
#-----------------------------------------------------
include(FetchContent)
FetchContent_Declare(
ctpl
URL https://github.com/vit-vit/CTPL/archive/refs/tags/ctpl_v.0.0.2.zip
)
FetchContent_MakeAvailable(ctpl)
#-----------------------------------------------------
IF(ENABLE_UNIT_TESTS)
ADD_DEFINITIONS(-DUNIT_TEST_BUILD)
ENDIF(ENABLE_UNIT_TESTS)
#-----------------------------------------------------
FIND_PACKAGE(Threads)
INCLUDE(version.cmake)
IF(NOT WIN32)
INCLUDE(CheckFunctionExists)
CHECK_FUNCTION_EXISTS(dlopen DLOPEN_IN_LIBC)
SET(DL_INCLUDES)
SET(DL_LFLAGS)
SET(DL_LIBS)
IF(NOT DLOPEN_IN_LIBC)
FIND_LIBRARY(DL_LIBS dl)
ENDIF(NOT DLOPEN_IN_LIBC)
IF(DLOPEN_IN_LIBC OR DL_LIBS)
ADD_DEFINITIONS(-DHAVE_LIBDL)
ENDIF()
ENDIF(NOT WIN32)
# RPATH handling
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
#Default is to build both drivers
IF(UNICODE OR NOT ANSI)
MESSAGE(STATUS "Configuring to build Unicode driver")
SET(IS_UNICODE_DRIVER 1)
SET(CONNECTOR_DRIVER_TYPE "Unicode")
SET(CONNECTOR_DRIVER_TYPE_LIST "Unicode")
SET(CONNECTOR_DRIVER_TYPES_SHORT "w")
SET(PACKAGE_DRIVER_TYPES_SUFFIX "")
ENDIF(UNICODE OR NOT ANSI)
IF(ANSI OR NOT UNICODE)
MESSAGE(STATUS "Configuring to build ANSI driver")
SET(IS_UNICODE_DRIVER ${IS_UNICODE_DRIVER} 0)
# We need space separated string
IF(UNICODE OR NOT ANSI)
SET(CONNECTOR_DRIVER_TYPE "${CONNECTOR_DRIVER_TYPE} ANSI")
ELSE(UNICODE OR NOT ANSI)
SET(CONNECTOR_DRIVER_TYPE "ANSI")
ENDIF(UNICODE OR NOT ANSI)
LIST(APPEND CONNECTOR_DRIVER_TYPE_LIST "ANSI")
SET(CONNECTOR_DRIVER_TYPES_SHORT ${CONNECTOR_DRIVER_TYPES_SHORT} "a")
SET(PACKAGE_DRIVER_TYPES_SUFFIX ${PACKAGE_DRIVER_TYPE_SUFFIX} "-ansi")
ENDIF(ANSI OR NOT UNICODE)
SET(EDIT_WARNING_MESSAGE "Please do not edit this file - it is generated by cmake. Edit its source file instead.")
LIST(LENGTH IS_UNICODE_DRIVER DRIVERS_COUNT)
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()
#
# Macro to enable C++14 for all targets in the current directory and below.
#
macro(enable_cxx14)
if((CMAKE_VERSION VERSION_LESS 3.1) OR (CMAKE_CXX_COMPILER_ID MATCHES "SunPro"))
# Note: cmake does not know how to enable C++14 for SunPro compiler
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
# use C++14
set(CMAKE_CXX_STANDARD 14)
# error out if not supported
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# do not use compiler specific extensions
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
endmacro()
macro(enable_cxx17)
if((CMAKE_VERSION VERSION_LESS 3.8) OR (CMAKE_CXX_COMPILER_ID MATCHES "SunPro"))
# Note: cmake does not know how to enable C++17 for SunPro compiler
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
else()
# use C++17
set(CMAKE_CXX_STANDARD 17)
# error out if not supported
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# do not use compiler specific extensions
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
endmacro()
enable_cxx17()
if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
endif()
INCLUDE(CheckTypeSize)
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/character_sets.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/libutils.cmake)
# 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 "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 "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()
INCLUDE(configure.cmake)
#-------------- Coverage --------------------
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/gcov.cmake)
#-------------- find mysql --------------------
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/FindMySQL.cmake)
#-----------------------------------------------------
IF(MYSQL_VERSION_ID GREATER 80002)
ADD_DEFINITIONS(-DMYSQL8)
SET(MYSQL8 1)
ENDIF(MYSQL_VERSION_ID GREATER 80002)
IF(MYSQLCLIENT_STATIC_LINKING)
ADD_DEFINITIONS(-DMYSQLCLIENT_STATIC_LINKING)
ENDIF(MYSQLCLIENT_STATIC_LINKING)
IF(MYSQL8)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/config8.h.cmake ${CMAKE_SOURCE_DIR}/include/mysql-8.0/my_config.h)
INCLUDE_DIRECTORIES(include/mysql-8.0)
ELSE()
# Run platform tests
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_SOURCE_DIR}/include/sys/my_config.h)
ENDIF(MYSQL8)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/VersionInfo.h.cmake ${CMAKE_SOURCE_DIR}/VersionInfo.h @ONLY)
IF(WIN32)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/Install.bat.cmake ${CMAKE_SOURCE_DIR}/Install.bat @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/Uninstall.bat.cmake ${CMAKE_SOURCE_DIR}/Uninstall.bat @ONLY)
ENDIF(WIN32)
#SET(CMAKE_VERBOSE_MAKEFILE ON)
IF(NOT WIN32 AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
SET(DISABLE_GUI 1)
ENDIF(NOT WIN32 AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
# Disable mysql client debug and PSI
ADD_DEFINITIONS(-DNDEBUG -DDISABLE_ALL_PSI)
#-------------- unixodbc/iodbc/win -------------------
IF(WIN32)
SET(ODBCLIB odbc32)
IF (ODBCCP32_LIB)
SET(ODBCINSTLIB ${ODBCCP32_LIB})
ELSE (ODBCCP32_LIB)
SET(ODBCINSTLIB odbccp32)
ENDIF (ODBCCP32_LIB)
MESSAGE(STATUS "ODBC Installation Library: ${ODBCINSTLIB}")
ELSE(WIN32)
IF(WITH_UNIXODBC)
SET(ODBCLIB odbc)
SET(ODBCINSTLIB odbcinst)
ELSE(WITH_UNIXODBC)
IF(ODBCINST_LIB_DIR)
SET(ODBCLIB iODBC)
SET(ODBCINSTLIB iODBCinst)
ELSE(ODBCINST_LIB_DIR)
SET(ODBCLIB iodbc)
SET(ODBCINSTLIB iodbcinst)
ENDIF(ODBCINST_LIB_DIR)
ENDIF(WITH_UNIXODBC)
# FindODBC uses ODBCLIB and ODBCINSTLIB in some cases
INCLUDE(cmake/FindODBC.cmake)
IF(WITH_UNIXODBC)
TRY_COMPILE(COMPILE_RESULT ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/havelpcwstr.c
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES='${ODBC_INCLUDES} ${ODBC_INCLUDE_DIR}'")
MESSAGE(STATUS "Checking if LPCWSTR type is present - ${COMPILE_RESULT}")
IF(COMPILE_RESULT)
ADD_DEFINITIONS(-DHAVE_LPCWSTR)
ADD_DEFINITIONS(-DUSE_UNIXODBC)
ENDIF(COMPILE_RESULT)
ELSE(WITH_UNIXODBC)
# ADD_DEFINITIONS(-DHAVE_SQLGETPRIVATEPROFILESTRINGW)
#---- if it is not UnixODBC we assume iODBC -------
ADD_DEFINITIONS(-DUSE_IODBC)
ENDIF(WITH_UNIXODBC)
ENDIF(WIN32)
#-----------------------------------------------------
#-------- configuring paths to odbc heders for compatibility checks ---------
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/sqlcolattrib1.c.cmake ${CMAKE_BINARY_DIR}/cmake/sqlcolattrib1.c @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/sqlcolattrib2.c.cmake ${CMAKE_BINARY_DIR}/cmake/sqlcolattrib2.c @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/sqlparamopt1.c.cmake ${CMAKE_BINARY_DIR}/cmake/sqlparamopt1.c @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/sqlparamopt2.c.cmake ${CMAKE_BINARY_DIR}/cmake/sqlparamopt2.c @ONLY)
#-----------------------------------------------------
#------------------ check compatibility---------------
TRY_COMPILE(COMPILE_RESULT ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/cmake/sqlcolattrib1.c)
MESSAGE(STATUS "Checking if SQLColAttribute last arg is compatible with SQLLEN* - ${COMPILE_RESULT}")
IF(COMPILE_RESULT)
ADD_DEFINITIONS(-DUSE_SQLCOLATTRIBUTE_SQLLEN_PTR)
ELSE(COMPILE_RESULT)
TRY_COMPILE(COMPILE_RESULT1 ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/cmake/sqlcolattrib2.c)
MESSAGE(STATUS "Checking if SQLColAttribute last arg is compatible with SQLPOINTER - ${COMPILE_RESULT1}")
IF(COMPILE_RESULT1)
ADD_DEFINITIONS(-DUSE_SQLCOLATTRIBUTE_SQLPOINTER)
ELSE(COMPILE_RESULT1)
# By default using SQLLEN parameter
ADD_DEFINITIONS(-DUSE_SQLCOLATTRIBUTE_SQLLEN_PTR)
ENDIF(COMPILE_RESULT1)
ENDIF(COMPILE_RESULT)
TRY_COMPILE(COMPILE_RESULT ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/cmake/sqlparamopt1.c)
MESSAGE(STATUS "Checking if SQLParamOptions() 2nd and 3rd arg is compatible with SQLULEN - ${COMPILE_RESULT}")
IF(COMPILE_RESULT)
ADD_DEFINITIONS(-DUSE_SQLPARAMOPTIONS_SQLULEN_PTR)
ELSE(COMPILE_RESULT)
TRY_COMPILE(COMPILE_RESULT1 ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/cmake/sqlparamopt2.c)
MESSAGE(STATUS "Checking if SQLParamOptions() 2nd and 3rd arg is compatible with SQLUINTEGER - ${COMPILE_RESULT1}")
IF(COMPILE_RESULT1)
ADD_DEFINITIONS(-DUSE_SQLPARAMOPTIONS_SQLUINTEGER_PTR)
ELSE(COMPILE_RESULT1)
# SQLULEN is a default
MESSAGE(STATUS "Apparently odbc headers could not be found. 2nd and 3rd parameters assumed to be (*)SQLULEN by default")
ADD_DEFINITIONS(-DUSE_SQLPARAMOPTIONS_SQLULEN_PTR)
ENDIF(COMPILE_RESULT1)
ENDIF(COMPILE_RESULT)
#-----------------------------------------------------
IF(NOT NO_THREADS)
MESSAGE(STATUS "Enabling threads support")
ADD_DEFINITIONS(-DTHREAD)
ENDIF(NOT NO_THREADS)
#------------ build options for windows --------------
set(MAINTAINER_MODE OFF CACHE BOOL "Build sources in maintainer mode")
mark_as_advanced(MAINTAINER_MODE)
IF(WIN32)
REMOVE_DEFINITIONS(-DUNICODE)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
ADD_DEFINITIONS(-DENGLISH -D_USERDLL)
ADD_DEFINITIONS(-D_WIN32 -DWIN32 -D_WINDOWS -D__WIN__)
#Since 5.5.13 libmysql introduces dependency on Secur32.lib
FILE(STRINGS "${MYSQL_INCLUDE_DIR}\\mysql_version.h" mysql_version REGEX "^\#define[ \t]+MYSQL_VERSION_ID")
STRING(REGEX REPLACE "^\#define[ \t]+MYSQL_VERSION_ID[ \t]+([0-9]+)" "\\1" MYSQL_CLIENT_VERSION "${mysql_version}")
IF(MYSQL_CLIENT_VERSION GREATER 50512)
MESSAGE(STATUS "MySQL client lib(version ${MYSQL_CLIENT_VERSION}) requires Secure32.lib - TRUE")
SET(SECURE32_LIB Secur32)
ENDIF(MYSQL_CLIENT_VERSION GREATER 50512)
# edits for all config build flags
FOREACH(TYPE C CXX)
# makefiles use blank configuration
FOREACH(CFG "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
SET(NEW_FLAGS "${CMAKE_${TYPE}_FLAGS${CFG}}")
# fix up static libc flags
IF(STATIC_MSVCRT)
STRING(REPLACE "/MD" "/MT" NEW_FLAGS "${NEW_FLAGS}")
IF(CFG STREQUAL "_DEBUG")
SET(NEW_FLAGS "${NEW_FLAGS} /MTd")
ELSEIF()
SET(NEW_FLAGS "${NEW_FLAGS} /MT")
ENDIF()
ELSEIF()
STRING(REPLACE "/MT" "/MD" NEW_FLAGS "${NEW_FLAGS}")
IF(CFG STREQUAL "_DEBUG")
SET(NEW_FLAGS "${NEW_FLAGS} /MDd")
ELSEIF()
SET(NEW_FLAGS "${NEW_FLAGS} /MD")
ENDIF()
ENDIF()
# Add some additional help for debug builds
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
STRING(REPLACE "/Zi" "/ZI" NEW_FLAGS "${NEW_FLAGS}")
SET(NEW_FLAGS "${NEW_FLAGS} /RTC1 ")
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
IF(CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
SET(NEW_FLAGS "${NEW_FLAGS} /Od")
ENDIF(CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
# *FORCE* to override whats already placed into the cache
SET(CMAKE_${TYPE}_FLAGS${CFG} "${NEW_FLAGS}" CACHE STRING
"CMAKE_${TYPE}_FLAGS${CFG} (overwritten for odbc)" FORCE)
ENDFOREACH(CFG)
ENDFOREACH(TYPE)
if (FIX_WARNINGS)
# TODO: Increase warning level and once all warnings are cleared, enable
# higher warning level in MAINTAINER_MODE. We start with no warnings on
# level /W1
add_compile_options(/W1)
else()
add_compile_options(/W1 /wd4133 /wd4047 /wd4313 /wd4197)
endif()
ELSE(WIN32)
ADD_DEFINITIONS(-D_UNIX_)
if(FIX_WARNINGS)
# TODO: Fix the compile warnings generated without `-w`. Once done,
# remove this option in MAINTAINER_MODE so that we see when new
# warnings appear. Then proceed to `-w extra`.
add_compile_options(-Werror)
else()
add_compile_options( -w )
endif()
ENDIF(WIN32)
#------------ find the AWS SDK for C++ package---------
LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/aws_sdk/install")
FIND_PACKAGE(AWSSDK REQUIRED COMPONENTS rds secretsmanager sts)
#------------------------------------------------------
SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
SET(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib")
SET(LIB_SUBDIR "lib")
IF(RPM_BUILD AND CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|ppc64|ppc64p7|s390x|sparc64|aarch64)")
SET(LIB_SUBDIR "lib64")
ENDIF()
MESSAGE(STATUS "Installation library subdir: ${LIB_SUBDIR}")
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/ssl_setup.cmake)
setup_ssl_libs()
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
INCLUDE_DIRECTORIES(${ctpl_SOURCE_DIR})
ADD_LIBRARY(otel_api INTERFACE)
# Note: For now make it phony target on platforms other than Linux
if(NOT (WIN32 OR APPLE OR CMAKE_SYSTEM_NAME MATCHES "SunOS"))
message(STATUS "Adding OTel support")
set(TELEMETRY ON)
target_include_directories(otel_api INTERFACE
"${CMAKE_SOURCE_DIR}/extra/otel/opentelemetry-cpp-1.8.3/api/include"
)
target_compile_definitions(otel_api INTERFACE TELEMETRY)
endif()
ADD_SUBDIRECTORY(util)
ADD_SUBDIRECTORY(driver)
IF(NOT DISABLE_GUI)
ADD_SUBDIRECTORY(setupgui)
ENDIF(NOT DISABLE_GUI)
ADD_SUBDIRECTORY(dltest)
ADD_SUBDIRECTORY(installer)
ADD_SUBDIRECTORY(test)
IF(ENABLE_INTEGRATION_TESTS OR ENABLE_PERFORMANCE_TESTS)
ADD_SUBDIRECTORY(integration)
ENDIF()
IF(ENABLE_UNIT_TESTS)
ADD_SUBDIRECTORY(unit_testing)
ENDIF()
# For dynamic linking use the built-in sys and strings
IF(NOT MYSQLCLIENT_STATIC_LINKING)
ADD_SUBDIRECTORY(mysql_sys)
ADD_SUBDIRECTORY(mysql_strings)
ENDIF()
# Set values to help generate odbc.ini and odbcinst.ini files for Dockerized tests
IF(ENABLE_UNIT_TESTS OR ENABLE_INTEGRATION_TESTS)
SET(ODBC_PATH ${CMAKE_SOURCE_DIR}/testframework/src/test/resources/)
SET(TEST_DRIVER "MyODBCa")
SET(DRIVER_PATH "/app/build/lib/awsmysqlodbca.so")
SET(DRIVER_DESCRIPTION "AWS ANSI Driver for connecting to MySQL database server")
SET(DESCRIPTION "AWS MySQL ODBC ${CONNECTOR_MAJOR}.${CONNECTOR_MINOR} ANSI Driver for Dockerized tests")
IF(ENABLE_UNIT_TESTS)
SET(TEST_DSN "awsmysqlodbca")
SET(TEST_DATABASE "test")
SET(TEST_SERVER "mysql-instance")
SET(TEST_UID "root")
ENDIF()
IF(ENABLE_INTEGRATION_TESTS)
SET(TEST_DSN "atlas")
SET(THREADING "0")
ENDIF()
CONFIGURE_FILE(${ODBC_PATH}/odbcinst.ini.in ${ODBC_PATH}/odbcinst.ini @ONLY)
CONFIGURE_FILE(${ODBC_PATH}/odbc.ini.in ${ODBC_PATH}/odbc.ini @ONLY)
ENDIF()
##############################################################################
#
# Packaging
#
##############################################################################
# Some stuff for building RPMs, that is not using CPack
# RPMs doesn't allow "-" in version, so we use like "x.x.0_alpha"
STRING(REPLACE "-" "_" CONNECTOR_NODASH_VERSION "${CONNECTOR_VERSION}")
IF(UNIX)
EXECUTE_PROCESS(COMMAND "date" "+%Y" OUTPUT_VARIABLE CURRENT_YEAR OUTPUT_STRIP_TRAILING_WHITESPACE)
ENDIF()
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/scripts/myodbc3.spec.sh ${CMAKE_SOURCE_DIR}/myodbc3.spec @ONLY)
# The rest is mainly about CPack
SET(CPACK_PACKAGE_VERSION_MAJOR ${CONNECTOR_MAJOR})
SET(CPACK_PACKAGE_VERSION_MINOR ${CONNECTOR_MINOR})
SET(CPACK_PACKAGE_VERSION_PATCH ${CONNECTOR_PATCH})
IF(NOT EXTRA_NAME_SUFFIX)
SET(EXTRA_NAME_SUFFIX "")
ENDIF(NOT EXTRA_NAME_SUFFIX)
IF(NOT EXTRA_NAME_SUFFIX2)
SET(EXTRA_NAME_SUFFIX2 "")
ENDIF(NOT EXTRA_NAME_SUFFIX2)
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "AWS ODBC Driver for MySQL, a library for connecting to MySQL servers.")
SET(CPACK_PACKAGE_NAME "aws-mysql-odbc${EXTRA_NAME_SUFFIX}")
SET(CPACK_PACKAGE_VENDOR "Amazon")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt")
IF(EXISTS "${CMAKE_SOURCE_DIR}/README.txt")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.txt")
ELSE()
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
ENDIF()
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CONNECTOR_VERSION}-src")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}-${CONNECTOR_VERSION}${EXTRA_NAME_SUFFIX2}${PACKAGE_DRIVER_TYPE_SUFFIX}-${CONNECTOR_PLATFORM}")
IF(WIN32)
SET(CPACK_GENERATOR "ZIP")
SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-noinstall-${CONNECTOR_VERSION}${EXTRA_NAME_SUFFIX2}${PACKAGE_DRIVER_TYPE_SUFFIX}-${CONNECTOR_PLATFORM}")
ELSEIF(APPLE)
SET(CPACK_GENERATOR "productbuild")
SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
SET(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local/${CPACK_PACKAGE_FILE_NAME}")
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/scripts/macosx/Welcome.html.in ${CMAKE_SOURCE_DIR}/scripts/macosx/Welcome.html @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/scripts/macosx/ReadMe.html.in ${CMAKE_SOURCE_DIR}/scripts/macosx/ReadMe.html @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/scripts/macosx/postflight.in ${CMAKE_SOURCE_DIR}/scripts/macosx/postflight @ONLY)
SET(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_SOURCE_DIR}/scripts/macosx/Welcome.html")
SET(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/scripts/macosx/ReadMe.html")
SET(CPACK_POSTFLIGHT_UNSPECIFIED_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/macosx/postflight")
ELSE()
SET(CPACK_GENERATOR "TGZ")
SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
ENDIF()
SET(CPACK_SOURCE_IGNORE_FILES
\\\\.bzr/
\\\\.bzr-mysql
\\\\.bzrignore
CMakeCache\\\\.txt
CPackSourceConfig\\\\.cmake
CPackConfig\\\\.cmake
VersionInfo\\\\.h$
postflight$
/cmake_install\\\\.cmake
/CTestTestfile\\\\.cmake
/CMakeFiles/
/_CPack_Packages/
Makefile$
cmake/sql.*\\\\.c$
)
#------------ Installation ---------------------------
INCLUDE(cmake/info_bin.cmake)
INSTALL(FILES LICENSE.txt DESTINATION .)
if(EXISTS "${CMAKE_SOURCE_DIR}/README.txt")
INSTALL(FILES README.txt DESTINATION .)
else()
INSTALL(FILES README.md DESTINATION .)
INSTALL(FILES CONTRIBUTING.md DESTINATION .)
endif()
IF(WIN32)
# For conveninence copy (un)install.bat scripts to the build
# directory to ease testing.
CONFIGURE_FILE(Install.bat ${CMAKE_BINARY_DIR}/Install.bat COPYONLY)
CONFIGURE_FILE(Uninstall.bat ${CMAKE_BINARY_DIR}/Uninstall.bat COPYONLY)
# TODO: line-ending conversions unix->dos
INSTALL(FILES CHANGELOG.md DESTINATION .)
INSTALL(FILES Install.bat DESTINATION .)
INSTALL(FILES Uninstall.bat DESTINATION .)
# Install all .pdb files to enable debugging. Note that what build
# type and what sub directory the binaries ends up in, like
# "Release" and "Debug", is not determined until we run "devenv" or
# similar. So when running "cmake" we don't know the location. We
# can't test for the location here, a IF(EXISTS ...) is run at
# "cmake" invocation time, not when we are to install. So we do a
# bit of a hack here until finding a better solution.
# FIXME: Have an option to install PDBs also for Release builds?
#
# FIXME: Better control over PDBs that we install/ship -- for example
# install only PDBs for specific targets using install(FILE ...) and
# generator expression $<TARGET_PDB_FILE:tgt>
INSTALL(DIRECTORY
${PROJECT_BINARY_DIR}/bin/RelWithDebInfo/
DESTINATION bin
CONFIGURATIONS RelWithDebInfo
FILES_MATCHING PATTERN myodbc-installer.pdb
)
INSTALL(DIRECTORY
${PROJECT_BINARY_DIR}/bin/Debug/
DESTINATION bin/Debug
CONFIGURATIONS Debug
FILES_MATCHING PATTERN myodbc-installer.pdb
)
INSTALL(DIRECTORY
${PROJECT_BINARY_DIR}/lib/RelWithDebInfo/
DESTINATION lib
CONFIGURATIONS RelWithDebInfo
FILES_MATCHING PATTERN *.pdb
)
INSTALL(DIRECTORY
${PROJECT_BINARY_DIR}/lib/Debug/
DESTINATION lib/Debug
CONFIGURATIONS Debug
FILES_MATCHING PATTERN *.pdb
)
ELSE(WIN32)
INSTALL(FILES CHANGELOG.md DESTINATION .)
ENDIF(WIN32)
#
# Bundle 3rd party dependencies if needed
# =======================================
# If build is configured with BUNDEL_DEPENDENCIES enabled then client-side
# plugins, their dependencies and other dependencies of the client library that
# are found at the client library installation location are copied to the
# location where ODBC driver is installed.
#
# The lists of known plugins and 3rd party libraries are specified below. Only
# the specified plugins and libraries will be bundled. Also plugins and
# libraries that can be found with the server but which should be ignored are
# specified below. When building in MAINTAINER_MODE cmake will report error if
# it finds a plugin or 3rd party librariy which is not listed here. When that
# happens the lists should be updated.
#
# TODO: Move these checks to cmake/FindMySQL.cmake ?
#
set(AUTH_PLUGINS
ldap_sasl
oci
)
if(NOT CMAKE_SYSTEM_NAME MATCHES "SunOS")
list(APPEND AUTH_PLUGINS webauthn fido)
# Note: Kerberos authentication plugin is not supported on macOS
if(NOT APPLE)
list(APPEND AUTH_PLUGINS kerberos)
endif()
endif()
# Plugin dependencies.
#
# Warning: If one library name is a prefix of the other, the longer name
# should be listed first, otherwise the logic detecting missing dependencies
# will break... For example: `krb5support` must go before `krb5`
set(AUTH_DEPS_webauthn fido2)
set(AUTH_DEPS_fido fido2)
if(WIN32)
set(AUTH_DEPS_kerberos
comerr gssapi k5sprt krbcc xpprof krb5
)
else()
set(AUTH_DEPS_kerberos gssapi_krb5 k5crypto krb5support krb5 com_err)
endif()
# Note: The SASL/GSSAPI module further depends on Kerberos libraries.
#
# Note: On Solaris and macOS all dependencies of ldap_sasl plugin are assumed
# to be part of the OS.
if(NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "SunOS")
set(AUTH_DEPS_ldap_sasl libsasl ${AUTH_DEPS_kerberos})
endif()
if(WIN32)
list(APPEND AUTH_DEPS_ldap_sasl
saslSCRAM saslGSSAPI.dll ${AUTH_DEPS_kerberos}
)
endif()
# additional client-side plugins (if any)
set(PLUGINS)
# additional bundled dependencies of the client library
if(APPLE)
set(BUNDLED_LIBS
libssl libcrypto ssleay libeay
libaws-c-auth libaws-c-cal libaws-c-common libaws-c-compression libaws-c-event-stream libaws-c-http libaws-c-io
libaws-c-mqtt libaws-c-s3 libaws-c-sdkutils libaws-checksums libaws-cpp-sdk-core libaws-cpp-sdk-rds libaws-cpp-sdk-secretsmanager libaws-crt-cpp
)
else(APPLE)
set(BUNDLED_LIBS
libssl libcrypto ssleay libeay ${AWSSDK_LINK_LIBRARIES}
)
endif(APPLE)
# List plugins and other libraries that can be found bundled with the server
# but which are not relevant on client-side and can be safely ignored.
set(IGNORED_PLUGINS qa_auth_client telemetry_client)
set(IGNORED_LIBS
abseil_dll # Added in 8.0.37
libmysql lber libprotobuf
ldap # note: this is needed only by server-side plugin
libcurl libmecab zlib
jemalloc
# New DLLs added in .32
connection_pool
http_auth_backend http_auth_realm http_server
io keepalive metadata_cache
rest_api rest_connection_pool rest_metadata_cache rest_router rest_routing
harness-library mysqlharness_stdx mysqlharness_tls
router_openssl router_protobuf routing
mysqlrouter_mysqlxmessages
mysqlrouter_connection_pool
mysqlrouter_http
mysqlrouter_http_auth_backend
mysqlrouter_http_auth_realm
mysqlrouter_io_component
mysqlrouter_lib
mysqlrouter_metadata_cache
mysqlrouter_routing
# New DLLs added in .33
destination_status
mysqlrouter_destination_status
)
# -------------
function(bundle_lib lib)
get_filename_component(lib_name ${lib} NAME)
if(bundled_${lib_name})
return()
endif()
set(bundled_${lib_name} true PARENT_SCOPE)
message("Bundling library: ${lib}")
if(WIN32)
install(FILES ${lib}
CONFIGURATIONS Release RelWithDebInfo
DESTINATION "${LIB_SUBDIR}"
COMPONENT OdbcDll
)
elseif(APPLE)
install(FILES ${lib}
DESTINATION "${LIB_SUBDIR}"
COMPONENT OdbcDll
)
else()
install(FILES ${lib}
DESTINATION "${LIB_SUBDIR}/private"
COMPONENT OdbcDll
)
endif()
endfunction(bundle_lib)
macro(copy_lib_for_wix lib)
if(WIN32)
get_filename_component(lib_name ${lib} NAME)
configure_file(${lib} ${CMAKE_SOURCE_DIR}/wix/x64/${lib_name} COPYONLY)
endif(WIN32)
endmacro(copy_lib_for_wix)
# Bundle libraries listed in a list variable ${to_bundle}.
# Libraries that were found and bundled are removed from ${to_bundle} list.
# Other libraries found but not listed in ${to_bundle} are returned
# in ${ignored} variable.
# If additional arguments are given, they are used as glob expressions to find
# the libraries to be bundled, otherwise 3rd parties bundled in with the server
# are searched in ${MYSQL_LIB_DIR} locations.
macro(bundle_libs to_bundle ignored)
#message("== bundle_libs: ${${to_bundle}}")
if(ARGN)
file(GLOB _bundled ${ARGN})
else()
file(GLOB _bundled
"${MYSQL_LIB_DIR}/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
"${MYSQL_LIB_DIR}/private/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
"${CMAKE_SOURCE_DIR}/aws_sdk/install/lib/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
)
# On windows, libs are in bin directory
if(WIN32)
file(GLOB _bundled1 "${MYSQL_DIR}/bin/*${CMAKE_SHARED_LIBRARY_SUFFIX}*")
endif()
endif()
# Process collected libraries
set(libs ${${to_bundle}})
foreach(lib IN LISTS _bundled _bundled1)
get_filename_component(lib_name ${lib} NAME)
#message("== looking at 3rd party lib: ${lib_name} (${bundled_${lib_name}})")
# Match library name against names in to_bundle list and in case of match remove that name from the list
unset(found)
foreach(name ${libs})
#message(STATUS "checking lib ${pos}: ${name}")
if(
(lib_name MATCHES "^${name}")
OR ((NOT WIN32) AND (lib_name MATCHES "^lib${name}"))
)
#message(STATUS "removing from list: ${name}")
list(REMOVE_ITEM ${to_bundle} ${name})
bundle_lib(${lib})
copy_lib_for_wix(${lib})
set(found ${name})
break()
endif()
endforeach()
if(NOT found)
#message(STATUS "ignoring it (${lib_name})")
list(APPEND ${ignored} ${lib_name})
endif()
endforeach()
endmacro(bundle_libs)
# Bundle plugins listed in PLUGINS list. Each bundled plugin P is removed from
# the list and its dependedencies listed in DEPS_${P} are also bundled. Client
# side plugins found with the server and not listed in PLUGINS are returned
# in ${ignored} list.
macro(bundle_plugins ignored)
#message("== PLUGINS: ${PLUGINS}")
file(GLOB _bundled "${MYSQL_PLUGIN_DIR}/*${CMAKE_SHARED_MODULE_SUFFIX}*")
set(plugins ${PLUGINS})
foreach(lib ${_bundled})
get_filename_component(lib_name ${lib} NAME_WE)
if(NOT lib_name MATCHES "_client")
continue()
endif()
#message("== looking at client-side plugin: ${lib_name}")
# Match plugin name against names in PLUGINS list and in case of match
# remove that name from the list
unset(plugin)
foreach(check ${plugins})
#message(STATUS "checking plugin ${pos}: ${check}")
if(
lib_name MATCHES "^${check}"
)
#message(STATUS "plugin name match")
set(plugin ${check})
list(REMOVE_ITEM PLUGINS ${plugin})
break()
endif()