添加 tests/CMakeList.txt

This commit is contained in:
root 2026-04-27 04:54:10 +00:00
parent aa1d62a53b
commit 6c09cb9292
1 changed files with 30 additions and 0 deletions

30
tests/CMakeList.txt Normal file
View File

@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.10.0)
project(test_main)
include(FetchContent)
if (MSVC)
add_compile_options(/utf-8)
endif()
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_SOURCE_DIR}/include)
#include_directories(D:/workspace/googletest-demo/test_main)
#add_executable(demo max.cpp main.cpp)
# 调用 find_package它会使用你提供的变量
find_package(GTest REQUIRED)
include(CTest)
enable_testing()
add_executable(test_main test_app.cpp ../src/app.cpp)
target_link_libraries(test_main gtest gmock gtest_main)
include(GoogleTest)
gtest_discover_tests(test_main)