Skip to content

Commit

Permalink
Prefer prebuilt gtest libraries and fallback to sources
Browse files Browse the repository at this point in the history
Source-only gtest is available on Trusty (14.04) and prebuilt packages
are available on Focal (20.04).

Also simplifies test matrix for Travis CI.
  • Loading branch information
Chih-Hsuan Yen committed Jul 9, 2020
1 parent 2e8f194 commit d199ecb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
22 changes: 13 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: cpp

os:
- linux
- osx
os: linux

env:
matrix:
Expand All @@ -11,18 +9,24 @@ env:
- CTEST_OUTPUT_ON_FAILURE=1 OPTION='-DCMAKE_CXX_FLAGS=-O0 -DENABLE_GCOV=yes' COVERALLS=yes

matrix:
exclude:
include:
# To test source-only gtest/gmock packages
- os: linux
dist: xenial
env: CTEST_OUTPUT_ON_FAILURE=1
- os: linux
dist: bionic
env: CTEST_OUTPUT_ON_FAILURE=1
- os: linux
- os: osx
env: CTEST_OUTPUT_ON_FAILURE=1 CFLAGS='-fsanitize=address'
- os: osx
env: CTEST_OUTPUT_ON_FAILURE=1 OPTION='-DCMAKE_CXX_FLAGS=-O0 -DENABLE_GCOV=yes' COVERALLS=yes
env: CTEST_OUTPUT_ON_FAILURE=1

git:
depth: 1

# opt-in Ubuntu Trusty
# opt-in Ubuntu Focal
sudo: required
dist: xenial
dist: focal
cache: ccache

install:
Expand Down
23 changes: 20 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,25 @@ endif()

# testing
enable_testing()
find_package(GTest REQUIRED)
find_package(GTest)
if (GTEST_FOUND AND FALSE)
set(GTEST_LIBS GTest::GTest GTest::Main)
else()
# /usr/src/googletest is used by Ubuntu 18.04
# /usr/src/gtest is used by Ubuntu 16.04
foreach (GTEST_DIR /usr/src/googletest /usr/src/gtest)
message(STATUS "Checking gtest in ${GTEST_DIR}")
if (EXISTS ${GTEST_DIR})
add_subdirectory(${GTEST_DIR} gtest)
set(GTEST_LIBS gtest gtest_main)
break()
endif()
endforeach()
endif()

if (NOT DEFINED GTEST_LIBS)
message(SEND_ERROR "Unable to find gtest")
endif()

file(GLOB run-test_src
test/*.cpp
Expand All @@ -262,8 +280,7 @@ add_executable(run-test
${run-test_src}
)
target_link_libraries(run-test
GTest::GTest
GTest::Main
${GTEST_LIBS}

exporter
importer
Expand Down

0 comments on commit d199ecb

Please sign in to comment.