Skip to content

Commit e448601

Browse files
committed
tests: Add test for using connector build system as a sub-project.
Test can be performed by building sub_project_test target.
1 parent d4e5a08 commit e448601

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
cmake_minimum_required(VERSION 3.0)
30+
31+
#
32+
# This is test cmake project that uses Connector/C++ as a subproject,
33+
# to verify that this usage scenario works.
34+
#
35+
36+
project(Sub_project_test C CXX)
37+
38+
#
39+
# Find Connector/C++ sources.
40+
#
41+
42+
if (NOT DEFINED CONCPP_SRC)
43+
get_filename_component(CONCPP_SRC ../.. REALPATH)
44+
endif()
45+
46+
message("- using Con/C++ sources at: ${CONCPP_SRC}")
47+
48+
if (NOT EXISTS ${CONCPP_SRC}/CMakeLists.txt)
49+
message(FATAL_ERROR
50+
"Could not find CMakeLists.txt at Con/C++ source location."
51+
)
52+
endif()
53+
54+
#
55+
# If CONCPP_CACHE is defined, it should point at Connector/C++
56+
# build location where a cmake cache is stored. Various settings
57+
# required to build connector source are read from that cache.
58+
#
59+
60+
if (DEFINED CONCPP_CACHE)
61+
62+
message("- loading settings from Con/C++ cmake cache at: ${CONCPP_CACHE}")
63+
load_cache(${CONCPP_CACHE} READ_WITH_PREFIX ""
64+
WITH_SSL
65+
WITH_JDBC
66+
WITH_BOOST
67+
WITH_MYSQL MYSQL_INCLUDE_DIR MYSQL_LIB_DIR MYSQL_CONFIG_EXECUTABLE
68+
)
69+
70+
message("- WITH_SSL: ${WITH_SSL}")
71+
message("- WITH_BOOST: ${WITH_BOOST}")
72+
message("- WITH_MYSQL: ${WITH_MYSQL} (${MYSQL_INCLUDE_DIR} ${MYSQL_LIB_DIR})")
73+
74+
endif()
75+
76+
#
77+
# Include Connector/C++ as a sub-project
78+
#
79+
80+
add_subdirectory(${CONCPP_SRC} connector-cpp)
81+
82+
#
83+
# Define test applications to verify that they build correctly.
84+
#
85+
86+
set(CMAKE_CXX_STANDARD 11)
87+
88+
add_executable(devapi_test ${CONCPP_SRC}/testapp/devapi_test.cc)
89+
target_link_libraries(devapi_test connector)
90+
91+
add_executable(xapi_test ${CONCPP_SRC}/testapp/xapi_test.c)
92+
target_link_libraries(xapi_test connector)
93+
94+
if (WITH_JDBC)
95+
96+
add_executable(jdbc_test ${CONCPP_SRC}/testapp/jdbc_test.cc)
97+
target_link_libraries(jdbc_test connector-jdbc)
98+
99+
endif()

testing/tests.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,39 @@ IF (WITH_TESTS)
5757
ADD_HEADERS_TEST()
5858
ENDIF (WITH_TESTS)
5959

60+
#
61+
# Sub-project test
62+
# ----------------
63+
#
64+
# This test checks using Con/C++ build system as a sub-project in
65+
# a master cmake project.
66+
#
67+
68+
file(REMOVE_RECURSE ${PROJECT_BINARY_DIR}/sub_project_test)
69+
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/sub_project_test)
70+
71+
if(CMAKE_GENERATOR_PLATFORM)
72+
list(APPEND cmake_options -A ${CMAKE_GENERATOR_PLATFORM})
73+
endif()
74+
75+
if(CMAKE_GENERATOR_TOOLSET)
76+
list(APPEND cmake_options -T ${CMAKE_GENERATOR_TOOLSET})
77+
endif()
78+
79+
add_custom_target(sub_project_test
80+
COMMAND ${CMAKE_COMMAND} -E remove -f ${PROJECT_BINARY_DIR}/sub_project_test/CMakeCache.txt
81+
COMMAND ${CMAKE_COMMAND}
82+
-G "${CMAKE_GENERATOR}"
83+
${cmake_options}
84+
-D CONCPP_CACHE=${PROJECT_BINARY_DIR}
85+
${PROJECT_SOURCE_DIR}/testing/sub_project_test
86+
COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIGURATION> --clean-first
87+
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/sub_project_test
88+
VERBATIM
89+
)
90+
91+
set_target_properties(sub_project_test PROPERTIES FOLDER "Tests")
92+
6093

6194
#
6295
# Linking test

0 commit comments

Comments
 (0)