blob: cc1d024f8ffa30644abcbd329ad4614fca57711e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
find_path(GTEST_ROOT src/gtest.cc
/usr/src/googletest/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(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)
add_optional_compile_options(Wno-ctor-dtor-privacy)
# Definition of the C++ files used to build the test binary - note that this
# is expanded at CMake time, so you have to rerun cmake if you add or remove
# a file (you can just run cmake . in the build directory)
file(GLOB files gtest_runner.cc *-helpers.cc *_test.cc)
add_executable(libapt_test ${files})
target_include_directories(libapt_test PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(libapt_test ${GTEST_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} apt-private apt-inst)
if (GTEST_DEPENDENCIES)
add_dependencies(libapt_test ${GTEST_DEPENDENCIES})
endif()
add_test(NAME AptTests
COMMAND libapt_test
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
|