24
24
CMAKE_MINIMUM_REQUIRED (VERSION 2.8.12 )
25
25
CMAKE_POLICY (VERSION 2.8.12 )
26
26
cmake_policy (SET CMP0022 NEW )
27
+ cmake_policy (SET CMP0023 OLD )
27
28
28
29
#
29
30
# Prevent cmake from setting its default value of CMAKE_INSTALL_PREFIX
@@ -38,19 +39,36 @@ PROJECT(MySQL_CONCPP)
38
39
message ("Building on system: ${CMAKE_SYSTEM} (${CMAKE_SYSTEM_PROCESSOR} )" )
39
40
message ("Using cmake generator: ${CMAKE_GENERATOR} " )
40
41
42
+ if (CMAKE_SYSTEM_NAME MATCHES "SunOS" )
43
+ set (SUNOS ON CACHE INTERNAL "" )
44
+ endif ()
45
+
41
46
if (CMAKE_SIZEOF_VOID_P EQUAL 8 )
42
47
set (IS64BIT 1 )
43
48
message ("Using 64bit generator" )
44
49
else ()
45
50
message ("Using 32bit genereator" )
46
51
endif ()
47
52
53
+ #
54
+ # On Windows, set VS to "vsNN" where NN is the MSVC version.
55
+ #
56
+
57
+ set (VS )
58
+ if (WIN32 )
59
+ if (MSVC12 )
60
+ set (VS "vs12" )
61
+ elseif (MSVC14 )
62
+ set (VS "vs14" )
63
+ endif ()
64
+ endif ()
65
+
66
+
48
67
include (version .cmake )
49
68
50
69
51
70
# Base name for the connector libraries.
52
71
53
- #set(LIB_NAME_BASE "mysqlcppconn2")
54
72
set (LIB_NAME_BASE "mysqlcppconn${CONCPP_VERSION_MAJOR} " )
55
73
56
74
#
@@ -68,6 +86,43 @@ LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cdk/cmake)
68
86
69
87
include (libutils )
70
88
89
+ #
90
+ # Install settings
91
+ # ================
92
+ #
93
+
94
+ include (install_layout.cmake )
95
+
96
+ set (
97
+ BUNDLE_DEPENDENCIES OFF CACHE BOOLEAN
98
+ "If enabled, external libraries used by the connector, such as openSSL,
99
+ will be installed together with the connector library"
100
+ )
101
+
102
+ #
103
+ # Default install location
104
+ #
105
+
106
+ if (NOT CMAKE_INSTALL_PREFIX )
107
+
108
+ if (WIN32 )
109
+
110
+ if (DEFINED ENV{HOMEPATH} )
111
+ string (REPLACE "\\ " "/" install_prefix "$ENV{HOMEDRIVE}$ENV{HOMEPATH} " )
112
+ else ()
113
+ set (install_prefix "C:/Program Files (x86)" )
114
+ endif ()
115
+ set (CMAKE_INSTALL_PREFIX "${install_prefix} /MySQL/MySQL Connector C++ ${CONCPP_PACKAGE_BASE_VERSION} " )
116
+
117
+ else ()
118
+
119
+ set (CMAKE_INSTALL_PREFIX "/usr/local/mysql/connector-c++-${CONCPP_PACKAGE_BASE_VERSION} " )
120
+
121
+ endif ()
122
+
123
+ endif ()
124
+
125
+
71
126
#
72
127
# Compiler settings
73
128
# =================
@@ -183,6 +238,22 @@ include(gcov)
183
238
#endforeach()
184
239
185
240
241
+ #
242
+ # Linker settings
243
+ # ===============
244
+ #
245
+
246
+ #
247
+ # Produce rpath dependent libraries on MacOS
248
+ # see: <https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/RunpathDependentLibraries.html#//apple_ref/doc/uid/TP40008306-SW1>
249
+ # and: <https://cmake.org/cmake/help/v3.0/prop_tgt/MACOSX_RPATH.html>
250
+ #
251
+
252
+ if (APPLE )
253
+ set (CMAKE_MACOSX_RPATH ON )
254
+ endif ()
255
+
256
+
186
257
#
187
258
# Main project and its dependencies
188
259
# =================================
@@ -260,24 +331,11 @@ SET(WITH_CDK_DOC 0)
260
331
OPTION (WITH_CDK_TESTS "cdk tests" OFF )
261
332
set (WITH_PIC ${CMAKE_POSITION_INDEPENDENT_CODE} )
262
333
263
-
264
- if (NOT DEFINED WITH_SSL )
265
- SET (WITH_SSL "bundled" CACHE STRING "" )
266
- endif ()
267
-
268
- IF (WITH_SSL )
269
- IF (WITH_SSL STREQUAL "bundled" )
270
- ADD_DEFINITIONS (-DWITH_SSL_YASSL )
271
- ENDIF ()
272
- ADD_DEFINITIONS (-DWITH_SSL )
273
- ENDIF ()
274
-
275
-
276
-
277
334
ADD_SUBDIRECTORY (cdk )
278
335
INCLUDE_DIRECTORIES (${CDK_INCLUDE_DIR} )
279
336
INCLUDE_DIRECTORIES (cdk/parser )
280
337
338
+
281
339
#
282
340
# Unit tests framework
283
341
#
@@ -353,7 +411,8 @@ ADD_SUBDIRECTORY(devapi)
353
411
add_library_ex (libconcpp ${LIB_TYPE}
354
412
${WITH_UUID} /src/uuid_gen.cc
355
413
OBJECTS xapi devapi common
356
- LIBS cdk
414
+ LIBS
415
+ cdk
357
416
)
358
417
359
418
target_include_directories (libconcpp PRIVATE "${WITH_UUID} /include" )
@@ -366,6 +425,39 @@ if(MSVC)
366
425
)
367
426
endif ()
368
427
428
+ #
429
+ # Embed rpath information in the connector library.
430
+ #
431
+
432
+ set_property (TARGET libconcpp PROPERTY BUILD_WITH_INSTALL_RPATH ON )
433
+
434
+ # The $ORIGIN/@loader_path entry tells to look for dependent libraries in the
435
+ # location where our connector library is stored.
436
+
437
+ if (APPLE )
438
+ set_property (TARGET libconcpp APPEND PROPERTY INSTALL_RPATH "@loader_path" )
439
+ elseif (NOT WIN32 )
440
+ set_property (TARGET libconcpp APPEND PROPERTY INSTALL_RPATH "$ORIGIN" )
441
+ endif ()
442
+
443
+
444
+ if (0 )
445
+ #
446
+ # Add command to list rpath information
447
+ #
448
+
449
+ if (APPLE )
450
+ set (list_rpath_cmd otool -l $< TARGET_FILE:libconcpp> "|" grep RPATH -A2 )
451
+ elseif (NOT WIN32 )
452
+ set (list_rpath_cmd objdump -x $< TARGET_FILE:libconcpp> "|" grep RPATH -A2 )
453
+ endif ()
454
+
455
+ add_custom_command (TARGET libconcpp POST_BUILD
456
+ COMMAND ${list_rpath_cmd}
457
+ COMMENT "RPATH setting"
458
+ )
459
+ endif ()
460
+
369
461
370
462
#
371
463
# Pick output library name
@@ -384,15 +476,6 @@ endif()
384
476
# static runtime.
385
477
#
386
478
387
- set (VS )
388
- if (WIN32 )
389
- if (MSVC12 )
390
- set (VS "vs12" )
391
- elseif (MSVC14 )
392
- set (VS "vs14" )
393
- endif ()
394
- endif ()
395
-
396
479
if (BUILD_STATIC )
397
480
398
481
set (LIB_NAME "${LIB_NAME_BASE} -static" )
@@ -422,59 +505,19 @@ set_target_properties(libconcpp PROPERTIES
422
505
SOVERSION "${API_VERSION_MAJOR} "
423
506
)
424
507
425
- #
426
- # Pick install location for the main library
427
- # ------------------------------------------
428
- #
429
- # On Windows the install layout is as follows, where NN is the MSVC version
430
- # used to build the connector:
431
- #
432
- # {lib,lib64}/mysqlcppconnX-vsNN.dll <-- shared library
433
- # {lib,lib64}/vsNN/mysqlcppconnX-static.lib <-- static with /MD
434
- # {lib,lib64}/vsNN/mysqlcppconnX-static-mt.lib <-- static with /MT
435
- # {lib,lib64}/vsNN/mysqlcppconnX.lib <-- import library for DLL
436
- #
437
- # On Linux it is as follows, where A.B is the API version number
438
- #
439
- # {lib,lib64}/libmysqlcppconnX.so.A.B <-- shared library
440
- # {lib,lib64}/libmysqlcppconnX.so.A <-- soname link
441
- # {lib,lib64}/libmysqlcppconnX.so <-- development link
442
- # {lib,lib64}/libmysqlcppconnX-static.a <-- static library
443
- #
444
- # Additionally, if connector is built in debug mode, the libraries are installed
445
- # in debug/ subfolder of {lib,lib64}/ or {lib,lib64}/vsNN/.
446
- #
447
-
448
- set (LIB_DIR "" CACHE PATH "Library install location (relative to install root)" )
449
-
450
- if (NOT LIB_DIR )
451
- if (IS64BIT )
452
- set (LIB_DIR "lib64" )
453
- else ()
454
- set (LIB_DIR "lib" )
455
- endif ()
456
- endif ()
457
-
458
- message ("Connector library will be installed at: ${LIB_DIR} " )
459
-
460
- set (LIB_DIR_STATIC "${LIB_DIR} " )
461
- if (VS )
462
- set (LIB_DIR_STATIC "${LIB_DIR_STATIC} /${VS} " )
463
- endif ()
464
-
465
508
466
509
install (TARGETS libconcpp
467
510
CONFIGURATIONS Release RelWithDebInfo
468
- ARCHIVE DESTINATION "${LIB_DIR_STATIC } "
469
- RUNTIME DESTINATION "${LIB_DIR } "
470
- LIBRARY DESTINATION "${LIB_DIR } "
511
+ ARCHIVE DESTINATION "${INSTALL_LIB_DIR_STATIC } "
512
+ RUNTIME DESTINATION "${INSTALL_LIB_DIR } "
513
+ LIBRARY DESTINATION "${INSTALL_LIB_DIR } "
471
514
)
472
515
473
516
install (TARGETS libconcpp
474
517
CONFIGURATIONS Debug
475
- ARCHIVE DESTINATION "${LIB_DIR_STATIC } /debug"
476
- RUNTIME DESTINATION "${LIB_DIR } /debug"
477
- LIBRARY DESTINATION "${LIB_DIR } /debug"
518
+ ARCHIVE DESTINATION "${INSTALL_LIB_DIR_STATIC } /debug"
519
+ RUNTIME DESTINATION "${INSTALL_LIB_DIR } /debug"
520
+ LIBRARY DESTINATION "${INSTALL_LIB_DIR } /debug"
478
521
)
479
522
480
523
@@ -483,7 +526,6 @@ install(TARGETS libconcpp
483
526
# =====
484
527
#
485
528
486
-
487
529
remove_definitions (-DCONCPP_BUILD_STATIC )
488
530
remove_definitions (-DCONCPP_BUILD_SHARED )
489
531
@@ -540,14 +582,15 @@ endif()
540
582
541
583
#
542
584
# Linking test
585
+ # ------------
543
586
#
544
- # This test compiles test application using internall installation of built
587
+ # This test compiles test application using internal installation of built
545
588
# connector. It is important to work with installed files because otherwise
546
- # cmake does its magic to resolve missing dependencies when buiding test code.
589
+ # cmake does its magic to resolve missing dependencies when building test code.
547
590
# We don't want this to happen to make sure that test code can be built with
548
591
# connector library only, as we distribute it.
549
592
#
550
- # Note: internall installation into <binary_dir>/install is done by directly
593
+ # Note: internal installation into <binary_dir>/install is done by directly
551
594
# executing cmake_install.cmake script which is generated by cmake.
552
595
#
553
596
# TODO: Also test dynamic linking (requires adopting test app project)
@@ -567,6 +610,7 @@ add_custom_target(link_test
567
610
COMMAND ${CMAKE_COMMAND}
568
611
-G "${CMAKE_GENERATOR} "
569
612
-D WITH_CONCPP=${PROJECT_BINARY_DIR}/install
613
+ -D WITH_SSL= "${WITH_SSL} "
570
614
-D BUILD_STATIC=${BUILD_STATIC}
571
615
-D STATIC_MSVCRT=${STATIC_MSVCRT}
572
616
${PROJECT_SOURCE_DIR} /testapp
@@ -587,26 +631,8 @@ add_test(NAME Link_test
587
631
# ========================
588
632
#
589
633
590
- if (NOT CMAKE_INSTALL_PREFIX )
591
-
592
- if (WIN32 )
593
-
594
- if (DEFINED ENV{HOMEPATH} )
595
- string (REPLACE "\\ " "/" install_prefix "$ENV{HOMEDRIVE}$ENV{HOMEPATH} " )
596
- else ()
597
- set (install_prefix "C:/Program Files (x86)" )
598
- endif ()
599
- set (CMAKE_INSTALL_PREFIX "${install_prefix} /MySQL/MySQL Connector C++ ${CONCPP_PACKAGE_BASE_VERSION} " )
600
-
601
- else ()
602
-
603
- set (CMAKE_INSTALL_PREFIX "/usr/local/mysql/connector-c++-${CONCPP_PACKAGE_BASE_VERSION} " )
604
-
605
- endif ()
606
-
607
- endif ()
608
-
609
634
message ("Install location: ${CMAKE_INSTALL_PREFIX} " )
635
+ message ("Connector library will be installed at: ${INSTALL_LIB_DIR} " )
610
636
611
637
option (WITH_PACKAGES "Configure for building binary/source packages" OFF )
612
638
if (WITH_PACKAGES )
0 commit comments