Skip to content

Commit 688a3f4

Browse files
committed
Merge remote-tracking branch 'origin/wl10893'
2 parents a5784d2 + 9db5acb commit 688a3f4

27 files changed

+1477
-106
lines changed

CMakeLists.txt

Lines changed: 92 additions & 17 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
#
@@ -418,6 +449,10 @@ ADD_SUBDIRECTORY(common)
418449
ADD_SUBDIRECTORY(xapi)
419450
ADD_SUBDIRECTORY(devapi)
420451

452+
#
453+
# Packaging
454+
#
455+
ADD_SUBDIRECTORY(packaging)
421456

422457
#
423458
# Target which builds the final connector library
@@ -434,6 +469,19 @@ add_library_ex(connector ${LIB_TYPE}
434469

435470
target_include_directories(connector PRIVATE "${WITH_UUID}/include")
436471

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

439487
if(MSVC)
@@ -495,12 +543,14 @@ endif()
495543
# static runtime.
496544
#
497545

546+
set(LIB_NAME_STATIC "${LIB_NAME_BASE}-static")
547+
if(WIN32 AND STATIC_MSVCRT)
548+
set(LIB_NAME_STATIC "${LIB_NAME}-mt")
549+
endif()
550+
498551
if(BUILD_STATIC)
499552

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

505555
else()
506556

@@ -530,33 +580,57 @@ set_target_properties(connector PROPERTIES
530580

531581
install(TARGETS connector
532582
CONFIGURATIONS Release RelWithDebInfo
533-
ARCHIVE DESTINATION "${INSTALL_LIB_DIR_STATIC}"
534-
RUNTIME DESTINATION "${INSTALL_LIB_DIR}"
535-
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
583+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR_STATIC}" COMPONENT XDevAPIDev
584+
RUNTIME DESTINATION "${INSTALL_LIB_DIR}" COMPONENT XDevAPIDll
585+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT XDevAPIDll
536586
)
537587

538588
install(TARGETS connector
539589
CONFIGURATIONS Debug
540-
ARCHIVE DESTINATION "${INSTALL_LIB_DIR_STATIC}/debug"
541-
RUNTIME DESTINATION "${INSTALL_LIB_DIR}/debug"
542-
LIBRARY DESTINATION "${INSTALL_LIB_DIR}/debug"
590+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR_STATIC}/debug" COMPONENT XDevAPIDev
591+
RUNTIME DESTINATION "${INSTALL_LIB_DIR}/debug" COMPONENT XDevAPIDll
592+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}/debug" COMPONENT XDevAPIDll
543593
)
544594

595+
if(MAINTAINER_MODE)
596+
597+
set_property(TARGET connector-static PROPERTY OUTPUT_NAME ${LIB_NAME_STATIC})
598+
599+
set_target_properties(connector-static PROPERTIES
600+
VERSION "${ABI_VERSION_MAJOR}.${CONCPP_VERSION}"
601+
SOVERSION "${ABI_VERSION_MAJOR}"
602+
)
603+
604+
install(TARGETS connector-static
605+
CONFIGURATIONS Static
606+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR_STATIC}" COMPONENT XDevAPIDev
607+
RUNTIME DESTINATION "${INSTALL_LIB_DIR}" COMPONENT XDevAPIDll
608+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT XDevAPIDll
609+
)
610+
611+
endif()
545612

546613
#
547614
# Tests
548615
# =====
549616
#
550617

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

554628
if(BUILD_STATIC)
555629
add_definitions(-DSTATIC_CONCPP)
556630
endif()
557631

558-
# Auto-generated test targets
559632

633+
# Auto-generated test targets
560634

561635
IF (WITH_TESTS)
562636
# Unit tests declared with ADD_NG_TEST() (see cdk/cmake/testing.cmake)
@@ -571,14 +645,14 @@ ENDIF (WITH_TESTS)
571645
# Sample code to try things out
572646
#
573647

574-
ADD_EXECUTABLE(try try.cc)
648+
ADD_EXECUTABLE(try EXCLUDE_FROM_ALL try.cc)
575649
TARGET_LINK_LIBRARIES(try connector)
576650
SET_INTERFACE_OPTIONS(try devapi)
577651
# ADD_GCOV(try)
578652

579653
if(WITH_JDBC)
580654

581-
add_executable(try_jdbc try_jdbc.cc)
655+
add_executable(try_jdbc EXCLUDE_FROM_ALL try_jdbc.cc)
582656
target_link_libraries(try_jdbc ${JDBC_LIBS})
583657
add_dependencies(try_jdbc build_jdbc)
584658
target_include_directories(try_jdbc PRIVATE ${JDBC_INCLUDES})
@@ -695,5 +769,6 @@ message("Connector libraries will be installed at: ${INSTALL_LIB_DIR}")
695769
option(WITH_PACKAGES "Configure for building binary/source packages" OFF)
696770
if(WITH_PACKAGES)
697771
include(PackageSpecs.cmake)
772+
ADD_SUBDIRECTORY(packaging/WiX)
698773
endif()
699774

PackageSpecs.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ foreach(file ${info_files})
148148
set(file_bin "${CMAKE_BINARY_DIR}/${file}${info_ext}")
149149

150150
configure_file("${file_src}" "${file_bin}" NEWLINE_STYLE ${newline})
151-
install(FILES "${file_bin}" DESTINATION .)
151+
install(FILES "${file_bin}" DESTINATION . COMPONENT Readme)
152152

153153
endforeach()
154154

buildinfo.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,4 @@ if(WITH_JDBC)
112112
endif()
113113

114114

115-
install(FILES "${PROJECT_BINARY_DIR}/BUILDINFO.txt" DESTINATION .)
115+
install(FILES "${PROJECT_BINARY_DIR}/BUILDINFO.txt" DESTINATION . COMPONENT Readme)

cdk/cmake/libutils.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ function(add_library_ex TARGET)
133133
list(REMOVE_AT ARGN 0)
134134
endif()
135135

136+
unset(exclude)
137+
if(arg STREQUAL "EXCLUDE_FROM_ALL")
138+
set(exclude "EXCLUDE_FROM_ALL")
139+
list(GET ARGN 0 arg)
140+
list(REMOVE_AT ARGN 0)
141+
endif()
142+
136143
#
137144
# Collect library sources, up to first OBJECTS or LIBS word
138145
#
@@ -243,7 +250,7 @@ function(add_library_ex TARGET)
243250
endforeach()
244251
endif()
245252

246-
add_library(${TARGET} ${type} ${srcs})
253+
add_library(${TARGET} ${type} ${exclude} ${srcs})
247254
#message("- added ${type} library: ${TARGET}")
248255

249256
if(mangle_paths)

cdk/cmake/protobuf.cmake

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,32 @@ message("Configuring Protobuf build using cmake generator: ${CMAKE_GENERATOR}")
4444
file(REMOVE ${PROJECT_BINARY_DIR}/protobuf/CMakeCache.txt)
4545
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/protobuf)
4646

47-
# If specified, use the same build type for Protobuf
47+
#
48+
# Pick build configuration for the protobuf build. Normally we build using the
49+
# same build configuration that is used for building CDK (Release/Debug/etc.).
50+
# But we also support building CDK under non-standard build configuration
51+
# named 'Static' (this is a dirty trick we use to simplify building our MSIs).
52+
# Since protobuf does not know 'Static' build configuration, we build protobuf
53+
# under 'Release' configuration in that case.
54+
#
55+
# We need to handle two cases. For some build systems, like Makefiles, the build
56+
# configuration is specified at cmake time using CMAKE_BUILD_TYPE variable. In
57+
# that case we also set it during protobuf build configuration. Another case is
58+
# a multi-configuration build system like MSVC. In this case we use generator
59+
# expression to pick correct configuration when the build command is invoked
60+
# below.
61+
#
4862

4963
if(CMAKE_BUILD_TYPE)
50-
set(set_build_type -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
64+
if(CMAKE_BUILD_TYPE MATCHES "[Ss][Tt][Aa][Tt][Ii][Cc]")
65+
set(set_build_type -DCMAKE_BUILD_TYPE=Release)
66+
else()
67+
set(set_build_type -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
68+
endif()
5169
endif()
5270

71+
set(CONFIG_EXPR $<$<CONFIG:Static>:Release>$<$<NOT:$<CONFIG:Static>>:$<CONFIG>>)
72+
5373
execute_process(
5474
COMMAND ${CMAKE_COMMAND}
5575
-G "${CMAKE_GENERATOR}"
@@ -76,8 +96,11 @@ include(${PROJECT_BINARY_DIR}/protobuf/exports.cmake)
7696
# a sub-project of a parent project, because the parent project
7797
# must have access to these targets.
7898
#
79-
# For that reason blow we create global protobuf/protobuf-lite targets
80-
# and copy their loactions from the imported targets.
99+
# For that reason below we create global protobuf/protobuf-lite targets
100+
# and copy their locations from the imported targets.
101+
#
102+
# Note: we can't use ALIAS library because it does not work with imported
103+
# targets
81104
#
82105

83106
add_library(protobuf STATIC IMPORTED GLOBAL)
@@ -91,40 +114,32 @@ foreach(lib protobuf protobuf-lite)
91114

92115
get_target_property(LOC pb_${lib} IMPORTED_LOCATION_${CONF})
93116
if(LOC)
94-
#message("- settig imported location to: ${LOC}")
95-
set(location "${LOC}")
117+
#message("- setting imported location to: ${LOC}")
96118
set_target_properties(${lib} PROPERTIES
97119
IMPORTED_LOCATION_${CONF} "${LOC}"
98120
)
99121
set_property(TARGET ${lib} APPEND PROPERTY
100-
IMPORTED_CONFIGURATIONS ${CONF})
122+
IMPORTED_CONFIGURATIONS ${CONF}
123+
)
101124
endif()
102125

103126
endforeach(CONF)
104127

105-
# For multi-configuration builders like MSVC, set a generic
106-
# location of the form <prefix>/$(Configuration)/<name> which will
107-
# work with any configuration choosen at build time.
108-
# It is constructed from one of per-configurartion locations
109-
# determined above and saved in ${location}. The logic assumes
110-
# that the per-configration location is of the form
111-
# <prefix>/<config>/<name>
112-
113-
if(CMAKE_CONFIGURATION_TYPES)
128+
endforeach(lib)
114129

115-
get_filename_component(name "${location}" NAME)
116-
get_filename_component(LOC "${location}" PATH)
117-
get_filename_component(LOC "${LOC}" PATH)
118-
set(LOC "${LOC}/$(Configuration)/${name}")
130+
#
131+
# To support 'Static' build configuration the targets imported from the
132+
# Protobuf project need to have IMPORTED_LOCATION_STATIC defined. We use
133+
# 'Release' locations as Protobuf is built using 'Release' configuration in
134+
# that case.
135+
#
119136

120-
message("- setting generic location to: ${LOC}")
121-
set_target_properties(${lib} PROPERTIES
122-
IMPORTED_LOCATION "${LOC}"
123-
)
137+
foreach(tgt protobuf protobuf-lite pb_protoc)
124138

125-
endif()
139+
get_target_property(LOC ${tgt} IMPORTED_LOCATION_RELEASE)
140+
set_property(TARGET ${tgt} PROPERTY IMPORTED_LOCATION_STATIC ${LOC})
126141

127-
endforeach(lib)
142+
endforeach(tgt)
128143

129144

130145
# protobuf depends on protobuf-lite
@@ -151,17 +166,18 @@ if(NOT DEFINED PROTOBUF_BUILD_STAMP)
151166
message(FATAL_ERROR "Protobuf build stamp file not defined")
152167
endif()
153168

169+
154170
if(CMAKE_VERSION VERSION_LESS 3.0)
155171
add_custom_command(OUTPUT ${PROTOBUF_BUILD_STAMP}
156172
COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIGURATION>
157173
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/protobuf
158-
COMMENT "Building protobuf using configuration: $<CONFIGURATION>"
174+
COMMENT "Building protobuf using configuration: $(Configuration)"
159175
)
160176
else()
161177
add_custom_command(OUTPUT ${PROTOBUF_BUILD_STAMP}
162-
COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG>
178+
COMMAND ${CMAKE_COMMAND} --build . --config ${CONFIG_EXPR}
163179
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/protobuf
164-
COMMENT "Building protobuf using configuration: $<CONFIG>"
180+
COMMENT "Building protobuf using configuration: $(Configuration)"
165181
)
166182
endif()
167183

cdk/cmake/ssl.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,11 @@ function(bundle_ssl_libs)
412412
#message("result: ${lib_dll}")
413413

414414
message("bundling: ${lib}")
415-
install(FILES "${lib}" DESTINATION "${INSTALL_LIB_DIR_STATIC}")
415+
install(FILES "${lib}" DESTINATION "${INSTALL_LIB_DIR_STATIC}" COMPONENT OpenSSLDev)
416416

417417
if(lib_dll)
418418
message("bundling: ${lib_dll}")
419-
install(FILES "${lib_dll}" DESTINATION "${INSTALL_LIB_DIR}")
419+
install(FILES "${lib_dll}" DESTINATION "${INSTALL_LIB_DIR}" COMPONENT OpenSSLDll)
420420
else()
421421

422422
message(WARNING "Could not find DLL library for openSSL library ${lib_name} at ${lib_path}. OpenSSL libraries can not be bundled with the connector.")
@@ -434,7 +434,7 @@ function(bundle_ssl_libs)
434434
else()
435435

436436
message("bundling: ${lib_file}")
437-
install(FILES "${lib_file}" DESTINATION "${INSTALL_LIB_DIR_STATIC}")
437+
install(FILES "${lib_file}" DESTINATION "${INSTALL_LIB_DIR_STATIC}" COMPONENT OpenSSLDev)
438438
get_filename_component(lib_dir "${lib_file}" DIRECTORY)
439439
get_filename_component(lib_name "${lib_file}" NAME)
440440

0 commit comments

Comments
 (0)