Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2013 如何使用CMake和长目标名称为VS 2013启用增量构建?_Visual Studio 2013_Cmake - Fatal编程技术网

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

Visual studio 2013 如何使用CMake和长目标名称为VS 2013启用增量构建?,visual-studio-2013,cmake,Visual Studio 2013,Cmake,我有一个CMake项目,目标名称相当长(比如说RatherLongLibraryName,长度为21个字符),我用它来生成Visual Studio解决方案。在我的持续集成设置中,在清除CMake缓存后,每次生成时都会重新生成此解决方案。在第一次构建(第二次构建、第三次构建等)之后,我收到以下警告: [...]\Microsoft.CppBuild.targets(388,5): warning MSB8028: The intermediate directory (RatherLongLib

我有一个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.
在警告中,将在每个构建的括号中添加projectname
RatherLongLibraryName.vcxproj
。因此,对于第三个构建,这里将提到两个
.vcxproj
s。而且,瞧,重建行为确实是不正确的:库每次都会重建

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

由于较短的目标名称不存在此问题,我研究了长度,发现当目标名称长度超过16个字符时,Visual Studio会切换
*.tlog
目录的格式(从
targetname.tlog
.tlog
)。由于现在有一个额外的
tlog
目录,因此会触发完整的重建

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



解决方法:我曾一度通过缩短目标名称来解决这个问题,但这实在是太难看了。但是它可以工作。

一种方法是修复
CMakeLists.txt
中的GUID。这样,每个解决方案生成的GUID都匹配,并且只创建一个
.tlog
目录。这似乎并没有混淆VisualStudio,构建是按预期的增量进行的

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

set( RatherLongLibraryName_GUID_CMAKE <generated GUID> CACHE INTERNAL "remove this and Visual Studio will mess up incremental builds")
set(RatherLongLibraryName\u GUID\u CMAKE缓存内部“删除此项,Visual Studio将破坏增量生成”)


我不确定这对非Visual Studio版本会有什么影响,但我猜这个值将被忽略。

我将添加我当前的解决方案作为答案,但如果出现更好的解决方案,我不会立即接受它。很好的检测工作,谢谢!