From 8b06913534e305037682b6e81010025482d89b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 11 Oct 2016 16:43:53 +0200 Subject: [PATCH] CMake: make the plugin directories used in utilities more configurable. In particular it is now possible to override the MAGNUM_PLUGINS_DIR variables and even specify them relative, which will make them relative to executable location. It's nice when everything clicks together :) --- CMakeLists.txt | 20 +++++++++++++------ doc/building.dox | 8 ++++++++ src/Magnum/Text/fontconverter.cpp | 2 +- .../TextureTools/distancefieldconverter.cpp | 2 +- src/Magnum/Trade/imageconverter.cpp | 2 +- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22f25a4ae..870f9803d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -291,17 +291,25 @@ set(MAGNUM_PLUGINS_AUDIOIMPORTER_RELEASE_LIBRARY_INSTALL_DIR ${MAGNUM_PLUGINS_RE # Plugin dirs based on wheter we are in debug or release build, needed by some # command-line tools if(CORRADE_TARGET_WINDOWS) - set(MAGNUM_PLUGINS_DEBUG_DIR ${MAGNUM_PLUGINS_DEBUG_BINARY_INSTALL_DIR}) - set(MAGNUM_PLUGINS_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_BINARY_INSTALL_DIR}) + set(MAGNUM_PLUGINS_DEBUG_DIR_INIT ${MAGNUM_PLUGINS_DEBUG_BINARY_INSTALL_DIR}) + set(MAGNUM_PLUGINS_RELEASE_DIR_INIT ${MAGNUM_PLUGINS_RELEASE_BINARY_INSTALL_DIR}) else() - set(MAGNUM_PLUGINS_DEBUG_DIR ${MAGNUM_PLUGINS_DEBUG_LIBRARY_INSTALL_DIR}) - set(MAGNUM_PLUGINS_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_LIBRARY_INSTALL_DIR}) + set(MAGNUM_PLUGINS_DEBUG_DIR_INIT ${MAGNUM_PLUGINS_DEBUG_LIBRARY_INSTALL_DIR}) + set(MAGNUM_PLUGINS_RELEASE_DIR_INIT ${MAGNUM_PLUGINS_RELEASE_LIBRARY_INSTALL_DIR}) endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(MAGNUM_PLUGINS_DIR ${MAGNUM_PLUGINS_DEBUG_DIR}) + set(MAGNUM_PLUGINS_DIR_INIT ${MAGNUM_PLUGINS_DEBUG_DIR}) else() - set(MAGNUM_PLUGINS_DIR ${MAGNUM_PLUGINS_RELEASE_DIR}) + set(MAGNUM_PLUGINS_DIR_INIT ${MAGNUM_PLUGINS_RELEASE_DIR}) endif() +# Make these paths configurable from outside +set(MAGNUM_PLUGINS_DEBUG_DIR ${MAGNUM_PLUGINS_DEBUG_DIR_INIT} + CACHE PATH "Base directory where to look for Magnum plugins for debug builds") +set(MAGNUM_PLUGINS_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_DIR_INIT} + CACHE PATH "Base directory where to look for Magnum plugins for release builds") +set(MAGNUM_PLUGINS_DIR ${MAGNUM_PLUGINS_DIR_INIT} + CACHE PATH "Base directory where to look for Magnum plugins") + add_subdirectory(modules) add_subdirectory(src) diff --git a/doc/building.dox b/doc/building.dox index 54ac96445..90beea486 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -244,6 +244,14 @@ There are also a few command-line utilities, also disabled by default: - `WITH_IMAGECONVERTER` - @ref magnum-imageconverter "magnum-imageconverter" executable for converting images of different formats. +Some of these utilities operate with plugins and they search for them in the +default plugin locations. You can override those locations using +`MAGNUM_PLUGINS_DIR` and `MAGNUM_PLUGINS_[DEBUG|RELEASE]_DIR` variables, much +like when using Magnum from dependent projects -- see @ref cmake for more +information. In particular, if you specify them as relative paths, the path +will be taken relative to executable location, which is useful for making +relocatable installations. + Magnum also contains a set of dependency-less plugins for importing essential file formats. Additional plugins are provided in separate plugin repository, see @ref building-plugins for more information. None of the plugins is built by diff --git a/src/Magnum/Text/fontconverter.cpp b/src/Magnum/Text/fontconverter.cpp index 74111c13a..5482b47f5 100644 --- a/src/Magnum/Text/fontconverter.cpp +++ b/src/Magnum/Text/fontconverter.cpp @@ -119,7 +119,7 @@ FontConverter::FontConverter(const Arguments& arguments): Platform::WindowlessAp .addArgument("output").setHelp("output", "output filename prefix") .addNamedArgument("font").setHelp("font", "font plugin") .addNamedArgument("converter").setHelp("converter", "font converter plugin") - .addOption("plugin-dir", MAGNUM_PLUGINS_DIR).setHelp("plugin-dir", "base plugin dir", "DIR") + .addOption("plugin-dir", Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), MAGNUM_PLUGINS_DIR)).setHelp("plugin-dir", "base plugin dir", "DIR") .addOption("characters", "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789?!:;,. ").setHelp("characters", "characters to include in the output") diff --git a/src/Magnum/TextureTools/distancefieldconverter.cpp b/src/Magnum/TextureTools/distancefieldconverter.cpp index 47d5e9d90..45a042aa1 100644 --- a/src/Magnum/TextureTools/distancefieldconverter.cpp +++ b/src/Magnum/TextureTools/distancefieldconverter.cpp @@ -120,7 +120,7 @@ DistanceFieldConverter::DistanceFieldConverter(const Arguments& arguments): Plat .addArgument("output").setHelp("output", "output image") .addOption("importer", "AnyImageImporter").setHelp("importer", "image importer plugin") .addOption("converter", "AnyImageConverter").setHelp("converter", "image converter plugin") - .addOption("plugin-dir", MAGNUM_PLUGINS_DIR).setHelp("plugin-dir", "base plugin dir", "DIR") + .addOption("plugin-dir", Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), MAGNUM_PLUGINS_DIR)).setHelp("plugin-dir", "base plugin dir", "DIR") .addNamedArgument("output-size").setHelp("output-size", "size of output image", "\"X Y\"") .addNamedArgument("radius").setHelp("radius", "distance field computation radius", "N") .addSkippedPrefix("magnum", "engine-specific options") diff --git a/src/Magnum/Trade/imageconverter.cpp b/src/Magnum/Trade/imageconverter.cpp index f1fbd138a..9821ddcac 100644 --- a/src/Magnum/Trade/imageconverter.cpp +++ b/src/Magnum/Trade/imageconverter.cpp @@ -74,7 +74,7 @@ int main(int argc, char** argv) { .addArgument("output").setHelp("output", "output image") .addOption("importer", "AnyImageImporter").setHelp("importer", "image importer plugin") .addOption("converter", "AnyImageConverter").setHelp("converter", "image converter plugin") - .addOption("plugin-dir", MAGNUM_PLUGINS_DIR).setHelp("plugin-dir", "base plugin dir", "DIR") + .addOption("plugin-dir", Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), MAGNUM_PLUGINS_DIR)).setHelp("plugin-dir", "base plugin dir", "DIR") .setHelp("Converts images of different formats.") .parse(argc, argv);