summaryrefslogtreecommitdiff
path: root/test/libapt
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-01-07 21:29:11 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2020-01-07 21:32:23 +0100
commit01ff55f375b3d9e96b178d3a963d9e3d5ac5134b (patch)
tree4abb592bfd345b80208f9fe15f79d7548d2213d3 /test/libapt
parentf2ad6eb0c579f1c825aa1efec192b4d4eb5e6171 (diff)
Add support for GTest 1.9, do not fail silently if its missing
Require passing -DWITH_TESTS=OFF to CMakeList to disable unit tests, rather than ignoring them if GTest cannot be found; which just happened on CI...
Diffstat (limited to 'test/libapt')
-rw-r--r--test/libapt/CMakeLists.txt55
1 files changed, 31 insertions, 24 deletions
diff --git a/test/libapt/CMakeLists.txt b/test/libapt/CMakeLists.txt
index f5cc91d44..11d4d22c7 100644
--- a/test/libapt/CMakeLists.txt
+++ b/test/libapt/CMakeLists.txt
@@ -1,28 +1,35 @@
-set(PROJECT_TEST_LIBRARIES apt-private)
-find_path(GTEST_ROOT src/gtest.cc
- /usr/src/googletest
- /usr/src/gtest
-)
-find_package(GTest)
-set(GTEST_DEPENDENCIES)
-
-if(NOT GTEST_FOUND AND EXISTS ${GTEST_ROOT})
- include(ExternalProject)
- ExternalProject_Add(gtest PREFIX ./gtest
- SOURCE_DIR ${GTEST_ROOT}
- INSTALL_COMMAND true)
-
- link_directories(${CMAKE_CURRENT_BINARY_DIR}/gtest/src/gtest-build)
-
- set(GTEST_LIBRARIES "-lgtest")
- set(GTEST_DEPENDENCIES "gtest")
- set(GTEST_FOUND TRUE)
- find_path(GTEST_INCLUDE_DIRS NAMES gtest/gtest.h PATHS ${GTEST_ROOT}/include)
-
- message(STATUS "Found GTest at ${GTEST_ROOT}, headers at ${GTEST_INCLUDE_DIRS}")
-endif()
+if (WITH_TESTS)
+ set(PROJECT_TEST_LIBRARIES apt-private)
+ find_path(GTEST_ROOT src/gtest.cc
+ /usr/src/googletest/googletest
+ /usr/src/googletest
+ /usr/src/gtest
+ )
+ find_package(GTest)
+ set(GTEST_DEPENDENCIES)
+
+ if(NOT GTEST_FOUND AND EXISTS ${GTEST_ROOT})
+ include(ExternalProject)
+ ExternalProject_Add(gtest PREFIX ./gtest
+ SOURCE_DIR ${GTEST_ROOT}
+ INSTALL_COMMAND true)
+
+ link_directories(${CMAKE_CURRENT_BINARY_DIR}/gtest/src/gtest-build)
+ link_directories(${CMAKE_CURRENT_BINARY_DIR}/gtest/src/gtest-build/lib)
+
+ set(GTEST_LIBRARIES "-lgtest")
+ set(GTEST_DEPENDENCIES "gtest")
+ set(GTEST_FOUND TRUE)
+ find_path(GTEST_INCLUDE_DIRS NAMES gtest/gtest.h PATHS ${GTEST_ROOT}/include)
+
+ message(STATUS "Found GTest at ${GTEST_ROOT}, headers at ${GTEST_INCLUDE_DIRS}")
+ endif()
+
+ if (NOT GTEST_FOUND)
+ message(FATAL_ERROR "Could not find GTest")
+ endif()
+
-if(GTEST_FOUND)
# gtest produces some warnings with the set of warnings we activate,
# so disable the offending warnings while compiling tests for now
add_optional_compile_options(Wno-undef)