I have a simple project structure derived from the amazing tutorial
https://rix0r.nl/blog/2015/08/13/cmake-guide/
It looks as follows:
- src
- CMakeLists.txt
- mylib
- include/mylib/mylibclass.h
- src/mylibclass.cpp
- CMakeLists.txt
- myapp
- src/myapp.cpp
- CMakeLists.txt
The top level CMakeLists.txt contains:
cmake_minimum_required( VERSION 3.6 )
project( sample_project VERSION 0.1 LANGUAGES CXX )
set( BUILD_SHARED_LIBS ON CACHE BOOL "" )
add_subdirectory( mylib )
add_subdirectory( myapp )
The CMakeLists.txt in the mylib folder contains:
add_library( mylib src/mylibclass.cpp include/mylib/mylibclass.h )
set_target_properties( mylib PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
target_include_directories( mylib
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> PRIVATE src )
And the one in the myapp folder contains:
add_executable( myapp src/myapp.cpp )
target_link_libraries( myapp mylib )
I want to use this structure to develop both mylib (as a shared or static library as determined by BUILD_SHARED_LIBS) and myapp. For this, I want to set myapp as my startup project in Visual Studio and compile and run in the MSVC debugger. This is not possible for the shared library case without extra CMake code, as the myapp.exe doesn't know where to find the mylib.dll.
What is best CMake practice to tell the program where to find the dll?
Edit:
Based on the suggestions by @Andre, I've added the following lines to the top level CMakeLists.txt:
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out CACHE STRING "" )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out CACHE STRING "" )