Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake RUNTIME_OUTPUT_DIRECTORY on Windows

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 sub-directory 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 sub-directories altogether?

like image 607
thekidder Avatar asked Feb 12 '09 20:02

thekidder


2 Answers

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}") 
like image 181
Christopher Bruns Avatar answered Sep 19 '22 17:09

Christopher Bruns


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

like image 37
Ogapo Avatar answered Sep 20 '22 17:09

Ogapo