在CMake中设置中间文件(如.obj)的目录 [英] Set the directory for Intermediate files (like .obj) in CMake

查看:1472
本文介绍了在CMake中设置中间文件(如.obj)的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've seen that CMake put the intermediate files, like .obj in a directory like this :

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个单独的目录来生成库或可执行文件调试和发布。在我也有了平台之后……

For moment, I used 2 separate directory to generate each time my libraries or executable for the Debug and the release. And after I have also the platform...

是否存在类似于CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE或CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ...

Is there something similar to CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE or CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE...

对于中间文件。obj?

for intermediate files.obj ?

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

I've try too the /Fo but when I used this FLAG, Cmake override with his configuration :

警告D9025:用'/ FoCMakeFiles\project覆盖'/Fo;../x64/Debug/' .dir\src\project\main.cpp.obj'

请问,有人解决方案吗?

Please, does someone have a solution ?

推荐答案

您不能-至少此刻,请参见 0014999:更改Visual Studio 2012的中间目录功能请求-更改CMake中的中间目录以及Makefile生成器的中间目录-如您的情况 NMake -您只能有一个每个二进制构建输出目录的构建配置类型

You can't - at least at the moment, see 0014999: Changing Intermediate Directory of Visual Studio 2012 feature request - change the intermediate directories in CMake and for makefile generators - like in your case NMake - you can have only one build configuration type per binary build output directory.

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

So as @usr1234567 has commented, using two build directories is the right thing to do.

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

Or - if this is an option - use the Visual Studio multi-configuration generator. It does exactly use the intermediate directories you have suggested:

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

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

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

The differences can also be seen in the wrapper scripts I normally use to build my CMake based systems.

所以 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 Sol ution变量是这样的:

And my prefered Visual Studio Solution variant something like this:

@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"

其他参考

  • CMAKE_BUILD_TYPE not being used in CMakeLists.txt
  • cmake build multiple targets in different build directories
  • CMake: how to specify the version of Visual C++ to work with?
  • The Architecture of Open Source Applications - CMake

这篇关于在CMake中设置中间文件(如.obj)的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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