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?
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}")
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)
now there is a simple solution. cmake said:
Multi-configuration generators (Visual Studio, Xcode, Ninja Multi-Config) append a per-configuration subdirectory to the specified directory unless a generator expression is used.
so we can use a generator expression. like below:
set_target_properties(foo PROPERTIES ARCHIVE_OUTPUT_DIRECTORY $<1:${PROJECT_SOURCE_DIR}/lib>)
set_target_properties(foo PROPERTIES LIBRARY_OUTPUT_DIRECTORY $<1:${PROJECT_SOURCE_DIR}/lib>)
set_target_properties(foo PROPERTIES RUNTIME_OUTPUT_DIRECTORY $<1:${PROJECT_SOURCE_DIR}/bin>)
if you want to put to config dir, use this:
set_target_properties(foo PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/output/$<CONFIG>/lib)
set_target_properties(foo PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/output/$<CONFIG>/lib)
set_target_properties(foo PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/output/$<CONFIG>/bin)
The answer of hgyxbll worked for me on a global bases( for all targets )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${PROJECT_SOURCE_DIR}/bin>)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY $<1:${PROJECT_SOURCE_DIR}/bin>)
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.
© 2022 - 2024 — McMap. All rights reserved.