Question

I'm using for managing my cross-platform builds, and I have everything worked out except for this problem. I set RUNTIME_OUTPUT_DIRECTORY to a bin/ directory where I have data files stored. On Linux, this works fine. On Windows, the executables get placed in the Debug/Release sub-directory depending on the build type. Is there any way to get to copy the executable to the proper directory, or (even better) stop using these sub-directories altogether?

Was it helpful?

Solution

I've been using the fine prefix property hack reported by Ogapo for years. It works.

But as of CMake version 2.8, there is official support for avoiding the Release/Debug subdirectories on Windows.

Use either the global CMAKE_<ARTIFACT>_OUTPUT_DIRECTORY_<CONFIGURATION> variables, or the per-target <ARTIFACT>_OUTPUT_DIRECTORY_<CONFIGURATION> properties, like so:

SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")

OTHER TIPS

I am not sure if these directories are intentional or a bug, but at the risk of forward incompatibility you could add:

if (MSVC_IDE)
    # hack to get around the "Debug" and "Release" directories cmake tries to add on Windows
    set_target_properties (${NAME} PROPERTIES PREFIX "../")
endif()

this has been working for me

I found a few good discussions on this topic:

http://www.cmake.org/pipermail/cmake/2008-April/021355.html

http://www.vtk.org/Bug/bug_view_advanced_page.php?bug_id=8366

Would it be possible to use the deprecated EXECUTABLE_OUTPUT_PATH instead of RUNTIME_OUTPUT_DIRECTORY? I'm not sure what functionality has changed between the 2, but it might be worth a try.

Some cmake variables have build specific versions.

CMAKE_C_FLAGS 
    the compiler flags for compiling C sources. Note you can also specify switches with ADD_DEFINITIONS(). 
CMAKE_C_FLAGS_DEBUG 
    compiler flags for compiling a debug build from C sources. 
CMAKE_C_FLAGS_RELEASE 
    compiler flags for compiling a release build from C sources. 
CMAKE_C_FLAGS_RELWITHDEBINFO 
    compiler flags for compiling a release build with debug flags from C sources. 

I have not verified these vars exist, but maybe setting RUNTIME_OUTPUT_DIRECTORY_DEBUG && RUNTIME_OUTPUT_DIRECTORY_RELEASE to the same thing might work.

So far, the best answer I've found is to simply write CMake install commands for each of my targets and data files, and set up the MSVC debugger to run out of the install directory. This has the added benefit of using CPack for creating installers.

For me a global:

set(CMAKE_STATIC_LIBRARY_PREFIX "../lib")
set(CMAKE_SHARED_LIBRARY_PREFIX "../lib")

did the work, so I don't have to set it for each library (CMake 2.8.4)

You need to change the build location of your visual studio projects. Go to Project Properties and on the Compile tab specify the 'Build output path' to be wherever you wish.

Note

Do not know how relevant this is as I don't know about CMake.

You can use the following token in Visual Studio build events:

$(TargetPath)

This will be the path to the location that your project is built to so depending on your project settings this will either be the Debug or Release folder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top