From cf2321196a64dbf6ae2f480f1acf2e17e1dce1c7 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 2 Dec 2022 14:49:36 +0100 Subject: [PATCH] Test: [skip ci] fix linking errors of Google tests with MSVC --- tests/CMakeLists.txt | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7ddf4a9452..b123414bc8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,37 @@ # 'Google_test' is the subproject name project(Google_tests) +if(WIN32) + add_definitions(-DCOIN_DLL) +endif(WIN32) + +if(MSVC) + option( + gtest_force_shared_crt + "Use shared (DLL) run-time lib even when Google Test is built as static lib." + ON) + + set(Google_Tests_LIBS + oldnames.lib + debug msvcrtd.lib + debug msvcprtd.lib + optimized msvcrt.lib + optimized msvcprt.lib + ) + + #Universal C runtime introduced in VS 2015 (cl version 19) + if (NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19")) + list(APPEND Google_Tests_LIBS + debug vcruntimed.lib + debug ucrtd.lib + debug concrtd.lib + optimized vcruntime.lib + optimized ucrt.lib + optimized concrt.lib + ) + endif() +endif() + # 'lib' is the folder with Google Test sources add_subdirectory(lib) include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) @@ -14,7 +45,7 @@ add_executable( src/test2.cpp ) -target_link_libraries(Google_Tests_run gtest gtest_main) +target_link_libraries(Google_Tests_run gtest gtest_main ${Google_Tests_LIBS}) # ------------------------------------------------------