Merge pull request #232 from xvitaly/system-gtest

Added support of packaged GTest for running unit tests
This commit is contained in:
Sébastien Rombauts 2019-11-25 21:43:00 +01:00 committed by GitHub
commit ddcc042a10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -301,13 +301,19 @@ endif (SQLITECPP_BUILD_EXAMPLES)
option(SQLITECPP_BUILD_TESTS "Build and run tests." OFF) option(SQLITECPP_BUILD_TESTS "Build and run tests." OFF)
if (SQLITECPP_BUILD_TESTS) if (SQLITECPP_BUILD_TESTS)
# add the unit test executable
add_executable(SQLiteCpp_tests ${SQLITECPP_TESTS})
find_package(GTest)
if (GTEST_FOUND)
target_link_libraries(SQLiteCpp_tests GTest::GTest GTest::Main SQLiteCpp sqlite3)
else (GTEST_FOUND)
# deactivate some warnings for compiling the gtest library # deactivate some warnings for compiling the gtest library
if (NOT MSVC) if (NOT MSVC)
add_compile_options(-Wno-variadic-macros -Wno-long-long -Wno-switch-enum -Wno-float-equal -Wno-conversion-null -Wno-switch-default -Wno-pedantic) add_compile_options(-Wno-variadic-macros -Wno-long-long -Wno-switch-enum -Wno-float-equal -Wno-conversion-null -Wno-switch-default -Wno-pedantic)
endif (NOT MSVC) endif (NOT MSVC)
# add the subdirectory containing the CMakeLists.txt for the gtest library # add the subdirectory containing the CMakeLists.txt for the gtest library
# TODO: under Linux, uses libgtest-dev if found
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/googletest/CMakeLists.txt") if (NOT EXISTS "${PROJECT_SOURCE_DIR}/googletest/CMakeLists.txt")
message(FATAL_ERROR "Missing 'googletest' submodule! Either use 'git submodule init' and 'git submodule update' to get googletest according to the README, or deactivate unit tests with -DSQLITECPP_BUILD_TESTS=OFF") message(FATAL_ERROR "Missing 'googletest' submodule! Either use 'git submodule init' and 'git submodule update' to get googletest according to the README, or deactivate unit tests with -DSQLITECPP_BUILD_TESTS=OFF")
endif () endif ()
@ -324,9 +330,9 @@ if (SQLITECPP_BUILD_TESTS)
endif (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919) endif (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919)
endif (MSVC) endif (MSVC)
# add the unit test executable
add_executable(SQLiteCpp_tests ${SQLITECPP_TESTS})
target_link_libraries(SQLiteCpp_tests gtest_main SQLiteCpp sqlite3) target_link_libraries(SQLiteCpp_tests gtest_main SQLiteCpp sqlite3)
endif (GTEST_FOUND)
# Link target with dl for linux # Link target with dl for linux
if (UNIX AND NOT APPLE) if (UNIX AND NOT APPLE)
target_link_libraries(SQLiteCpp_tests dl) target_link_libraries(SQLiteCpp_tests dl)