Skip to content

Commit

Permalink
fix building GTEST_SOURCE passed directly
Browse files Browse the repository at this point in the history
Fix issue #4 when specifying GTEST_SOURCE result in failure to link with
gtest.
Nikolay Orliuk committed Sep 1, 2014
1 parent 2321190 commit bff2bfc
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions cmake_modules/FindGTest.cmake
Original file line number Diff line number Diff line change
@@ -158,23 +158,21 @@ else()
PATHS /usr/src/gtest
DOC "Source code for GTest"
ONLY_CMAKE_FIND_ROOT_PATH)
if(GTEST_SOURCE STREQUAL GTEST_SOURCE-NOTFOUND)
# fallback to libraries
_gtest_find_library(GTEST_LIBRARY gtest)
_gtest_find_library(GTEST_LIBRARY_DEBUG gtestd)
_gtest_find_library(GTEST_MAIN_LIBRARY gtest_main)
_gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_maind)
else()
message(STATUS "Found GTest sources: ${GTEST_SOURCE}")
add_subdirectory(${GTEST_SOURCE} ${CMAKE_BINARY_DIR}/imported-gtest EXCLUDE_FROM_ALL)
set(GTEST_LIBRARY gtest CACHE INTERNAL "GTest library")
set(GTEST_MAIN_LIBRARY gtest_main CACHE INTERNAL "GTest library for main()")
mark_as_advanced(GTEST_LIBRARY)
mark_as_advanced(GTEST_MAIN_LIBRARY)
endif()
endif()
if(NOT GTEST_SOURCE STREQUAL GTEST_SOURCE-NOTFOUND)
link_directories(${CMAKE_BINARY_DIR}/imported-gtest)
if(GTEST_SOURCE STREQUAL GTEST_SOURCE-NOTFOUND)
# fallback to libraries
_gtest_find_library(GTEST_LIBRARY gtest)
_gtest_find_library(GTEST_LIBRARY_DEBUG gtestd)
_gtest_find_library(GTEST_MAIN_LIBRARY gtest_main)
_gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_maind)
else()
message(STATUS "Found GTest sources: ${GTEST_SOURCE}")
add_subdirectory(${GTEST_SOURCE} ${CMAKE_BINARY_DIR}/imported-gtest EXCLUDE_FROM_ALL)
#link_directories(${CMAKE_BINARY_DIR}/imported-gtest)
set(GTEST_LIBRARY gtest CACHE INTERNAL "GTest library")
set(GTEST_MAIN_LIBRARY gtest_main CACHE INTERNAL "GTest library for main()")
mark_as_advanced(GTEST_LIBRARY)
mark_as_advanced(GTEST_MAIN_LIBRARY)
endif()
endif()

0 comments on commit bff2bfc

Please sign in to comment.