doc: document how to use generator expressions + explain why we no longer provide CMake variables

This commit is contained in:
Anonymous Maarten
2024-05-05 20:46:49 +02:00
committed by Ryan C. Gordon
parent 026edbeab0
commit a4371d28ac
2 changed files with 30 additions and 5 deletions

View File

@@ -114,9 +114,13 @@ cmake --build . --config Release
### Shared or static
By default, only a shared SDL library is built and installed.
By default, only a dynamic (=shared) SDL library is built and installed.
The options `-DSDL_SHARED=` and `-DSDL_STATIC=` accept boolean values to change this.
Exceptions exist:
- some platforms don't support dynamic libraries, so only `-DSDL_STATIC=ON` makes sense.
- a static Apple framework is not supported
### Pass custom compile options to the compiler
- Use [`CMAKE_<LANG>_FLAGS`](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS.html) to pass extra
@@ -283,6 +287,25 @@ At the end of SDL CMake configuration, a table shows all CMake options along wit
| `-DSDL_DISABLE_INSTALL_DOCS=` | `ON`/`OFF` | Don't install the SDL documentation |
| `-DSDL_INSTALL_TESTS=` | `ON`/`OFF` | Install the SDL test programs |
## CMake FAQ
### How do I copy a SDL3 dynamic library to another location?
Use [CMake generator expressions](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#target-dependent-expressions).
Generator expressions support multiple configurations, and are evaluated during build system generation time.
On Windows, the following example this copies `SDL3.dll` to the directory where `mygame.exe` is built.
On Unix systems, `$<TARGET_FILE:...>` will refer to the dynamic library (or framework).
```cmake
if(WIN32)
add_custom_command(
TARGET mygame POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_FILE:SDL3::SDL3-shared> $<TARGET_FILE_DIR:mygame>
VERBATIM
)
endif()
```
## Help, it doesn't work!
Below, a SDL3 CMake project can be found that builds 99.9% of time (assuming you have internet connectivity).