Is there QMake analogue for ".." from bash?

93 views Asked by At

I'm writing a unit test using QtTest framework. I have a .pro file representing test project where i want to specify a relative path to the source files i want to test with INCLUDEPATH keyword. The source files are in the source folder, which is 2 levels above the .pro file in folder hierarchy. So, if i were to get there with bash i would go with cd .. then cd .. then cd source. I tried INCLUDEPATH += $$PWD/../../source, but this doesn't seem to work. I also couldn't find any related info in Qt docs.

How can i achieve the behaviour i want from qmake? Any help would be great.

2

There are 2 answers

0
George On BEST ANSWER

The following code did the trick for me:

defineReplace(cleanPath) {
    win32:1 ~= s|\\\\|/|g
    contains(1, ^/.*):pfx = /
    else:pfx =
    segs = $$split(1, /)
    out =
    for(seg, segs) {
        equals(seg, ..):out = $$member(out, 0, -2)
        else:!equals(seg, .):out += $$seg
    }
    win32:return($$join(out, \\, $$pfx))
    return($$join(out, /, $$pfx))
}

srs_path = $$_PRO_FILE_PWD_/../../source
srs_path_clean = $$cleanPath($$srs_path)

INCLUDEPATH += $$srs_path_clean
0
Matt On

There is a builtin (replace) function called clean_path. Documented here.