cmake上的相对路径/如果之后更改了路径,则出现错误
我有一个VS 12解决方案和我自己的项目,这取决于一些依赖项(使用cmake生成的项目文件)。我使用cmake生成了这些VS12项目,并将这些项目添加到我的解决方案中(使用相对路径)。然后,我必须调整这些项目的输出目录,在我自己的项目可以找到它们的地方构建目标(因此,在路径更改后再次运行cmake并不能解决我的问题,因为那时我必须再次编辑所有项目) 如果现在解决方案的绝对路径发生变化,那么解决方案仍然可以找到项目——但在构建时,我收到了来自cmake的错误,即“旧路径”不存在 重现问题的步骤:cmake上的相对路径/如果之后更改了路径,则出现错误,cmake,visual-studio-2013,Cmake,Visual Studio 2013,我有一个VS 12解决方案和我自己的项目,这取决于一些依赖项(使用cmake生成的项目文件)。我使用cmake生成了这些VS12项目,并将这些项目添加到我的解决方案中(使用相对路径)。然后,我必须调整这些项目的输出目录,在我自己的项目可以找到它们的地方构建目标(因此,在路径更改后再次运行cmake并不能解决我的问题,因为那时我必须再次编辑所有项目) 如果现在解决方案的绝对路径发生变化,那么解决方案仍然可以找到项目——但在构建时,我收到了来自cmake的错误,即“旧路径”不存在 重现问题的步骤:
C:\cmake
C:\cmake\build
C:\cmake\build
cmake..
C:\cmake
目录重命名为C:\cmake2
C:\cmake2\build\CMake.sln
1>------ Build started: Project: ZERO_CHECK, Configuration: Debug Win32 ------
2>------ Skipped Build: Project: RUN_TESTS, Configuration: Debug Win32 ------
2>Project not selected to build for this solution configuration
1> Checking Build System
1> CMake is re-running because C:/cmake/build/CMakeFiles/generate.stamp dependency file is missing.
1>CUSTOMBUILD : CMake error : The source directory "C:/cmake" does not appear to contain CMakeLists.txt.
1> Specify --help for usage, or press the help button on the CMake GUI.
3>------ Build started: Project: cmbzip2, Configuration: Debug Win32 ------
4>------ Build started: Project: cmzlib, Configuration: Debug Win32 ------
5>------ Build started: Project: cmexpat, Configuration: Debug Win32 ------
6>------ Build started: Project: cmsys, Configuration: Debug Win32 ------
3>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.Targets(1422,5): warning : The referenced project 'C:/cmake/build/ZERO_CHECK.vcxproj' does not exist.
我只想生成一次VS项目文件,如果文件夹位置发生更改,则不会再次生成。有没有关于cmake如何利用相对路径的想法?即使这个问题被否决,我也会在这里为面临相同问题的人提供答案(根据他们的环境,我认为这可能是一个真正的问题) 我从解决方案中引用的所有项目文件中删除了至少以下部分:
<ItemGroup>
<CustomBuild Include="..\..\Source\CMakeLists.txt">
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Building Custom Rule C:/cmake/Source/CMakeLists.txt</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">setlocal
"C:\Program Files\CMake 2.8\bin\cmake.exe" -HC:/cmake -BC:/cmake/build --check-stamp-file C:\cmake\build\Source\CMakeFiles\generate.stamp
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">C:/cmake/Source/CMakeLists.txt;C:\cmake\Source\CMakeLists.txt;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.cmake;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.c.in;C:\cmake\Source\cmConfigure.cmake.h.in;C:\cmake\Source\cmVersionConfig.h.in;C:\cmake\Source\CPack\cmCPackConfigure.h.in;C:\cmake\Source\CMakeLists.txt;%(AdditionalInputs)</AdditionalInputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">C:\cmake\build\Source\CMakeFiles\generate.stamp</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkObjects>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Building Custom Rule C:/cmake/Source/CMakeLists.txt</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">setlocal
"C:\Program Files\CMake 2.8\bin\cmake.exe" -HC:/cmake -BC:/cmake/build --check-stamp-file C:\cmake\build\Source\CMakeFiles\generate.stamp
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">C:/cmake/Source/CMakeLists.txt;C:\cmake\Source\CMakeLists.txt;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.cmake;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.c.in;C:\cmake\Source\cmConfigure.cmake.h.in;C:\cmake\Source\cmVersionConfig.h.in;C:\cmake\Source\CPack\cmCPackConfigure.h.in;C:\cmake\Source\CMakeLists.txt;%(AdditionalInputs)</AdditionalInputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">C:\cmake\build\Source\CMakeFiles\generate.stamp</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkObjects>
<Message Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|Win32'">Building Custom Rule C:/cmake/Source/CMakeLists.txt</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|Win32'">setlocal
"C:\Program Files\CMake 2.8\bin\cmake.exe" -HC:/cmake -BC:/cmake/build --check-stamp-file C:\cmake\build\Source\CMakeFiles\generate.stamp
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|Win32'">C:/cmake/Source/CMakeLists.txt;C:\cmake\Source\CMakeLists.txt;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.cmake;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.c.in;C:\cmake\Source\cmConfigure.cmake.h.in;C:\cmake\Source\cmVersionConfig.h.in;C:\cmake\Source\CPack\cmCPackConfigure.h.in;C:\cmake\Source\CMakeLists.txt;%(AdditionalInputs)</AdditionalInputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|Win32'">C:\cmake\build\Source\CMakeFiles\generate.stamp</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|Win32'">false</LinkObjects>
<Message Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">Building Custom Rule C:/cmake/Source/CMakeLists.txt</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">setlocal
"C:\Program Files\CMake 2.8\bin\cmake.exe" -HC:/cmake -BC:/cmake/build --check-stamp-file C:\cmake\build\Source\CMakeFiles\generate.stamp
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">C:/cmake/Source/CMakeLists.txt;C:\cmake\Source\CMakeLists.txt;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.cmake;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.c.in;C:\cmake\Source\cmConfigure.cmake.h.in;C:\cmake\Source\cmVersionConfig.h.in;C:\cmake\Source\CPack\cmCPackConfigure.h.in;C:\cmake\Source\CMakeLists.txt;%(AdditionalInputs)</AdditionalInputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">C:\cmake\build\Source\CMakeFiles\generate.stamp</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">false</LinkObjects>
</CustomBuild>
</ItemGroup>
生成自定义规则C:/cmake/Source/CMakeLists.txt
setlocal
“C:\Program Files\CMake 2.8\bin\CMake.exe”-HC:/CMake-BC:/CMake/build--检查戳记文件C:\CMake\build\Source\CMakeFiles\generate.stamp
如果%errorlevel%neq 0转到:cmEnd
:cmEnd
(完);呼叫:cmErrorLevel%errorlevel%&;转到:cmDone
:cmErrorLevel
退出/b%1
:cmDone
如果%errorlevel%neq 0转到:VCEnd
C:/cmake/Source/CMakeLists.txt;C:\cmake\Source\CMakeLists.txt;C:\Program Files\CMake 2.8\share\CMake-2.8\Modules\CheckIncludeFile.CMake;C:\Program Files\CMake 2.8\share\CMake-2.8\Modules\CheckIncludeFile.C.in;C:\cmake\Source\cmConfigure.cmake.h.in;C:\cmake\Source\cmVersionConfig.h.in;C:\cmake\Source\CPack\cmCPackConfigure.h.in;C:\cmake\Source\CMakeLists.txt;%(其他投入)
C:\cmake\build\Source\CMakeFiles\generate.stamp
假的
生成自定义规则C:/cmake/Source/CMakeLists.txt
setlocal
“C:\Program Files\CMake 2.8\bin\CMake.exe”-HC:/CMake-BC:/CMake/build--检查戳记文件C:\CMake\build\Source\CMakeFiles\generate.stamp
如果%errorlevel%neq 0转到:cmEnd
:cmEnd
(完);呼叫:cmErrorLevel%errorlevel%&;转到:cmDone
:cmErrorLevel
退出/b%1
:cmDone
如果%errorlevel%neq 0转到:VCEnd
C:/cmake/Source/CMakeLists.txt;C:\cmake\Source\CMakeLists.txt;C:\Program Files\CMake 2.8\share\CMake-2.8\Modules\CheckIncludeFile.CMake;C:\Program Files\CMake 2.8\share\CMake-2.8\Modules\CheckIncludeFile.C.in;C:\cmake\Source\cmConfigure.cmake.h.in;C:\cmake\Source\cmVersionConfig.h.in;C:\cmake\Source\CPack\cmCPackConfigure.h.in;C:\cmake\Source\CMakeLists.txt;%(其他投入)
C:\cmake\build\Source\CMakeFiles\generate.stamp
假的
生成自定义规则C:/cmake/Source/CMakeLists.txt
setlocal
“C:\Program Files\CMake 2.8\bin\CMake.exe”-HC:/CMake-BC:/CMake/build--检查戳记文件C:\CMake\build\Source\CMakeFiles\generate.stamp
如果%errorlevel%neq 0转到:cmEnd
:cmEnd
(完);呼叫:cmErrorLevel%errorlevel%&;转到:cmDone
:cmErrorLevel
退出/b%1
:cmDone
如果%errorlevel%neq 0转到:VCEnd
C:/cmake/Source/CMakeLists.txt;C:\cmake\Source\CMakeLists.txt;C:\Program Files\CMake 2.8\share\CMake-2.8\Modules\CheckIncludeFile.CMake;C:\Program Files\CMake 2.8\share\CMake-2.8\Modules\CheckIncludeFile.C.in;C:\cmake\Source\cmConfigure.cmake.h.in;C:\cmake\Source\cmVersionConfig.h.in;C:\cmake\Source\CPack\cmCPackConfigure.h.in;C:\cmake\Source\CMakeLists.txt;%(其他投入)
C:\cmake\build\Source\CMakeFiles\generate.stamp
假的
生成自定义规则C:/cmake/Source/CMakeLists.txt
setlocal
“C:\Program Files\CMake 2.8\bin\CMake.exe”-HC:/CMake-BC:/CMake/build--检查戳记文件C:\CMake\build\Source\CMakeFiles\generate.stamp
如果%errorlevel%neq 0转到:cmEnd
:cmEnd
(完);呼叫:cmErrorLevel%errorlevel%&;转到:cmDone
:cmErrorLevel
退出/b%1
:cmDone
如果%errorlevel%neq 0转到:VCEnd
C:/cmake/Source/CMakeLists.txt;C:\cmake\Source\CMakeLists.txt;C:\Program Files\CMake 2.8\share\CMake-2.8\Modules\CheckIncludeFile.CMake;C:\Program Files\CMake 2.8\share\CMake-2.8\Modules\CheckIncludeFile.C.in;C:\cmake\Source\cmConfigure.cmake.h.in;C:\cmake\Source\cmVersionConfig.h.in;C:\cmake\Source\CPack\cmCPackConfigure.h.in;C:\cmake\Source\CMakeLists.txt;%(其他投入)
C:\cmake\build\Source\CMakeFiles\generate.stamp
假的
以及:
FE0DC35D-28F6-4786-A563-DFE14862A57F
这样可以防止在每次生成之前检查CMakeLists.txt的更改行为。如果项目文件中的所有其他路径都是相对路径,则cmake项目现在可以在硬盘上自由移动
此自定义生成步骤的问题是:它不显示在Visual Studio项目设置中,因此必须手动编辑plain.vcxproj。不是错误。不要试图像那样移动build dir。@steveire我从来没有说过也没有想过这会是一个bug。我试图找到原因并解决我的问题-只是说“不要这样做”,而没有解释为什么我不应该这样做既不是解决方案也不是建设性的我在生成Visual Studio时也遇到过类似的问题
<ItemGroup>
<ProjectReference Include="C:/cmake/build/ZERO_CHECK.vcxproj">
<Project>FE0DC35D-28F6-4786-A563-DFE14862A57F</Project>
</ProjectReference>
</ItemGroup>