Skip to content

Commit 4beeeb1

Browse files
committed
cmake: Add maintainer mode.
If MAINTAINER_MODE is enabled then: 1. New target 'connector-static' is added for building static connector library. 2. New build configuration 'Static' is defined that should be used for building 'connector-static' target. 3. If WITH_JDBC is enabled, both static and dynamic legacy libraries are built.
1 parent f65c24d commit 4beeeb1

File tree

4 files changed

+135
-23
lines changed

4 files changed

+135
-23
lines changed

CMakeLists.txt

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,13 @@ option(BUILD_STATIC "Build static version of connector library" OFF)
272272
if(BUILD_STATIC)
273273
message("Building static connector library")
274274
set(LIB_TYPE STATIC)
275-
add_definitions(-DCONCPP_BUILD_STATIC)
275+
276+
set_property(
277+
DIRECTORY .
278+
APPEND PROPERTY COMPILE_DEFINITIONS
279+
$<$<NOT:$<CONFIG:Static>>:CONCPP_BUILD_STATIC>
280+
)
281+
276282
else()
277283
message("Building shared connector library")
278284

@@ -281,7 +287,15 @@ else()
281287
endif()
282288

283289
set(LIB_TYPE SHARED)
284-
add_definitions(-DCONCPP_BUILD_SHARED)
290+
291+
set_property(
292+
DIRECTORY .
293+
APPEND PROPERTY COMPILE_DEFINITIONS
294+
$<$<NOT:$<CONFIG:Static>>:CONCPP_BUILD_SHARED>
295+
)
296+
297+
#TODO: do not set options below when building Static configuration?
298+
285299
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
286300

287301
# Hide all symbols that are not explicitly exported.
@@ -296,6 +310,23 @@ else()
296310

297311
endif()
298312

313+
if(MAINTAINER_MODE)
314+
315+
list(APPEND CMAKE_CONFIGURATION_TYPES Static)
316+
317+
set(CMAKE_CXX_FLAGS_STATIC ${CMAKE_CXX_FLAGS_RELEASE})
318+
set(CMAKE_C_FLAGS_STATIC ${CMAKE_C_FLAGS_RELEASE})
319+
set(CMAKE_SHARED_LINKER_FLAGS_STATIC ${CMAKE_SHARED_LINKER_FLAGS_RELEASE})
320+
set(CMAKE_EXE_LINKER_FLAGS_STATIC ${CMAKE_EXE_LINKER_FLAGS_RELEASE})
321+
322+
set_property(
323+
DIRECTORY .
324+
APPEND PROPERTY COMPILE_DEFINITIONS
325+
$<$<CONFIG:Static>:CONCPP_BUILD_STATIC>
326+
)
327+
328+
endif()
329+
299330
OPTION(WITH_TESTS "Build project's unit tests" 0)
300331

301332
#
@@ -434,6 +465,19 @@ add_library_ex(connector ${LIB_TYPE}
434465

435466
target_include_directories(connector PRIVATE "${WITH_UUID}/include")
436467

468+
469+
if(MAINTAINER_MODE)
470+
471+
add_library_ex(connector-static STATIC EXCLUDE_FROM_ALL
472+
${WITH_UUID}/src/uuid_gen.cc
473+
OBJECTS xapi devapi common
474+
LIBS cdk
475+
)
476+
477+
target_include_directories(connector-static PRIVATE "${WITH_UUID}/include")
478+
479+
endif()
480+
437481
# Disable warnings in code which is not ours.
438482

439483
if(MSVC)
@@ -495,12 +539,14 @@ endif()
495539
# static runtime.
496540
#
497541

542+
set(LIB_NAME_STATIC "${LIB_NAME_BASE}-static")
543+
if(WIN32 AND STATIC_MSVCRT)
544+
set(LIB_NAME_STATIC "${LIB_NAME}-mt")
545+
endif()
546+
498547
if(BUILD_STATIC)
499548

500-
set(LIB_NAME "${LIB_NAME_BASE}-static")
501-
if(WIN32 AND STATIC_MSVCRT)
502-
set(LIB_NAME "${LIB_NAME}-mt")
503-
endif()
549+
set(LIB_NAME ${LIB_NAME_STATIC})
504550

505551
else()
506552

@@ -542,21 +588,45 @@ install(TARGETS connector
542588
LIBRARY DESTINATION "${INSTALL_LIB_DIR}/debug"
543589
)
544590

591+
if(MAINTAINER_MODE)
592+
593+
set_property(TARGET connector-static PROPERTY OUTPUT_NAME ${LIB_NAME_STATIC})
594+
595+
set_target_properties(connector-static PROPERTIES
596+
VERSION "${ABI_VERSION_MAJOR}.${CONCPP_VERSION}"
597+
SOVERSION "${ABI_VERSION_MAJOR}"
598+
)
599+
600+
install(TARGETS connector-static
601+
CONFIGURATIONS Static
602+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR_STATIC}"
603+
RUNTIME DESTINATION "${INSTALL_LIB_DIR}"
604+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
605+
)
606+
607+
endif()
545608

546609
#
547610
# Tests
548611
# =====
549612
#
550613

551-
remove_definitions(-DCONCPP_BUILD_STATIC)
552-
remove_definitions(-DCONCPP_BUILD_SHARED)
614+
#
615+
# Note: We must clear compile flags - the ones used to build the connector
616+
# are not good for building client code that uses the connector.
617+
#
618+
619+
set_property(
620+
DIRECTORY .
621+
PROPERTY COMPILE_DEFINITIONS ""
622+
)
553623

554624
if(BUILD_STATIC)
555625
add_definitions(-DSTATIC_CONCPP)
556626
endif()
557627

558-
# Auto-generated test targets
559628

629+
# Auto-generated test targets
560630

561631
IF (WITH_TESTS)
562632
# Unit tests declared with ADD_NG_TEST() (see cdk/cmake/testing.cmake)

devapi/tests/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2828

2929
#
30-
# Undefine macros which indicate building of the connector library
31-
# (as opposed to using it from test code). This is used by public headers.
30+
# Note: We must clear compile flags - the ones used to build the connector
31+
# are not good for building client code that uses the connector.
3232
#
3333

34-
remove_definitions(-DCONCPP_BUILD_STATIC)
35-
remove_definitions(-DCONCPP_BUILD_SHARED)
34+
set_property(
35+
DIRECTORY .
36+
PROPERTY COMPILE_DEFINITIONS ""
37+
)
3638

3739
if(WIN32)
3840
add_definitions(-D_CRT_SECURE_NO_WARNINGS)

jdbc.cmake

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,30 @@ file(MAKE_DIRECTORY "${JDBC_DIR}")
2020
# Configure legacy connector build environment in ${JDBC_DIR}
2121
#
2222

23-
list(APPEND jdbc_cmake_opts -DMYSQLCLIENT_STATIC_LINKING=ON)
24-
25-
if(CMAKE_BUILD_TYPE)
26-
list(APPEND jdbc_cmake_opts -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
27-
endif()
28-
2923
if(BUILD_STATIC)
3024
list(APPEND jdbc_cmake_opts -DENABLE_BUILD_STATIC=ON)
3125
else()
3226
list(APPEND jdbc_cmake_opts -DENABLE_BUILD_DYNAMIC=ON)
3327
endif()
3428

29+
if(MAINTAINER_MODE)
30+
list(APPEND jdbc_cmake_opts -DENABLE_BUILD_STATIC=ON)
31+
endif()
32+
3533
if(MYSQL_DIR)
3634
list(APPEND jdbc_cmake_opts -DMYSQL_DIR=${MYSQL_DIR})
3735
endif()
3836

37+
list(APPEND jdbc_cmake_opts -DMYSQLCLIENT_STATIC_LINKING=ON)
38+
39+
if(CMAKE_BUILD_TYPE)
40+
if(CMAKE_BUILD_TYPE MATCHES "[Ss][Tt][Aa][Tt][Ii][Cc]")
41+
list(APPEND jdbc_cmake_opts -DCMAKE_BUILD_TYPE=Release)
42+
else()
43+
list(APPEND jdbc_cmake_opts -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
44+
endif()
45+
endif()
46+
3947
if(DEFINED STATIC_MSVCRT)
4048
list(APPEND jdbc_cmake_opts -DSTATIC_MSVCRT=${STATIC_MSVCRT})
4149
endif()
@@ -102,11 +110,15 @@ set(JDBC_BUILD_STAMP "${PROJECT_BINARY_DIR}/jdbc.buildstamp")
102110
file(REMOVE "${JDBC_BUILD_STAMP}")
103111
#message("JDBC_BUILD_STAMP: ${JDBC_BUILD_STAMP}")
104112

113+
set(CONFIG_EXPR
114+
$<$<CONFIG:Static>:Release>$<$<NOT:$<CONFIG:Static>>:$<CONFIGURATION>>
115+
)
116+
105117
add_custom_command(OUTPUT ${JDBC_BUILD_STAMP}
106118

107119
COMMAND ${CMAKE_COMMAND} -E remove_directory install
108120
COMMAND ${CMAKE_COMMAND}
109-
--build . --target install --config $<CONFIGURATION> --clean-first
121+
--build . --target install --config ${CONFIG_EXPR} --clean-first
110122

111123
# Move installed headers from include/ to include/jdbc and rename lib/
112124
# to lib64/ for 64-bit platform
@@ -120,7 +132,7 @@ add_custom_command(OUTPUT ${JDBC_BUILD_STAMP}
120132
COMMAND ${CMAKE_COMMAND} -E touch ${JDBC_BUILD_STAMP}
121133

122134
WORKING_DIRECTORY ${JDBC_DIR}
123-
COMMENT "Building legacy connector library using configuration: $<CONFIGURATION>"
135+
COMMENT "Building legacy connector library using configuration: $(Configuration)"
124136
)
125137

126138
# Collect sources of legacy connector and specify them in the build
@@ -261,6 +273,26 @@ install(
261273
DESTINATION ${INSTALL_INCLUDE_DIR}
262274
)
263275

276+
#
277+
# In maintainer mode add specifications for installing the static library
278+
# which is always built in this mode.
279+
#
280+
281+
if(MAINTAINER_MODE)
282+
283+
add_dependencies(mysqlcppconn-static build_jdbc)
284+
get_target_property(location mysqlcppconn-static IMPORTED_LOCATION_RELEASE)
285+
message("jdbc installing: ${location} (MAINTAINER_MODE)")
286+
287+
install(
288+
FILES ${location}
289+
CONFIGURATIONS Static
290+
DESTINATION "${INSTALL_LIB_DIR_STATIC}"
291+
COMPONENT JDBCDev
292+
)
293+
294+
endif()
295+
264296

265297
#
266298
# Install external dependencies of MySQL client library, such as OpenSSL,

xapi/tests/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@
2626
# along with this program; if not, write to the Free Software Foundation, Inc.,
2727
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2828

29-
remove_definitions(-DCONCPP_BUILD_STATIC)
30-
remove_definitions(-DCONCPP_BUILD_SHARED)
29+
#
30+
# Note: We must clear compile flags - the ones used to build the connector
31+
# are not good for building client code that uses the connector.
32+
#
33+
34+
set_property(
35+
DIRECTORY .
36+
PROPERTY COMPILE_DEFINITIONS ""
37+
)
38+
3139
if(BUILD_STATIC)
3240
add_definitions(-DSTATIC_CONCPP)
3341
endif()

0 commit comments

Comments
 (0)