mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
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:
parent
d50e76f48a
commit
3c65c6177d
5 changed files with 19 additions and 13 deletions
|
@ -25,7 +25,7 @@ First you need to install the prerequisites:
|
|||
|
||||
* Install Rust by following the [Rust Getting Started Guide](https://www.rust-lang.org/learn/get-started). Once this is done,
|
||||
you should have the ```rustc``` compiler and the ```cargo``` build system installed in your path.
|
||||
* **[cmake](https://cmake.org/download/)** (3.19 or newer)
|
||||
* **[cmake](https://cmake.org/download/)** (3.21 or newer)
|
||||
* A C++ compiler that supports C++20 (e.g., **MSVC 2019 16.6** on Windows)
|
||||
|
||||
You can include Slint in your CMake project using CMake's `FetchContent` feature. Insert the following snippet into your
|
||||
|
@ -103,7 +103,7 @@ After extracting the artifact or running the installer, you can place the `lib`
|
|||
A typical example looks like this:
|
||||
|
||||
```cmake
|
||||
cmake_minimum_required(VERSION 3.19)
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
project(my_application LANGUAGES CXX)
|
||||
|
||||
# Note: Use find_package(Slint) instead of the following three commands, if you prefer the package
|
||||
|
@ -120,6 +120,10 @@ FetchContent_MakeAvailable(Slint)
|
|||
add_executable(my_application main.cpp)
|
||||
target_link_libraries(my_application PRIVATE Slint::Slint)
|
||||
slint_target_sources(my_application my_application_ui.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()
|
||||
```
|
||||
|
||||
The `slint_target_sources` cmake command allows you to add .slint files to your build. Finally it is
|
||||
|
|
|
@ -34,7 +34,7 @@ First you need to install the prerequisites:
|
|||
* Install Rust by following the [Rust Getting Started Guide](https://www.rust-lang.org/learn/get-started). If you already
|
||||
have Rust installed, make sure that it's at least version 1.60 or newer. You can check which version you have installed
|
||||
by running `rustc --version`. Once this is done, you should have the ```rustc``` compiler and the ```cargo``` build system installed in your path.
|
||||
* **[cmake](https://cmake.org/download/)** (3.19 or newer)
|
||||
* **[cmake](https://cmake.org/download/)** (3.21 or newer)
|
||||
* A C++ compiler that supports C++20 (e.g., **MSVC 2019 16.6** on Windows)
|
||||
|
||||
You can include Slint in your CMake project using CMake's [`FetchContent`](https://cmake.org/cmake/help/latest/module/FetchContent.html) feature.
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue