1

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.

George
  • 578
  • 4
  • 21
  • The .. folder is (like) a hardlink to the parent directory (see [here](https://stackoverflow.com/q/23242004/6934037)) and don't have anything to do with bash. If this path doesn't work, I don't think it's because of the dots. – anonymus1994.1 Apr 30 '21 at 00:41

2 Answers2

1

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

Matt
  • 13,674
  • 1
  • 18
  • 27
0

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
George
  • 578
  • 4
  • 21