build: enhance CMakeLists for MSVC and test linking

- Updated MSVC runtime library setting to support both Debug and Release configurations.
- Added specific compiler flags for Release and Debug builds.
- Included gmock and gmock_main in the test executable linking to ensure comprehensive testing capabilities.
This commit is contained in:
Yanyi Wu 2025-05-02 22:49:55 +08:00
parent 9f7e37c50b
commit 5928872950

View File

@ -1,8 +1,10 @@
message(STATUS "MSVC value: ${MSVC}") message(STATUS "MSVC value: ${MSVC}")
if (MSVC) if (MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebugDLL") set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_compile_options(/utf-8) add_compile_options(/utf-8)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
endif() endif()
include(FetchContent) include(FetchContent)
@ -40,7 +42,7 @@ ADD_EXECUTABLE(test.run
textrank_test.cpp textrank_test.cpp
) )
TARGET_LINK_LIBRARIES(test.run gtest gtest_main) TARGET_LINK_LIBRARIES(test.run gtest gtest_main gmock gmock_main)
enable_testing() enable_testing()
ADD_TEST(NAME test.run COMMAND test.run) ADD_TEST(NAME test.run COMMAND test.run)