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:
parent
c865add821
commit
eed4d3ffc8
@ -35,7 +35,6 @@ addons:
|
||||
- python-xcbgen
|
||||
- xcb-proto
|
||||
- xutils-dev
|
||||
- libgtest0
|
||||
- libgtest-dev
|
||||
|
||||
env:
|
||||
|
@ -7,8 +7,36 @@ include_directories(${dirs})
|
||||
include_directories(${PROJECT_SOURCE_DIR}/src)
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(GTEST REQUIRED gtest)
|
||||
message(STATUS "BIN ${CMAKE_BINARY_DIR}")
|
||||
|
||||
# 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)
|
||||
set(multi_value_args SOURCES)
|
||||
@ -27,8 +55,7 @@ function(unit_test file tests)
|
||||
add_executable(${name} unit_tests/${file}.cpp ${sources})
|
||||
|
||||
# Link against googletest
|
||||
target_link_libraries(${name} ${GTEST_LDFLAGS})
|
||||
target_compile_options(${name} PUBLIC ${GTEST_CFLAGS})
|
||||
target_link_libraries(${name} gtest_main)
|
||||
|
||||
add_test(NAME ${name} COMMAND ${name})
|
||||
|
||||
|
15
tests/CMakeLists.txt.in
Normal file
15
tests/CMakeLists.txt.in
Normal 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 ""
|
||||
)
|
Loading…
Reference in New Issue
Block a user