如果路径随后更改,则cmake / errors上的相对路径

时间:2014-02-19 13:34:37

标签: cmake visual-studio-2013

我有自己的项目的VS 12解决方案,这取决于一些依赖项(使用cmake生成的项目文件)。我使用cmake生成了这些VS12项目,并将这些项目添加到我的解决方案中(使用相对路径)。然后我不得不调整这些项目的输出目录,在我自己的项目可以找到的其他地方构建目标(所以在路径更改后再次运行cmake不能解决我的问题,因为我必须编辑所有项目然后再次)。

如果现在解决方案的绝对路径发生变化,解决方案仍然可以找到项目 - 但在构建时我收到来自cmake的错误,“旧路径”不存在。

重现我的问题的步骤:

  1. here下载cmake项目。
  2. C:\cmake
  3. 上提取到目录
  4. 在名为C:\cmake\build
  5. 的目录中创建
  6. 打开命令行并转到C:\cmake\build
  7. 执行cmake ..
  8. C:\cmake目录重命名为C:\cmake2
  9. 打开解决方案C:\cmake2\build\CMake.sln
  10. 会出现一个包含错误的长列表(太长时间不能完全包含在这里) - 所有这些都是因为旧路径“C:\ cmake \”仍在某处使用而引起的。一个例子:

    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 Project文件 - 如果文件夹的位置发生变化,则不会再次生成。有关cmake如何使用相对路径的任何想法吗?

1 个答案:

答案 0 :(得分:5)

即使这个问题被低估了,我也会在这里为那些面临同样问题的人提供答案(根据他们的环境,我认为这可能是一个真正的问题)。

我从我的解决方案中引用的所有项目文件中删除了至少以下部分:

<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 &amp; call :cmErrorLevel %errorlevel% &amp; 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 &amp; call :cmErrorLevel %errorlevel% &amp; 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 &amp; call :cmErrorLevel %errorlevel% &amp; 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 &amp; call :cmErrorLevel %errorlevel% &amp; 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>

<ItemGroup>
    <ProjectReference Include="C:/cmake/build/ZERO_CHECK.vcxproj">
      <Project>FE0DC35D-28F6-4786-A563-DFE14862A57F</Project>
    </ProjectReference>
</ItemGroup>

这可以防止在每次构建之前检查CMakeLists.txt的更改行为。如果项目文件中的所有其他路径都是相对的,则cmake项目现在可以在硬盘上自由移动。

此自定义构建步骤的问题是:它不会显示在Visual Studios项目设置中,因此必须手动编辑普通.vcxproj。