Proper CTest integration with Visual Studio?

I’d like to tightly integrate my test suite with Visual Studio 2019. If I understand correctly, the correct way is to reference one project to another:

So how would one do equivalent using cmake ? For the example let’s consider the simple setup:

> cat .\src\CMakeLists.txt
add_library(foo SHARED foo.c foo.h)
target_include_directories(
  foo PUBLIC $<BUILD_INTERFACE:${p_SOURCE_DIR}/src>
)

and tests directory is:

> cat .\tests\CMakeLists.txt
add_executable(footest footest.c)
target_link_libraries(footest PRIVATE foo)
add_test(NAME footest COMMAND footest)

By default footest.exe will fail to execute since foo.dll will be located in a different directory.

Please no suggestion about tweaking the PATH in a set_tests_properties call or putting all *.dll inside a single CMAKE_RUNTIME_OUTPUT_DIRECTORY . I’d really like to reference projects so that Visual Studio copies the Debug/Release/… dll for me (I’d prefer a solution without an explicit copy in a POST_BUILD custom command).

Currently:

with:

image

Thanks

You can direct where binaries go by setting CMAKE_RUNTIME_OUTPUT_DIRECTORY at the top-level. Then all .exe and .dll files will live beside each other. This doesn’t help with third party DLLs though; see $<TARGET_RUNTIME_DLLS>. for that (if all relevant deps are represented as CMake targets).