2

I have a cross-platform project which uses CMake. I am doing out-of-source builds so basically I have a source directory "src" which contains the CMakeLists.txt and then I have a "src/build" directory where I generate the out-of-source build.

However when using Visual Studio (2013) it does not place the executable in the build dir but to "src/build/Debug" for example (depends on the selected configuration). I think this was referred as "$(OutDir)" inside VS. How do I refer to the (runtime) output directory in my CMakeLists.txt so I can copy DLLs and shaders where my executable is?

Edit: The suggested duplicate answer does not seem correct to me. In that answer you just force the output directories to be static which sounds wrong if you are using a multi-configuration build system like Visual Studio.

Dago
  • 1,349
  • 1
  • 11
  • 19
  • You can use $ – StAlphonzo Mar 11 '15 at 13:50
  • $ does not seem to work. Just get "file COPY cannot copy file "C:\blaa\src\file" to "C:\blaa\src\build\$\file" – Dago Mar 11 '15 at 13:53
  • Sorry, I see that $ is deprecated in favor of $. It is a runtime variable though. It will not be available at configure/generate time. Normally, if you need this value during those phases, you will need to write a cmake script which does the install/copy and call it. http://www.cmake.org/cmake/help/v3.0/manual/cmake-generator-expressions.7.html – StAlphonzo Mar 11 '15 at 13:59
  • 1
    possible duplicate of [In CMake, how do I work around the Debug and Release directories Visual Studio 2010 tries to add?](http://stackoverflow.com/questions/7747857/in-cmake-how-do-i-work-around-the-debug-and-release-directories-visual-studio-2) – André Mar 12 '15 at 10:03

1 Answers1

2

I solved my problem by copying the files with the "file (GENERATE OUTPUT)" which supports the cmake-generator-expressions suggested by StAlphonzo:

foreach (file ${SHADER_SOURCES})
    file (GENERATE OUTPUT $<CONFIG>/${file} INPUT ${PROJECT_SOURCE_DIR}/${file})
endforeach()

I would also like to mention a second way of solving this problem I discovered that I think is actually more correct, by adding a custom command:

add_custom_command(TARGET target ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCES_DIR}/foo $<TARGET_FILE_DIR:target>)
Dago
  • 1,349
  • 1
  • 11
  • 19