Donner SVG main
0.8.0 ยท 382bd0190.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
cmake_consumer Directory Reference
Directory dependency graph for cmake_consumer:

Detailed Description

Getting started with Donner from CMake

This example is a standalone CMake project for users who want to add Donner to their own CMake application from a Donner source checkout. It imports Donner with add_subdirectory(), links the exported donner target, parses a small SVG document, queries the DOM, renders it, and exits non-zero if any step fails.

Fonts are external package resources. With text enabled, deploy the generated fallback-font directory beside the executable as donner-assets; linking the library alone does not copy data. The example replaces its generated companion directory in its post-build step, so an incremental asset change cannot leave obsolete files behind. Keep the complete directory, including its manifest, with the executable when relocating or packaging it. A host with a different installation layout can explicitly install a PackagedResourceDirectoryProvider instead. Resource lookup never uses the working directory. No-text builds do not need this font data.

The important part is the same pattern an external project should use:

set(DONNER_SOURCE_DIR "/path/to/donner" CACHE PATH "Path to Donner")
add_subdirectory("${DONNER_SOURCE_DIR}" "${CMAKE_BINARY_DIR}/_deps/donner")
add_executable(my_app main.cc)
target_link_libraries(my_app PRIVATE donner)
if(DONNER_TEXT)
get_target_property(font_assets donner_third_party_public-sans_public-sans DONNER_RESOURCE_DIRECTORY)
add_custom_command(TARGET my_app POST_BUILD
COMMAND ${CMAKE_COMMAND} "-DSOURCE=${font_assets}"
"-DDESTINATION=$<TARGET_FILE_DIR:my_app>/donner-assets"
-P "${DONNER_SOURCE_DIR}/tools/cmake/stage_consumer_resources.cmake"
VERBATIM)
endif()

Generate Donner's CMake files before configuring your project:

python3 tools/cmake/gen_cmakelists.py
cmake -S examples/cmake_consumer -B build/cmake-consumer
cmake --build build/cmake-consumer --target donner_cmake_consumer
ctest --test-dir build/cmake-consumer --output-on-failure

From another source tree, point the example at a Donner checkout:

cmake -S /path/to/donner/examples/cmake_consumer -B build/cmake-consumer \
-DDONNER_SOURCE_DIR=/path/to/donner
cmake --build build/cmake-consumer --target donner_cmake_consumer
ctest --test-dir build/cmake-consumer --output-on-failure