QMake: Automatically compiling all files in a directory

♀尐吖头ヾ 提交于 2019-11-29 16:46:09

问题


For my Qt project, I use a .pro file that includes a separate .pri file for the various header, source, form and resource files. However, every time I add a new file I need to manually add it to the .pri file. This is tedious and error-prone. Is there a way to "magically" add all files from a directory, either directly in the .pri file or by telling qmake to run a separate script beforehand?


回答1:


Running qmake -project from the directory will create a project file that includes all the .cpp and .h files in that directory. You could add a pre-compile step that calls qmake -project, then pass the generated file to a script that removes the first few lines. Here's a quick one-liner that could do the job :

qmake -project -o MyFiles.pro && sed '1,/^# Input/d' MyFiles.pro > MyFiles.pri && rm MyFiles.pro



回答2:


You can use:

SOURCES += *.cpp
HEADERS += *.h

in your pro file. Of course you still have to remember to re-run qmake after creating new files.



来源:https://stackoverflow.com/questions/3806833/qmake-automatically-compiling-all-files-in-a-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!