Skip to content

Commit

Permalink
qmake: cache() for Qt4 and ready to use compile test. unified with Qt5
Browse files Browse the repository at this point in the history
Now we can cache the BUILD_DIR exactly in $$BUILD_DIR, with emulated
cache() for Qt4, and built-in cache() for Qt5. The code is a little
complex for Qt4
TODO:
1. 1cahce(): erase the existing lines contain the value
  • Loading branch information
wang-bin committed Mar 2, 2013
1 parent 080322f commit 10f8613
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 7 deletions.
28 changes: 25 additions & 3 deletions QtAV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,31 @@ tests.depends += libqtav
OTHER_FILES += README.md TODO.txt Changelog
OTHER_FILES += templates/vo.h templates/vo.cpp templates/COPYRIGHT.h templates/mkclass.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

out_dir = $$OUT_PWD
greaterThan(QT_MAJOR_VERSION, 5): {
!isEmpty(new_compile_tests):write_file($$OUT_PWD/.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
lessThan(QT_MAJOR_VERSION, 5):include(common.pri)
build_dir = "BUILD_DIR=$$OUT_PWD"
write_file($$PWD/.build.cache, build_dir)
####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_")
}
cache(BUILD_DIR, set, out_dir)

#qtCompileTest(ffmpeg)|error("FFmpeg is required, but not available")
#qtCompileTest(portaudio)|warning("PortAudio is not available. No audio output in QtAV")
#qtCompileTest(gdiplus)
#qtCompileTest(direct2d)
#qtCompileTest(openal)
9 changes: 5 additions & 4 deletions common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,13 @@ defineTest(empty_file) {
}
}

##TODO: add defineReplace(getValue): parameter is varname
lessThan(QT_MAJOR_VERSION, 5): {

defineTest(write_file) {
!isEmpty(4): error("write_file(name, [content var, [append]]) requires one to three arguments.")
##TODO: 1.how to replace old value
##getting the value requires a function whose parameter has var name and return a string. join() is the only function
##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)
Expand All @@ -173,9 +174,9 @@ defineTest(getBuildRoot) {
isEmpty(BUILD_DIR) {
BUILD_DIR=$$(BUILD_DIR)
isEmpty(BUILD_DIR) {
build_cache = $$PROJECTROOT/.build.cache #use root project's cache for subdir projects
!exists($$build_cache):build_cache = $$PWD/.build.cache #common.pri is in the root dir of a sub project
exists($$build_cache):include($$build_cache)
#build_cache = $$PROJECTROOT/.build.cache #use root project's cache for subdir projects
#!exists($$build_cache):build_cache = $$PWD/.build.cache #common.pri is in the root dir of a sub project
#exists($$build_cache):include($$build_cache)
isEmpty(BUILD_DIR) {
BUILD_DIR=$$[BUILD_DIR]
isEmpty(BUILD_DIR) {
Expand Down
131 changes: 131 additions & 0 deletions configure.prf
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
### 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
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)
return(false)
}

!isEmpty(2):isEqual(2, set):mode_set=1
isEmpty(3) {
isEmpty(mode_set):error("cache(): modes other than 'set' require a source variable.")
srcvar = $$1
} else {
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?
isEqual(2, add) {
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?
} else:isEqual(2, set) {
varstr = "$$1 = $$join($$srcvar, $$escape_expand(\t))" ##TODO: how to use white space?
} else {
error("cache(): invalid flag $$2.")
}
}
#error("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)
}

equals(MAKEFILE_GENERATOR, UNIX) {
QMAKE_MAKE = make
} else:equals(MAKEFILE_GENERATOR, MINGW) {
!equals(QMAKE_HOST.os, Windows): \
QMAKE_MAKE = make
else: \
QMAKE_MAKE = mingw32-make
} else:if(equals(MAKEFILE_GENERATOR, MSVC.NET)|equals(MAKEFILE_GENERATOR, MSBUILD)) {
QMAKE_MAKE = nmake
} else {
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)
system("$$1 >> \"$$QMAKE_CONFIG_LOG\" 2>&1")|return(false)
return(true)
}

# Try to build the test project in $$QMAKE_CONFIG_TESTS_DIR/$$1
# ($$_PRO_FILE_PWD_/config.tests/$$1 by default).
#
# If the test passes, config_$$1 will be added to CONFIG.
# The result is automatically cached. Use of cached results
# can be suppressed by passing CONFIG+=recheck to qmake.
#
# Returns: true iff the test passes
defineTest(qtCompileTest) {
positive = config_$$1
done = done_config_$$1

$$done:!recheck {
$$positive:return(true)
return(false)
}

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

test_dir = $$QMAKE_CONFIG_TESTS_DIR/$$1
test_out_dir = $$shadowed($$test_dir)
test_cmd_base = "cd $$system_quote($$system_path($$test_out_dir)) &&"

# Disable qmake features which are typically counterproductive for tests
qmake_configs = "\"CONFIG -= qt debug_and_release app_bundle lib_bundle\""

# Clean up after previous run
exists($$test_out_dir/Makefile):qtRunLoggedCommand("$$test_cmd_base $$QMAKE_MAKE distclean")

mkpath($$test_out_dir)|error("Aborting.")

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)")
msg = "test $$1 succeeded"
write_file($$QMAKE_CONFIG_LOG, msg, append)

!$$positive {
CONFIG += $$positive
cache(CONFIG, add, positive)
}
!$$done {
CONFIG += $$done
cache(CONFIG, add, done)
}
export(CONFIG)
return(true)
}
}

log("no$$escape_expand(\\n)")
msg = "test $$1 FAILED"
write_file($$QMAKE_CONFIG_LOG, msg, append)

$$positive {
CONFIG -= $$positive
cache(CONFIG, sub, positive)
}
!$$done {
CONFIG += $$done
cache(CONFIG, add, done)
}
export(CONFIG)
return(false)
}

0 comments on commit 10f8613

Please sign in to comment.