From b4cc3504be9589e2560576e8c700567a1104c506 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 Sep 2022 01:10:46 +0200 Subject: [PATCH] Add an example of using wxrc docs with CMake add_subdirectory() There are a couple of non-trivial points when using wxrc in this configuration, so document using $ and having to use "DEPENDS wxrc" in this case. See #22815. (cherry picked from commit 5ac3c85cce0937ee370943f969e6ce80bd83b148) --- docs/doxygen/overviews/cmake.md | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/doxygen/overviews/cmake.md b/docs/doxygen/overviews/cmake.md index 0209f88025..1c0131b02d 100644 --- a/docs/doxygen/overviews/cmake.md +++ b/docs/doxygen/overviews/cmake.md @@ -132,3 +132,42 @@ add_subdirectory(libs/wxWidgets) add_executable(myapp myapp.cpp) target_link_libraries(myapp wx::net wx::core wx::base) ~~~ + +Note that you can predefine the build options before using `add_subdirectory()` +by either defining them on command line with e.g. `-DwxBUILD_SHARED=OFF`, or by +adding +~~~~ +set(wxBUILD_SHARED OFF) +~~~~ +to your *CMakeLists.txt* if you want to always use static wxWidgets libraries. + + +Using XRC +--------- + +To embed XRC resources into your application, you need to define a custom +command to generate a source file using `wxrc`. When using an installed version +of wxWidgets you can just use `wxrc` directly, but when using wxWidgets from a +subdirectory you need to ensure that it is built first and use the correct path +to it, e.g.: + +~~~~{.cmake} +# One or more XRC files containing your resources. +set(xrc_files ${CMAKE_CURRENT_SOURCE_DIR}/resource.xrc) + +# Generate this file somewhere under the build directory. +set(resource_cpp ${CMAKE_CURRENT_BINARY_DIR}/resource.cpp) + +# Not needed with the installed version, just use "wxrc". +set(wxrc $) + +add_custom_command( + OUTPUT ${resource_cpp} + COMMAND ${wxrc} -c -o ${resource_cpp} ${xrc_files} + DEPENDS ${xrc_files} + DEPENDS wxrc # Not needed with the installed version. + COMMENT "Compiling XRC resources" +) + +target_sources(myapp PRIVATE ${resource_cpp}) +~~~~