You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

45 lines
1.7 KiB

  1. set(PROJECT_TEST_LIBRARIES apt-private)
  2. find_path(GTEST_ROOT src/gtest.cc
  3. /usr/src/googletest/googletest
  4. /usr/src/gtest
  5. )
  6. find_package(GTest)
  7. set(GTEST_DEPENDENCIES)
  8. if(NOT GTEST_FOUND AND EXISTS ${GTEST_ROOT})
  9. include(ExternalProject)
  10. ExternalProject_Add(gtest PREFIX ./gtest
  11. SOURCE_DIR ${GTEST_ROOT}
  12. INSTALL_COMMAND true)
  13. link_directories(${CMAKE_CURRENT_BINARY_DIR}/gtest/src/gtest-build)
  14. set(GTEST_LIBRARIES "-lgtest")
  15. set(GTEST_DEPENDENCIES "gtest")
  16. set(GTEST_FOUND TRUE)
  17. find_path(GTEST_INCLUDE_DIRS NAMES gtest/gtest.h PATHS ${GTEST_ROOT}/include)
  18. message(STATUS "Found GTest at ${GTEST_ROOT}, headers at ${GTEST_INCLUDE_DIRS}")
  19. endif()
  20. if(GTEST_FOUND)
  21. # gtest produces some warnings with the set of warnings we activate,
  22. # so disable the offending warnings while compiling tests for now
  23. add_optional_compile_options(Wno-undef)
  24. add_optional_compile_options(Wno-ctor-dtor-privacy)
  25. # Definition of the C++ files used to build the test binary - note that this
  26. # is expanded at CMake time, so you have to rerun cmake if you add or remove
  27. # a file (you can just run cmake . in the build directory)
  28. file(GLOB files gtest_runner.cc *-helpers.cc *_test.cc)
  29. add_executable(lib${PROJECT_NAME}_test ${files})
  30. target_include_directories(lib${PROJECT_NAME}_test PRIVATE ${GTEST_INCLUDE_DIRS})
  31. target_link_libraries(lib${PROJECT_NAME}_test ${GTEST_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${PROJECT_TEST_LIBRARIES})
  32. if (GTEST_DEPENDENCIES)
  33. add_dependencies(lib${PROJECT_NAME}_test ${GTEST_DEPENDENCIES})
  34. endif()
  35. add_test(NAME ${PROJECT_NAME}Tests
  36. COMMAND lib${PROJECT_NAME}_test
  37. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  38. endif()