Search code examples
qtqmake

How to instruct Qmake to prepend a folder name to all it headers and sources listed?


I have a Qt app pro file lets say MyQtApp.pro. I have various platform specific files in different folders I want to compile on different platforms.

OSXFiles is the folder where lets say sources for OSX reside

macx {
    MY_FOLDER = OSXFiles

    SOURCES += $$MY_FOLDER/File_1.hpp $$MY_FOLDER/File_3.hpp $$MY_FOLDER/File_3.hpp
    SOURCES += $$MY_FOLDER/File_1.cpp $$MY_FOLDER/File_3.cpp $$MY_FOLDER/File_3.cpp
}

Above technique works but is there a way get rid of hassle of prepending $$MY_FOLDER to every file? Isnt there some cool trick like this for instance which would understand that for every default look into $$MY_FOLDER?

SOURCES += $$MY_FOLDER/ += File_1.hpp File_3.hpp 

Solution

  • You may use a for function

    MY_FOLDER = OSXFiles
    for(a, SOURCES){
        OSXFILES += $$MY_FOLDER/$$a
    }
    

    Or join:

    OSXFILES = $$join(SOURCES, " $$MY_FOLDER/", $$MY_FOLDER/)