Skip to content

Commit

Permalink
Use external gtest by default when detected
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Feb 1, 2022
1 parent ab50434 commit e3efedd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/clang_linux/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
apt-get update -y
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
sudo autoconf automake libtool clang++-10 python3-clang-10 make cmake ccache pkg-config tar zip \
sqlite3 libsqlite3-dev libtiff-dev libcurl4-openssl-dev jq python3-pip nlohmann-json3-dev
sqlite3 libsqlite3-dev libtiff-dev libcurl4-openssl-dev jq python3-pip nlohmann-json3-dev libgtest-dev

python3 -m pip install --user jsonschema
export PATH=$HOME/.local/bin:$PATH
Expand Down
20 changes: 18 additions & 2 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
# CMake configuration for PROJ unit tests

option(USE_EXTERNAL_GTEST "Compile against external GTest" OFF)
find_package(GTest 1.8.1)
if(GTest_FOUND)
option(USE_EXTERNAL_GTEST "Compile against external GTest" ON)
else()
option(USE_EXTERNAL_GTEST "Compile against external GTest" OFF)
endif()

if(USE_EXTERNAL_GTEST)

if(NOT GTest_FOUND)
message(FATAL_ERROR "External GTest >= 1.8.1 not found")
endif()
message(STATUS "Using external GTest")
find_package(GTest 1.8.1 CONFIG REQUIRED)

# CMake < 3.20.0 uses GTest::GTest
# CMake >= 3.20 uses GTest::gtest, and deprecates GTest::GTest
# so for older CMake, create an alias from GTest::GTest to GTest::gtest
if(NOT TARGET GTest::gtest)
add_library(GTest::gtest INTERFACE IMPORTED)
set_target_properties(GTest::gtest PROPERTIES
INTERFACE_LINK_LIBRARIES "GTest::GTest")
endif()

else()

Expand Down

0 comments on commit e3efedd

Please sign in to comment.