Commit 68e22894 by Eric Fiselier

Fix #538 - gtest.h not found when building with older CMake versions.

Older CMake versions, in particular 2.8, don't seem to correctly handle interface include directories. This causes failures when building the tests. Additionally, older CMake versions use a different library install directory than expected (i.e. they use lib/<target-triple>). This caused certain tests to fail to link. This patch fixes both those issues. The first by manually adding the correct include directory when building the tests. The second by specifying the library output directory when configuring the GTest build.
parent 674d0498
...@@ -31,8 +31,14 @@ macro(build_external_gtest) ...@@ -31,8 +31,14 @@ macro(build_external_gtest)
list(APPEND GTEST_FLAGS "-Wno-unused-function") list(APPEND GTEST_FLAGS "-Wno-unused-function")
endif() endif()
split_list(GTEST_FLAGS) split_list(GTEST_FLAGS)
set(EXCLUDE_FROM_ALL_OPT "")
set(EXCLUDE_FROM_ALL_VALUE "")
if (${CMAKE_VERSION} VERSION_GREATER "3.0.99")
set(EXCLUDE_FROM_ALL_OPT "EXCLUDE_FROM_ALL")
set(EXCLUDE_FROM_ALL_VALUE "ON")
endif()
ExternalProject_Add(googletest ExternalProject_Add(googletest
EXCLUDE_FROM_ALL ON ${EXCLUDE_FROM_ALL_OPT} ${EXCLUDE_FROM_ALL_VALUE}
GIT_REPOSITORY https://github.com/google/googletest.git GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master GIT_TAG master
PREFIX "${CMAKE_BINARY_DIR}/googletest" PREFIX "${CMAKE_BINARY_DIR}/googletest"
...@@ -42,6 +48,7 @@ macro(build_external_gtest) ...@@ -42,6 +48,7 @@ macro(build_external_gtest)
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_INSTALL_LIBDIR:PATH=<INSTALL_DIR>/lib
-DCMAKE_CXX_FLAGS:STRING=${GTEST_FLAGS} -DCMAKE_CXX_FLAGS:STRING=${GTEST_FLAGS}
-Dgtest_force_shared_crt:BOOL=ON -Dgtest_force_shared_crt:BOOL=ON
) )
...@@ -69,7 +76,7 @@ macro(build_external_gtest) ...@@ -69,7 +76,7 @@ macro(build_external_gtest)
add_dependencies(gtest googletest) add_dependencies(gtest googletest)
add_dependencies(gtest_main googletest) add_dependencies(gtest_main googletest)
set(GTEST_BOTH_LIBRARIES gtest gtest_main) set(GTEST_BOTH_LIBRARIES gtest gtest_main)
#set(GTEST_INCLUDE_DIRS ${install_dir}/include) set(GTEST_INCLUDE_DIRS ${install_dir}/include)
endmacro(build_external_gtest) endmacro(build_external_gtest)
if (BENCHMARK_ENABLE_GTEST_TESTS) if (BENCHMARK_ENABLE_GTEST_TESTS)
......
...@@ -144,8 +144,11 @@ if (BENCHMARK_ENABLE_GTEST_TESTS) ...@@ -144,8 +144,11 @@ if (BENCHMARK_ENABLE_GTEST_TESTS)
if (TARGET googletest) if (TARGET googletest)
add_dependencies(${name} googletest) add_dependencies(${name} googletest)
endif() endif()
if (GTEST_INCLUDE_DIRS)
target_include_directories(${name} PRIVATE ${GTEST_INCLUDE_DIRS})
endif()
target_link_libraries(${name} benchmark target_link_libraries(${name} benchmark
"${GTEST_BOTH_LIBRARIES}" ${CMAKE_THREAD_LIBS_INIT}) ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endmacro(compile_gtest) endmacro(compile_gtest)
macro(add_gtest name) macro(add_gtest name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment