如何在默认情况下使用CMake构建/ MDd(而不是/ MTd)? [英] How to make GTest build /MDd (instead of /MTd) by default, using CMake?

查看:1570
本文介绍了如何在默认情况下使用CMake构建/ MDd(而不是/ MTd)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尽可能无缝地整合 GTest CMake 。但是我的测试项目的默认生成类型是 / MDd ,GTest默认为 / MTd 。我手动更改GTest项目属性以产生调试DLL。



但每次我对 CMakeLists.txt ,GTest默认为 / MTd

我们通过绕过GTest自己的构建系统并编译GTest作为一个解决方案,解决了这个问题。 http://www.cmake.org/cmake/help/v2.8.9/cmake.html#command%3aadd_library =nofollow> CMake对象库从其统一构建源文件 gtest-all.cc

 #将Google Test作为对象库编译
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)

这样GTest将总是编译与我们用于项目相同的选项。
使用GTest的测试可执行文件可以通过以下方式构建:

  add_executable(test_executable $ {TESTS_SRC} $< TARGET_OBJECTS:gtest>)
add_test(NAME test COMMAND test_executable)


I am trying to integrate GTest with CMake as seamlessly as possible. But the default build type for my test projects are /MDd and GTest defaults to /MTd. I am manually changing GTest project properties to emit debug DLL.

But every time I make changes to my CMakeLists.txt, GTest defaults back to /MTd. How do I stop this?

解决方案

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} $<TARGET_OBJECTS:gtest>)
add_test(NAME test COMMAND test_executable)

这篇关于如何在默认情况下使用CMake构建/ MDd(而不是/ MTd)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆