From 5c36b39ba2724a270135bd454fc9e79348e40628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 11 Sep 2022 13:03:58 +0200 Subject: [PATCH] CMake: add a possibility to link static plugins to utility executables. Funny/sad that this possibility took me so long to realize. Until now it was "you can have command-line utilities or static plugins but never both", and only with CMake 3.13+ it was possible to link static plugins to these executables from outside. Now it's a builtin and supported option. --- CMakeLists.txt | 7 +++++++ doc/building.dox | 16 ++++++++++++++++ doc/changelog.dox | 7 +++++++ src/Magnum/SceneTools/CMakeLists.txt | 14 +++++++++++++- src/Magnum/ShaderTools/CMakeLists.txt | 3 ++- src/Magnum/Text/CMakeLists.txt | 3 ++- src/Magnum/TextureTools/CMakeLists.txt | 15 ++++++++++++++- src/Magnum/Trade/CMakeLists.txt | 3 ++- 8 files changed, 63 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 87ba2f365..f5433172b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,6 +157,9 @@ endif() if(CORRADE_TARGET_UNIX OR CORRADE_TARGET_WINDOWS) option(MAGNUM_WITH_FONTCONVERTER "Build magnum-fontconverter utility" OFF) option(MAGNUM_WITH_DISTANCEFIELDCONVERTER "Build magnum-distancefieldconverter utility" OFF) + + set(MAGNUM_FONTCONVERTER_STATIC_PLUGINS "" CACHE STRING "Static plugins to link to the magnum-fontconverter utility") + set(MAGNUM_DISTANCEFIELDCONVERTER_STATIC_PLUGINS "" CACHE STRING "Static plugins to link to the magnum-distancefieldconverter utility") endif() # API-independent utilities @@ -164,6 +167,10 @@ option(MAGNUM_WITH_IMAGECONVERTER "Build magnum-imageconverter utility" OFF) option(MAGNUM_WITH_SCENECONVERTER "Build magnum-sceneconverter utility" OFF) option(MAGNUM_WITH_SHADERCONVERTER "Build magnum-shaderconverter utility" OFF) +set(MAGNUM_IMAGECONVERTER_STATIC_PLUGINS "" CACHE STRING "Static plugins to link to the magnum-imageconverter utility") +set(MAGNUM_SCENECONVERTER_STATIC_PLUGINS "" CACHE STRING "Static plugins to link to the magnum-sceneconverter utility") +set(MAGNUM_SHADERCONVERTER_STATIC_PLUGINS "" CACHE STRING "Static plugins to link to the magnum-shaderconverter utility") + # Magnum AL Info option(MAGNUM_WITH_AL_INFO "Build magnum-al-info utility" OFF) diff --git a/doc/building.dox b/doc/building.dox index 5abf9d80d..783177e4e 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -674,6 +674,22 @@ Options controlling the build: update your code whenever there's a breaking API change. It's however recommended to have this option disabled when deploying a final application as it can result in smaller binaries. +- `MAGNUM_DISTANCEFIELDCONVERTER_STATIC_PLUGINS`, + `MAGNUM_FONTCONVERTER_STATIC_PLUGINS`, + `MAGNUM_IMAGECONVERTER_STATIC_PLUGINS`, + `MAGNUM_SCENECONVERTER_STATIC_PLUGINS` and + `MAGNUM_SHADERCONVERTER_STATIC_PLUGINS` --- Static plugins to link to the + @ref magnum-distancefieldconverter "magnum-distancefieldconverter", + @ref magnum-fontconverter "magnum-fontconverter", + @ref magnum-imageconverter "magnum-imageconverter", + @ref magnum-sceneconverter "magnum-sceneconverter" and + @ref magnum-shaderconverter "magnum-shaderconverter" utilities, + respectively. Intended for use in scenarios where both + `MAGNUM_BUILD_STATIC` and `MAGNUM_BUILD_PLUGINS_STATIC` is enabled, in + which case these executables don't have a possibility to load dynamic + plugins from a filesystem. Plugins from the Magnum Plugins repository + (and elsewhere) can be linked if it's added as a CMake subproject. Expects + a semicolon-separated list of existing CMake targets, for example `Magnum::AnyImageImporter;MagnumPlugins::StbImageImporter`. - Additional options are inherited from the @ref CORRADE_BUILD_MULTITHREADED, @ref CORRADE_BUILD_CPU_RUNTIME_DISPATCH and @ref CORRADE_CPU_USE_IFUNC options specified when building Corrade. diff --git a/doc/changelog.dox b/doc/changelog.dox index d596ee711..7e6e319c7 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -672,6 +672,13 @@ See also: [mosra/magnum#570](https://github.com/mosra/magnum/pull/570). - Fixed wrong `.gitattributes` option for LF line endings in MSYS PKGBUILDs (see [mosra/magnum#574](https://github.com/mosra/magnum/issues/574)) +- Added `MAGNUM_DISTANCEFIELDCONVERTER_STATIC_PLUGINS`, + `MAGNUM_FONTCONVERTER_STATIC_PLUGINS`, + `MAGNUM_IMAGECONVERTER_STATIC_PLUGINS`, + `MAGNUM_SCENECONVERTER_STATIC_PLUGINS` and + `MAGNUM_SHADERCONVERTER_STATIC_PLUGINS` CMake options for linking static + plugins to the command-line utilities. See @ref building-features for more + information. @subsection changelog-latest-bugfixes Bug fixes diff --git a/src/Magnum/SceneTools/CMakeLists.txt b/src/Magnum/SceneTools/CMakeLists.txt index ab7e8fcc2..f82451f7b 100644 --- a/src/Magnum/SceneTools/CMakeLists.txt +++ b/src/Magnum/SceneTools/CMakeLists.txt @@ -27,6 +27,17 @@ # property that would have to be set on each target separately. set(CMAKE_FOLDER "Magnum/SceneTools") +# Somehow, due to MagnumTradeObjects having target_include_directories() with +# $, +# if MAGNUM_SCENECONVERTER_STATIC_PLUGINS is non-empty then CMake fails with +# +# Target "Corrade::PluginManager" not found. +# +# unless the find_package() is here. Not sure why, probably some bug in CMake +# dependency handling? Changing target_include_directories() to PRIVATE doesn't +# help, removing it altogether helps. +find_package(Corrade REQUIRED PluginManager) + # Files shared between main library and unit test library set(MagnumSceneTools_SRCS ) @@ -88,7 +99,8 @@ if(MAGNUM_WITH_SCENECONVERTER) Magnum MagnumMeshTools MagnumSceneTools - MagnumTrade) + MagnumTrade + ${MAGNUM_SCENECONVERTER_STATIC_PLUGINS}) install(TARGETS magnum-sceneconverter DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}) diff --git a/src/Magnum/ShaderTools/CMakeLists.txt b/src/Magnum/ShaderTools/CMakeLists.txt index 131daa46a..400af9302 100644 --- a/src/Magnum/ShaderTools/CMakeLists.txt +++ b/src/Magnum/ShaderTools/CMakeLists.txt @@ -91,7 +91,8 @@ if(MAGNUM_WITH_SHADERCONVERTER) add_executable(magnum-shaderconverter shaderconverter.cpp) target_link_libraries(magnum-shaderconverter PRIVATE Magnum - MagnumShaderTools) + MagnumShaderTools + ${MAGNUM_SHADERCONVERTER_STATIC_PLUGINS}) install(TARGETS magnum-shaderconverter DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}) diff --git a/src/Magnum/Text/CMakeLists.txt b/src/Magnum/Text/CMakeLists.txt index 4fd075698..8dd3b71b0 100644 --- a/src/Magnum/Text/CMakeLists.txt +++ b/src/Magnum/Text/CMakeLists.txt @@ -116,7 +116,8 @@ if(MAGNUM_WITH_FONTCONVERTER) target_link_libraries(magnum-fontconverter PRIVATE Magnum MagnumText - MagnumTrade) + MagnumTrade + ${MAGNUM_FONTCONVERTER_STATIC_PLUGINS}) if(MAGNUM_TARGET_EGL) target_link_libraries(magnum-fontconverter PRIVATE MagnumWindowlessEglApplication) elseif(CORRADE_TARGET_IOS) diff --git a/src/Magnum/TextureTools/CMakeLists.txt b/src/Magnum/TextureTools/CMakeLists.txt index 625b71a25..f701a6396 100644 --- a/src/Magnum/TextureTools/CMakeLists.txt +++ b/src/Magnum/TextureTools/CMakeLists.txt @@ -27,6 +27,18 @@ # property that would have to be set on each target separately. set(CMAKE_FOLDER "Magnum/TextureTools") +# Somehow, due to MagnumTradeObjects having target_include_directories() with +# $, +# if MAGNUM_DISTANCEFIELDCONVERTER_STATIC_PLUGINS is non-empty then CMake fails +# with +# +# Target "Corrade::PluginManager" not found. +# +# unless the find_package() is here. Not sure why, probably some bug in CMake +# dependency handling? Changing target_include_directories() to PRIVATE doesn't +# help, removing it altogether helps. +find_package(Corrade REQUIRED PluginManager) + set(MagnumTextureTools_GracefulAssert_SRCS Atlas.cpp) @@ -84,7 +96,8 @@ if(MAGNUM_WITH_DISTANCEFIELDCONVERTER) target_link_libraries(magnum-distancefieldconverter PRIVATE Magnum MagnumTextureTools - MagnumTrade) + MagnumTrade + ${MAGNUM_DISTANCEFIELDCONVERTER_STATIC_PLUGINS}) if(MAGNUM_TARGET_EGL) target_link_libraries(magnum-distancefieldconverter PRIVATE MagnumWindowlessEglApplication) elseif(CORRADE_TARGET_IOS) diff --git a/src/Magnum/Trade/CMakeLists.txt b/src/Magnum/Trade/CMakeLists.txt index 6c981bc54..547bed61a 100644 --- a/src/Magnum/Trade/CMakeLists.txt +++ b/src/Magnum/Trade/CMakeLists.txt @@ -160,7 +160,8 @@ if(MAGNUM_WITH_IMAGECONVERTER) MagnumTrade # BasisImageConverter uses these, and linking pthread to just the # plugin doesn't work. See its documentation for details. - Threads::Threads) + Threads::Threads + ${MAGNUM_IMAGECONVERTER_STATIC_PLUGINS}) install(TARGETS magnum-imageconverter DESTINATION ${MAGNUM_BINARY_INSTALL_DIR})