From 8689730d01548883509b34f7a51449633224918f Mon Sep 17 00:00:00 2001 From: wang-bin Date: Fri, 15 Feb 2013 15:09:38 +0800 Subject: [PATCH] common.pri: fix create empty error in windows --- common.pri | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/common.pri b/common.pri index 12dc2ebdf..9dee596df 100644 --- a/common.pri +++ b/common.pri @@ -130,6 +130,18 @@ defineReplace(qtLongName) { return($$LONG_NAME) } +defineTest(empty_file) { + isEmpty(1): error("empty_file(name) requires one argument") +#"type NUL >filename" can create an empty file in windows, see http://stackoverflow.com/questions/210201/how-to-create-empty-text-file-from-a-batch-file +# 'echo. >file' or 'echo >file' will insert a new line, so use stderr + win32:isEmpty(QMAKE_SH) { + system("echo. 2> $$1")|return(false) + } else { +#if sh is after win's echo, then "echo >$$1" fails because win's echo is used + system("sh -c echo 2> $$1")|return(false) + } +} + lessThan(QT_MAJOR_VERSION, 5): { defineTest(write_file) { @@ -140,21 +152,17 @@ defineTest(write_file) { ## echo a string with "\n" will fail, so we can not use join #val = $$join($$2, $$escape_expand(\n))$$escape_expand(\n) isEmpty(3)|!isEqual(3, append) { - #win32:system("echo. > $$1")|return(false) #may has sh - #else - system("$$QMAKE_DEL_FILE $$1") +#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) } for(val, $$2) { - system("echo $$val >> $$1")|return(false) + system("echo $$val >> \"$$1\"")|return(false) } return(true) } #defineTest(cache) { # !isEmpty(4): error("cache(var, [set|add|sub] [transient] [super], [srcvar]) requires one to three arguments.") - -#} - #} } @@ -165,8 +173,9 @@ defineTest(getBuildRoot) { isEmpty(BUILD_DIR) { BUILD_DIR=$$(BUILD_DIR) isEmpty(BUILD_DIR) { - exists($$PROJECTROOT/.build.cache):include($$PROJECTROOT/.build.cache) -message("BUILD_DIR=$$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) isEmpty(BUILD_DIR) { BUILD_DIR=$$[BUILD_DIR] isEmpty(BUILD_DIR) { @@ -215,7 +224,7 @@ defineTest(preparePaths) { export(UI_DIR) export(OBJECTS_DIR) export(DESTDIR) - export(TARGET) + #export(TARGET) return(true) } COMMON_PRI_INCLUDED = 1