如何使用CMake和长目标名称为VS 2013启用增量构建?

时间:2015-03-10 08:54:10

标签: visual-studio-2013 cmake

我有一个CMake项目,它有一个相当长的目标名称(让我们说RatherLongLibraryName长度为21个字符),我用它来生成一个Visual Studio解决方案。在我的持续集成设置中,在清除CMake缓存后,每个构建都会重新生成此解决方案。在第一次构建(第二次构建,第三次构建等)之后,我收到以下警告:

[...]\Microsoft.CppBuild.targets(388,5): warning MSB8028: The intermediate directory (RatherLongLibraryName.dir\Release\) contains files shared from another project (RatherLongLibraryName.vcxproj)).  This can lead to incorrect clean and rebuild behavior.

在警告中,项目名RatherLongLibraryName.vcxproj将添加到每个构建的括号中。所以对于第三次构建,那里会提到两个.vcxproj。并且,看,重建行为确实是错误的:每次都重建库。

经过一番挖掘后,我发现在build目录中有一个RatherLongLibraryName.dir\Debug\RatherLo.<first-8-GUID-chars>.tlog目录。每次重新生成解决方案时,目标RatherLongLibraryName的GUID都会更改,这会导致另一个目录RatherLo.<first-8-GUID-chars>.tlog导致Visual Studio抱怨上述警告。

由于这个问题不存在,目标名称较短,我玩了长度,发现当目标名称长于 16个字符时,Visual Studio会切换{{1目录(从*.tlogtargetname.tlog)。由于现在有一个额外的<first-8-chars-of-target-name>.<first-8-GUID-chars>.tlog目录,因此会触发完整的重建。

所以,我的问题是:如何在CMake经常重新生成的Visual Studio解决方案中为长目标名称允许增量构建?


解决方法:我通过简单地缩短目标名称来解决这个问题一段时间,但这很简单。它虽然有效。

1 个答案:

答案 0 :(得分:2)

一种方法是修复CMakeLists.txt中的GUID。这样,GUID匹配每个解决方案生成,并且只创建一个.tlog目录。这似乎并没有使Visual Studio混淆,并且构建按照预期逐步发生。

为此,您必须在项目的CMakeLists.txt中设置缓存变量:

set( RatherLongLibraryName_GUID_CMAKE <generated GUID> CACHE INTERNAL "remove this and Visual Studio will mess up incremental builds")

Further documentation of the set command

我不确定这对非Visual Studio版本会做什么,但我的猜测是该值将被忽略。