Skip to content

Commit

Permalink
the toppest project includes root.pri is the root project
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Apr 20, 2013
1 parent 4907a8a commit 057e821
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 73 deletions.
64 changes: 1 addition & 63 deletions QtAV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,81 +14,19 @@ OTHER_FILES += \
templates/final.h templates/final.cpp
#OTHER_FILES += config.test/mktest.sh

#cache mkspecs. compare mkspec with cached one. if not equal, remove old cache to run new compile tests
#TODO: Qt5 does not have QMAKE_MKSPECS, use QMAKE_SPEC, QMAKE_XSPEC
mkspecs_build = $$[QMAKE_MKSPECS]
mkspecs_build ~= s,\\\\,/,g #avoid warning for '\'. qmake knows how to deal with '/'
!isEmpty(mkspecs_cached) {
!isEqual(mkspecs_cached, $$mkspecs_build):CONFIG += recheck
} else {
CONFIG += recheck
}

##TODO: BUILD_DIR=>BUILD_ROOT
#if not empty, it means the parent project may already set it
isEmpty(out_dir):out_dir = $$OUT_PWD
out_dir ~= s,\\\\,/,g #avoid warning for '\'. qmake knows how to deal with '/'
isEmpty(SOURCE_ROOT):SOURCE_ROOT = $$PWD
SOURCE_ROOT ~= s,\\\\,/,g #avoid warning for '\'. qmake knows how to deal with '/'
isEmpty(BUILD_DIR):BUILD_DIR=$$out_dir
message("BUILD_DIR=$$BUILD_DIR")

greaterThan(QT_MAJOR_VERSION, 4) {
#recheck:write_file($$BUILD_DIR/.qmake.cache) #FIXME: empty_file result in no qtCompileTest result in cache
load(configure)
} else {
_QMAKE_CACHE_QT4_ = $$_QMAKE_CACHE_
#_QMAKE_CACHE_QT4_ is built in and always not empty
isEmpty(_QMAKE_CACHE_QT4_)|isEqual(_QMAKE_CACHE_QT4_,) {
_QMAKE_CACHE_QT4_=$$BUILD_DIR/.qmake.cache
}
include(common.pri)
#recheck:write_file($$BUILD_DIR/.qmake.cache) #FIXME: empty_file result in no qtCompileTest result in cache
#use the following lines when building as a sub-project, write cache to this project src dir.
#if build this project alone and do not have sub-project depends on this lib, those lines are not necessary
####ASSUME compile tests and .qmake.cache is in project out root dir
#vars in .qmake.cache will affect all projects in subdirs, even if qmake's working dir is not in .qmake.cache dir
#write_file($$BUILD_DIR/.qmake.cache) ##TODO: erase the existing lines!!
include(configure.prf)
#clear config.log iff reconfigure is required
write_file($$QMAKE_CONFIG_LOG)
#cache() is available after include configure.prf
#load(configure.prf) #what's the difference?
message("cache: $$_QMAKE_CACHE_QT4_")
}
cache(BUILD_DIR, set, BUILD_DIR)
#cache(BUILD_ROOT, set, BUILD_DIR)
cache(SOURCE_ROOT, set, SOURCE_ROOT)
cache(mkspecs_cached, set, mkspecs_build)

EssentialDepends = avutil avcodec avformat swscale
OptionalDepends = portaudio direct2d gdiplus gl #openal

unix {
isEqual(QT_MAJOR_VERSION, 4) {
OptionalDepends += xv
}
}

for(d, EssentialDepends) {
!config_$$d {
CONFIG *= recheck
}
qtCompileTest($$d)|error("$$d is required, but compiler can not find it")
# CONFIG -= recheck
}
message("checking for optional features...")
for(d, OptionalDepends) {
qtCompileTest($$d)
}

include(root.pri)

PACKAGE_VERSION = 1.1.11
PACKAGE_NAME= QtAV

include(pack.pri)
#packageSet(1.1.11, QtAV)

!isEmpty(EssentialDepends)|!isEmpty(OptionalDepends) {
message("To recheck the dependencies, run qmake with argument 'CONFIG+=recheck'")
}
2 changes: 2 additions & 0 deletions configure.prf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#Designed by Wang Bin(Lucas Wang). 2013 <[email protected]>

### ONLY FOR Qt4. common.pri must be included before it so that write_file() can be used#######
### .qmake.cache MUST be created before it!
####ASSUME compile tests and .qmake.cache is in project out root dir
Expand Down
14 changes: 9 additions & 5 deletions doc/UseQtAVinYourProjects-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ myproject/myproject.pro
TEMPLATE = subdirs
SUBDIRS += libQtAV myplayer
myplayer.depends += libQtAV
libQtAV.file = QtAV/src/libQtAV.pro
libQtAV.file = QtAV/QtAV.pro
include(QtAV/root.pri)

###2. 把 QtAV 放到myproject

Expand All @@ -20,6 +21,7 @@ myproject/myproject.pro

> myproject/myproject.pro
> myproject/myplayer/myplayer.pro
> myproject/QtAV/QtAV.pro
> myproject/QtAV/src/libQtAV.pro
> myproject/QtAV/src/libQtAV.pri
Expand All @@ -31,11 +33,13 @@ myproject/myproject.pro

###4. 生成 Makefile

`qmake -r BUILD_DIR=some_dir`
qmake

必须使用参数 **_-r_****_BUILD_DIR=some_dir_**, 否则可能会出现依赖问题.
or

如果使用 QtCreator 来构建, 你可以点 _Projects_->_Build Steps_->_qmake_->_Additional arguments_, 添加 BUILD_DIR=your/buid/dir
qmake -r

###5. make
player 会生成在 $$BUILD_DIR/bin. 在windows下, QtAV 的 dll文件也会在那里生成
player 会生成在编译目录下的bin目录. 在windows下, QtAV 的 dll文件也会在那里生成

注意:windows 下如果用`qmake`命令(命令行下。QtCreator 默认使用`qmake -r`),则可能需要运行`qmake`两次,否则 make 可能失败
14 changes: 9 additions & 5 deletions doc/UseQtAVinYourProjects.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ myproject/myproject.pro
TEMPLATE = subdirs
SUBDIRS += libQtAV myplayer
myplayer.depends += libQtAV
libQtAV.file = QtAV/src/libQtAV.pro
libQtAV.file = QtAV/QtAV.pro
include(QtAV/root.pri)

###2. Put QtAV to myproject

Expand All @@ -20,6 +21,7 @@ the directory now is

> myproject/myproject.pro
> myproject/myplayer/myplayer.pro
> myproject/QtAV/QtAV.pro
> myproject/QtAV/src/libQtAV.pro
> myproject/QtAV/src/libQtAV.pri
Expand All @@ -30,11 +32,13 @@ in myproject/myplayer/myplayer.pro, add

###4. generate Makefile

`qmake -r BUILD_DIR=some_dir`
qmake

YOU MUST use parameter **_-r_** and **_BUILD_DIR=some_dir_**, or the dependence will be broken when building due to my pro structure.
or

If you are using QtCreator to build the project, you should go to _Projects_->_Build Steps_->_qmake_->_Additional arguments_, add BUILD_DIR=your/buid/dir
qmake -r

###5. make
you player binary will be created in $$BUILD_DIR/bin. If you are in windows, the QtAV dll also be there
you player binary will be created in `bin` under build dir. If you are in windows, the QtAV dll also be there

Note: for windows user, if you run `qmake`(command line build. QtCreator uses `qmake -r` by default) you may run `qmake` twice. otherwise make may fail.
2 changes: 2 additions & 0 deletions pack.pri
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#Designed by Wang Bin(Lucas Wang). 2013 <[email protected]>

##TODO: Why use function to add makefile target failed
# add a make command
defineReplace(mcmd) {
Expand Down
69 changes: 69 additions & 0 deletions root.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#Designed by Wang Bin(Lucas Wang). 2013 <[email protected]>

#cache mkspecs. compare mkspec with cached one. if not equal, remove old cache to run new compile tests
#TODO: Qt5 does not have QMAKE_MKSPECS, use QMAKE_SPEC, QMAKE_XSPEC
mkspecs_build = $$[QMAKE_MKSPECS]
mkspecs_build ~= s,\\\\,/,g #avoid warning for '\'. qmake knows how to deal with '/'
!isEmpty(mkspecs_cached) {
!isEqual(mkspecs_cached, $$mkspecs_build):CONFIG += recheck
} else {
CONFIG += recheck
}

##TODO: BUILD_DIR=>BUILD_ROOT
#if not empty, it means the parent project may already set it
isEmpty(out_dir):out_dir = $$OUT_PWD
out_dir ~= s,\\\\,/,g #avoid warning for '\'. qmake knows how to deal with '/'
isEmpty(SOURCE_ROOT):SOURCE_ROOT = $$PWD
SOURCE_ROOT ~= s,\\\\,/,g #avoid warning for '\'. qmake knows how to deal with '/'
isEmpty(BUILD_DIR):BUILD_DIR=$$out_dir
message("BUILD_DIR=$$BUILD_DIR")

greaterThan(QT_MAJOR_VERSION, 4) {
#recheck:write_file($$BUILD_DIR/.qmake.cache) #FIXME: empty_file result in no qtCompileTest result in cache
load(configure)
} else {
_QMAKE_CACHE_QT4_ = $$_QMAKE_CACHE_
#_QMAKE_CACHE_QT4_ is built in and always not empty
isEmpty(_QMAKE_CACHE_QT4_)|isEqual(_QMAKE_CACHE_QT4_,) {
_QMAKE_CACHE_QT4_=$$BUILD_DIR/.qmake.cache
}
include(common.pri)
#recheck:write_file($$BUILD_DIR/.qmake.cache) #FIXME: empty_file result in no qtCompileTest result in cache
#use the following lines when building as a sub-project, write cache to this project src dir.
#if build this project alone and do not have sub-project depends on this lib, those lines are not necessary
####ASSUME compile tests and .qmake.cache is in project out root dir
#vars in .qmake.cache will affect all projects in subdirs, even if qmake's working dir is not in .qmake.cache dir
#write_file($$BUILD_DIR/.qmake.cache) ##TODO: erase the existing lines!!
include(configure.prf)
#clear config.log iff reconfigure is required
write_file($$QMAKE_CONFIG_LOG)
#cache() is available after include configure.prf
#load(configure.prf) #what's the difference?
message("cache: $$_QMAKE_CACHE_QT4_")
}
cache(BUILD_DIR, set, BUILD_DIR)
#cache(BUILD_ROOT, set, BUILD_DIR)
cache(SOURCE_ROOT, set, SOURCE_ROOT)
cache(mkspecs_cached, set, mkspecs_build)

#config.tests
isEmpty(EssentialDepends) {
for(d, EssentialDepends) {
!config_$$d {
CONFIG *= recheck
}
qtCompileTest($$d)|error("$$d is required, but compiler can not find it")
# CONFIG -= recheck
}
}
!isEmpty(OptionalDepends) {
message("checking for optional features...")
for(d, OptionalDepends) {
qtCompileTest($$d)
}
}

!isEmpty(EssentialDepends)|!isEmpty(OptionalDepends) {
message("To recheck the dependencies, run qmake with argument 'CONFIG+=recheck'")
}

0 comments on commit 057e821

Please sign in to comment.