How to make GTest build /MDd (instead of /MTd) by default, using CMake?

前端 未结 4 541
一向
一向 2020-12-06 05:53

I am trying to integrate GTest with CMake as seamlessly as possible. But the default build type for my test projects are /MDd

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-06 06:24

    We solved the problem by bypassing GTest's own build system and compiling GTest as a CMake object library from its unity build source file gtest-all.cc:

    # compile Google Test as an object library
    add_library(gtest OBJECT "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.6.0/src/gtest-all.cc")
    set_property(TARGET gtest PROPERTY INCLUDE_DIRECTORIES
        "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.6.0"
        "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.6.0/include")
    

    That way GTest will always be compiled with the same options that we use for the project. A test executable that uses GTest can then be built in the following way:

    add_executable(test_executable ${TESTS_SRC} $)
    add_test(NAME test COMMAND test_executable)
    

提交回复
热议问题