fix(tests): Compile gtest at configure time

Ubuntu (and thus travis CI) doesn't have the gtest library in its repos,
only the header files and according to [1], gtest should be compiled in
every project anyways

[1]: https://github.com/google/googletest/blob/master/googletest/docs/FAQ.md#why-is-it-not-recommended-to-install-a-pre-compiled-copy-of-google-test-for-example-into-usrlocal
This commit is contained in:
patrick96 2018-04-07 23:35:47 +02:00 committed by Patrick Ziegler
parent c865add821
commit eed4d3ffc8
3 changed files with 46 additions and 5 deletions

View File

@ -35,7 +35,6 @@ addons:
- python-xcbgen - python-xcbgen
- xcb-proto - xcb-proto
- xutils-dev - xutils-dev
- libgtest0
- libgtest-dev - libgtest-dev
env: env:

View File

@ -7,8 +7,36 @@ include_directories(${dirs})
include_directories(${PROJECT_SOURCE_DIR}/src) include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${CMAKE_CURRENT_LIST_DIR}) include_directories(${CMAKE_CURRENT_LIST_DIR})
find_package(PkgConfig REQUIRED) message(STATUS "BIN ${CMAKE_BINARY_DIR}")
pkg_check_modules(GTEST REQUIRED gtest)
# Download and unpack googletest at configure time {{{
configure_file(
CMakeLists.txt.in
${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt
)
execute_process( COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download)
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
# }}}
function(unit_test file tests) function(unit_test file tests)
set(multi_value_args SOURCES) set(multi_value_args SOURCES)
@ -27,8 +55,7 @@ function(unit_test file tests)
add_executable(${name} unit_tests/${file}.cpp ${sources}) add_executable(${name} unit_tests/${file}.cpp ${sources})
# Link against googletest # Link against googletest
target_link_libraries(${name} ${GTEST_LDFLAGS}) target_link_libraries(${name} gtest_main)
target_compile_options(${name} PUBLIC ${GTEST_CFLAGS})
add_test(NAME ${name} COMMAND ${name}) add_test(NAME ${name} COMMAND ${name})

15
tests/CMakeLists.txt.in Normal file
View File

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 2.8.2)
project(googletest-download NONE)
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)