From 6502fc05bc49dea7c87f34211794d54de51c344f Mon Sep 17 00:00:00 2001 From: Rafal Somla Date: Tue, 31 Mar 2020 13:24:54 +0200 Subject: [PATCH 01/16] Bug #31007317 JDBC: OPENSSL LIBRARIES BUNDLED WITH THE CONNECTOR CAN'T BE FOUND AT RUN-TIME --- jdbc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdbc b/jdbc index 9de205246..9bf6f97fd 160000 --- a/jdbc +++ b/jdbc @@ -1 +1 @@ -Subproject commit 9de2052461e5a9658456d9bbd1bef1ae1bf66075 +Subproject commit 9bf6f97fddf21de09a0c9b51050bf7795a9e0fb0 From dfc0005d7f5d3275358e071d06d54982f847e180 Mon Sep 17 00:00:00 2001 From: Rafal Somla Date: Tue, 31 Mar 2020 15:37:42 +0200 Subject: [PATCH 02/16] cmake: Fix include paths for compression libraries --- cdk/extra/CMakeLists.txt | 13 +++++++------ cdk/extra/zstd/CMakeLists.txt | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cdk/extra/CMakeLists.txt b/cdk/extra/CMakeLists.txt index 8962067cf..ae16c5384 100644 --- a/cdk/extra/CMakeLists.txt +++ b/cdk/extra/CMakeLists.txt @@ -36,9 +36,13 @@ endif() enable_pic() add_subdirectory(zlib) +# Note: zlib writes configuration header into build location +# and this location needs to be added to include path when +# using zlib. + target_include_directories(zlib PUBLIC - ${PROJECT_BINARY_DIR}/extra/zlib - ${PROJECT_SOURCE_DIR}/extra/zlib + ${CMAKE_CURRENT_BINARY_DIR}/zlib + zlib ) @@ -55,7 +59,4 @@ target_include_directories(lz4 PUBLIC lz4) add_subdirectory(zstd) -target_include_directories(zstd PUBLIC - ${PROJECT_BINARY_DIR}/extra/zstd/lib - ${PROJECT_SOURCE_DIR}/extra/zstd/lib -) +target_include_directories(zstd PUBLIC zstd/lib) diff --git a/cdk/extra/zstd/CMakeLists.txt b/cdk/extra/zstd/CMakeLists.txt index f74c4b58d..737f69663 100644 --- a/cdk/extra/zstd/CMakeLists.txt +++ b/cdk/extra/zstd/CMakeLists.txt @@ -11,7 +11,7 @@ PROJECT(zstd) CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9) SET(ZSTD_LIB_DIR - "${CMAKE_SOURCE_DIR}/cdk/extra/zstd/lib") + "${PROJECT_SOURCE_DIR}/lib") INCLUDE_DIRECTORIES( ${ZSTD_LIB_DIR} ${ZSTD_LIB_DIR}/common From 699ed5cafd6898529a779f75aa756a2540a9c8c3 Mon Sep 17 00:00:00 2001 From: Rafal Somla Date: Tue, 31 Mar 2020 17:27:39 +0200 Subject: [PATCH 03/16] cmake: Configure public include paths for the legacy connector target. --- CMakeLists.txt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6ab664b6..ce6125406 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -330,6 +330,15 @@ add_config_option(WITH_JDBC BOOL DEFAULT OFF if(WITH_JDBC) add_subdirectory(jdbc) + + # Note: Include path must contain build location because + # this is where config.h header is written. + + target_include_directories(connector-jdbc + PUBLIC "${PROJECT_BINARY_DIR}/jdbc/cppconn" + PUBLIC "${PROJECT_SOURCE_DIR}/include" + ) + endif() @@ -512,10 +521,6 @@ if(WITH_JDBC) add_executable(try_jdbc EXCLUDE_FROM_ALL try_jdbc.cc) target_link_libraries(try_jdbc connector-jdbc) - target_include_directories(try_jdbc - PRIVATE "${PROJECT_BINARY_DIR}/include/mysql" - PRIVATE "${PROJECT_BINARY_DIR}/include/jdbc/cppconn" - ) endif() From 6ea0ab8110df9628871c386e690e8a74ba09e58b Mon Sep 17 00:00:00 2001 From: Rafal Somla Date: Tue, 31 Mar 2020 17:28:43 +0200 Subject: [PATCH 04/16] cmake: Support using connector project as a cmake sub-project. --- CMakeLists.txt | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce6125406..56712763f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,8 +65,6 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) PROJECT(MySQL_CONCPP) -include(version.cmake) - # Load cmake modules include(cdk/cmake/setup.cmake) @@ -77,6 +75,26 @@ include(dependency) # find_dependency() include(config_options) # add_config_option() include(libutils) # merge_libraries() +# +# Detect if we are configured as stand-alone project, or sub-project. +# + +if(PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME) + + SET(concpp_stand_alone 1) + +else() + + MESSAGE("Building Connector/C++ as part of ${CMAKE_PROJECT_NAME} project") + SET(concpp_stand_alone 0) + set(WITH_TESTS OFF) + set(WITH_DOC OFF) + set(WITH_HEADER_CHECKS OFF) + +endif() + +include(version.cmake) + message("Building on system: ${CMAKE_SYSTEM} (${CMAKE_SYSTEM_PROCESSOR})") message("Using cmake generator: ${CMAKE_GENERATOR}") #message("Compiler identification: ${CMAKE_CXX_COMPILER_ID}") @@ -425,6 +443,13 @@ add_custom_command(TARGET libconcpp POST_BUILD ) endif() +# +# Stop here if this is a sub-project of a bigger project. +# + +if (NOT concpp_stand_alone) + return() +endif() # # Install specifications From 6bfc6f047d826363b804a4e0bd62d95d3dd81e09 Mon Sep 17 00:00:00 2001 From: Rafal Somla Date: Tue, 31 Mar 2020 17:29:54 +0200 Subject: [PATCH 05/16] cmake: Move extra tests to testing/tests.cmake --- CMakeLists.txt | 72 +------------------------- testing/tests.cmake | 122 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 70 deletions(-) create mode 100644 testing/tests.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 56712763f..8b10a726e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -522,18 +522,6 @@ if(BUILD_STATIC) add_definitions(-DSTATIC_CONCPP) endif() - -# Auto-generated test targets - -IF (WITH_TESTS) - # Unit tests declared with ADD_NG_TEST() (see cdk/cmake/testing.cmake) - ADD_TEST_TARGET() - - # Test for public headers declared with ADD_HEADERS() - # (see cdk/cmake/headers.cmake) - ADD_HEADERS_TEST() -ENDIF (WITH_TESTS) - # # Sample code to try things out # @@ -585,67 +573,11 @@ endif() endif() # -# Linking test -# ------------ +# Other tests. # -# This test compiles test application using internal installation of built -# connector. It is important to work with installed files because otherwise -# cmake does its magic to resolve missing dependencies when building test code. -# We don't want this to happen to make sure that test code can be built with -# connector library only, as we distribute it. -# -# Note: internal installation into /install is done by directly -# executing cmake_install.cmake script which is generated by cmake. -# -# TODO: Also test dynamic linking (requires adopting test app project) -# - -file(REMOVE_RECURSE ${PROJECT_BINARY_DIR}/link_test) -file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/link_test) -unset(jdbc_options) -if(WITH_JDBC) - #message("-- BOOST_ROOT: ${BOOST_ROOT}") - list(APPEND jdbc_options -DWITH_JDBC=ON -DWITH_BOOST=${BOOST_ROOT}) -endif() - -add_custom_target(link_test - COMMAND ${CMAKE_COMMAND} -E remove_directory ${PROJECT_BINARY_DIR}/install - COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/install - COMMAND ${CMAKE_COMMAND} - -D CMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/install - -D CMAKE_INSTALL_CONFIG_NAME=$<$>:$>$<$>>:Release> - -P ${PROJECT_BINARY_DIR}/cmake_install.cmake - COMMAND ${CMAKE_COMMAND} -E remove -f ${PROJECT_BINARY_DIR}/link_test/CMakeCache.txt - COMMAND ${CMAKE_COMMAND} - -G "${CMAKE_GENERATOR}" - -D WITH_CONCPP=${PROJECT_BINARY_DIR}/install - -D WITH_SSL="${WITH_SSL}" - -D BUILD_STATIC=${BUILD_STATIC} - -D STATIC_MSVCRT=${STATIC_MSVCRT} - ${jdbc_options} - ${PROJECT_SOURCE_DIR}/testapp - COMMAND ${CMAKE_COMMAND} --build . --config $ --clean-first - WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/link_test - VERBATIM -) +include(testing/tests.cmake) -set_target_properties(link_test PROPERTIES FOLDER "Tests") - -add_dependencies(link_test connector) -#if(TARGET connector-merge) -# add_dependencies(link_test connector-merge) -#endif() -#if(WITH_JDBC) -# add_dependencies(link_test build_jdbc) -#endif() - -# TDOD: Use ${CMAKE_COMMAND}, but evaluated at test time, not here. - -add_test(NAME Link_test - COMMAND cmake --build . --target link_test --config $ - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} -) # # Create the INFO_SRC and INFO_BIN files diff --git a/testing/tests.cmake b/testing/tests.cmake new file mode 100644 index 000000000..38fac21b3 --- /dev/null +++ b/testing/tests.cmake @@ -0,0 +1,122 @@ +# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License, version 2.0, as +# published by the Free Software Foundation. +# +# This program is also distributed with certain software (including +# but not limited to OpenSSL) that is licensed under separate terms, +# as designated in a particular file or component or in included license +# documentation. The authors of MySQL hereby grant you an +# additional permission to link the program and your derivative works +# with the separately licensed software that they have included with +# MySQL. +# +# Without limiting anything contained in the foregoing, this file, +# which is part of MySQL Connector/C++, is also subject to the +# Universal FOSS Exception, version 1.0, a copy of which can be found at +# http://oss.oracle.com/licenses/universal-foss-exception. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License, version 2.0, for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +# Note: This file is meant to be included from the main CMakeLists.txt. +# It defines tests for the build tree. +# ===================================================================== + +# +# Note: We must clear compile flags - the ones used to build the connector +# are not good for building client code that uses the connector. +# + +set_property( + DIRECTORY . + PROPERTY COMPILE_DEFINITIONS "" +) + +if(BUILD_STATIC) + add_definitions(-DSTATIC_CONCPP) +endif() + + +# Auto-generated test targets + +IF (WITH_TESTS) + # Unit tests declared with ADD_NG_TEST() (see cdk/cmake/testing.cmake) + ADD_TEST_TARGET() + + # Test for public headers declared with ADD_HEADERS() + # (see cdk/cmake/headers.cmake) + ADD_HEADERS_TEST() +ENDIF (WITH_TESTS) + + +# +# Linking test +# ------------ +# +# This test compiles test application using internal installation of built +# connector. It is important to work with installed files because otherwise +# cmake does its magic to resolve missing dependencies when building test code. +# We don't want this to happen to make sure that test code can be built with +# connector library only, as we distribute it. +# +# Note: internal installation into /install is done by directly +# executing cmake_install.cmake script which is generated by cmake. +# +# TODO: Also test dynamic linking (requires adopting test app project) +# + +file(REMOVE_RECURSE ${PROJECT_BINARY_DIR}/link_test) +file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/link_test) + +unset(jdbc_options) +if(WITH_JDBC) + #message("-- BOOST_ROOT: ${BOOST_ROOT}") + list(APPEND jdbc_options -DWITH_JDBC=ON -DWITH_BOOST=${BOOST_ROOT}) +endif() + +add_custom_target(link_test + COMMAND ${CMAKE_COMMAND} -E remove_directory ${PROJECT_BINARY_DIR}/install + COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/install + COMMAND ${CMAKE_COMMAND} + -D CMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/install + -D CMAKE_INSTALL_CONFIG_NAME=$<$>:$>$<$>>:Release> + -P ${PROJECT_BINARY_DIR}/cmake_install.cmake + COMMAND ${CMAKE_COMMAND} -E remove -f ${PROJECT_BINARY_DIR}/link_test/CMakeCache.txt + COMMAND ${CMAKE_COMMAND} + -G "${CMAKE_GENERATOR}" + -D WITH_CONCPP=${PROJECT_BINARY_DIR}/install + -D WITH_SSL="${WITH_SSL}" + -D BUILD_STATIC=${BUILD_STATIC} + -D STATIC_MSVCRT=${STATIC_MSVCRT} + ${jdbc_options} + ${PROJECT_SOURCE_DIR}/testapp + COMMAND ${CMAKE_COMMAND} --build . --config $ --clean-first + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/link_test + VERBATIM +) + +set_target_properties(link_test PROPERTIES FOLDER "Tests") + +add_dependencies(link_test connector) +#if(TARGET connector-merge) +# add_dependencies(link_test connector-merge) +#endif() +#if(WITH_JDBC) +# add_dependencies(link_test build_jdbc) +#endif() + +# TDOD: Use ${CMAKE_COMMAND}, but evaluated at test time, not here. + +add_test(NAME Link_test + COMMAND cmake --build . --target link_test --config $ + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} +) From 263543153d04d981205d4defe53bb1104c957f16 Mon Sep 17 00:00:00 2001 From: Rafal Somla Date: Thu, 2 Apr 2020 10:42:41 +0200 Subject: [PATCH 06/16] cmake: Fix include path for legacy connector when used from the build tree. --- CMakeLists.txt | 6 ++++-- jdbc | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b10a726e..2a27dacc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -349,12 +349,14 @@ add_config_option(WITH_JDBC BOOL DEFAULT OFF if(WITH_JDBC) add_subdirectory(jdbc) - # Note: Include path must contain build location because - # this is where config.h header is written. + # Note: These include paths are to be used in a build tree. In + # this situation the jdbc public headers are not installed yet and + # we use a copy of them placed inside the build tree. target_include_directories(connector-jdbc PUBLIC "${PROJECT_BINARY_DIR}/jdbc/cppconn" PUBLIC "${PROJECT_SOURCE_DIR}/include" + PUBLIC "${PROJECT_BINARY_DIR}/jdbc/include/jdbc" ) endif() diff --git a/jdbc b/jdbc index 9bf6f97fd..d5b0788b3 160000 --- a/jdbc +++ b/jdbc @@ -1 +1 @@ -Subproject commit 9bf6f97fddf21de09a0c9b51050bf7795a9e0fb0 +Subproject commit d5b0788b3fed063f421d3d1b9e50fca2c22017f7 From d4e5a08d4ba90900936bef556b6bc055145b0d2d Mon Sep 17 00:00:00 2001 From: Rafal Somla Date: Thu, 2 Apr 2020 10:47:15 +0200 Subject: [PATCH 07/16] Bug #31095993 (99093) MYSQL-CONNECTOR-CPP CMAKE FILES NOT WORK WELL WHEN AS A THIRD PARTY Our libutils need to be updated to work correctly when used from within a cmake sub-project. Thanks to Lou Shuai for providing the initial patch. --- cmake/libutils.cmake | 137 +++++++++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 63 deletions(-) diff --git a/cmake/libutils.cmake b/cmake/libutils.cmake index 958f564dd..35bb88b64 100644 --- a/cmake/libutils.cmake +++ b/cmake/libutils.cmake @@ -35,89 +35,100 @@ # Includes all transitive dependencies of the libraries being merged. # -get_filename_component(LIBUTILS_SCRIPT_DIR ${CMAKE_CURRENT_LIST_FILE} PATH) -set(LIBUTILS_SCRIPT_DIR "${LIBUTILS_SCRIPT_DIR}/libutils") +# Include this script only once. -# -# Locate required tools. -# +if(COMMAND libutils_setup) + return() +endif() -if(CMAKE_BUILD_TOOL MATCHES "MSBuild") - set(MSBUILD ON) +macro(libutils_setup) - # Use lib.exe from the same location as other compiler tools + get_filename_component(LIBUTILS_SCRIPT_DIR ${CMAKE_CURRENT_LIST_FILE} PATH) + set(LIBUTILS_SCRIPT_DIR "${LIBUTILS_SCRIPT_DIR}/libutils") + set(LIBUTILS_BIN_DIR "${CMAKE_CURRENT_BINARY_DIR}/libutils" CACHE INTERNAL "") - get_filename_component(path "${CMAKE_LINKER}" DIRECTORY) - set(LIB_TOOL "${path}/lib.exe") + # + # Locate required tools. + # -endif() + if(CMAKE_BUILD_TOOL MATCHES "MSBuild") + set(MSBUILD ON) -if(APPLE) + # Use lib.exe from the same location as other compiler tools - find_program(LIB_TOOL libtool) + get_filename_component(path "${CMAKE_LINKER}" DIRECTORY) + set(LIB_TOOL "${path}/lib.exe") - # We need install_name_tool to do rpath mangling (see below) + endif() - find_program(INSTALL_NAME_TOOL install_name_tool) - # If available, otool is used to show runtime dependencies for libraries we - # build + if(APPLE) - find_program(OTOOL otool) + find_program(LIB_TOOL libtool) -endif() + # We need install_name_tool to do rpath mangling (see below) + find_program(INSTALL_NAME_TOOL install_name_tool) -# -# Infrastructure for merging static libraries -# =========================================== -# -# It is used to merge a static library with all other static libraries -# on which it depends, so that, when using the merged library, one does -# not have to worry about dependencies. -# -# The main logic for mering static libraries on different platforms is -# in the merge_archives.cmake script. Calling merge_static_library() on -# a library target arranges for this script to be called with all required -# parameters every time the library is (re-)built. -# -# Extra effort is needed to get the list of all dependencies of the library. -# These dependencies are computed by cmake, but there is no easy way to -# get them out of cmake. We use the trick with custom language linker. Hovewer, -# it does not work with MSBuild generator where we do other tricks. In either -# case the idea is to define a phony target that depends on the static library -# and capture link options that cmake uses to build this phony target. -# + # If available, otool is used to show runtime dependencies for libraries we + # build -# -# Create merge script from template, setting required internal variables in it. -# -# TODO: This will work only if this file is included in the same folder in which -# static libraries are linked. -# + find_program(OTOOL otool) -configure_file( - ${LIBUTILS_SCRIPT_DIR}/merge_archives.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/merge_archives.cmake - @ONLY -) + endif() -# -# This small program saves in a file all command line options that -# were passed to it. It is used to capture linker invocation options. -# -if(NOT MSBUILD AND NOT TARGET save_linker_opts) - add_executable(save_linker_opts ${LIBUTILS_SCRIPT_DIR}/save_linker_opts.cc) - set_property(TARGET save_linker_opts PROPERTY - OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} + # + # Infrastructure for merging static libraries + # =========================================== + # + # It is used to merge a static library with all other static libraries + # on which it depends, so that, when using the merged library, one does + # not have to worry about dependencies. + # + # The main logic for mering static libraries on different platforms is + # in the merge_archives.cmake script. Calling merge_static_library() on + # a library target arranges for this script to be called with all required + # parameters every time the library is (re-)built. + # + # Extra effort is needed to get the list of all dependencies of the library. + # These dependencies are computed by cmake, but there is no easy way to + # get them out of cmake. We use the trick with custom language linker. Hovewer, + # it does not work with MSBuild generator where we do other tricks. In either + # case the idea is to define a phony target that depends on the static library + # and capture link options that cmake uses to build this phony target. + # + + # + # Create merge script from template, setting required internal variables in it. + # + + configure_file( + ${LIBUTILS_SCRIPT_DIR}/merge_archives.cmake.in + ${LIBUTILS_BIN_DIR}/merge_archives.cmake + @ONLY ) -endif() + + # + # This small program saves in a file all command line options that + # were passed to it. It is used to capture linker invocation options. + # + + if(NOT MSBUILD AND NOT TARGET save_linker_opts) + add_executable(save_linker_opts ${LIBUTILS_SCRIPT_DIR}/save_linker_opts.cc) + set_property(TARGET save_linker_opts PROPERTY + RUNTIME_OUTPUT_DIRECTORY ${LIBUTILS_BIN_DIR} + ) + endif() + +endmacro(libutils_setup) + +libutils_setup() # -# Merge static libraries into single static or shared library. +# Merge static libraries into a single static or shared library. # # Given a static library target, this function sets up an infrastructure # for merging this static libraray with its dependencies. It creates @@ -185,7 +196,7 @@ function(merge_libraries TARGET) -DMSBUILD=${MSBUILD} -DINFO=${INFO} -DINFO_PREFIX=${INFO_PREFIX} - -P merge_archives.cmake + -P ${LIBUTILS_BIN_DIR}/merge_archives.cmake ) endif() @@ -218,7 +229,7 @@ function(merge_libraries TARGET) add_dependencies(${TARGET}-deps save_linker_opts) set_target_properties(${TARGET}-deps PROPERTIES - RULE_LAUNCH_LINK "${CMAKE_BINARY_DIR}/save_linker_opts ${log_file}.STATIC " + RULE_LAUNCH_LINK "${LIBUTILS_BIN_DIR}/save_linker_opts ${log_file}.STATIC " ) # Arrange for ${TARGET}-deps to be built before ${TARGET} @@ -236,7 +247,7 @@ function(merge_libraries TARGET) # set_target_properties(${TARGET} PROPERTIES - RULE_LAUNCH_LINK "${CMAKE_BINARY_DIR}/save_linker_opts ${log_file}.SHARED " + RULE_LAUNCH_LINK "${LIBUTILS_BIN_DIR}/save_linker_opts ${log_file}.SHARED " ) else(NOT MSBUILD) From e44860130ff1b086aa2d77996944f462f72f5032 Mon Sep 17 00:00:00 2001 From: Rafal Somla Date: Fri, 3 Apr 2020 10:58:35 +0200 Subject: [PATCH 08/16] tests: Add test for using connector build system as a sub-project. Test can be performed by building sub_project_test target. --- testing/sub_project_test/CMakeLists.txt | 99 +++++++++++++++++++++++++ testing/tests.cmake | 33 +++++++++ 2 files changed, 132 insertions(+) create mode 100644 testing/sub_project_test/CMakeLists.txt diff --git a/testing/sub_project_test/CMakeLists.txt b/testing/sub_project_test/CMakeLists.txt new file mode 100644 index 000000000..09ed927f0 --- /dev/null +++ b/testing/sub_project_test/CMakeLists.txt @@ -0,0 +1,99 @@ +# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License, version 2.0, as +# published by the Free Software Foundation. +# +# This program is also distributed with certain software (including +# but not limited to OpenSSL) that is licensed under separate terms, +# as designated in a particular file or component or in included license +# documentation. The authors of MySQL hereby grant you an +# additional permission to link the program and your derivative works +# with the separately licensed software that they have included with +# MySQL. +# +# Without limiting anything contained in the foregoing, this file, +# which is part of MySQL Connector/C++, is also subject to the +# Universal FOSS Exception, version 1.0, a copy of which can be found at +# http://oss.oracle.com/licenses/universal-foss-exception. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License, version 2.0, for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +cmake_minimum_required(VERSION 3.0) + +# +# This is test cmake project that uses Connector/C++ as a subproject, +# to verify that this usage scenario works. +# + +project(Sub_project_test C CXX) + +# +# Find Connector/C++ sources. +# + +if (NOT DEFINED CONCPP_SRC) + get_filename_component(CONCPP_SRC ../.. REALPATH) +endif() + +message("- using Con/C++ sources at: ${CONCPP_SRC}") + +if (NOT EXISTS ${CONCPP_SRC}/CMakeLists.txt) + message(FATAL_ERROR + "Could not find CMakeLists.txt at Con/C++ source location." + ) +endif() + +# +# If CONCPP_CACHE is defined, it should point at Connector/C++ +# build location where a cmake cache is stored. Various settings +# required to build connector source are read from that cache. +# + +if (DEFINED CONCPP_CACHE) + + message("- loading settings from Con/C++ cmake cache at: ${CONCPP_CACHE}") + load_cache(${CONCPP_CACHE} READ_WITH_PREFIX "" + WITH_SSL + WITH_JDBC + WITH_BOOST + WITH_MYSQL MYSQL_INCLUDE_DIR MYSQL_LIB_DIR MYSQL_CONFIG_EXECUTABLE + ) + + message("- WITH_SSL: ${WITH_SSL}") + message("- WITH_BOOST: ${WITH_BOOST}") + message("- WITH_MYSQL: ${WITH_MYSQL} (${MYSQL_INCLUDE_DIR} ${MYSQL_LIB_DIR})") + +endif() + +# +# Include Connector/C++ as a sub-project +# + +add_subdirectory(${CONCPP_SRC} connector-cpp) + +# +# Define test applications to verify that they build correctly. +# + +set(CMAKE_CXX_STANDARD 11) + +add_executable(devapi_test ${CONCPP_SRC}/testapp/devapi_test.cc) +target_link_libraries(devapi_test connector) + +add_executable(xapi_test ${CONCPP_SRC}/testapp/xapi_test.c) +target_link_libraries(xapi_test connector) + +if (WITH_JDBC) + + add_executable(jdbc_test ${CONCPP_SRC}/testapp/jdbc_test.cc) + target_link_libraries(jdbc_test connector-jdbc) + +endif() diff --git a/testing/tests.cmake b/testing/tests.cmake index 38fac21b3..ebfebe419 100644 --- a/testing/tests.cmake +++ b/testing/tests.cmake @@ -57,6 +57,39 @@ IF (WITH_TESTS) ADD_HEADERS_TEST() ENDIF (WITH_TESTS) +# +# Sub-project test +# ---------------- +# +# This test checks using Con/C++ build system as a sub-project in +# a master cmake project. +# + +file(REMOVE_RECURSE ${PROJECT_BINARY_DIR}/sub_project_test) +file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/sub_project_test) + +if(CMAKE_GENERATOR_PLATFORM) + list(APPEND cmake_options -A ${CMAKE_GENERATOR_PLATFORM}) +endif() + +if(CMAKE_GENERATOR_TOOLSET) + list(APPEND cmake_options -T ${CMAKE_GENERATOR_TOOLSET}) +endif() + +add_custom_target(sub_project_test + COMMAND ${CMAKE_COMMAND} -E remove -f ${PROJECT_BINARY_DIR}/sub_project_test/CMakeCache.txt + COMMAND ${CMAKE_COMMAND} + -G "${CMAKE_GENERATOR}" + ${cmake_options} + -D CONCPP_CACHE=${PROJECT_BINARY_DIR} + ${PROJECT_SOURCE_DIR}/testing/sub_project_test + COMMAND ${CMAKE_COMMAND} --build . --config $ --clean-first + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/sub_project_test + VERBATIM +) + +set_target_properties(sub_project_test PROPERTIES FOLDER "Tests") + # # Linking test From a3b7a46b4597c49f69343a0cd559ca51f64b860a Mon Sep 17 00:00:00 2001 From: Gipson Pulla Date: Thu, 23 Apr 2020 11:12:03 +0530 Subject: [PATCH 09/16] ET#66748 Updating License file for C/CPP 8.0.21 release branch --- LICENSE.txt | 61 +++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 4649957c5..92d55661b 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -10,7 +10,7 @@ Introduction third-party software which may be included in this distribution of MySQL Connector/C++ 8.0. - Last updated: March 2020 + Last updated: April 2020 Licensing Information @@ -921,33 +921,38 @@ zlib Oracle gratefully acknowledges the contributions of Jean-loup Gailly and Mark Adler in creating the zlib general purpose compression library which is used in this product. -zlib.h -- interface of the 'zlib' general purpose compression library -Copyright (C) 1995-2004 Jean-loup Gailly and Mark Adler - -zlib.h -- interface of the 'zlib' general purpose compression library -version 1.2.3, July 18th, 2005 -Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler - -zlib.h -- interface of the 'zlib' general purpose compression library -version 1.2.5, April 19th, 2010 -Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the -use of this software. Permission is granted to anyone to use this software -for any purpose,including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would - be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not - be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. - -Jean-loup Gailly jloup@gzip.org -Mark Adler madler@alumni.caltech.edu +(C) 1995-2017 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + +If you use the zlib library in a product, we would appreciate *not* receiving +lengthy legal documents to sign. The sources are provided for free but without +warranty of any kind. The library has been entirely written by Jean-loup +Gailly and Mark Adler; it does not include third-party code. + +If you redistribute modified sources, we would appreciate that you include in +the file ChangeLog history information documenting your changes. Please read +the FAQ for more information on the distribution of modified source versions. ZSTD From 563817d4c778cafdd65491a7d1eb32af30b1ae88 Mon Sep 17 00:00:00 2001 From: Gipson Pulla Date: Wed, 27 May 2020 20:23:25 +0530 Subject: [PATCH 10/16] ET#67124 INFO_SRC and INFO_BIN file checks Updated the CMAKE varialbe to generate value in INFO_SRC file --- buildinfo.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildinfo.cmake b/buildinfo.cmake index 82dadc704..7d038cb5c 100644 --- a/buildinfo.cmake +++ b/buildinfo.cmake @@ -100,7 +100,7 @@ FUNCTION(GENERATE_INFO_SRC) MESSAGE("Generating INFO_SRC") IF (NOT EXISTS INFO_SRC) - SET(INFO_VERSION "${CONCPP_PACKAGE_VERSION}") + SET(INFO_VERSION "${CONCPP_VERSION}") find_program(GIT_FOUND NAMES git) From 938d76674c808cebbe462eedc43a14bb3d282cc4 Mon Sep 17 00:00:00 2001 From: Gipson Pulla Date: Tue, 2 Jun 2020 23:33:17 +0530 Subject: [PATCH 11/16] ET#67376 [Connctor/C++] Fix the build-date in the INFO_BIN in Fedora packages The rpm build for fedora platform sets the changelog date for SOURCE_DATE_EPOCH env variable. Unsetting the SOURCE_DATE_EPOCH env variable to use the current system date --- buildinfo.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/buildinfo.cmake b/buildinfo.cmake index 7d038cb5c..5b31416f3 100644 --- a/buildinfo.cmake +++ b/buildinfo.cmake @@ -36,6 +36,7 @@ FUNCTION(GENERATE_INFO_BIN) ENDIF() MESSAGE("Generating INFO_BIN") + UNSET(ENV{SOURCE_DATE_EPOCH}) string(TIMESTAMP INFO_DATE "%Y-%m-%d") IF (CMAKE_BUILD_TYPE) From 40fa681b62be3161f571bedf8769d824b56da3e5 Mon Sep 17 00:00:00 2001 From: Gipson Pulla Date: Thu, 4 Jun 2020 16:26:40 +0530 Subject: [PATCH 12/16] ET#67376 [Connctor/C++] Fix the build-date in the INFO_BIN in Fedora packages Updated the spec file to override the default value of epoch date from the macros. Removed the unsetting the SOURCE_DATE_EPOCH env variable in cmake. --- buildinfo.cmake | 1 - packaging/mysql-connector-c++.spec.in | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/buildinfo.cmake b/buildinfo.cmake index 5b31416f3..7d038cb5c 100644 --- a/buildinfo.cmake +++ b/buildinfo.cmake @@ -36,7 +36,6 @@ FUNCTION(GENERATE_INFO_BIN) ENDIF() MESSAGE("Generating INFO_BIN") - UNSET(ENV{SOURCE_DATE_EPOCH}) string(TIMESTAMP INFO_DATE "%Y-%m-%d") IF (CMAKE_BUILD_TYPE) diff --git a/packaging/mysql-connector-c++.spec.in b/packaging/mysql-connector-c++.spec.in index 20ba00513..dd4bd4721 100644 --- a/packaging/mysql-connector-c++.spec.in +++ b/packaging/mysql-connector-c++.spec.in @@ -48,6 +48,8 @@ %global dist .sl15 %endif +%global source_date_epoch_from_changelog 0 + Summary: MySQL database connector for C++ Name: mysql-connector-c++%{?product_suffix} Version: @CONCPP_VERSION@ @@ -222,6 +224,9 @@ rm %{buildroot}/usr/{INFO_SRC,INFO_BIN} %endif %changelog +* Thu Jun 04 2020 Gipson Pulla - 8.0.21-1 +- Updated the macro to use the system date + * Fri Feb 15 2019 Bjorn Munch - 8.0.16-1 - CMake 3 should not be used on Fedora, only on Oracle Linux or Red Hat - Removed use of cmake_path as it is no longer needed From 6b2fc1020534b908f90610f5ebdcf36a7df67cfd Mon Sep 17 00:00:00 2001 From: Hery Ramilison Date: Thu, 18 Jun 2020 05:54:02 +0200 Subject: [PATCH 13/16] Updated the LICENSE files --- LICENSE.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 92d55661b..def51a891 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -10,7 +10,7 @@ Introduction third-party software which may be included in this distribution of MySQL Connector/C++ 8.0. - Last updated: April 2020 + Last updated: June 2020 Licensing Information @@ -33,8 +33,7 @@ Licensing Information a copy of which is reproduced below and can also be found along with its FAQ at http://oss.oracle.com/licenses/universal-foss-exception. - Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights - reserved. + Copyright (c) 2008, 2020, Oracle and/or its affiliates. Election of GPLv2 From 5937d61c1058728488ea9b027857be5f5459c625 Mon Sep 17 00:00:00 2001 From: Eric Beuque Date: Mon, 13 Jul 2020 12:16:58 +0000 Subject: [PATCH 14/16] Set some compiler option only for MSVC --- cdk/extra/zlib/CMakeLists.txt | 2 +- cdk/protobuf/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cdk/extra/zlib/CMakeLists.txt b/cdk/extra/zlib/CMakeLists.txt index b80a084af..f6fb4bdca 100644 --- a/cdk/extra/zlib/CMakeLists.txt +++ b/cdk/extra/zlib/CMakeLists.txt @@ -141,7 +141,7 @@ string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*" # ------------------------------------------------------------------------- # Disable compile warnings -if(WIN32) +if(MSVC) add_compile_options( /wd4996 diff --git a/cdk/protobuf/CMakeLists.txt b/cdk/protobuf/CMakeLists.txt index c5fb588a3..11727b401 100644 --- a/cdk/protobuf/CMakeLists.txt +++ b/cdk/protobuf/CMakeLists.txt @@ -163,7 +163,7 @@ if(APPLE) endif() -if(WIN32) +if(MSVC) add_compile_options( /wd4018 From a742c23a499cc4d3d0c06156bf6bbde65bebf733 Mon Sep 17 00:00:00 2001 From: Eric Beuque Date: Mon, 13 Jul 2020 12:16:58 +0000 Subject: [PATCH 15/16] Add some fix to allow MinGW32 compilation --- cdk/cmake/DepFindProtobuf.cmake | 16 +++++++++++++++- cdk/foundation/CMakeLists.txt | 6 +++++- cdk/foundation/connection_openssl.cc | 2 +- cdk/foundation/socket_detail.cc | 2 +- cdk/mysqlx/CMakeLists.txt | 2 +- cdk/parser/parser.h | 2 +- common/session.cc | 2 ++ 7 files changed, 26 insertions(+), 6 deletions(-) diff --git a/cdk/cmake/DepFindProtobuf.cmake b/cdk/cmake/DepFindProtobuf.cmake index e3726831f..0dd5b4d53 100644 --- a/cdk/cmake/DepFindProtobuf.cmake +++ b/cdk/cmake/DepFindProtobuf.cmake @@ -95,6 +95,17 @@ if(CMAKE_GENERATOR_TOOLSET) set(set_toolset -T ${CMAKE_GENERATOR_TOOLSET}) endif() +# CMAKE_HOST_SYSTEM_NAME +set(set_system_name) +if(CMAKE_SYSTEM_NAME) + set(set_system_name -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}) +endif() + +set(set_system_processor) +if(CMAKE_SYSTEM_PROCESSOR) + set(set_system_processor -DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}) +endif() + if(NOT EXISTS "${PB_BINARY_DIR}/exports.cmake") message("==== Configuring Protobuf build using cmake generator: ${CMAKE_GENERATOR} ${set_arch} ${set_toolset}") @@ -114,6 +125,8 @@ if(NOT EXISTS "${PB_BINARY_DIR}/exports.cmake") ${set_arch} ${set_toolset} ${set_build_type} + ${set_system_name} + ${set_system_processor} -DSTATIC_MSVCRT=${STATIC_MSVCRT} -DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} @@ -322,7 +335,8 @@ function(mysqlx_protobuf_generate_cpp SRCS HDRS) set_source_files_properties(${srcs} APPEND_STRING PROPERTY COMPILE_FLAGS "-w" ) - ELSE(WIN32) + ENDIF() + IF(MSVC) set_source_files_properties(${srcs} APPEND_STRING PROPERTY COMPILE_FLAGS "/W1 /wd4018 /wd4996 /wd4244 /wd4267" diff --git a/cdk/foundation/CMakeLists.txt b/cdk/foundation/CMakeLists.txt index 0a34c7d7e..f9b7c00e3 100644 --- a/cdk/foundation/CMakeLists.txt +++ b/cdk/foundation/CMakeLists.txt @@ -94,7 +94,11 @@ target_link_libraries(cdk_foundation ) IF(WIN32) - target_link_libraries(cdk_foundation PRIVATE Dnsapi) + if(MSVC) + target_link_libraries(cdk_foundation PRIVATE Dnsapi) + else() + target_link_libraries(cdk_foundation PRIVATE dnsapi) + endif() ELSEIF(NOT FREEBSD) target_link_libraries(cdk_foundation PRIVATE resolv) ENDIF() diff --git a/cdk/foundation/connection_openssl.cc b/cdk/foundation/connection_openssl.cc index 2f00503f1..95aa4de52 100644 --- a/cdk/foundation/connection_openssl.cc +++ b/cdk/foundation/connection_openssl.cc @@ -49,7 +49,7 @@ POP_SYS_WARNINGS_CDK #pragma comment directive. */ -#ifdef _WIN32 +#ifdef _MSC_VER #pragma comment(lib,"ws2_32") #if defined(WITH_SSL) #if OPENSSL_VERSION_NUMBER < 0x10100000L diff --git a/cdk/foundation/socket_detail.cc b/cdk/foundation/socket_detail.cc index 1bb2b7b49..718544556 100644 --- a/cdk/foundation/socket_detail.cc +++ b/cdk/foundation/socket_detail.cc @@ -844,7 +844,7 @@ int poll_one(Socket socket, Poll_mode mode, bool wait, DIAGNOSTIC_PUSH_CDK -#ifdef _WIN32 +#ifdef _MSC_VER // 4548 = expression has no effect // This warning is generated by FD_SET DISABLE_WARNING_CDK(4548) diff --git a/cdk/mysqlx/CMakeLists.txt b/cdk/mysqlx/CMakeLists.txt index c92d8004d..afacde65f 100644 --- a/cdk/mysqlx/CMakeLists.txt +++ b/cdk/mysqlx/CMakeLists.txt @@ -33,7 +33,7 @@ ADD_DEFINITIONS(-DSIZEOF_LONG=${SIZEOF_LONG} -DSIZEOF_LONG_LONG=${SIZEOF_LONG_LO # TODO: Fix compile warnings in auth_mysql41.cc -if(WIN32) +if(MSVC) set_property(SOURCE auth_hash.cc PROPERTY COMPILE_FLAGS "/W3" ) diff --git a/cdk/parser/parser.h b/cdk/parser/parser.h index 84dc3189d..e1e31cc92 100644 --- a/cdk/parser/parser.h +++ b/cdk/parser/parser.h @@ -35,7 +35,7 @@ #include "tokenizer.h" -#ifdef _WIN32 +#ifdef _MSC_VER /* 4061 = enum constant not explicitly handled by switch() case. diff --git a/common/session.cc b/common/session.cc index 1cc891e95..7b1806c21 100644 --- a/common/session.cc +++ b/common/session.cc @@ -119,7 +119,9 @@ std::string get_os_version_info(std::string &platform) else { PUSH_SYS_WARNINGS +#ifdef _MSC_VER DISABLE_WARNING(4996) +#endif if (GetVersionEx(&ver) == 0) ver_info << ""; POP_SYS_WARNINGS From 82e81dd0e39cb43634268a2e288e09004d204892 Mon Sep 17 00:00:00 2001 From: Eric Beuque Date: Wed, 15 Jul 2020 12:20:06 +0000 Subject: [PATCH 16/16] More fix for MingGW32 compilation --- cdk/extra/uuid/src/uuid_gen.cc | 2 ++ cdk/foundation/socket_detail.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/cdk/extra/uuid/src/uuid_gen.cc b/cdk/extra/uuid/src/uuid_gen.cc index dca7c8964..6bf20cfc7 100644 --- a/cdk/extra/uuid/src/uuid_gen.cc +++ b/cdk/extra/uuid/src/uuid_gen.cc @@ -41,6 +41,7 @@ #ifdef _WIN32 +#ifndef __WINPTHREADS_VERSION typedef CRITICAL_SECTION pthread_mutex_t; typedef DWORD pthread_t; typedef struct thread_attr { @@ -55,6 +56,7 @@ typedef struct thread_attr { #define pthread_mutex_trylock(A) win_pthread_mutex_trylock((A)) #define pthread_mutex_unlock(A) (LeaveCriticalSection(A), 0) #define pthread_mutex_destroy(A) (DeleteCriticalSection(A), 0) +#endif #else diff --git a/cdk/foundation/socket_detail.cc b/cdk/foundation/socket_detail.cc index 718544556..9ba45aa33 100644 --- a/cdk/foundation/socket_detail.cc +++ b/cdk/foundation/socket_detail.cc @@ -74,6 +74,8 @@ namespace detail { Used for handling Winsock errors. */ +const error_category& winsock_error_category(); + class error_category_winsock : public error_category_base { error_category_winsock() {}