qt creator中的项目树与项目文件中的SOURCES变量不对应

时间:2015-11-16 21:18:06

标签: qt qt-creator qmake

在项目文件中:

SOURCES = Test.cpp

warning("Sources before: " $$SOURCES)

qqqqqqqq = 12
isEmpty(qqqqqqqq) {
    SOURCES += options1.cpp
    warning("Var is empty !!!")
} else {
    SOURCES += options2.cpp
    warning("Var is NOT empty !!!")
}

warning("Sources after: " $$SOURCES)

结果输出:

Project WARNING: Sources before:  Test.cpp
Project WARNING: Var is NOT empty !!!
Project WARNING: Sources after:  Test.cpp options2.cpp

一切都好。但在项目树中,我看到3个项目而不是2:

Test.cpp
options1.cpp    <-- where does it come from?
options2.cpp

有人知道这个options1.cpp的位置(“isEmpty(qqqqqqqq)”不应该执行)?

P.S。我还使用defineReplace来生成用户函数,进行一些文件操作(例如,通过regex从列表中提取一些文件)并返回文件列表。

结果是一样的:返回的文件列表在变量中是正常的(我使用“warning()”检查它)但是我在项目树中的所有文件都已在我的自定义函数中使用,就像任何if-statments被忽略一样(但是因为我通过“warning()”检查了它们,所以不会忽略它们)。我不需要这种垃圾((

scl_root_dir = ./..
scl_dir_public_include = $$scl_root_dir/include
scl_dir_src =           $$scl_root_dir/src
scl_dir_core =          $$scl_root_dir/src/core
scl_dir_components =    $$scl_root_dir/src/components

scl_src_components = \
    \
    $$scl_dir_components/SclCore/SclCoreConv.cpp \
    $$scl_dir_components/SclCore/SclCoreExports.h \
    $$scl_dir_components/SclCore/SclCoreImpl.cpp \
    $$scl_dir_components/SclCore/SclCoreImpl.h \
    $$scl_dir_components/SclCore/SclCorePrint.cpp \
    $$scl_dir_components/SclCore/ProgBase.cl \
    $$scl_dir_components/SclCore/ProgCore.cl \
    \
    $$scl_dir_components/MathBase/MathBaseImpl.cpp \
    $$scl_dir_components/MathBase/MathBaseImpl.h \
    $$scl_dir_components/MathBase/ProgMathBase.cl \
    $$scl_dir_components/MathBase/ProgMathBaseEx.cl

# ##############################################################################

defineReplace(get_headers) {
    variable = $$1
    names = $$eval($$variable)
    files =

    for(name, names) {
        res = $$find(name, \.h$)
        count(res,1) {
            files += $$name
            message("FileH: " $$name)
        }
    }

    return($$files)
}

defineReplace(get_sources) {
    variable = $$1
    names = $$eval($$variable)
    files =

    for(name, names) {
        res = $$find(name, \.cpp$)
        count(res,1) {
            files += $$name
            message("FileCpp: " $$name)
        }
    }

    return($$files)
}

defineReplace(get_opencl) {
    variable = $$1
    names = $$eval($$variable)
    files =

    for(name, names) {
        res = $$find(name, \.cl$)
        count(res,1) {
            files += $$name
            message("FileCL: " $$name)
        }
    }

    return($$files)
}


#################################################################################################

warning("---------------------------------------------------------")

list_cpp = $$get_sources(scl_src_components)
list_hpp = $$get_headers(scl_src_components)
list_ocl = $$get_opencl(scl_src_components)

message("list_cpp: " $$list_cpp)
message("list_hpp: " $$list_hpp)
message("list_ocl: " $$list_ocl)

message("SOURCES before: " $$SOURCES)
message("HEADERS before: " $$HEADERS)

SOURCES = $$list_ocl

SOURCES = $$list_cpp $$list_ocl
HEADERS = $$list_hpp

message("SOURCES after: " $$SOURCES)
message("HEADERS after: " $$HEADERS)

项目树中的结果(变量正常):

Headers:
    components:
        MathBase:
            MathBaseImpl.cpp
            MathBaseImpl.h
            ProgMathBase.cl
            ProgMathBaseEx.cl
        SclCore
            ProgBase.cl
            ProgCore.cl
            SclCoreConv.cpp
            SclCoreExports.h
            SclCoreImpl.cpp
            SclCoreImpl.h
            SclCorePrint.cpp
Sources
    components:
        MathBase:
            MathBaseImpl.cpp
            MathBaseImpl.h
            ProgMathBase.cl
            ProgMathBaseEx.cl
        SclCore
            ProgBase.cl
            ProgCore.cl
            SclCoreConv.cpp
            SclCoreExports.h
            SclCoreImpl.cpp
            SclCoreImpl.h
            SclCorePrint.cpp

0 个答案:

没有答案