aboutsummaryrefslogtreecommitdiff
path: root/ports/qt5-base/fixcmake.py
blob: 6f677327c1ca4de055a112e8fef5b11346135a2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
import re
import sys
from glob import glob

port="qt5"
if len(sys.argv) > 1:
    port=sys.argv[1]

files = [y for x in os.walk('.') for y in glob(os.path.join(x[0], '*.cmake'))]
tooldir="/tools/"+port+"/bin/"

for f in files:
    openedfile = open(f, "r")
    builder = ""
    dllpatterndebug = re.compile("_install_prefix}/bin/Qt5.*d+(.dll|.so)")
    libpatterndebug = re.compile("_install_prefix}/lib/Qt5.*d+(.lib|.a)")
    exepattern = re.compile("_install_prefix}/bin/[a-z]+(.exe|)")
    toolexepattern = re.compile("_install_prefix}/tools/qt5/bin/[a-z]+(.exe|)")
    tooldllpattern = re.compile("_install_prefix}/tools/qt5/bin/Qt5.*d+(.dll|.so)")
    populatepluginpattern = re.compile("_populate_[^_]+_plugin_properties\([^ ]+ RELEASE")
    populatetargetpattern = re.compile("_populate_[^_]+_target_properties\(RELEASE ")
    for line in openedfile:
        if "_install_prefix}/tools/qt5/${LIB_LOCATION}" in line:
            builder += "    if (${Configuration} STREQUAL \"RELEASE\")"
            builder += "\n    " + line.replace("/tools/qt5/bin", "/bin/")
            builder += "    else()" #This requires a release and debug build since Qt will check that the file exists! 
            #It would be better to use an elseif here with a EXISTS check but that requires a more complicated regex to build the complete filepath since each module uses its own _(qtmodule)_install_prefix
            #so single configuration builds of Qt are currently not supported. Thus =>
            #TODO: Make single configuration builds of Qt work correctly!
            builder += "\n    " + line.replace("/tools/qt5/debug/bin", "/debug/bin/") 
            builder += "    endif()\n"
        elif "_install_prefix}/bin/${LIB_LOCATION}" in line:
            builder += "    if (${Configuration} STREQUAL \"RELEASE\")"
            builder += "\n    " + line
            builder += "    else()" #This requires a release and debug build!
            builder += "\n    " + line.replace("/bin/", "/debug/bin/") 
            builder += "    endif()\n"
        elif "_install_prefix}/lib/${LIB_LOCATION}" in line:
            builder += "    if (${Configuration} STREQUAL \"RELEASE\")"
            builder += "\n    " + line
            builder += "    else()" #This requires a release and debug build!
            builder += "\n    " + line.replace("/lib/", "/debug/lib/")
            builder += "    endif()\n"
        elif "_install_prefix}/lib/${IMPLIB_LOCATION}" in line:
            builder += "    if (${Configuration} STREQUAL \"RELEASE\")"
            builder += "\n    " + line
            builder += "    else()" #This requires a release and debug build!
            builder += "\n    " + line.replace("/lib/", "/debug/lib/")
            builder += "    endif()\n"
        elif "_install_prefix}/plugins/${PLUGIN_LOCATION}" in line:
            builder += "    if (${Configuration} STREQUAL \"RELEASE\")"
            builder += "\n    " + line
            builder += "    else()" #This requires a release and debug build!
            builder += "\n    " + line.replace("/plugins/", "/debug/plugins/")
            builder += "    endif()\n"
        elif "_install_prefix}/lib/qtmaind.lib" in line:
            # qtmaind.lib has been moved to manual-link:
            builder += line.replace("/lib/", "/debug/lib/manual-link/")
        elif "_install_prefix}/lib/qtmain.lib" in line:
            # qtmain(d).lib has been moved to manual-link:
            builder += line.replace("/lib/", "/lib/manual-link/")
            builder += "    set(imported_location_debug \"${_qt5Core_install_prefix}/debug/lib/manual-link/qtmaind.lib\")\n"
            builder += "\n"
            builder += "    set_target_properties(Qt5::WinMain PROPERTIES\n"
            builder += "        IMPORTED_LOCATION_DEBUG ${imported_location_debug}\n"
            builder += "    )\n"
        elif populatepluginpattern.search(line) != None:
            builder += line
            builder += line.replace("RELEASE", "DEBUG").replace(".dll", "d.dll").replace(".lib", "d.lib")
        elif populatetargetpattern.search(line) != None:
            builder += line
            builder += line.replace("RELEASE", "DEBUG").replace(".dll", "d.dll").replace(".lib", "d.lib")
        elif dllpatterndebug.search(line) != None:
            builder += line.replace("/bin/", "/debug/bin/")
        elif libpatterndebug.search(line) != None:
            builder += line.replace("/lib/", "/debug/lib/")
        elif tooldllpattern.search(line) != None:
            builder += line.replace("/tools/qt5/bin", "/debug/bin/")
        elif exepattern.search(line) != None:
            builder += line.replace("/bin/", tooldir)
        elif toolexepattern.search(line) != None:
            builder += line.replace("/tools/qt5/bin/",tooldir)
        else:
            builder += line
    new_file = open(f, "w")
    new_file.write(builder)
    new_file.close()