Skip to content

Commit 6bfc6f0

Browse files
committed
cmake: Move extra tests to testing/tests.cmake
1 parent 6ea0ab8 commit 6bfc6f0

File tree

2 files changed

+124
-70
lines changed

2 files changed

+124
-70
lines changed

CMakeLists.txt

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -522,18 +522,6 @@ if(BUILD_STATIC)
522522
add_definitions(-DSTATIC_CONCPP)
523523
endif()
524524

525-
526-
# Auto-generated test targets
527-
528-
IF (WITH_TESTS)
529-
# Unit tests declared with ADD_NG_TEST() (see cdk/cmake/testing.cmake)
530-
ADD_TEST_TARGET()
531-
532-
# Test for public headers declared with ADD_HEADERS()
533-
# (see cdk/cmake/headers.cmake)
534-
ADD_HEADERS_TEST()
535-
ENDIF (WITH_TESTS)
536-
537525
#
538526
# Sample code to try things out
539527
#
@@ -585,67 +573,11 @@ endif()
585573
endif()
586574

587575
#
588-
# Linking test
589-
# ------------
576+
# Other tests.
590577
#
591-
# This test compiles test application using internal installation of built
592-
# connector. It is important to work with installed files because otherwise
593-
# cmake does its magic to resolve missing dependencies when building test code.
594-
# We don't want this to happen to make sure that test code can be built with
595-
# connector library only, as we distribute it.
596-
#
597-
# Note: internal installation into <binary_dir>/install is done by directly
598-
# executing cmake_install.cmake script which is generated by cmake.
599-
#
600-
# TODO: Also test dynamic linking (requires adopting test app project)
601-
#
602-
603-
file(REMOVE_RECURSE ${PROJECT_BINARY_DIR}/link_test)
604-
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/link_test)
605578

606-
unset(jdbc_options)
607-
if(WITH_JDBC)
608-
#message("-- BOOST_ROOT: ${BOOST_ROOT}")
609-
list(APPEND jdbc_options -DWITH_JDBC=ON -DWITH_BOOST=${BOOST_ROOT})
610-
endif()
611-
612-
add_custom_target(link_test
613-
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PROJECT_BINARY_DIR}/install
614-
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/install
615-
COMMAND ${CMAKE_COMMAND}
616-
-D CMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/install
617-
-D CMAKE_INSTALL_CONFIG_NAME=$<$<BOOL:$<CONFIGURATION>>:$<CONFIGURATION>>$<$<NOT:$<BOOL:$<CONFIGURATION>>>:Release>
618-
-P ${PROJECT_BINARY_DIR}/cmake_install.cmake
619-
COMMAND ${CMAKE_COMMAND} -E remove -f ${PROJECT_BINARY_DIR}/link_test/CMakeCache.txt
620-
COMMAND ${CMAKE_COMMAND}
621-
-G "${CMAKE_GENERATOR}"
622-
-D WITH_CONCPP=${PROJECT_BINARY_DIR}/install
623-
-D WITH_SSL="${WITH_SSL}"
624-
-D BUILD_STATIC=${BUILD_STATIC}
625-
-D STATIC_MSVCRT=${STATIC_MSVCRT}
626-
${jdbc_options}
627-
${PROJECT_SOURCE_DIR}/testapp
628-
COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIGURATION> --clean-first
629-
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/link_test
630-
VERBATIM
631-
)
579+
include(testing/tests.cmake)
632580

633-
set_target_properties(link_test PROPERTIES FOLDER "Tests")
634-
635-
add_dependencies(link_test connector)
636-
#if(TARGET connector-merge)
637-
# add_dependencies(link_test connector-merge)
638-
#endif()
639-
#if(WITH_JDBC)
640-
# add_dependencies(link_test build_jdbc)
641-
#endif()
642-
643-
# TDOD: Use ${CMAKE_COMMAND}, but evaluated at test time, not here.
644-
645-
add_test(NAME Link_test
646-
COMMAND cmake --build . --target link_test --config $<CONFIGURATION>
647-
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
648-
)
649581

650582
#
651583
# Create the INFO_SRC and INFO_BIN files

testing/tests.cmake

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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

Comments
 (0)