Use GTest imported target in tests/CMakelists.txt

parent c065b648
...@@ -102,8 +102,6 @@ if (PISTACHE_BUILD_TESTS) ...@@ -102,8 +102,6 @@ if (PISTACHE_BUILD_TESTS)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}) add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif() endif()
endif() endif()
enable_testing()
add_subdirectory(tests) add_subdirectory(tests)
endif() endif()
......
...@@ -5,8 +5,13 @@ function(pistache_test test_name) ...@@ -5,8 +5,13 @@ function(pistache_test test_name)
set(TEST_SOURCE ${test_name}.cc) set(TEST_SOURCE ${test_name}.cc)
add_executable(${TEST_EXECUTABLE} ${TEST_SOURCE}) add_executable(${TEST_EXECUTABLE} ${TEST_SOURCE})
target_include_directories(${TEST_EXECUTABLE} PRIVATE ${GTEST_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS}) target_include_directories(${TEST_EXECUTABLE} PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(${TEST_EXECUTABLE} gtest gtest_main pistache_static ${CURL_LIBRARIES}) # CMake 3.20 and upstream GTest define GTest::gtest, older versions define GTest::GTest
if (TARGET GTest::gtest)
target_link_libraries(${TEST_EXECUTABLE} GTest::gtest GTest::gtest_main pistache_static ${CURL_LIBRARIES})
else ()
target_link_libraries(${TEST_EXECUTABLE} GTest::GTest GTest::Main pistache_static ${CURL_LIBRARIES})
endif ()
add_test(${test_name} ${TEST_EXECUTABLE}) add_test(${test_name} ${TEST_EXECUTABLE})
endfunction() endfunction()
......
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