Преглед изворни кода

FindGTest: Add GTest::{gtest,gtest_main} library names

This introduces 2 new INTERFACE IMPORTED libraries: GTest::gtest and
GTest::gtest_main. They link to GTest::GTest and GTest::Main targets
respectively, therefore working as aliases. These new names map the
names of the targets from upstream GTest's CMake package config.

Fixes: #20255
Paweł Bylica пре 5 година
родитељ
комит
fbd3ea2047
2 измењених фајлова са 15 додато и 0 уклоњено
  1. 11 0
      Modules/FindGTest.cmake
  2. 4 0
      Tests/FindGTest/Test/CMakeLists.txt

+ 11 - 0
Modules/FindGTest.cmake

@@ -240,4 +240,15 @@ if(GTEST_FOUND)
         __gtest_import_library(GTest::Main GTEST_MAIN_LIBRARY "RELEASE")
         __gtest_import_library(GTest::Main GTEST_MAIN_LIBRARY "DEBUG")
     endif()
+
+    # Add targets mapping the same library names as defined in
+    # GTest's CMake package config.
+    if(NOT TARGET GTest::gtest)
+        add_library(GTest::gtest INTERFACE IMPORTED)
+        target_link_libraries(GTest::gtest INTERFACE GTest::GTest)
+    endif()
+    if(NOT TARGET GTest::gtest_main)
+        add_library(GTest::gtest_main INTERFACE IMPORTED)
+        target_link_libraries(GTest::gtest_main INTERFACE GTest::Main)
+    endif()
 endif()

+ 4 - 0
Tests/FindGTest/Test/CMakeLists.txt

@@ -8,6 +8,10 @@ add_executable(test_gtest_tgt main.cxx)
 target_link_libraries(test_gtest_tgt GTest::Main)
 add_test(NAME test_gtest_tgt COMMAND test_gtest_tgt)
 
+add_executable(test_gtest_tgt_upstream main.cxx)
+target_link_libraries(test_gtest_tgt_upstream GTest::gtest_main)
+add_test(NAME test_gtest_tgt_upstream COMMAND test_gtest_tgt_upstream)
+
 add_executable(test_gtest_var main.cxx)
 target_include_directories(test_gtest_var PRIVATE ${GTEST_INCLUDE_DIRS})
 target_link_libraries(test_gtest_var PRIVATE ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})