From e794fe0d01bac5264b708d9df5f6923940e52c54 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Fri, 31 Aug 2018 12:24:00 +0200
Subject: [PATCH] fix(gtest): prefer target_link_libraries
From commit 880896c6f4814f4c7798355a652dc6167be2b75f in googletest cmake
test configuration fails with errors like
CMake Error: install(EXPORT "gtestConfigInternal" ...) includes target
"gtest" which requires target "i3ipc++" that is not in the export set.
The issue was that link_libraries also affected the googletest internal
targets that came after it making the whole thing fail.
This could also have been solved by moving link_libraries after the
configuration of googletest but according to the cmake documentation [1]
target_link_libraries should be prefered over link_libraries anyways.
[1]: https://cmake.org/cmake/help/latest/command/link_libraries.html
Fixes #1393
---
tests/CMakeLists.txt | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 71069834..b3efec93 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -2,7 +2,6 @@
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage -Wno-missing-field-initializers")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
-link_libraries(${libs})
include_directories(${dirs})
include_directories(${CMAKE_CURRENT_LIST_DIR})
@@ -59,7 +58,7 @@ function(unit_test file tests)
add_executable(${name} unit_tests/${file}.cpp ${sources})
# Link against gmock (this automatically links against gtest)
- target_link_libraries(${name} gmock_main)
+ target_link_libraries(${name} gmock_main ${libs})
add_test(NAME ${name} COMMAND ${name})