Bug 487214 - Qt6 "kcoreaddons_add_plugin" attempts to link plugin in /INSTALL_NAMESPACE
Summary: Qt6 "kcoreaddons_add_plugin" attempts to link plugin in /INSTALL_NAMESPACE
Status: RESOLVED NOT A BUG
Alias: None
Product: extra-cmake-modules
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 6.1.0
Platform: Manjaro Linux
: NOR normal
Target Milestone: ---
Assignee: ecm-bugs-null@kde.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-19 00:56 UTC by grmpf
Modified: 2024-05-20 17:09 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description grmpf 2024-05-19 00:56:16 UTC
SUMMARY
I am trying to migrate a Kate plugin from Qt5.15.* to 6.1. The CMakeLists.txt is calling 
kcoreaddons_add_plugin(my_plugin_name 
    INSTALL_NAMESPACE "ktexteditor"), 
which with Qt6 builds the sources but fails upon linking because it is trying to link not in the build folder but in 
/INSTALL_NAMESPACE, i.e. in 
/ktexteditor

(For Qt6 the install namespace should be kf6/ktexteditor).

STEPS TO REPRODUCE
In $project_dir I run:
rm -rf build/
cmake -B build/ -D CMAKE_BUILD_TYPE=Release -D QT_MAJOR_VERSION=6 (or 5)
cmake --build build/

This is working fine with Qt5 and will create ./build/plugin_name.so in the build folder. A subsequent 
sudo cmake --install build/
would then copy the plugin .so to 
/usr/lib/qt/plugins/ktexteditor/

With Qt6 I am getting a linker error:
cmake --build build/
[......]
[ 85%] Linking CXX shared module /kf6/ktexteditor/my_plugin.so
/usr/bin/ld: cannot open output file /kf6/ktexteditor/my_plugin.so: No such file or directory
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/my_plugin.dir/build.make:153: /kf6/ktexteditor/my_plugin.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:653: CMakeFiles/my_plugin.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

OBSERVED RESULT
cmake --build build/ 
attempts to link the plugin .so in /kf6/ktexteditor/

EXPECTED RESULT
cmake --build build/ 
should link the plugin .so in ./build/

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Manjaro 
KDE Plasma Version: 6.0.4
KDE Frameworks Version: 6.1.0
Qt Version: 6.7.0

ADDITIONAL INFORMATION
Comment 1 Nicolas Fella 2024-05-19 12:26:34 UTC
Can you show your full project sources?
Comment 2 grmpf 2024-05-19 12:33:04 UTC
(In reply to Nicolas Fella from comment #1)
> Can you show your full project sources?

Sure. Here you go:
https://github.com/dennis2society/kate-gpg-plugin

I have been digging through the KF6CoreAddonsMacro.cmake and see that the CMAKE_LIBRARY_OUTPUT_DIRECTORY is empty,
which in line 62 is prepended to /INSTALL_NAMESPACE. This obviously leads to the /kf6/ktexteditor output path.
Comment 3 Nicolas Fella 2024-05-19 12:49:30 UTC
In https://github.com/dennis2society/kate-gpg-plugin/commit/609bd6d2634862459d13f61825a4e1bdcbad4944 you removed the version from the find_package(ECM) call. This changed the condition in https://invent.kde.org/frameworks/extra-cmake-modules/-/blob/master/kde-modules/KDECMakeSettings.cmake#L253 and causes CMAKE_LIBRARY_OUTPUT_DIRECTORY to be empty
Comment 4 grmpf 2024-05-19 12:56:32 UTC
Thanks for the hint. I have restored the find_package(ECM...) line to its previous state but linking is still attempted in /INSTALL_NAMESPACE.
Comment 5 Nicolas Fella 2024-05-19 15:49:21 UTC
Is KF5_DEP_VERSION set at this point? What if you specify e.g. 6.0 as version?
Comment 6 grmpf 2024-05-19 20:19:00 UTC
Yes. I have tried putting it higher in the CMakeLists and setting a specific version (i.e. 6.0)  but without any effect.
Comment 7 grmpf 2024-05-20 17:09:14 UTC
Thanks Nicolas for giving the correct hint! I could solve it by moving the line
set(KF_DEP_VERSION "${QT_MAJOR_VERSION}")
almost to the very top of the file. With this I can now build my plugin with both Qt5 and Qt6.

I am closing the bug report because the change for the  link/output path was probably intentional instead of a bug.

However I am still curious why the Qt5 build links the binary in ./build/ 
while Qt6 creates the library in ./build/bin/kf6/ktexteditor/
Is there any reason why this was changed?