gpt4 book ai didi

cmake - 如果之后更改路径,则 cmake 上的相对路径/错误

转载 作者:行者123 更新时间:2023-12-05 01:05:09 25 4
gpt4 key购买 nike

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

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

重现我的问题的步骤:

  • here 下载 cmake 项目.
  • 提取到 C:\cmake 上的目录中
  • 在名为 C:\cmake\build 的目录中创建
  • 打开命令行并转到 C:\cmake\build
  • 执行 cmake ..
  • 重命名 C:\cmake目录到 C:\cmake2
  • 打开解决方案 C:\cmake2\build\CMake.sln

  • 将会出现一长串错误列表(太长而无法在此处完整包含)-所有原因都是因为旧路径“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 项目文件 - 如果文件夹的位置发生更改,则不会再生成一次。 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 &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。

    关于cmake - 如果之后更改路径,则 cmake 上的相对路径/错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21882071/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com