cmake上的相对路径/错误(如果路径后来更改) [英] Relative path on cmake / errors if path is changed afterwards

查看:4545
本文介绍了cmake上的相对路径/错误(如果路径后来更改)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a VS 12 solution with my own project, which depends on some dependencies (project files generated using cmake). I generated these VS12 projects using cmake and added these projects to my solution (using a relative path). Then I had to adjust the output directories of these projects, to build the target somewhere else where my own project can find them (so just running cmake again after the path changes doesn't solve my problem, because I would have to edit all projects again then).

如果现在解决方案的绝对路径更改,解决方案仍然可以找到项目 - 但是在构建我从cmake收到错误,老路径不存在。

If now the absolute path for the solution changes, the solution can still find the projects - but at building I receive errors from cmake, that the "old path" didn't exists.

重现我的问题的步骤


  1. 下载cmake项目 a>。

  2. 解压缩到 C:\cmake
  3. 的目录
  4. code> C:\ cmake \build

  5. 打开命令行并转到 C :\cmake\build

  6. 执行 cmake ..

  7. C:\cmake 目录重命名为 C:\cmake2

  8. 打开解决方案 C:\cmake2\build\CMake.sln

  1. Download the cmake Project from here.
  2. Extract into a Directory on C:\cmake
  3. Create inside a Directory called C:\cmake\build
  4. Open a command-line and go to C:\cmake\build
  5. execute cmake ..
  6. rename the C:\cmake Directory to C:\cmake2
  7. Open the solution C:\cmake2\build\CMake.sln

将出现一个包含错误的长列表(太长,无法完全包含在内) - 都是由于旧路径C:\cmake \ist仍在某处使用而导致的。示例:

There will occur a long list with errors (too long to include here completly) - all caused because the old path "C:\cmake\" ist still used from somewhere. An example:

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可以使用相对路径?

I want to generate VS Project files just one time - not again, if the Location of the folder changes. Any ideas how cmake can make use of relative paths instead?

推荐答案

即使问题是downvote我会提供一个答案在这里人们面临同样的问题(根据他们的环境,这可能是我的意见中真正的问题)。

Even that the question is downvoted I will provide an answer here for people that are facing the same problem (and depending on their environment it can be real a problem in my opinion).

我从我的参考的所有项目文件中删除至少解决以下部分:

I removed from all project files that are referenced from my solution at least the following part:

<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项目现在可以在硬盘上自由移动。

That prevents the behaviour that CMakeLists.txt is checked for changes before each build. If all other paths in the project file are relative the cmake project is free moveable on the harddisk now.

这个自定义构建步骤的问题是:在Visual Studios项目设置中,因此必须手动编辑纯文本.vcxproj。

The Problem with this custom build step is: It isn't displayed in Visual Studios Project Settings, so the plain .vcxproj must be edited manually.

这篇关于cmake上的相对路径/错误(如果路径后来更改)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆