VS 2019 中的 CMake 和 GTest 测试构建失败

CMake and GTest in VS 2019 test building failure

不知何故,我遇到了与上次相同的问题see here,这次我无法解决。 我有我的 CMakeLists.txt 文件:

cmake_minimum_required (VERSION 3.20)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_TOOLCHAIN_FILE "C:/Users/JackOfShadows/vcpkg/scripts/buildsystems/vcpkg.cmake")

project ("CMakeProject1")

find_package(GTest CONFIG REQUIRED)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

add_executable (CMakeProject1 "main.cpp" TestClass.cpp TestClass.h)
target_link_libraries (CMakeProject1
    PRIVATE GTest::gmock GTest::gtest GTest::gmock_main GTest::gtest_main
)

enable_testing()
find_package(GTest CONFIG REQUIRED)
add_executable(SomeTests
    "AppTests.cpp" TestClass.cpp TestClass.h
)

target_link_libraries (SomeTests
    PRIVATE GTest::gmock GTest::gtest GTest::gmock_main GTest::gtest_main
)

include (GoogleTest)
gtest_discover_tests(SomeTests)

它按预期构建和链接。但是 AppTests.cpp:

中没有发现测试
#include <gtest/gtest.h>

namespace SomeNamespaceTests {
    // Demonstrate some basic assertions.

    TEST(HelloTest, BasicAssertions) {

        // Expect two strings not to be equal.
        EXPECT_STRNE("hello", "world");
        // Expect equality.
        EXPECT_EQ(7 * 6, 42);
    }
}

根据@local_ninja 的建议,我只将项目链接到 gtest_main,现在测试 运行 没问题。