2017-10-15 19:22:17 +08:00
import os
import re
2019-09-13 01:07:22 +08:00
import sys
2017-10-15 19:22:17 +08:00
from glob import glob
2019-09-13 01:07:22 +08:00
port = " qt5 "
if len ( sys . argv ) > 1 :
port = sys . argv [ 1 ]
2017-10-15 19:22:17 +08:00
files = [ y for x in os . walk ( ' . ' ) for y in glob ( os . path . join ( x [ 0 ] , ' *.cmake ' ) ) ]
2019-09-13 01:07:22 +08:00
tooldir = " /tools/ " + port + " /bin/ "
2017-10-15 19:22:17 +08:00
for f in files :
openedfile = open ( f , " r " )
builder = " "
2020-01-07 04:36:51 +08:00
dllpatterndebug = re . compile ( " _install_prefix}/bin/Qt5.*d+(.dll|.so) " )
libpatterndebug = re . compile ( " _install_prefix}/lib/Qt5.*d+(.lib|.a) " )
2019-09-13 01:07:22 +08:00
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) " )
2020-01-07 04:36:51 +08:00
populatepluginpattern = re . compile ( " _populate_[^_]+_plugin_properties \ ([^ ]+ RELEASE " )
populatetargetpattern = re . compile ( " _populate_[^_]+_target_properties \ (RELEASE " )
2017-10-15 19:22:17 +08:00
for line in openedfile :
2017-10-20 06:56:54 +08:00
if " _install_prefix}/tools/qt5/$ {LIB_LOCATION} " in line :
builder + = " if ($ {Configuration} STREQUAL \" RELEASE \" ) "
2019-09-13 01:07:22 +08:00
builder + = " \n " + line . replace ( " /tools/qt5/bin " , " /bin/ " )
2020-01-07 04:36:51 +08:00
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/ " )
2017-10-20 06:56:54 +08:00
builder + = " endif() \n "
elif " _install_prefix}/bin/$ {LIB_LOCATION} " in line :
2017-10-15 19:22:17 +08:00
builder + = " if ($ {Configuration} STREQUAL \" RELEASE \" ) "
builder + = " \n " + line
2020-01-07 04:36:51 +08:00
builder + = " else() " #This requires a release and debug build!
builder + = " \n " + line . replace ( " /bin/ " , " /debug/bin/ " )
2017-10-15 19:22:17 +08:00
builder + = " endif() \n "
elif " _install_prefix}/lib/$ {LIB_LOCATION} " in line :
builder + = " if ($ {Configuration} STREQUAL \" RELEASE \" ) "
builder + = " \n " + line
2020-01-07 04:36:51 +08:00
builder + = " else() " #This requires a release and debug build!
2017-10-15 19:22:17 +08:00
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
2020-01-07 04:36:51 +08:00
builder + = " else() " #This requires a release and debug build!
2017-10-15 19:22:17 +08:00
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
2020-01-07 04:36:51 +08:00
builder + = " else() " #This requires a release and debug build!
2017-10-15 19:22:17 +08:00
builder + = " \n " + line . replace ( " /plugins/ " , " /debug/plugins/ " )
builder + = " endif() \n "
2017-12-03 16:19:08 +08:00
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 "
2020-01-07 04:36:51 +08:00
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 :
2017-10-15 19:22:17 +08:00
builder + = line . replace ( " /bin/ " , " /debug/bin/ " )
2020-01-07 04:36:51 +08:00
elif libpatterndebug . search ( line ) != None :
2017-10-15 19:22:17 +08:00
builder + = line . replace ( " /lib/ " , " /debug/lib/ " )
2017-10-20 06:56:54 +08:00
elif tooldllpattern . search ( line ) != None :
2019-09-13 01:07:22 +08:00
builder + = line . replace ( " /tools/qt5/bin " , " /debug/bin/ " )
2017-10-15 19:22:17 +08:00
elif exepattern . search ( line ) != None :
2019-09-13 01:07:22 +08:00
builder + = line . replace ( " /bin/ " , tooldir )
elif toolexepattern . search ( line ) != None :
builder + = line . replace ( " /tools/qt5/bin/ " , tooldir )
2017-10-15 19:22:17 +08:00
else :
builder + = line
new_file = open ( f , " w " )
new_file . write ( builder )
2019-09-13 01:07:22 +08:00
new_file . close ( )