Skip to content

Commit

Permalink
Introduce option to select default gtest installation. Refs Tencent#309
Browse files Browse the repository at this point in the history
This will introduce RAPIDJSON_BUILD_THIRDPARTY_GTEST option. If it is set to
TRUE, cmake will look for GTest installation in `thirdparty/gtest` before
looking in other places.

Current default value (OFF) for RAPIDJSON_BUILD_THIRDPARTY_GTEST represents
previous behaviour when system-wide gtest installation is used whenever
possible.

This commit will as well eliminate problem described in Tencent#309 when source
directory found is `thirdparty/gtest` while include files are found
system-wide. This however won't give the user possibility to select gtest
installation to use.
  • Loading branch information
jollyroger committed Apr 21, 2015
1 parent 8d39282 commit 04b6736
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -17,6 +17,8 @@ SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
option(RAPIDJSON_BUILD_DOC "Build rapidjson documentation." ON)
option(RAPIDJSON_BUILD_EXAMPLES "Build rapidjson examples." ON)
option(RAPIDJSON_BUILD_TESTS "Build rapidjson perftests and unittests." ON)
option(RAPIDJSON_BUILD_THIRDPARTY_GTEST
"Use gtest installation in `thirdparty/gtest` by default if available" OFF)

option(RAPIDJSON_HAS_STDSTRING "" OFF)
if(RAPIDJSON_HAS_STDSTRING)
Expand Down
8 changes: 7 additions & 1 deletion CMakeModules/FindGTestSrc.cmake
@@ -1,9 +1,14 @@

SET(GTEST_SEARCH_PATH
"${GTEST_SOURCE_DIR}"
"${CMAKE_SOURCE_DIR}/thirdparty/gtest")

IF(UNIX)
LIST(INSERT GTEST_SEARCH_PATH 1 "/usr/src/gtest")
IF(RAPIDJSON_BUILD_THIRDPARTY_GTEST)
LIST(APPEND GTEST_SEARCH_PATH "/usr/src/gtest")
ELSE()
LIST(INSERT GTEST_SEARCH_PATH 1 "/usr/src/gtest")
ENDIF()
ENDIF()

FIND_PATH(GTEST_SOURCE_DIR
Expand All @@ -15,6 +20,7 @@ FIND_PATH(GTEST_SOURCE_DIR
FIND_PATH(GTEST_INCLUDE_DIR
NAMES gtest/gtest.h
PATH_SUFFIXES include
HINTS ${GTEST_SOURCE_DIR}
PATHS ${GTEST_SEARCH_PATH})

INCLUDE(FindPackageHandleStandardArgs)
Expand Down

0 comments on commit 04b6736

Please sign in to comment.