原答案
这是通过使用构建系统来实现的。通常在 Gnome 中,这是 Meson Build System(之前是 Autotools)。
作为一个非常简单的解释,该工具在运行时会查看各种meson.build 文件(例如,this one 用于视图)并构建一个 Makefile 来构建项目.在这些文件中,描述了文件和资源之间的依赖关系。实际上,介子的意义远不止于此,我鼓励您阅读它。
这是位于gui 目录下的meson.build 文件:
subdir('calendar-management')
subdir('event-editor')
subdir('gtk')
subdir('icons')
subdir('importer')
subdir('views')
calendar_incs += include_directories('.')
built_sources += gnome.compile_resources(
'gui-resources',
'gui.gresource.xml',
c_name: 'gui',
)
sources += files(
'gcal-application.c',
'gcal-calendar-popover.c',
'gcal-event-popover.c',
'gcal-event-widget.c',
'gcal-expandable-entry.c',
'gcal-meeting-row.c',
'gcal-quick-add-popover.c',
'gcal-search-button.c',
'gcal-weather-settings.c',
'gcal-window.c',
)
您可以在第 6 行看到包含子目录 views。这是gcal-window.ui 了解其观点的地方。
跟进
如果您要删除 quick_add_popover.ui 文件,当您尝试使用您的实际 Makefile 进行构建时,构建将失败,因为 Makefile 中的某个位置 Meson 会为您编写,该资源(在本例中为 quick_add_popover.ui)将被引用,但在你的代码中它会消失。
其他有趣的文件:
-
gui.gresource.xml 在gui 下。这是定义 ui 文件资源的地方。
-
meson.buildgui 下的文件。这是通过gnome.compile_resources 函数将gui.gressource.xml 告知Meson 的地方。
我建议您阅读有关 Meson 的信息或在 YouTube 上查看以了解更多信息。