Use target gtest instead of GTEST_LIB and GTEST_INCLUDE_DIR

This simplifies usage of GoogleTest, since independent handling of
GTEST_LIB and GTEST_INCLUDE_DIR is not necessary anymore.

Additionally CMake creates a dependency now between target gtest and all
test applications using it. This improves build process when building
GoogleTest from source code. When any test application is built,
GoogleTest library is automatically rebuilt if necessary now for
instance.
This commit is contained in:
Christian Gruber
2019-08-18 00:30:42 +02:00
parent 7e71a9724f
commit b303fc6d99
5 changed files with 12 additions and 12 deletions

View File

@@ -82,6 +82,13 @@ if (GTEST_SRC_DIR)
target_compile_options(gtest PRIVATE -Wno-missing-declarations)
endif()
target_include_directories(gtest PUBLIC ${GTEST_INCLUDE_DIR} ${GTEST_SRC_DIR})
else()
add_library(gtest UNKNOWN IMPORTED GLOBAL)
set_target_properties(gtest PROPERTIES
IMPORTED_LOCATION ${GTEST_SHARED_LIB}
INTERFACE_INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIR}
INTERFACE_LINK_LIBRARIES ${GTEST_MAIN_LIB}
)
endif()
if (GMOCK_SRC_DIR)
set (lib_gmock_SOURCES ${GMOCK_SRC})