summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2016-09-02 14:09:52 +0200
committerJulian Andres Klode <jak@debian.org>2016-09-02 14:34:37 +0200
commit99ba7cc1901c761c97d67775f23858b86594f2ba (patch)
treeec81643ec047aacd8d43abd4ed8912265e6729c6
parent7cdb840725d46a1524ec37e90902196735aa6a57 (diff)
CMake: test/libapt: Use a prebuilt GTest library if available
If a non-existing source directory is specified, try finding the system gtest library. Debian derived distributions are a bit strange because they only ship the source code and not the library...
-rw-r--r--test/libapt/CMakeLists.txt41
1 files changed, 26 insertions, 15 deletions
diff --git a/test/libapt/CMakeLists.txt b/test/libapt/CMakeLists.txt
index 7f9990526..f3df14848 100644
--- a/test/libapt/CMakeLists.txt
+++ b/test/libapt/CMakeLists.txt
@@ -1,22 +1,33 @@
-include(ExternalProject)
-
set(GTEST_ROOT "/usr/src/gtest" CACHE FILEPATH "Path to GTest CMake project")
-message(STATUS "Found GTest at ${GTEST_ROOT}")
+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)
-if (EXISTS ${GTEST_ROOT})
+ link_directories(${CMAKE_CURRENT_BINARY_DIR}/gtest/src/gtest-build)
-ExternalProject_Add(gtest PREFIX ./gtest
- SOURCE_DIR ${GTEST_ROOT}
- INSTALL_COMMAND true)
+ set(GTEST_LIBRARIES "-lgtest")
+ set(GTEST_DEPENDENCIES "gtest")
+ set(GTEST_FOUND TRUE)
+ find_path(GTEST_INCLUDE_DIRS NAMES gtest/gtest.h)
-link_directories(${CMAKE_CURRENT_BINARY_DIR}/gtest/src/gtest-build)
-FILE(GLOB files gtest_runner.cc *-helpers.cc *_test.cc)
-add_executable(libapt_test ${files})
-target_link_libraries(libapt_test -lgtest ${CMAKE_THREAD_LIBS_INIT} apt-private apt-inst)
-add_dependencies(libapt_test gtest)
-add_test(NAME AptTests
- COMMAND libapt_test
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+ message(STATUS "Found GTest at ${GTEST_ROOT}, headers at ${GTEST_INCLUDE_DIRS}")
+endif()
+if(GTEST_FOUND)
+ 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()