cmake build with qt6 (macos) does not include "plugins"

pdv pdvisschere at edpnet.be
Tue Mar 19 15:02:34 UTC 2024


On 07/11/2023 17:42, pdv wrote:
> On 06/11/2023 19:17, pdv wrote:
>> On 04/11/2023 20:35, Kornel Benko wrote:
>>> Am Sat, 4 Nov 2023 18:05:42 +0100
>>> schrieb pdv <pdvisschere at edpnet.be>:
>>>
>>>> On 04/11/2023 17:55, pdv wrote:
>>>>> On 21/03/2023 19:27, Kornel Benko wrote:
>>>>>> Am Tue, 21 Mar 2023 15:27:41 +0100
>>>>>> schrieb pdv <pdvisschere at edpnet.be>:
>>>>>>
>>>>>>> On 21/03/2023 11:00, Kornel Benko wrote:
>>>>>>>> Am Mon, 20 Mar 2023 20:05:32 +0100
>>>>>>>> schrieb pdv <pdvisschere at edpnet.be>:
>>>>>>>>> It's within the first if() else(), that's thus for qt6(see 
>>>>>>>>> below). I
>>>>>>>>> suppose this should work for all platforms, but I checked it on 
>>>>>>>>> macos
>>>>>>>>> only. Your patch is limited to APPLE and also works for me; If 
>>>>>>>>> this
>>>>>>>>> problem doesn't occur for other platforms, it's ok for me of 
>>>>>>>>> course.
>>>>>>>>
>>>>>>>> Probably no one else is using the bundle option (-DLYX_BUNDLE=ON).
>>>>>>>>
>>>>>>>> If you could try to use cmake without this option, I'd be 
>>>>>>>> interested
>>>>>>>> if it works for
>>>>>>>> you too.
>>>>>>>
>>>>>>> Apparently no problem. -DLYX_BUNDLE=OFF works too for me.
>>>>>>>
>>>>>>>> In this case we could get rid of it (probably).
>>>>>>>>
>>>>>>>>      Kornel
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> Good, so I will disable this option for lyx2.5 then.
>>>>>>
>>>>>>      Kornel
>>>>>>
>>>>>>
>>>>> I have build the latest lyx-master and I still need my (previous) 
>>>>> patch
>>>>> to build a LyX.app which includes all required Qt6 frameworks (I 
>>>>> want a
>>>>> stand-alone app).
>>>>>
>>>>> I'm using a recent version of CMake and apparently versions older than
>>>>> 3.5 will not longer be supported. To get rid of the annoying warnings
>>>>> I've upped the minimum version from 3.1 to 3.5 (new patch included).
>>>>>
>>>>> pdv
>>>>>
>>>> Sorry, forgot to include the patch.
>>>
>>> Will be done for 2.4.x versions. Also for other CMakeLists.txt's in 
>>> the lyx-sources.
>>>
>>>     Kornel
>>>
>>>
>> OK, thanks.
>>
>> Regarding the original issue, I'm still largely in the dark.
>>
>> I've build qt-6.2 (-debug-and-release option), installed cmake3.26 and 
>> I'm using macos 10.14 and xcode. lyx has been updated to a very recent 
>> master-version.
>>
>> Building a complete (qt frameworks included) debuggable LyX2.4.app 
>> with cmake does not work for me; the plug-ins are not copied into the 
>> bundle and cmake's fixup_bundle step subsequently fails.
>>
>> When I apply my patch (see first message) the plugins are copied but 
>> the fixup_bundle step still fails.
>>
>> Only the QtCore, ... frameworks have been copied to the bundle 
>> (probably by the install command in my patch), but not the 
>> QtCore_debug, ... versions, although no error is reported by 
>> fixup_bundle at copy time.
>>
>> That's because they are copied to a folder named /@rpath/ in my 
>> build-folder instead of into the bundle.
>> Apparently the @rpath used in the qt libraries is not handled properly 
>> by the cmake scripts.
>>
>> Can anyone confirm that a stand-alone LyX2.4.app can be build with 
>> cmake on macos or have any other suggestion?
>>
>> pdv
>>
>>
>>
> The problem with the _debug libraries is obvious. As for qt5 no _debug 
> libraries should be copied for qt6 either. I adapted my patch (included) 
> accordingly.
> 
> I once more tested a number of configurations and this is my conclusion.
> I can build a bundle with LYX_DMG=off and LYX_BUNDLE=on, the latter sets 
> also LYX_CPACK=on.
> 
> These are my resulting settings after cmake configure:
> 
> LYX_ENABLE_BUILD_TYPE:STRING       = AUTO   : Allows to tweak the 
> compiled code (AUTO release prerelease development gprof)
>      LYX_CPACK:BOOL                     = ON     : Use the CPack 
> management (Implies         LYX_INSTALL option)
>      LYX_LOCALVERSIONING:BOOL           = ON     : Add version info to 
> created package name (only used if LYX_CPACK option set)
>      LYX_INSTALL:BOOL                   = OFF    : Build install 
> projects/rules (implies a bunch of other options)
>      LYX_NLS:BOOL                       = ON     : Enable Native 
> Language Support (NLS)
>      LYX_REQUIRE_SPELLCHECK:BOOL        = OFF    : Abort if no 
> spellchecker available
>      LYX_ASPELL:BOOL                    = ON     : Require aspell
>      LYX_ENCHANT:BOOL                   = OFF    : Require Enchant
>      LYX_HUNSPELL:BOOL                  = ON     : Require Hunspell
>      LYX_RELEASE:BOOL                   = ON     : Build release 
> version, build debug when disabled
>      LYX_DEBUG:BOOL                     = OFF    : Enforce debug build
>      LYX_NO_OPTIMIZE:BOOL               = OFF    : Don't use any 
> optimization/debug flags
>      LYX_ENABLE_ASSERTIONS:BOOL         = ON     : Run sanity checks in 
> the program
>      LYX_PACKAGE_SUFFIX:BOOL            = ON     : Use version suffix 
> for packaging
>      LYX_SUFFIX_VALUE:STRING            =        : Use this string as 
> suffix
>      LYX_PCH:BOOL                       = OFF    : Use precompiled headers
>      LYX_MERGE_FILES:BOOL               = OFF    : Merge source files 
> into one compilation unit
>      LYX_MERGE_REBUILD:BOOL             = OFF    : Rebuild generated 
> files from merged files build
>      LYX_QUIET:BOOL                     = ON     : Don't generate 
> verbose makefiles
>      LYX_INSTALL_PREFIX:BOOL            = OFF    : Install path for LyX
>      LYX_BUNDLE:BOOL                    = ON     : Build bundle 
> (experimental)
>      LYX_ENABLE_URLTESTS:BOOL           = OFF    : Enable for URL tests
>      LYX_ENABLE_EXPORT_TESTS:BOOL       = OFF    : Enable for export tests
>      LYX_ENABLE_KEYTESTS:BOOL           = OFF    : Enable for keytests
>      LYX_ENABLE_VALGRIND_TESTS:BOOL     = OFF    : Enable for tests 
> involving valgrind
>      LYX_DEBUG_SANITIZE:STRING          = NONE   : Use sanitize check 
> (NONE ADDRESS UNSPECIFIED)
>      LYX_USE_QT:STRING                  = QT6    : Use Qt version as 
> frontend (AUTO QT5 QT6)
>      LYX_USE_IPO:STRING                 = OFF    : Interprocedural 
> optimization (OFF AUTO ON)
>      LYX_DISABLE_CALLSTACK_PRINTING:BOOL= OFF    : do not print a 
> callstack when crashing
>      LYX_EXTERNAL_Z:BOOL                = ON     : OFF := Build 3rdparty 
> lib zlib
>      LYX_EXTERNAL_DTL:BOOL              = OFF    : OFF := Build 3rdparty 
> commands dt2dv and dv2dt
>      LYX_EXTERNAL_ICONV:BOOL            = ON     : OFF := Build 3rdparty 
> lib iconvlib
>      LYX_EXTERNAL_HUNSPELL:BOOL         = ON     : OFF := Build 3rdparty 
> lib hunspelllib
>      LYX_EXTERNAL_MYTHES:STRING         = OFF    : OFF := Build 3rdparty 
> lib mytheslib (AUTO OFF ON)
>      LYX_DMG:BOOL                       = OFF    : Build as Mac bundle, 
> needed for .dmg  (experimental)
>      LYX_COCOA:BOOL                     = OFF    : Use Cocoa on Mac
> 
> This is with my patch applied.
> Without it, I can build a bundle but it crashes because the plugins are 
> missing.
> 
> The documentation of fixup_bundle clearly mentions that the plugins 
> should have been copied before running fixup_bundle;
> 
> Without applying my patch, how are these plugins copied when building 
> with qt6?
> 
> Probably not all ot6-plugins are needed by lyx and a selection could be 
> made.
> 
> pdv
> 

On macos-Sonoma the resulting app bundle (created with the install 
target in xcode) crashes, because of an invalid signature.

This is due to the fixup_bundle() code which modifies the library paths 
invalidating the signature.

The app must be signed again after the install target has been build.

I see no easy way to modify the install(CODE ...) steps and instead have 
defined a new target sign_install which just signs the app. The argument 
needed for the --sign option should be present in 
CPACK_BUNDLE_APPLE_CERT_APP.

There seems no way to make this sign_install target dependent on the 
(cmake generated) install target; therefore one must either build the 
install and sign_install targets consecutively or make the sign_install 
target dependent on the install target manually in xcode.

These steps have been added to my previous patch (new patch included) 
and I also derived the QT_PLUGINS_DIR and QT_LIBRARY_DIRS variables from 
the existing Qt6_DIR/Qt5_DIR variable, so they must not longer be supplied.

I only tested this with Qt6.

pdv
-------------- next part --------------
diff --git a/development/cmake/post_install/CMakeLists.txt b/development/cmake/post_install/CMakeLists.txt
index 52a2f782af..0f988e569d 100644
--- a/development/cmake/post_install/CMakeLists.txt
+++ b/development/cmake/post_install/CMakeLists.txt
@@ -28,14 +28,22 @@ if(LYX_BUNDLE)
     endif()
 
     if(Qt5Core_FOUND)
-	file(GLOB QT_PLUGIN_DIRECTORIES "${QT_PLUGINS_DIR}/imageformats")
-	install(DIRECTORY ${QT_PLUGIN_DIRECTORIES} DESTINATION "${qtplugin_dest_dir}/plugins/" COMPONENT Runtime REGEX "\\_debug\\.dylib$" EXCLUDE)
+       set(QT_PLUGINS_DIR ${Qt5_DIR}/../../../plugins)
+       set(QT_LIBRARY_DIRS ${Qt5_DIR}/../..)
+       file(GLOB QT_PLUGIN_DIRECTORIES "${QT_PLUGINS_DIR}/imageformats")
+       install(DIRECTORY ${QT_PLUGIN_DIRECTORIES} DESTINATION "${qtplugin_dest_dir}/plugins/" COMPONENT Runtime REGEX "\\_debug\\.dylib$" EXCLUDE)
        if(APPLE)
 		if(Qt5Core_VERSION VERSION_GREATER_EQUAL 5.10.0)
        			install_qt_plugin("Qt5::QMacStylePlugin")
        		endif()
         install_qt_plugin("Qt5::QCocoaIntegrationPlugin")
        endif()
+    else()
+    	set(QT_PLUGINS_DIR ${Qt6_DIR}/../../../plugins)
+    	set(QT_LIBRARY_DIRS ${Qt6_DIR}/../..)
+        # With QT6, just copy all the plugins
+        file(GLOB QT_PLUGIN_DIRECTORIES "${QT_PLUGINS_DIR}/*")
+        install(DIRECTORY ${QT_PLUGIN_DIRECTORIES} DESTINATION "${qtplugin_dest_dir}/plugins/" COMPONENT Runtime REGEX "\\_debug\\.dylib$" EXCLUDE)
     endif()
 
     # Install code does the following:
@@ -50,7 +58,10 @@ if(LYX_BUNDLE)
                     fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${installed_lyx_path}\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIRS}\")" 
                     COMPONENT Runtime
             )
-
+    # fixup_bundle invalidates the codesign, so the app must be signed again.
+    add_custom_target(sign_install WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}
+    	COMMAND /usr/bin/codesign --deep --force --sign "${CPACK_BUNDLE_APPLE_CERT_APP}" "LyX2.4.app" VERBATIM)
+    
     if (APPLE AND LYX_DMG)
         # Setup the disk image layout
         install(CODE "


More information about the lyx-devel mailing list