c++qmake

Qmake copy multiple files while building


I have a list of files in my Qmake project. And I want them copied in build directory at build time.

My qmake file is below

OTHER_FILES += \
    input1 \
    input2 \
    input3 \

I'm using Linux. I've read a few stack overflow questions and googled about my problem but cannot find the exact solution.


Solution

  • Can be done using for() loop. You may need to adjust the BUILD_DIR variable. The "other" files are takes from the current directory.

    OTHER_FILES += \
        input1 \
        input2 \
        input3 \
    
    BUILD_DIR = build
    
    for(file, OTHER_FILES) {
        eval($${file}.depends = $$file)
        eval($${file}.target = $$BUILD_DIR/$$file)
        eval($${file}.commands = cp $$file $$BUILD_DIR/)
    
        QMAKE_EXTRA_TARGETS += $${file}
        PRE_TARGETDEPS += $$BUILD_DIR/$$file
    }