西城

指尖代码,手上年华

联系 聚合 管理
  20 Posts :: 0 Stories :: 62 Comments :: 0 Trackbacks
与一个大四的学生同做一个项目,源文件有几十个,刚开始还在为写makefile发愁,幸好找到了automake工具链,觉得真是省了不少事。
后来他跟我说他用的是qmake,比用automake更省了不少事。一比较,发现qmake确实是一个更好地选择。

automake工具链比较复杂。一般要autoscan+修改configure.in+aclocal+写Makefile.am+configure+make。很不容易上手,而且
容易出错。automake提供了更为精细的控制,复杂但强大。但其实一般我们也用不了那么多的功能,而且中间生成的那些配置文件也不在
少数。这时候还要将源码与makefile部分分离开来。一般的开源软件就采用这种方法,文件层次清楚,易于管理。但是一般的很少的文件
的话,我觉得用qmake就足够了,易于上手,也不易出错。

qmake一般是qmake -project/qmake/make三步,中间需要适当地修改生成的*.pro文件,然后就差不多了。qmake -project主要就是用
来生成*.pro文件。主要做的就是读入当前目录的源文件。一些常用的配置变量如下:

VariableContents
CONFIGGeneral project configuration options.
DESTDIRThe directory in which the executable or binary file will be placed.
FORMSA list of UI files to be processed by uic.
HEADERSA list of filenames of header (.h) files used when building the project.
QTQt-specific configuration options.
RESOURCESA list of resource (.rc) files to be included in the final project. See the The Qt Resource System for more information about these files.
SOURCESA list of source code files to be used when building the project.
TEMPLATEThe template to use for the project. This determines whether the output of the build process will be an application, a library, or a plugin.
变量之间可以相互赋值比如。 TEMP_SOURCES = $$SOURCES

Template变量比较重要:用来决定所建工程的类型:
TemplateDescription of qmake output
app (default)Creates a Makefile to build an application.
libCreates a Makefile to build a library.
subdirsCreates a Makefile containing rules for the subdirectories specified using the SUBDIRSvariable. Each subdirectory must contain its own project file.
vcappCreates a Visual Studio Project file to build an application.
vclibCreates a Visual Studio Project file to build a library.
vcsubdirsCreates a Visual Studio Solution file to build projects in sub-directories.
一般用的都是app。

再说上面的config变量,内置的有:
OptionDescription
releaseThe project is to be built in release mode. This is ignored if debug is also specified.
debugThe project is to be built in debug mode.
debug_and_releaseThe project is built in both debug and release modes.
debug_and_release_targetThe project is built in both debug and release modes. TARGET is built intoboth the debug and release directories.
build_allIf debug_and_release is specified, the project is built in both debug and release modes by default.
autogen_precompile_sourceAutomatically generates a .cpp file that includes the precompiled header file specified in the .pro file.
orderedWhen using the subdirs template, this option specifies that the directories listed should be processed in the order in which they are given.
warn_onThe compiler should output as many warnings as possible. This is ignored ifwarn_off is specified.
warn_offThe compiler should output as few warnings as possible.
copy_dir_filesEnables the install rule to also copy directories, not just files.

debug_and_release建立两个版本。config还可以加上qt,thread,X11等用来指定建立相应的工程类型。
如果是qt工程的话,QT变量就是一个需要关注的对象。当用到相应的库时,就要加上相应的名字比如:
OptionFeatures
core (included by default)QtCore module
gui (included by default)QtGui module
networkQtNetwork module
openglQtOpenGL module
sqlQtSql module
svgQtSvg module
xmlQtXml module
xmlpatternsQtXmlPatterns module
qt3supportQt3Support module

常用的就是core,gui.其他的用到时加上就行。
另外一个比较重要问题就是QT与其他库的融合,LIBS和INCLUDEPATH可以做到这一点。看名字就知道其作用。
和Gcc命令行参数的用法类似。


qmake也有一些内置的函数用来提供更为强大的功能。常用到的有include,可以用来包含其他的工程文件,类似于C的头文件。还有条件控制类的,如:
win32 {      SOURCES += paintwidget_win.cpp  }
win32就是一个条件。甚至还有循环控制语句:
 EXTRAS = handlers tests docs  for(dir, EXTRAS) {      exists($$dir) {          SUBDIRS += $$dir      }  }
这样算下来,其实qmake也挺复杂的,不过相对于automake来说,还是很容易的。


posted on 2012-04-01 12:30 西城 阅读(2143) 评论(3)  编辑 收藏 引用 所属分类: Linux

Feedback

# re: qmake与automake 2012-04-01 13:39 yugi.fanxes
可以尝试下 waf 或者 cmake  回复  更多评论
  

# re: qmake与automake 2012-04-01 13:43 墨魂
@yugi.fanxes
多谢  回复  更多评论
  

# re: qmake与automake 2012-04-01 17:32 空明流转
CMake, Scons,都可以。不过CMake有些bug,Scons bug更多。。。  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理