Skip to content

Commit 563b39b

Browse files
cmake: add EXTERNAL_GTEST option
to allow disabling building the vendored copy of gtest, it's available on most platforms
1 parent dca6f4c commit 563b39b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cmake_minimum_required( VERSION 2.6 )
33
project( scitokens-cpp )
44

55
option( BUILD_UNITTESTS "Build the scitokens-cpp unit tests" OFF )
6+
option( EXTERNAL_GTEST "Use an external/pre-installed copy of GTest" OFF )
67

78
set( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake )
89

@@ -75,13 +76,14 @@ if (NOT DEFINED INCLUDE_INSTALL_DIR)
7576
endif()
7677

7778
if( BUILD_UNITTESTS )
78-
79+
if( NOT EXTERNAL_GTEST )
7980
include(ExternalProject)
8081
ExternalProject_Add(gtest
8182
PREFIX external/gtest
82-
URL file://${PROJECT_SOURCE_DIR}/vendor/gtest
83+
URL ${CMAKE_CURRENT_SOURCE_DIR}/vendor/gtest
8384
INSTALL_COMMAND :
8485
)
86+
endif()
8587
enable_testing()
8688
add_subdirectory(test)
8789
endif()

test/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ add_executable(scitokens-gtest main.cpp)
33
add_dependencies(scitokens-gtest gtest)
44
include_directories("${PROJECT_SOURCE_DIR}/vendor/gtest/googletest/include")
55

6-
target_link_libraries(scitokens-gtest SciTokens "${CMAKE_BINARY_DIR}/external/gtest/src/gtest-build/lib/libgtest.a" -lpthread)
6+
if(EXTERNAL_GTEST)
7+
set(LIBGTEST "gtest")
8+
else()
9+
set(LIBGTEST "${CMAKE_BINARY_DIR}/external/gtest/src/gtest-build/lib/libgtest.a")
10+
endif()
11+
12+
target_link_libraries(scitokens-gtest SciTokens "${LIBGTEST}" pthread)
713

814
add_test(
915
NAME

0 commit comments

Comments
 (0)