Warning, /frameworks/kirigami/src/IncludeStaticDependencies.cmake is written in an unsupported language. File is not indexed.

0001 # This function is mainly a workaround for QTBUG-114949
0002 #
0003 # qt_add_qml_module will create a separate object target for each resource
0004 # added to a module when doing a static build. These are then set as
0005 # dependencies of the plugin target. This breaks installation since CMake
0006 # requires these targets to be exported along with the rest of the library.
0007 # However, just exporting them does not help as Qt includes these objects in
0008 # a somewhat roundabout way that breaks for exported targets. The solution
0009 # to all of this mess is to manually include all the target objects from the
0010 # separate object targets, then wipe the link interface so there are no
0011 # further references to these targets. We can then recreate the link
0012 # interface.
0013 function(include_static_dependencies ARG_TARGET)
0014     if (BUILD_SHARED_LIBS)
0015         return()
0016     endif()
0017 
0018     if (TARGET ${ARG_TARGET}_qmlcache)
0019         target_sources(${ARG_TARGET} PRIVATE $<TARGET_OBJECTS:${ARG_TARGET}_qmlcache>)
0020     endif()
0021 
0022     # This assumes the target uses the default naming for the plugin target.
0023     target_sources(${ARG_TARGET}plugin PRIVATE $<TARGET_OBJECTS:${ARG_TARGET}plugin_init>)
0024 
0025     # There is not really an easy way to get which resource targets the target
0026     # depends on. Luckily they follow a simple naming scheme so we can just try
0027     # and find these targets by iterating.
0028     foreach(_index RANGE 100)
0029         if (TARGET ${ARG_TARGET}_resources_${_index})
0030             target_sources(${ARG_TARGET} PRIVATE $<TARGET_OBJECTS:${ARG_TARGET}_resources_${_index}>)
0031         endif()
0032     endforeach()
0033 
0034     # Wipe the link interfaces of the target and the plugin target so they no
0035     # longer contain any references to the object targets.
0036     set_target_properties(${ARG_TARGET} PROPERTIES INTERFACE_LINK_LIBRARIES "" INTERFACE_LINK_OPTIONS "" INTERFACE_SOURCES "")
0037     set_target_properties(${ARG_TARGET}plugin PROPERTIES INTERFACE_LINK_LIBRARIES "" INTERFACE_LINK_OPTIONS "" INTERFACE_SOURCES "" LINK_LIBRARIES "")
0038 
0039     # Recreate the link interface for the plugin target.
0040     # Note that we require WHOLE_ARCHIVE as otherwise the resources coming from
0041     # the object targets cannot be found by Qt as there is nothing using them
0042     # so the compiler discards them.
0043     target_link_libraries(${ARG_TARGET}plugin
0044         PUBLIC
0045         Qt6::Qml
0046         $<BUILD_INTERFACE:$<LINK_LIBRARY:WHOLE_ARCHIVE,${ARG_TARGET}>>
0047         $<INSTALL_INTERFACE:$<LINK_LIBRARY:WHOLE_ARCHIVE,KF6::${ARG_TARGET}>>
0048     )
0049 endfunction()