Fix C++ memory game tutorial not starting out of the box on Windows

After commit 3e5aa212d5 the Slint DLLs
aren't placed in the `bin/` directory by default anymore. Since the
tutorial builds Slint as an external sub-project, it is entirely
isolated and the CMAKE_*_OUTPUT_DIRECTORY variables do not propagate. On
macOS and Linux, the program still runs due to rpath. On Windows, the
instructions said to put `bin` into `%PATH%`, but that doesn't work
anymore, the dll is now in `_deps/slint-build`.

Instead of adjusting `%PATH%`, this change adjusts the documentation to
recommend the use of a custom command on Windows using
$<TARGET_RUNTIME_DLLS:tgt> to copy the DLL across. This is guarded with
WIN32 due to https://gitlab.kitware.com/cmake/cmake/-/issues/23543 ,
where the proposed solution requires CMake 3.26 (not released yet).
This commit is contained in:
Simon Hausmann 2023-01-06 10:53:09 +01:00 committed by Simon Hausmann
parent d50e76f48a
commit 3c65c6177d
5 changed files with 19 additions and 13 deletions

View file

@ -28,6 +28,10 @@ FetchContent_MakeAvailable(Slint)
add_executable(my_application main.cpp)
slint_target_sources(my_application my_application_ui.slint)
target_link_libraries(my_application PRIVATE Slint::Slint)
# On Windows, copy the Slint DLL next to the application binary so that it's found.
if (WIN32)
add_custom_command(TARGET my_application POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:my_application> $<TARGET_FILE_DIR:my_application> COMMAND_EXPAND_LISTS)
endif()
```
Suppose `my_application_ui.slint` was a "Hello World" like this: