Skip to content

Commit

Permalink
target arch test in qmake support. fix mkspec error for Qt5
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Sep 12, 2013
1 parent 53fdd66 commit 92514cf
Show file tree
Hide file tree
Showing 4 changed files with 485 additions and 11 deletions.
2 changes: 1 addition & 1 deletion common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ defineReplace(qtSharedLib) {

defineReplace(qtLongName) {
unset(LONG_NAME)
LONG_NAME = $$1$${_OS}$${_ARCH}$${_EXTRA}
LONG_NAME = $$1$${_OS}_$${TARGET_ARCH}$${_EXTRA}
return($$LONG_NAME)
}

Expand Down
59 changes: 49 additions & 10 deletions root.pri
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
#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
Expand All @@ -20,9 +10,11 @@ isEmpty(BUILD_DIR):BUILD_DIR=$$out_dir
message("BUILD_DIR=$$BUILD_DIR")

greaterThan(QT_MAJOR_VERSION, 4) {
mkspecs_build = $$[QMAKE_SPEC]
#recheck:write_file($$BUILD_DIR/.qmake.cache) #FIXME: empty_file result in no qtCompileTest result in cache
load(configure)
} else {
mkspecs_build = $$[QMAKE_MKSPECS]
_QMAKE_CACHE_QT4_ = $$_QMAKE_CACHE_
#_QMAKE_CACHE_QT4_ is built in and always not empty
isEmpty(_QMAKE_CACHE_QT4_)|isEqual(_QMAKE_CACHE_QT4_,) {
Expand All @@ -42,6 +34,53 @@ greaterThan(QT_MAJOR_VERSION, 4) {
#load(configure.pri) #what's the difference?
message("cache: $$_QMAKE_CACHE_QT4_")
}
mkspecs_build ~= s,\\\\,/,g #avoid warning for '\'. qmake knows how to deal with '/'

defineTest(qtRunCommandQuitly) {
#win32 always call windows command
win32 { #QMAKE_HOST.os?
system("$$1 2>&1 >nul")|return(false) #system always call win32 cmd
} else {
system("$$1 2>&1 >/dev/null")|return(false)
}
return(true)
}

defineTest(testArch) {
test_dir = $$_PRO_FILE_PWD_/tests/arch
test_out_dir = $$shadowed($$test_dir)
qtRunCommandQuitly("$$QMAKE_MKDIR $$test_out_dir")
win32:test_cmd_base = "cd /d $$system_quote($$system_path($$test_out_dir)) &&"
else: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):qtRunCommandQuitly("$$test_cmd_base $$QMAKE_MAKE distclean")

message("$$test_cmd_base $$system_quote($$system_path($$QMAKE_QMAKE)) $$qmake_configs $$system_path($$test_dir)")
qtRunCommandQuitly("$$test_cmd_base $$system_quote($$system_path($$QMAKE_QMAKE)) $$qmake_configs $$system_path($$test_dir)") {
MSG=$$system("$$test_cmd_base $$QMAKE_MAKE 2>&1")
}
V = $$find(MSG, .*=.*)
for(v, V) {
v=$$replace(v, "", ) # "ARCH=x86". can not evalate with ". why \" may fail? eval("expr")
greaterThan(QT_MAJOR_VERSION, 4):eval("$$v")
else:eval("\"$$v\"")
}
export(ARCH)
export(ARCH_SUB)
cache(TARGET_ARCH, set, ARCH)
cache(TARGET_ARCH_SUB, set, ARCH_SUB)
message("target arch: $$ARCH")
}

#cache mkspecs. compare mkspec with cached one. if not equal, remove old cache to run new compile tests
#Qt5 does not have QMAKE_MKSPECS, use QMAKE_SPEC, QMAKE_XSPEC
isEmpty(mkspecs_cached)|!isEmpty(mkspecs_cached):!isEqual(mkspecs_cached, $$mkspecs_build) {
CONFIG += recheck
testArch()
}

cache(BUILD_DIR, set, BUILD_DIR)
#cache(BUILD_ROOT, set, BUILD_DIR)
cache(SOURCE_ROOT, set, SOURCE_ROOT)
Expand Down
Loading

0 comments on commit 92514cf

Please sign in to comment.