Skip to content

Commit

Permalink
port useful builtin qmake functions to Qt4. qtCompileTest works
Browse files Browse the repository at this point in the history
TODO:
1. shell_quote, system_quote are not finished
2. win32 msys may need qmake twice, the first QMAKE path is not right in
Makefile
3. other qmake builtin functions in qt5
  • Loading branch information
wang-bin committed Mar 3, 2013
1 parent 10f8613 commit ed07bea
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 39 deletions.
57 changes: 39 additions & 18 deletions QtAV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,50 @@ tests.depends += libqtav

OTHER_FILES += README.md TODO.txt Changelog
OTHER_FILES += templates/vo.h templates/vo.cpp templates/COPYRIGHT.h templates/mkclass.sh

#OTHER_FILES += config.test/mktest.sh

#cache mkspecs. compare mkspec with cached one. if not equal, remove old cache to run new compile tests
!isEmpty(mkspecs_cached):!isEqual(mkspecs_cached, $$QMAKE_MKSPECS):new_compile_tests = 1
mkspecs_build = $$[QMAKE_MKSPECS]
!isEmpty(mkspecs_cached) {
!isEqual(mkspecs_cached, $$mkspecs_build):new_compile_tests = 1
} else {
new_compile_tests = 1
}

##TODO: BUILD_DIR=>BUILD_ROOT
#if not empty, it means the parent project may already set it
isEmpty(out_dir):out_dir = $$OUT_PWD
isEmpty(SOURCE_ROOT):SOURCE_ROOT = $$PWD
isEmpty(BUILD_DIR):BUILD_DIR=$$out_dir
message("BUILD_DIR=$$BUILD_DIR")

out_dir = $$OUT_PWD
greaterThan(QT_MAJOR_VERSION, 5): {
!isEmpty(new_compile_tests):write_file($$OUT_PWD/.qmake.cache)
load(configure)
greaterThan(QT_MAJOR_VERSION, 5) {
!isEmpty(new_compile_tests):write_file($$BUILD_DIR/.qmake.cache)
load(configure)
} else {
include(common.pri)
!isEmpty(new_compile_tests):write_file($$OUT_PWD/.qmake.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($$OUT_PWD/.qmake.cache) ##TODO: erase the existing lines!!
include(configure.prf)
#cache() is available after include configure.prf
#load(configure.prf) #what's the difference?
message("cache: $$_QMAKE_CACHE_")
_QMAKE_CACHE_QT4_ = $$_QMAKE_CACHE_
#_QMAKE_CACHE_QT4_ is built in and always not empty
isEmpty(_QMAKE_CACHE_QT4_)|isEqual(_QMAKE_CACHE_QT4_,) {
message("No .qmake.cache found")
_QMAKE_CACHE_QT4_=$$BUILD_DIR/.qmake.cache
}
message("_QMAKE_CACHE_QT4_: $$_QMAKE_CACHE_QT4_")
include(common.pri)
!isEmpty(new_compile_tests):write_file($$BUILD_DIR/.qmake.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)
#cache() is available after include configure.prf
#load(configure.prf) #what's the difference?
message("cache: $$_QMAKE_CACHE_QT4_")
}
cache(BUILD_DIR, set, out_dir)
cache(BUILD_DIR, set, BUILD_DIR)
cache(BUILD_ROOT, set, BUILD_DIR)
cache(SOURCE_ROOT, set, SOURCE_ROOT)
cache(mkspecs_cached, set, mkspecs_build)

#qtCompileTest(ffmpeg)|error("FFmpeg is required, but not available")
#qtCompileTest(portaudio)|warning("PortAudio is not available. No audio output in QtAV")
Expand Down
70 changes: 68 additions & 2 deletions common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,30 @@ defineTest(empty_file) {
##TODO: add defineReplace(getValue): parameter is varname
lessThan(QT_MAJOR_VERSION, 5): {

defineTest(log){
system(echo $$1)
}

defineTest(mkpath) {
win32 {
#why always return false?
system("md $$system_path($$1) 2>nul")|return(false)
} else {
log("mkdir -p $$shell_path($$1)")
#why msys failed?
system("mkdir -p $$shell_path($$1)")|return(false)
}
return(true)
}

defineTest(write_file) {
#log("write_file($$1, $$2, $$3)")
!isEmpty(4): error("write_file(name, [content var, [append]]) requires one to three arguments.")
##TODO: 1.how to replace old value
##getting the ref value requires a function whose parameter has var name and return a string. join() is the only function
## var name is $$2.
## echo a string with "\n" will fail, so we can not use join
#val = $$join($$2, $$escape_expand(\n))$$escape_expand(\n)
#val = $$join($$2, $$escape_expand(\\n))$$escape_expand(\\n)
isEmpty(3)|!isEqual(3, append) {
#system("$$QMAKE_DEL_FILE $$1") #for win commad "del", path format used in qmake such as D:/myfile is not supported, "/" will be treated as an otpion for "del"
empty_file($$1)
Expand All @@ -166,6 +183,55 @@ defineTest(write_file) {
# !isEmpty(4): error("cache(var, [set|add|sub] [transient] [super], [srcvar]) requires one to three arguments.")
#}

defineReplace(clean_path) {
win32:1 ~= s|\\\\|/|g
contains(1, ^/.*):pfx = /
else:pfx =
segs = $$split(1, /)
out =
for(seg, segs) {
equals(seg, ..):out = $$member(out, 0, -2)
else:!equals(seg, .):out += $$seg
}
return($$join(out, /, $$pfx))
}

#make sure BUILD_DIR is already defined. otherwise return the input path
#only operate on string, seperator is always "/"
defineReplace(shadowed) {
isEmpty(SOURCE_ROOT):return($$1)
1 ~= s,$$SOURCE_ROOT,,g
shadow_dir = $$BUILD_DIR/$$1
shadow_dir ~= s,//,/,g
return($$shadow_dir)
}

defineReplace(shell_path) {
# QMAKE_DIR_SEP: \ for win cmd and / for sh
return($$replace(1, /, $$QMAKE_DIR_SEP))
}

##TODO: see qmake/library/ioutils.cpp
defineReplace(shell_quote) {
isEmpty(1):error("shell_quote(arg) requires one argument.")
return($$quote($$1))
}

defineReplace(system_path) {
win32 {
1 ~= s,/,\\,g
} else {
1 ~= s,\\,/,g
}
return($$1)
}

##TODO: see qmake/library/ioutils.cpp
defineReplace(system_quote) {
isEmpty(1):error("system_quote(arg) requires one argument.")
return($$quote($$1))
}

}

#argument 1 is default dir if not defined
Expand All @@ -191,7 +257,7 @@ defineTest(getBuildRoot) {
}
}
export(BUILD_DIR)
message(BUILD_DIR=$$BUILD_DIR)
#message(BUILD_DIR=$$BUILD_DIR)
return(true)
}

Expand Down
37 changes: 18 additions & 19 deletions configure.prf
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
### 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

# Ensure that a cache is present. If none was found on startup, this will create
# one in the build directory of the project which loads this feature.
#cache()

QMAKE_CONFIG_LOG = $$dirname(_QMAKE_CACHE_QT4_)/config.log
QMAKE_CONFIG_TESTS_DIR = $$_PRO_FILE_PWD_/config.tests

defineTest(cache) {
!isEmpty(4): error("cache(var, [set|add|sub] [transient] [super], [srcvar]) requires one to three arguments.")
isEmpty(1) {
write_file($$_QMAKE_CACHE_):return(true)
write_file($$_QMAKE_CACHE_QT4_):return(true)
return(false)
}

Expand All @@ -16,21 +24,21 @@ defineTest(cache) {
eval(srcvar = $$3)
dstvar = $$1
#We need the ref value, so the function's parameter must be a var name. join() is!
varstr = $$1 = $$join($$srcvar, $$escape_expand(\t)) ##TODO: how to use white space?
varstr = $$1 = $$join($$srcvar, $$escape_expand(\\t)) ##TODO: how to use white space?
isEqual(2, add) {
varstr = "$$1 += $$join($$srcvar, $$escape_expand(\t))" ##TODO: how to use white space?
varstr = "$$1 += $$join($$srcvar, $$escape_expand(\\t))" ##TODO: how to use white space?
} else:isEqual(2, sub) {
varstr = "$$1 -= $$join($$srcvar, $$escape_expand(\t))" ##TODO: how to use white space?
varstr = "$$1 -= $$join($$srcvar, $$escape_expand(\\t))" ##TODO: how to use white space?
} else:isEqual(2, set) {
varstr = "$$1 = $$join($$srcvar, $$escape_expand(\t))" ##TODO: how to use white space?
varstr = "$$1 = $$join($$srcvar, $$escape_expand(\\t))" ##TODO: how to use white space?
} else {
error("cache(): invalid flag $$2.")
}
}
#error("varstr: $$varstr")
#log("varstr: $$varstr")
##TODO: remove existing lines contain $$srcvar
#because write_file() will write 1 line for each value(seperated by space), so the value must be closed with "", then it's 1 value, not list
write_file($$_QMAKE_CACHE_, varstr, append)
write_file($$_QMAKE_CACHE_QT4_, varstr, append)
}

equals(MAKEFILE_GENERATOR, UNIX) {
Expand All @@ -46,13 +54,6 @@ equals(MAKEFILE_GENERATOR, UNIX) {
error("Configure tests are not supported with the $$MAKEFILE_GENERATOR Makefile generator.")
}

# Ensure that a cache is present. If none was found on startup, this will create
# one in the build directory of the project which loads this feature.
#cache()

QMAKE_CONFIG_LOG = $$dirname(_QMAKE_CACHE_)/config.log
QMAKE_CONFIG_TESTS_DIR = $$_PRO_FILE_PWD_/config.tests

defineTest(qtRunLoggedCommand) {
msg = "+ $$1"
write_file($$QMAKE_CONFIG_LOG, msg, append)
Expand All @@ -77,8 +78,7 @@ defineTest(qtCompileTest) {
return(false)
}

# log("Checking for $${1}... ")
message("Checking for $${1}... ")
log("Checking for $${1}... ")
msg = "executing config test $$1"
write_file($$QMAKE_CONFIG_LOG, msg, append)

Expand All @@ -92,12 +92,11 @@ defineTest(qtCompileTest) {
# Clean up after previous run
exists($$test_out_dir/Makefile):qtRunLoggedCommand("$$test_cmd_base $$QMAKE_MAKE distclean")

mkpath($$test_out_dir)|error("Aborting.")
mkpath($$test_out_dir)#|error("Aborting.") #mkpath currently return false, do not know why

qtRunLoggedCommand("$$test_cmd_base $$system_quote($$system_path($$QMAKE_QMAKE)) $$qmake_configs $$shell_quote($$test_dir)") {
qtRunLoggedCommand("$$test_cmd_base $$QMAKE_MAKE") {
# log("yes$$escape_expand(\\n)")
message("yes$$escape_expand(\\n)")
log("yes$$escape_expand(\\n)")
msg = "test $$1 succeeded"
write_file($$QMAKE_CONFIG_LOG, msg, append)

Expand Down

0 comments on commit ed07bea

Please sign in to comment.