Set the directory for Intermediate files (like .ob

2019-02-12 07:04发布

问题:

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

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

Is there a way to have something like that :

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

and

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

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...

Is there something similar to CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE or CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE...

for intermediate files.obj ?

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

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

Please, does someone have a solution ?

回答1:

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.

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

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 vs. Visual Studio Solution on the Command Line

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

So NMake would look something like this:

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

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"

Additional References

  • 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