Skip to content

Commit 09e2259

Browse files
committed
WL#16156: Add version info resources on Windows
Change-id: Ied7be424376ccd5019992ab11a3516b2beb73bcd
1 parent 1bd8d46 commit 09e2259

File tree

9 files changed

+210
-11
lines changed

9 files changed

+210
-11
lines changed

CMakeLists.txt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ include(platform)
8181
include(dependency) # find_dependency()
8282
include(config_options) # add_config_option()
8383
include(libutils) # merge_libraries()
84+
include(version_info) # set_version_info()
8485

8586
#
8687
# Detect if we are configured as stand-alone project, or sub-project.
@@ -352,7 +353,6 @@ if(WITH_JDBC)
352353
PUBLIC "${PROJECT_BINARY_DIR}/include/jdbc"
353354
PUBLIC "${PROJECT_BINARY_DIR}/include/jdbc/cppconn"
354355
PUBLIC "${PROJECT_SOURCE_DIR}/include"
355-
356356
)
357357

358358
endif()
@@ -405,6 +405,11 @@ add_subdirectory(devapi)
405405
# Generate the main connector library.
406406

407407
merge_libraries(connector xapi devapi)
408+
add_version_info(connector
409+
"MySQL Connector/C++ XDevAPI library."
410+
"Implements MySQL Connector/C++ XDevAPI."
411+
)
412+
408413
target_include_directories(connector PUBLIC
409414
"${PROJECT_SOURCE_DIR}/include"
410415
# Note: This is needed when using connector directly from the build tree to
@@ -445,16 +450,16 @@ if(0)
445450
# Add command to show rpath information
446451
#
447452

448-
if(APPLE)
449-
set(list_rpath_cmd otool -l $<TARGET_FILE:libconcpp> "|" grep RPATH -A2)
450-
elseif(NOT WIN32)
451-
set(list_rpath_cmd objdump -x $<TARGET_FILE:libconcpp> "|" grep RPATH -A2)
452-
endif()
453+
if(APPLE)
454+
set(list_rpath_cmd otool -l $<TARGET_FILE:libconcpp> "|" grep RPATH -A2)
455+
elseif(NOT WIN32)
456+
set(list_rpath_cmd objdump -x $<TARGET_FILE:libconcpp> "|" grep RPATH -A2)
457+
endif()
453458

454-
add_custom_command(TARGET connector POST_BUILD
455-
COMMAND ${list_rpath_cmd}
456-
COMMENT "RPATH setting for: $<TARGET_FILE_NAME:mysqlcppconn>"
457-
)
459+
add_custom_command(TARGET connector POST_BUILD
460+
COMMAND ${list_rpath_cmd}
461+
COMMENT "RPATH setting for: $<TARGET_FILE_NAME:mysqlcppconn>"
462+
)
458463
endif()
459464

460465

@@ -500,7 +505,6 @@ endif()
500505
# Note: Locations and names are configured in install_layout.cmake
501506
#
502507

503-
504508
set_property(TARGET connector PROPERTY OUTPUT_NAME ${LIB_NAME})
505509
message("Connector library name: ${LIB_NAME}")
506510

cmake/version_info.cmake

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
2+
3+
add_config_option(SHOW_VERSION_INFO BOOL ADVANCED DEFAULT ${MAINTAINER_MODE}
4+
"Show version information for targets built on Windows"
5+
)
6+
7+
get_filename_component(VERSION_INFO_HOME "${CMAKE_CURRENT_LIST_DIR}/version_info" ABSOLUTE CACHE)
8+
9+
10+
#
11+
# Add Windows version info resources to the library/executable file produced
12+
# by target TGT.
13+
#
14+
# This is ignored on non-Windows platforms. The second argument is a string
15+
# to use as `FileDescription` attribute. If another argument is given, it
16+
# is used for `Comments` attribute.
17+
#
18+
# Note: Version information is taken from version.cmake file included by
19+
# gen_version_info.cmake script that generates resource definitions.
20+
#
21+
#
22+
23+
function(add_version_info TGT DESCR)
24+
25+
if(NOT WIN32)
26+
return()
27+
endif()
28+
29+
get_target_property(TYPE ${TGT} TYPE)
30+
31+
# Currently setting version resources for static libraries does not work.
32+
# Possibly because of the machinery we use to merge static library from
33+
# several smaller ones. For now we can live without version info in static
34+
# libraries.
35+
36+
if(TYPE STREQUAL "STATIC_LIBRARY")
37+
return()
38+
endif()
39+
40+
set(out "${CMAKE_CURRENT_BINARY_DIR}/${TGT}_version_info.rc")
41+
42+
# Command to generate .rc file with version information. This is done
43+
# by the gen_version_info.cmake script which uses version_info.rc.in template.
44+
45+
add_custom_command(OUTPUT "${out}"
46+
COMMAND ${CMAKE_COMMAND}
47+
-D "RC=${out}"
48+
-D "OUTPUT=$<TARGET_FILE:${TGT}>"
49+
-D "TYPE=${TYPE}"
50+
-D "DESCRIPTION=${DESCR}"
51+
-D "COMMENTS=${ARGN}"
52+
-D "VERSION=${CMAKE_SOURCE_DIR}/version.cmake"
53+
-D "CONFIG=$<CONFIG>"
54+
-P "${VERSION_INFO_HOME}/gen_version_info.cmake"
55+
)
56+
57+
# Add the generated .rc file to the sources of the target.
58+
59+
target_sources(${TGT} PRIVATE "${out}")
60+
61+
if(SHOW_VERSION_INFO)
62+
show_version_info(${TGT})
63+
endif()
64+
65+
#add_custom_command(TARGET ${TGT} POST_BUILD
66+
# COMMAND ${CMAKE_COMMAND} -E rm -rf "${out}"
67+
#)
68+
69+
message(STATUS "generated version info for target ${TGT} (${TYPE}): ${out}")
70+
71+
endfunction()
72+
73+
#
74+
# Arrange for a library/executable target TGT to show the version information
75+
# resources once its file is generated.
76+
#
77+
# This command is ignored on non-Windows platforms or if the target does not
78+
# exist.
79+
#
80+
81+
function(show_version_info TGT)
82+
83+
if(NOT WIN32 OR NOT TARGET ${TGT})
84+
return()
85+
endif()
86+
87+
add_custom_command(TARGET ${TGT} POST_BUILD
88+
COMMAND ${CMAKE_COMMAND}
89+
-D FILE=$<TARGET_FILE:${TGT}>
90+
-P "${VERSION_INFO_HOME}/show_version_info.cmake"
91+
)
92+
93+
endfunction()
94+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
message("Re-generating version info resource defintions: ${RC}")
2+
message("For output file: ${OUTPUT}")
3+
message("Of type: ${TYPE}")
4+
message("Build configuration: ${CONFIG}")
5+
6+
include("${VERSION}")
7+
8+
9+
set(PATH "${OUTPUT}")
10+
get_filename_component(BASE "${OUTPUT}" NAME)
11+
get_filename_component(BASE_WE "${OUTPUT}" NAME_WE)
12+
13+
string(REPLACE "." "," CONCPP_VERSION_RAW "${CONCPP_VERSION}")
14+
15+
if("STATIC_LIBRARY" STREQUAL TYPE)
16+
set(FILETYPE "VFT_STATIC_LIB")
17+
elseif(TYPE MATCHES "_LIBRARY")
18+
set(FILETYPE "VFT_DLL")
19+
elseif("EXECUTABLE" STREQUAL TYPE)
20+
set(FILETYPE "VFT_APP")
21+
else()
22+
set(FILETYPE 0)
23+
endif()
24+
25+
set(FILEFLAGS 0)
26+
if(CONFIG MATCHES "[Dd][Ee][Bb][Uu][Gg]")
27+
set(FILEFLAGS "VS_FF_DEBUG")
28+
endif()
29+
30+
31+
configure_file("${CMAKE_CURRENT_LIST_DIR}/version_info.rc.in" "${RC}" @ONLY)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
find_program(PWS powershell)
2+
if(PWS)
3+
message("Version information for: ${FILE}")
4+
execute_process(COMMAND ${PWS} -command "ls ${FILE} | % VersionInfo | fl *")
5+
endif()

cmake/version_info/version_info.rc.in

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Version info resources for @BASE@
2+
// Note: This is a generated file -- see cmake/version_info.cmake in the source tree.
3+
4+
#include <windows.h>
5+
#define VER_PRIVATEBUILD 0x0L
6+
#define VER_PRERELEASE 0x0L
7+
8+
9+
VS_VERSION_INFO VERSIONINFO
10+
FILEVERSION @CONCPP_VERSION_RAW@,0
11+
PRODUCTVERSION @CONCPP_VERSION_RAW@,0
12+
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
13+
FILEFLAGS @FILEFLAGS@
14+
FILEOS VOS__WINDOWS32
15+
FILETYPE @FILETYPE@
16+
BEGIN
17+
BLOCK "StringFileInfo"
18+
BEGIN
19+
BLOCK "040904b0"
20+
BEGIN
21+
VALUE "CompanyName", "Oracle Corporation\0"
22+
VALUE "ProductName", "MySQL Connector/C++\0"
23+
VALUE "ProductVersion", "@[email protected]\0"
24+
VALUE "FileVersion", "@[email protected]\0"
25+
VALUE "LegalCopyright", "Copyright (c) 1995, @COPYRIGHT_YEAR@, Oracle and/or its affiliates.\0"
26+
VALUE "LegalTrademarks", "Oracle(R), Java, MySQL, and NetSuite are registered trademarks of Oracle and/or its affiliates.\0"
27+
VALUE "OriginalFileName", "@BASE@\0"
28+
VALUE "InternalName", "@BASE_WE@\0"
29+
VALUE "FileDescription", "@DESCRIPTION@\0"
30+
VALUE "Comments", "@COMMENTS@\0"
31+
END
32+
END
33+
END

jdbc/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ set(INFO_PREFIX "jdbc-")
256256

257257
merge_libraries(connector-jdbc jdbc)
258258

259+
add_version_info(connector-jdbc
260+
"MySQL Connector/C++ legacy (JDBC) library."
261+
"Implements MySQL Connector/C++ legacy JDBC API."
262+
)
263+
264+
259265

260266
# Note: When connector links statically to the client library, targets using
261267
# the connector must be able to find dependencies of the client library, such

jdbc/test/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ ENDIF(CMAKE_COMPILER_IS_GNUCC AND MYSQLCPPCONN_GCOV_ENABLE)
6666

6767
ADD_EXECUTABLE(static_test static_test.cpp)
6868

69+
add_version_info(static_test
70+
"MySQL Connector/C++ unit test."
71+
"Tests MySQL Connector/C++ functionality."
72+
)
73+
6974
SET_TARGET_PROPERTIES(static_test PROPERTIES
7075
LINK_FLAGS "${MYSQLCPPCONN_LINK_FLAGS_ENV} ${MYSQL_LINK_FLAGS}"
7176
COMPILE_FLAGS "${MYSQLCPPCONN_COMPILE_FLAGS_ENV}"
@@ -80,6 +85,11 @@ TARGET_LINK_LIBRARIES(static_test ${MY_TARGET_LINK_LIBRARIES} ${MY_GCOV_LINK_LIB
8085
LINK_DIRECTORIES(${GLIB_DIR}/lib)
8186
ADD_EXECUTABLE(driver_test driver_test.cpp)
8287

88+
add_version_info(driver_test
89+
"MySQL Connector/C++ unit test."
90+
"Tests MySQL Connecto/C++ functionality."
91+
)
92+
8393
SET_TARGET_PROPERTIES(driver_test PROPERTIES
8494
LINK_FLAGS "${MYSQLCPPCONN_LINK_FLAGS_ENV} ${MYSQL_LINK_FLAGS}"
8595
COMPILE_FLAGS "${MYSQLCPPCONN_COMPILE_FLAGS_ENV}"
@@ -95,11 +105,18 @@ function(add_unit_test NAME)
95105

96106
if (ARGN)
97107
list(GET ARGN 0 TGT_NAME)
108+
set(description "MySQL Connector/C++ usage example.")
109+
set(comments "Runs demo code.")
98110
else()
99111
set(TGT_NAME test_${NAME})
112+
set(description "MySQL Connector/C++ unit test.")
113+
set(comments "Tests MySQL Connector/C++ functionality.")
100114
endif()
101115

102116
ADD_EXECUTABLE(${TGT_NAME} ${test_${NAME}_sources})
117+
118+
add_version_info(${TGT_NAME} "${description}" "${comments}")
119+
103120
SET_TARGET_PROPERTIES(${TGT_NAME} PROPERTIES
104121
OUTPUT_NAME "${NAME}"
105122
LINK_FLAGS "${MYSQLCPPCONN_LINK_FLAGS_ENV} ${MYSQL_LINK_FLAGS}"

testing/tests.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ IF (WITH_TESTS)
5353
# Unit tests declared with ADD_NG_TEST() (see cdk/cmake/testing.cmake)
5454
ADD_TEST_TARGET()
5555

56+
add_version_info(run_unit_tests
57+
"MySQL Connector/C++ unit tests."
58+
"Tests MySQL Connector/C++ functionality."
59+
)
60+
5661
# Install these as part of `Tests` component.
5762

5863
install(

version.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
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+
# Note: To be used in copyright notes of generated files
30+
31+
set(COPYRIGHT_YEAR "2024" CACHE INTERNAL "version info")
32+
2933
#
3034
# Connector/C++ version
3135
#

0 commit comments

Comments
 (0)