[flang] Harmonize standalone gtest support with other projects

Use the CMake rules of unittest libraries via `add_subdirectory()`
when using standalone builds, similarly to how e.g. Clang does that.
Besides making things more consistent, I hope this also unblocks D137035
and effectively we'll be able to simplify things further and have LLVM
semi-automatically include gtest support for us in the future.

Differential Revision: https://reviews.llvm.org/D138573
This commit is contained in:
Michał Górny 2022-11-23 16:07:03 +01:00
parent 12ebfca621
commit 02a2e18e60

View file

@ -153,23 +153,7 @@ if (FLANG_STANDALONE_BUILD)
set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
if (NOT TARGET llvm_gtest)
add_library(llvm_gtest
${UNITTEST_DIR}/googletest/src/gtest-all.cc
${UNITTEST_DIR}/googlemock/src/gmock-all.cc
)
target_include_directories(llvm_gtest
PUBLIC
"${UNITTEST_DIR}/googletest/include"
"${UNITTEST_DIR}/googlemock/include"
PRIVATE
"${UNITTEST_DIR}/googletest"
"${UNITTEST_DIR}/googlemock"
)
find_package(Threads)
target_link_libraries(llvm_gtest PUBLIC Threads::Threads)
add_library(llvm_gtest_main ${UNITTEST_DIR}/UnitTestMain/TestMain.cpp)
target_link_libraries(llvm_gtest_main PUBLIC llvm_gtest)
add_subdirectory(${UNITTEST_DIR} third-party/unittest)
endif()
set(FLANG_GTEST_AVAIL 1)
else()