views:

1289

answers:

5

I'm using cmake 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 subdirectory depending on the build type. Is there any way to get cmake to copy the executable to the proper directory, or (even better) stop using these subdirectories altogether?

+2  A: 

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.

Jon Tackabury
A: 

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.

Good luck!

Charlie
A: 

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.

verbalshadow
+2  A: 

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

Ogapo
This works fine for me too. For .lib files use SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES IMPORT_PREFIX "../")
Torleif
A: 

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.

thekidder