【发布时间】:2016-03-28 15:26:48
【问题描述】:
有很多关于如何从 CMake 在 Visual Studio 中设置运行时库的帖子,但就我而言,Visual Studio 似乎忽略了我的设置。
我想用/MD 构建google-mock。这是项目中的默认设置。
在一个新的构建目录中,构建:
cmake -G "Visual Studio 12 2013" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=C:\Users\mrussell\workspace\opal2\o2win32\Libs\gtest\"1.7.0" -DCMAKE_CXX_FLAGS_RELEASE="/MD /O2 /Ob2 /D NDEBUG" ../googlemock
我所有的 cmake 变量似乎都是正确的
但是,当我通过命令行(我习惯于 linux..)或 Visual Studio 进行构建时,它使用 /MT 标志。
我的构建命令(针对 32 位):
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
msbuild /m:4 /property:Configuration=%build_type% ALL_BUILD.vcxproj
输出:
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /IC:\Users\mrussell\workspace\opal2\o2win32\Libs\gtest\g
test\include /IC:\Users\mrussell\workspace\opal2\o2win32\Libs\gtest\gtest /Zi /nologo /W4 /WX /O2 /Ob2 /Oy- /D WIN32 /D _WIND
OWS /D NDEBUG /D WIN32 /D _WINDOWS /D _UNICODE /D UNICODE /D WIN32 /D _WIN32 /D STRICT /D WIN32_LEAN_AND_MEAN /D GTEST_HAS_PT
HREAD=0 /D _HAS_EXCEPTIONS=1 /D "CMAKE_INTDIR=\"Release\"" /D _UNICODE /D UNICODE /Gm- /EHsc /MT /GS /fp:precise /Zc:wchar_t
/Zc:forScope /GR /Fo"gtest.dir\Release\\" /Fd"gtest.dir\Release\vc120.pdb" /Gd /TP /wd4127 /wd4251 /wd4275 /analyze- /errorRe
port:queue -J "C:\Users\mrussell\workspace\opal2\o2win32\Libs\gtest\gtest\src\gtest-all.cc"
(注意/MT 隐藏在其中。)
在 Visual Studio 中,我打开解决方案,选择发布类型 Release,然后在任何目标中,例如 gtest、Properties -> Configuration Properties -> C/C++ -> Code Generation, Runtime Library 设置为 /MT,而不是 Cmake 文件中设置的 /MD。
如果我尝试构建 google-test (1.7.0),也会发生同样的事情
我只是不明白如何设置这些吗?或者有没有办法强制 Visual Studio 使用正确的标志,而无需手动打开 Visual Studio 并设置它?
【问题讨论】:
-
我认为其中一种解决方案(但不是选择的解决方案)实际上可以解决我的问题,但因为它不是选择的解决方案,所以我很犹豫是否按下“这解决了我的问题”按钮。我会尝试 @sakra 的解决方案(匹配 stackoverflow.com/a/12546288/1861346 )。谢谢!
标签: visual-studio cmake