Skip to content

Commit 970c07e

Browse files
committed
Merge remote-tracking branch 'origin/wl11376'
2 parents 4e1893d + adb03ca commit 970c07e

32 files changed

+1237
-3550
lines changed

CMakeLists.txt

Lines changed: 120 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
2525
CMAKE_POLICY(VERSION 2.8.12)
2626
cmake_policy(SET CMP0022 NEW)
27+
cmake_policy(SET CMP0023 OLD)
2728

2829
#
2930
# Prevent cmake from setting its default value of CMAKE_INSTALL_PREFIX
@@ -38,19 +39,36 @@ PROJECT(MySQL_CONCPP)
3839
message("Building on system: ${CMAKE_SYSTEM} (${CMAKE_SYSTEM_PROCESSOR})")
3940
message("Using cmake generator: ${CMAKE_GENERATOR}")
4041

42+
if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
43+
set(SUNOS ON CACHE INTERNAL "")
44+
endif()
45+
4146
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
4247
set(IS64BIT 1)
4348
message("Using 64bit generator")
4449
else()
4550
message("Using 32bit genereator")
4651
endif()
4752

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+
4867
include(version.cmake)
4968

5069

5170
# Base name for the connector libraries.
5271

53-
#set(LIB_NAME_BASE "mysqlcppconn2")
5472
set(LIB_NAME_BASE "mysqlcppconn${CONCPP_VERSION_MAJOR}")
5573

5674
#
@@ -68,6 +86,43 @@ LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cdk/cmake)
6886

6987
include(libutils)
7088

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+
71126
#
72127
# Compiler settings
73128
# =================
@@ -183,6 +238,22 @@ include(gcov)
183238
#endforeach()
184239

185240

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+
186257
#
187258
# Main project and its dependencies
188259
# =================================
@@ -260,24 +331,11 @@ SET(WITH_CDK_DOC 0)
260331
OPTION(WITH_CDK_TESTS "cdk tests" OFF)
261332
set(WITH_PIC ${CMAKE_POSITION_INDEPENDENT_CODE})
262333

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-
277334
ADD_SUBDIRECTORY(cdk)
278335
INCLUDE_DIRECTORIES(${CDK_INCLUDE_DIR})
279336
INCLUDE_DIRECTORIES(cdk/parser)
280337

338+
281339
#
282340
# Unit tests framework
283341
#
@@ -353,7 +411,8 @@ ADD_SUBDIRECTORY(devapi)
353411
add_library_ex(libconcpp ${LIB_TYPE}
354412
${WITH_UUID}/src/uuid_gen.cc
355413
OBJECTS xapi devapi common
356-
LIBS cdk
414+
LIBS
415+
cdk
357416
)
358417

359418
target_include_directories(libconcpp PRIVATE "${WITH_UUID}/include")
@@ -366,6 +425,39 @@ if(MSVC)
366425
)
367426
endif()
368427

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+
369461

370462
#
371463
# Pick output library name
@@ -384,15 +476,6 @@ endif()
384476
# static runtime.
385477
#
386478

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-
396479
if(BUILD_STATIC)
397480

398481
set(LIB_NAME "${LIB_NAME_BASE}-static")
@@ -422,59 +505,19 @@ set_target_properties(libconcpp PROPERTIES
422505
SOVERSION "${API_VERSION_MAJOR}"
423506
)
424507

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-
465508

466509
install(TARGETS libconcpp
467510
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}"
471514
)
472515

473516
install(TARGETS libconcpp
474517
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"
478521
)
479522

480523

@@ -483,7 +526,6 @@ install(TARGETS libconcpp
483526
# =====
484527
#
485528

486-
487529
remove_definitions(-DCONCPP_BUILD_STATIC)
488530
remove_definitions(-DCONCPP_BUILD_SHARED)
489531

@@ -540,14 +582,15 @@ endif()
540582

541583
#
542584
# Linking test
585+
# ------------
543586
#
544-
# This test compiles test application using internall installation of built
587+
# This test compiles test application using internal installation of built
545588
# 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.
547590
# We don't want this to happen to make sure that test code can be built with
548591
# connector library only, as we distribute it.
549592
#
550-
# Note: internall installation into <binary_dir>/install is done by directly
593+
# Note: internal installation into <binary_dir>/install is done by directly
551594
# executing cmake_install.cmake script which is generated by cmake.
552595
#
553596
# TODO: Also test dynamic linking (requires adopting test app project)
@@ -567,6 +610,7 @@ add_custom_target(link_test
567610
COMMAND ${CMAKE_COMMAND}
568611
-G "${CMAKE_GENERATOR}"
569612
-D WITH_CONCPP=${PROJECT_BINARY_DIR}/install
613+
-D WITH_SSL="${WITH_SSL}"
570614
-D BUILD_STATIC=${BUILD_STATIC}
571615
-D STATIC_MSVCRT=${STATIC_MSVCRT}
572616
${PROJECT_SOURCE_DIR}/testapp
@@ -587,26 +631,8 @@ add_test(NAME Link_test
587631
# ========================
588632
#
589633

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-
609634
message("Install location: ${CMAKE_INSTALL_PREFIX}")
635+
message("Connector library will be installed at: ${INSTALL_LIB_DIR}")
610636

611637
option(WITH_PACKAGES "Configure for building binary/source packages" OFF)
612638
if(WITH_PACKAGES)

0 commit comments

Comments
 (0)