我有一个文件“settings.ini”,需要驻留在 Qt 可执行文件旁边。
我可以在 Qt Creator 中为此添加一个自定义构建步骤,它调用如下内容:
copy %{sourceDir}/settings.ini %{buildDir}/settings.ini
到目前为止效果很好,但我想将其包含在 *.pro 文件中,这样我也可以将其放入我们的 SVN 中。
如何仅使用 qmake/.pro-files 来做到这一点?
要将
%{sourceDir}/settings.ini
复制到构建目录 而不需要调用 make install
,请使用:
copydata.commands = $(COPY_DIR) $$PWD/settings.ini $$OUT_PWD
first.depends = $(first) copydata
export(first.depends)
export(copydata.commands)
QMAKE_EXTRA_TARGETS += first copydata
$$PWD
是当前
.pro
文件的路径。如果您的
settings.ini
文件与项目文件不在同一目录中,则使用类似
$$PWD/more_dirs_here/settings.ini
的内容
注意:我在here找到了这个解决方案。我建议阅读整篇文章,因为它解释了它是如何工作的。
关键字。它将要求您在构建后运行
make install
,但它确实可以跨平台工作。
install_it.path = %{buildDir}
install_it.files += %{sourceDir}/settings.ini
INSTALLS += install_it
将 {AppName} 更改为相应的应用程序名称
# Define mac/windows specific target dirs
TARGETDIR = ''
macx {
TARGETDIR += $$OUT_PWD/{AppName}.app/Contents/MacOS/
}
else {
TARGETDIR += $$OUT_PWD
}
# Directories do not exist for the first build
# Without mkdata, build is successful after 5 tries. To avoid, use mkdata
mkdata.commands = $(MKDIR) $${TARGETDIR}
copydata.commands = $(COPY_FILE) $$PWD/settings.ini $${TARGETDIR}
first.depends = $(first) mkdata copydata
export(first.depends)
export(mkdata.commands)
export(copydata.commands)
QMAKE_EXTRA_TARGETS += first mkdata copydata
如果有人在评论中发布 Unix 解决方案,我很高兴添加 Unix 支持。
copyconfig.commands = $(COPY_DIR) $$shell_path($$PWD\config) $$shell_path($$DESTDIR\config)
copystyle.commands = $(COPY_DIR) $$shell_path($$PWD\style) $$shell_path($$DESTDIR\style)
first.depends = $(first) copyconfig copystyle
export(first.depends)
export(copyconfig.commands)
export(copystyle.commands)
QMAKE_EXTRA_TARGETS += first copyconfig copystyle