【问题标题】:Set the directory for Intermediate files (like .obj) in CMake在 CMake 中设置中间文件(如 .obj)的目录
【发布时间】:2015-03-03 12:04:45
【问题描述】:

我看到 CMake 将中间文件(如 .obj)放在这样的目录中:

project.dir/sort/of/copy/of/source/directory

有没有办法拥有这样的东西:

project.dir/Debug/ myfiles.obj    |--> for my debug

project.dir/Release/ myfiles.obj    |--> for my release

目前,我每次使用 2 个单独的目录来为调试和发布生成我的库或可执行文件。在我也有了平台之后……

是否有类似于 CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE 或 CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE 的东西...

对于中间文件.obj?

我也尝试过/Fo,但是当我使用这个 FLAG 时,Cmake 会用他的配置覆盖:

warning D9025 : overriding '/Fo;../x64/Debug/' with '/FoCMakeFiles\project.dir\src\project\main.cpp.obj'

请问有人有解决办法吗?

【问题讨论】:

  • 使用两个构建目录对我来说似乎是最自然的方式。

标签: cmake


【解决方案1】:

您不能 - 至少目前,请参阅 0014999: Changing Intermediate Directory of Visual Studio 2012 功能请求 - 更改 CMake 和 makefile 生成器中的中间目录 - 就像你的情况一样 NMake - 每个二进制文件只能有一个 build configuration type构建输出目录。

正如@usr1234567 所说,使用两个构建目录是正确的做法。

或者 - 如果这是一个选项 - 使用 Visual Studio 多配置生成器。它确实使用了您建议的中间目录:

project.dir/Debug/...
project.dir/Release/...

命令行上的 NMake 与 Visual Studio 解决方案

在我通常用于构建基于 CMake 的系统的包装脚本中也可以看到这些差异。

所以NMake 看起来像这样:

@ECHO off
"\Program Files (x86)\Microsoft Visual Studio 14.0\vc\vcvarsall.bat" x64
IF NOT EXIST "x64\Debug\Makefile" (
    cmake -H"." -B"x64/Debug" -DCMAKE_BUILD_TYPE=Debug -G"NMake Makefiles"
)
cmake --build "x64/Debug" --target "project"
IF NOT EXIST "x64\Release\Makefile" (
    cmake -H"." -B"x64/Release" -DCMAKE_BUILD_TYPE=Release -G"NMake Makefiles"
)
cmake --build "x64/Release" --target "project"

而我喜欢的 Visual Studio 解决方案变体是这样的:

@ECHO off
IF NOT EXIST "x64\*.sln" (
    cmake -H"." -B"x64" -G"Visual Studio 14 2015 Win64"
)
cmake --build "x64" --target "project" --config "Debug"
cmake --build "x64" --target "project" --config "Release"

其他参考资料

【讨论】:

    猜你喜欢
    • 2018-06-05
    • 1970-01-01
    • 2022-08-04
    • 2021-10-23
    • 2023-01-25
    • 2019-09-21
    • 2013-08-15
    • 1970-01-01
    相关资源
    最近更新 更多