diff --git a/CMakeLists.txt b/CMakeLists.txt index 69b3e3f..b281905 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,12 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) "Build type (Debug, Release, RelWithDebInfo, MinSizeRel)" FORCE) endif() +# Remember whether the user picked an install prefix *before* ECM's +# KDECMakeSettings runs: that module resets an unspecified prefix back to +# /usr/local, so we cannot rely on CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT +# after including it. We re-apply the user-local default below, post-include. +set(_deft_prefix_was_default ${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}) + find_package(ECM ${KF_MIN_VERSION} REQUIRED NO_MODULE) list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) @@ -24,12 +30,30 @@ include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) +# Default to a user-local install prefix when the user did not pick one. These +# are user KTextEditor plugins, not system packages: the stock /usr/local +# default needs root and is the wrong place for them. Applied here, after +# KDECMakeSettings, so it is not clobbered. +if(_deft_prefix_was_default) + set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local" CACHE PATH "Install prefix" FORCE) +endif() + set(CMAKE_POSITION_INDEPENDENT_CODE ON) find_package(Qt6 ${QT_MIN_VERSION} REQUIRED COMPONENTS Core Gui Widgets Concurrent) find_package(Qt6 ${QT_MIN_VERSION} COMPONENTS Test) find_package(KF6 ${KF_MIN_VERSION} COMPONENTS TextEditor XmlGui CoreAddons I18n) +# KDE's KDE_INSTALL_PLUGINDIR defaults to lib//plugins/, but Qt6 plugins +# (which is where Kate scans for KTextEditor plugins) live under +# lib//qt6/plugins/. Point the plugin install base at Qt's own plugin +# dir (QT6_INSTALL_PLUGINS is prefix-relative) so +# kcoreaddons_add_plugin(INSTALL_NAMESPACE kf6/ktexteditor) lands where Kate +# actually looks. kcoreaddons_add_plugin reads the *normal* variable, so set +# it directly (not just the cache entry, which the normal value would shadow). +set(KDE_INSTALL_PLUGINDIR "${QT6_INSTALL_PLUGINS}") +set(KDE_INSTALL_PLUGINDIR "${QT6_INSTALL_PLUGINS}" CACHE PATH "" FORCE) + enable_testing() add_subdirectory(src) diff --git a/README.md b/README.md index 941fbbb..fd894f2 100644 --- a/README.md +++ b/README.md @@ -65,13 +65,28 @@ KTextEditor plugins under `build/bin/kf6/ktexteditor/`: | `deft_sam.so` | `[deft:nineify] sam` | `sam`-style structural regular expressions | | `deft_plumb.so` | `[deft:nineify] plumb`| Plan 9 plumber (open under cursor) | -Drop whichever features you want where Kate scans for KTextEditor plugins (a -user path on `QT_PLUGIN_PATH`): +Drop whichever features you want where Kate scans for KTextEditor plugins. The +simplest way is `cmake --install`, which already targets the right place: ```sh -for so in build/bin/kf6/ktexteditor/deft_*.so; do - install -D "$so" ~/.local/lib/x86_64-linux-gnu/qt6/plugins/kf6/ktexteditor/"$(basename "$so")" -done +cmake --install build +``` + +**By default this installs into your home directory, not system-wide.** The +build sets `CMAKE_INSTALL_PREFIX` to `~/.local` when you don't pass one (these +are personal plugins, so installing them under `/usr/local` — the stock CMake +default — would need `root` and is the wrong place), and it points the plugin +install dir at Qt's own plugin path. So the plugins land at: + +``` +~/.local/lib//qt6/plugins/kf6/ktexteditor/deft_*.so +``` + +which is exactly the directory Kate scans (`QT_PLUGIN_PATH`). To install +system-wide instead, pass an explicit prefix (and expect to need `root`): + +```sh +cmake --install build --prefix /usr ``` Then in Kate: Settings → Configure Kate → Plugins → enable each **`[deft:…]`**