|
| 1 | +# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. |
| 2 | +# |
| 3 | +# This program is free software; you can redistribute it and/or modify |
| 4 | +# it under the terms of the GNU General Public License, version 2.0, as |
| 5 | +# published by the Free Software Foundation. |
| 6 | +# |
| 7 | +# This program is also distributed with certain software (including |
| 8 | +# but not limited to OpenSSL) that is licensed under separate terms, |
| 9 | +# as designated in a particular file or component or in included license |
| 10 | +# documentation. The authors of MySQL hereby grant you an |
| 11 | +# additional permission to link the program and your derivative works |
| 12 | +# with the separately licensed software that they have included with |
| 13 | +# MySQL. |
| 14 | +# |
| 15 | +# Without limiting anything contained in the foregoing, this file, |
| 16 | +# which is part of MySQL Connector/C++, is also subject to the |
| 17 | +# Universal FOSS Exception, version 1.0, a copy of which can be found at |
| 18 | +# http://oss.oracle.com/licenses/universal-foss-exception. |
| 19 | +# |
| 20 | +# This program is distributed in the hope that it will be useful, but |
| 21 | +# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 23 | +# See the GNU General Public License, version 2.0, for more details. |
| 24 | +# |
| 25 | +# You should have received a copy of the GNU General Public License |
| 26 | +# along with this program; if not, write to the Free Software Foundation, Inc., |
| 27 | +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 28 | + |
| 29 | + |
| 30 | +# Note: This file is meant to be included from the main CMakeLists.txt. |
| 31 | +# It defines tests for the build tree. |
| 32 | +# ===================================================================== |
| 33 | + |
| 34 | +# |
| 35 | +# Note: We must clear compile flags - the ones used to build the connector |
| 36 | +# are not good for building client code that uses the connector. |
| 37 | +# |
| 38 | + |
| 39 | +set_property( |
| 40 | + DIRECTORY . |
| 41 | + PROPERTY COMPILE_DEFINITIONS "" |
| 42 | +) |
| 43 | + |
| 44 | +if(BUILD_STATIC) |
| 45 | + add_definitions(-DSTATIC_CONCPP) |
| 46 | +endif() |
| 47 | + |
| 48 | + |
| 49 | +# Auto-generated test targets |
| 50 | + |
| 51 | +IF (WITH_TESTS) |
| 52 | + # Unit tests declared with ADD_NG_TEST() (see cdk/cmake/testing.cmake) |
| 53 | + ADD_TEST_TARGET() |
| 54 | + |
| 55 | + # Test for public headers declared with ADD_HEADERS() |
| 56 | + # (see cdk/cmake/headers.cmake) |
| 57 | + ADD_HEADERS_TEST() |
| 58 | +ENDIF (WITH_TESTS) |
| 59 | + |
| 60 | + |
| 61 | +# |
| 62 | +# Linking test |
| 63 | +# ------------ |
| 64 | +# |
| 65 | +# This test compiles test application using internal installation of built |
| 66 | +# connector. It is important to work with installed files because otherwise |
| 67 | +# cmake does its magic to resolve missing dependencies when building test code. |
| 68 | +# We don't want this to happen to make sure that test code can be built with |
| 69 | +# connector library only, as we distribute it. |
| 70 | +# |
| 71 | +# Note: internal installation into <binary_dir>/install is done by directly |
| 72 | +# executing cmake_install.cmake script which is generated by cmake. |
| 73 | +# |
| 74 | +# TODO: Also test dynamic linking (requires adopting test app project) |
| 75 | +# |
| 76 | + |
| 77 | +file(REMOVE_RECURSE ${PROJECT_BINARY_DIR}/link_test) |
| 78 | +file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/link_test) |
| 79 | + |
| 80 | +unset(jdbc_options) |
| 81 | +if(WITH_JDBC) |
| 82 | + #message("-- BOOST_ROOT: ${BOOST_ROOT}") |
| 83 | + list(APPEND jdbc_options -DWITH_JDBC=ON -DWITH_BOOST=${BOOST_ROOT}) |
| 84 | +endif() |
| 85 | + |
| 86 | +add_custom_target(link_test |
| 87 | + COMMAND ${CMAKE_COMMAND} -E remove_directory ${PROJECT_BINARY_DIR}/install |
| 88 | + COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/install |
| 89 | + COMMAND ${CMAKE_COMMAND} |
| 90 | + -D CMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/install |
| 91 | + -D CMAKE_INSTALL_CONFIG_NAME=$<$<BOOL:$<CONFIGURATION>>:$<CONFIGURATION>>$<$<NOT:$<BOOL:$<CONFIGURATION>>>:Release> |
| 92 | + -P ${PROJECT_BINARY_DIR}/cmake_install.cmake |
| 93 | + COMMAND ${CMAKE_COMMAND} -E remove -f ${PROJECT_BINARY_DIR}/link_test/CMakeCache.txt |
| 94 | + COMMAND ${CMAKE_COMMAND} |
| 95 | + -G "${CMAKE_GENERATOR}" |
| 96 | + -D WITH_CONCPP=${PROJECT_BINARY_DIR}/install |
| 97 | + -D WITH_SSL="${WITH_SSL}" |
| 98 | + -D BUILD_STATIC=${BUILD_STATIC} |
| 99 | + -D STATIC_MSVCRT=${STATIC_MSVCRT} |
| 100 | + ${jdbc_options} |
| 101 | + ${PROJECT_SOURCE_DIR}/testapp |
| 102 | + COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIGURATION> --clean-first |
| 103 | + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/link_test |
| 104 | + VERBATIM |
| 105 | +) |
| 106 | + |
| 107 | +set_target_properties(link_test PROPERTIES FOLDER "Tests") |
| 108 | + |
| 109 | +add_dependencies(link_test connector) |
| 110 | +#if(TARGET connector-merge) |
| 111 | +# add_dependencies(link_test connector-merge) |
| 112 | +#endif() |
| 113 | +#if(WITH_JDBC) |
| 114 | +# add_dependencies(link_test build_jdbc) |
| 115 | +#endif() |
| 116 | + |
| 117 | +# TDOD: Use ${CMAKE_COMMAND}, but evaluated at test time, not here. |
| 118 | + |
| 119 | +add_test(NAME Link_test |
| 120 | + COMMAND cmake --build . --target link_test --config $<CONFIGURATION> |
| 121 | + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} |
| 122 | +) |
0 commit comments