From 7d7025652be710191831dccf21fbad1d47d528d7 Mon Sep 17 00:00:00 2001
From: Dale Larson <dlarson42@gmail.com>
Date: Sat, 7 Sep 2019 20:18:14 -0500
Subject: [PATCH] Enable MuseScore build using Qt's debug DLL's on Windows.

This is a hack, pure and simple. A desperate move needed to
investigate an issue deep in Qt's QML garbage collector.

Important Note: MuseScore doesn't actually run successfully with
Qt's debug bits. Two things will assert and thus need workarounds:

1) During app startup in file "workspace.cpp" function "readGlobalMenuBar()"
calls "m->setParent(nullptr)" at line 838. This call will assert
in Qt because calling "setParent()" on a widget is apparently illegal.
See file "qobject.cpp" funtion "setParent()" at line 1996 which has
the test code "Q_ASSERT(!d->isWidget);". To get past this NOP
(intel opcode 0x90) out the Q_ASSERT code by using the disassembler
to locate it's 2 byte 'jne' instruction and set it to NOPs by using the
memory window to edit RAM. This sucks but the alternative is to try to
rebuild Qt without the assert. No thanks!

2) The MuseScore Start Center code will also cause a Qt assert
triggered when the "QWebEnginePage" class is being initialized in
file "startcenter.h" line 47. To avoid this "crash" run a retail
version of MuseScore and turn off the start center in the program's
preferences dialog. Then re-run the debug version of MuseScore
built with this patch. You should get past the assert.
---
 CMakeLists.txt        |  8 ++---
 CMakeSettings.json    |  6 ++--
 awl/CMakeLists.txt    |  6 ++--
 mscore/CMakeLists.txt | 76 +++++++++++++++++++++++++++----------------
 4 files changed, 58 insertions(+), 38 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8cdf3b1d0..6f8d162ae 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -223,7 +223,7 @@ endif (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
 
 if (NOT MSVC)
    set(CMAKE_CXX_FLAGS_DEBUG   "-g")
-   set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG -DQT_NO_DEBUG")
+   set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG -DQT_DEBUG")
 endif (NOT MSVC)
 
 if (APPLE)
@@ -248,8 +248,8 @@ else (APPLE)
          set(CMAKE_C_FLAGS    "${CMAKE_C_FLAGS} /arch:SSE")
       endif (USE_SSE)
       set(CMAKE_CXX_FLAGS_DEBUG          "/MT /permissive- /std:c++14 /W4 /Zi /Ob0 /Od /RTC1")
-      set(CMAKE_CXX_FLAGS_RELEASE        "/MT /permissive- /std:c++14 /W4 /O2 /Ob2 /DNDEBUG /DQT_NO_DEBUG /DQT_NO_DEBUG_OUTPUT")
-      set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MT /permissive- /std:c++14 /W4 /Zi /O2 /Ob1 /DNDEBUG /DQT_NO_DEBUG /DQT_NO_DEBUG_OUTPUT")
+      set(CMAKE_CXX_FLAGS_RELEASE        "/MT /permissive- /std:c++14 /W4 /O2 /Ob2 /DNDEBUG /DQT_DEBUG /DQT_DEBUG_OUTPUT")
+      set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MT /permissive- /std:c++14 /W4 /Zi /O2 /Ob1 /DNDEBUG /DQT_DEBUG /DQT_DEBUG_OUTPUT")
       set(CMAKE_C_FLAGS_DEBUG            "/MT /W4 /Zi /Ob0 /Od /RTC1")
       set(CMAKE_C_FLAGS_RELEASE          "/MT /W4 /O2 /Ob2 /DNDEBUG")
       set(CMAKE_C_FLAGS_RELWITHDEBINFO   "/MT /W4 /Zi /O2 /Ob1 /DNDEBUG")
@@ -265,7 +265,7 @@ else (APPLE)
       else (MINGW)
          set(CMAKE_CXX_FLAGS         "${CMAKE_CXX_FLAGS} -fPIC")
          set(CMAKE_CXX_FLAGS_DEBUG   "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Woverloaded-virtual")
-         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DQT_NO_DEBUG_OUTPUT")
+         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DQT_DEBUG_OUTPUT")
       endif (MINGW)
    endif (MSVC)
 endif(APPLE)
diff --git a/CMakeSettings.json b/CMakeSettings.json
index 8260460ea..ab9338d3e 100644
--- a/CMakeSettings.json
+++ b/CMakeSettings.json
@@ -2,9 +2,9 @@
    // See https://go.microsoft.com//fwlink//?linkid=834763 for more information about this file.
    "configurations": [
       {
-         "name": "x64-RelWithDebInfo",
+         "name": "x64-Debug",
          "generator": "Visual Studio 15 2017 Win64",
-         "configurationType": "RelWithDebInfo",
+         "configurationType": "Debug",
          "inheritEnvironments": [ "msvc_x64_x64" ],
          "buildRoot": "${projectDir}\\msvc.build_x64", // "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", 
          "installRoot": "${projectDir}\\msvc.install_x64", // "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
@@ -12,7 +12,7 @@
          "variables": [
             {
                "name": "CMAKE_BUILD_TYPE",
-               "value": "RELWITHDEBINFO"
+               "value": "DEBUG"
             },
             {
                "name": "BUILD_FOR_WINSTORE",
diff --git a/awl/CMakeLists.txt b/awl/CMakeLists.txt
index dbad12c46..0c7418af6 100644
--- a/awl/CMakeLists.txt
+++ b/awl/CMakeLists.txt
@@ -91,7 +91,7 @@ add_library (
       utils.cpp
       )
 
-##  "-D_GNU_SOURCE -D_REENTRANT -DHAVE_CONFIG_H -DQT_PLUGIN -DQT_SHARED -DQT_NO_DEBUG -include ${PROJECT_SOURCE_DIR}/all.h"
+##  "-D_GNU_SOURCE -D_REENTRANT -DHAVE_CONFIG_H -DQT_PLUGIN -DQT_SHARED -DQT_DEBUG -include ${PROJECT_SOURCE_DIR}/all.h"
 
 #
 # We cannot use our precompiled headers because of -fPIC
@@ -100,14 +100,14 @@ if (NOT MSVC)
    set_target_properties(awlplugin
       PROPERTIES
       COMPILE_FLAGS
-         "-fPIC -D_GNU_SOURCE -D_REENTRANT -DHAVE_CONFIG_H -DQT_PLUGIN -DQT_SHARED -DQT_NO_DEBUG -include ${PROJECT_SOURCE_DIR}/all.h"
+         "-fPIC -D_GNU_SOURCE -D_REENTRANT -DHAVE_CONFIG_H -DQT_PLUGIN -DQT_SHARED -DQT_DEBUG -include ${PROJECT_SOURCE_DIR}/all.h"
       )
 else (NOT MSVC)
    # x86 archictecture does not support position-independent code, the -fPIC option is not relevant for this processor.
    set_target_properties (
       awlplugin
       PROPERTIES
-         COMPILE_FLAGS "${PCH_INCLUDE} -D_GNU_SOURCE -D_REENTRANT -DHAVE_CONFIG_H -DQT_PLUGIN -DQT_SHARED -DQT_NO_DEBUG"
+         COMPILE_FLAGS "${PCH_INCLUDE} -D_GNU_SOURCE -D_REENTRANT -DHAVE_CONFIG_H -DQT_PLUGIN -DQT_SHARED -DQT_DEBUG"
       )
 endif (NOT MSVC)   
 
diff --git a/mscore/CMakeLists.txt b/mscore/CMakeLists.txt
index 60f4698f9..588ca7ff7 100644
--- a/mscore/CMakeLists.txt
+++ b/mscore/CMakeLists.txt
@@ -642,7 +642,7 @@ if (MINGW)
    foreach (QtLibrary ${QT_LIBRARIES})
       message("Library ${QtLibrary}")
       # always use release libs
-      set_target_properties(${QtLibrary} PROPERTIES MAP_IMPORTED_CONFIG_DEBUG "RELEASE")
+      set_target_properties(${QtLibrary} PROPERTIES MAP_IMPORTED_CONFIG_DEBUG "DEBUG")
       get_target_property(QtSharedLibrary ${QtLibrary} LOCATION_RELEASE)
       if (EXISTS ${QtSharedLibrary})
           list (APPEND QtInstallLibraries ${QtSharedLibrary})
@@ -923,18 +923,30 @@ else (MINGW)
 
       # Copy DLL dependencies to .EXE DIRECTORY
       list(APPEND dlls_to_copy
-                  "${QT_INSTALL_BINS}/Qt5Core.dll"  "${QT_INSTALL_BINS}/Qt5Gui.dll"  "${QT_INSTALL_BINS}/Qt5Help.dll"
-                  "${QT_INSTALL_BINS}/Qt5Network.dll"  "${QT_INSTALL_BINS}/Qt5PrintSupport.dll"
-                  "${QT_INSTALL_BINS}/Qt5Qml.dll"  "${QT_INSTALL_BINS}/Qt5Quick.dll"  "${QT_INSTALL_BINS}/Qt5Sql.dll"
-                  "${QT_INSTALL_BINS}/Qt5QuickControls2.dll" "${QT_INSTALL_BINS}/Qt5QuickTemplates2.dll"
-                  "${QT_INSTALL_BINS}/Qt5Svg.dll"  "${QT_INSTALL_BINS}/Qt5Widgets.dll"  "${QT_INSTALL_BINS}/Qt5Xml.dll"
-                  "${QT_INSTALL_BINS}/Qt5XmlPatterns.dll"
-                  "${QT_INSTALL_BINS}/Qt5WebChannel.dll"
-                  "${QT_INSTALL_BINS}/Qt5QuickWidgets.dll" "${QT_INSTALL_BINS}/Qt5Positioning.dll"
-                  "${QT_INSTALL_BINS}/libEGL.dll" "${QT_INSTALL_BINS}/libGLESv2.dll" "${QT_INSTALL_BINS}/opengl32sw.dll"
+                  "${QT_INSTALL_BINS}/Qt5Cored.dll"  "${QT_INSTALL_BINS}/Qt5Guid.dll"  "${QT_INSTALL_BINS}/Qt5Helpd.dll"
+                  "${QT_INSTALL_BINS}/Qt5Networkd.dll"  "${QT_INSTALL_BINS}/Qt5PrintSupportd.dll"
+                  "${QT_INSTALL_BINS}/Qt5Qmld.dll"  "${QT_INSTALL_BINS}/Qt5Quickd.dll"  "${QT_INSTALL_BINS}/Qt5Sqld.dll"
+                  "${QT_INSTALL_BINS}/Qt5QuickControls2d.dll" "${QT_INSTALL_BINS}/Qt5QuickTemplates2d.dll"
+                  "${QT_INSTALL_BINS}/Qt5Svgd.dll"  "${QT_INSTALL_BINS}/Qt5Widgetsd.dll"  "${QT_INSTALL_BINS}/Qt5Xmld.dll"
+                  "${QT_INSTALL_BINS}/Qt5XmlPatternsd.dll"
+                  "${QT_INSTALL_BINS}/Qt5WebChanneld.dll"
+                  "${QT_INSTALL_BINS}/Qt5QuickWidgetsd.dll" "${QT_INSTALL_BINS}/Qt5Positioningd.dll"
+                  "${QT_INSTALL_BINS}/libEGLd.dll" "${QT_INSTALL_BINS}/libGLESv2d.dll" "${QT_INSTALL_BINS}/opengl32sw.dll"
+                  )
+      # HACK IN THE PDBS...
+      list(APPEND pdbs_to_copy
+                  "${QT_INSTALL_BINS}/Qt5Cored.pdb"  "${QT_INSTALL_BINS}/Qt5Guid.pdb"  "${QT_INSTALL_BINS}/Qt5Helpd.pdb"
+                  "${QT_INSTALL_BINS}/Qt5Networkd.pdb"  "${QT_INSTALL_BINS}/Qt5PrintSupportd.pdb"
+                  "${QT_INSTALL_BINS}/Qt5Qmld.pdb"  "${QT_INSTALL_BINS}/Qt5Quickd.dll"  "${QT_INSTALL_BINS}/Qt5Sqld.pdb"
+                  "${QT_INSTALL_BINS}/Qt5QuickControls2d.pdb" "${QT_INSTALL_BINS}/Qt5QuickTemplates2d.pdb"
+                  "${QT_INSTALL_BINS}/Qt5Svgd.pdb"  "${QT_INSTALL_BINS}/Qt5Widgetsd.pdb"  "${QT_INSTALL_BINS}/Qt5Xmld.pdb"
+                  "${QT_INSTALL_BINS}/Qt5XmlPatternsd.pdb"
+                  "${QT_INSTALL_BINS}/Qt5WebChanneld.pdb"
+                  "${QT_INSTALL_BINS}/Qt5QuickWidgetsd.pdb" "${QT_INSTALL_BINS}/Qt5Positioningd.pdb"
+                  "${QT_INSTALL_BINS}/libEGLd.pdb" "${QT_INSTALL_BINS}/libGLESv2d.pdb"
                   )
       if (USE_WEBENGINE)
-         list(APPEND dlls_to_copy "${QT_INSTALL_BINS}/Qt5WebEngineWidgets.dll" "${QT_INSTALL_BINS}/Qt5WebEngineCore.dll")
+         list(APPEND dlls_to_copy "${QT_INSTALL_BINS}/Qt5WebEngineWidgetsd.dll" "${QT_INSTALL_BINS}/Qt5WebEngineCored.dll")
       endif(USE_WEBENGINE)
 
       set(CMAKE_FIND_LIBRARY_PREFIX "")
@@ -964,6 +976,8 @@ else (MINGW)
       set( output_dir_for_dlls "${PROJECT_BINARY_DIR}/../msvc.install${ARCH_TYPE}/bin")
 
       COPY_FILES_INTO_DIRECTORY_IF_CHANGED( "${dlls_to_copy}" ${output_dir_for_dlls}  mscore)
+      # HACK IN THE PDB COPIES...
+      COPY_FILES_INTO_DIRECTORY_IF_CHANGED( "${pdbs_to_copy}" ${output_dir_for_dlls}  mscore)
 
       add_dependencies(mscore pluginDocumentation)
 
@@ -975,14 +989,13 @@ else (MINGW)
       foreach (QtLibrary ${QT_LIBRARIES})
          message("Library ${QtLibrary}")
          # always use release libs
-         set_target_properties(${QtLibrary} PROPERTIES MAP_IMPORTED_CONFIG_DEBUG "RELEASE")
+         set_target_properties(${QtLibrary} PROPERTIES MAP_IMPORTED_CONFIG_DEBUG "DEBUG")
          get_target_property(QtSharedLibrary ${QtLibrary} LOCATION_RELEASE)
          if (EXISTS ${QtSharedLibrary})
              list (APPEND QtInstallLibraries ${QtSharedLibrary})
          endif (EXISTS ${QtSharedLibrary})
       endforeach (QtLibrary ${QT_LIBRARIES})
       list(REMOVE_DUPLICATES QtInstallLibraries)
-
       target_link_libraries(mscore ${QT_LIBRARIES})
       add_dependencies(mscore lrelease)
 
@@ -997,34 +1010,41 @@ else (MINGW)
             ${dll_ssl2}
             ${dll_winsparkle}
             ${QtInstallLibraries}
-            ${QT_INSTALL_BINS}/libEGL.dll
-            ${QT_INSTALL_BINS}/libGLESv2.dll
+            ${QT_INSTALL_BINS}/libEGLd.dll
+            ${QT_INSTALL_BINS}/libGLESv2d.dll
             ${QT_INSTALL_BINS}/opengl32sw.dll
-            ${QT_INSTALL_BINS}/Qt5Positioning.dll
-            ${QT_INSTALL_BINS}/Qt5WebChannel.dll
+            ${QT_INSTALL_BINS}/Qt5Positioningd.dll
+            ${QT_INSTALL_BINS}/Qt5WebChanneld.dll
             ${PROJECT_SOURCE_DIR}/build/qt.conf
             DESTINATION bin)
 
       install(FILES
-         ${QT_INSTALL_PLUGINS}/iconengines/qsvgicon.dll
+         ${QT_INSTALL_PLUGINS}/iconengines/qsvgicond.dll
+         ${QT_INSTALL_PLUGINS}/iconengines/qsvgicond.pdb
          DESTINATION bin/iconengines)
 
       install(FILES
-         ${QT_INSTALL_PLUGINS}/imageformats/qjpeg.dll
-         ${QT_INSTALL_PLUGINS}/imageformats/qsvg.dll
-         ${QT_INSTALL_PLUGINS}/imageformats/qtiff.dll
+         ${QT_INSTALL_PLUGINS}/imageformats/qjpegd.dll
+         ${QT_INSTALL_PLUGINS}/imageformats/qsvgd.dll
+         ${QT_INSTALL_PLUGINS}/imageformats/qtiffd.dll
+         ${QT_INSTALL_PLUGINS}/imageformats/qjpegd.pdb
+         ${QT_INSTALL_PLUGINS}/imageformats/qsvgd.pdb
+         ${QT_INSTALL_PLUGINS}/imageformats/qtiffd.pdb
          DESTINATION bin/imageformats)
 
       install(FILES
-         ${QT_INSTALL_PLUGINS}/platforms/qwindows.dll
+         ${QT_INSTALL_PLUGINS}/platforms/qwindowsd.dll
+         ${QT_INSTALL_PLUGINS}/platforms/qwindowsd.pdb
          DESTINATION bin/platforms)
 
       install(FILES
-         ${QT_INSTALL_PLUGINS}/printsupport/windowsprintersupport.dll
+         ${QT_INSTALL_PLUGINS}/printsupport/windowsprintersupportd.dll
+         ${QT_INSTALL_PLUGINS}/printsupport/windowsprintersupportd.pdb
          DESTINATION bin/printsupport)
 
       install(FILES
-         ${QT_INSTALL_PLUGINS}/sqldrivers/qsqlite.dll
+         ${QT_INSTALL_PLUGINS}/sqldrivers/qsqlited.dll
+         ${QT_INSTALL_PLUGINS}/sqldrivers/qsqlited.pdb
          DESTINATION bin/sqldrivers)
 
       install( TARGETS mscore RUNTIME DESTINATION bin ) # this duplicate due to the correctly package step
@@ -1047,8 +1067,8 @@ else (MINGW)
       install(DIRECTORY
          ${QT_INSTALL_QML}
          DESTINATION .
-         REGEX ".*d\\.dll" EXCLUDE
-         REGEX ".pdb" EXCLUDE
+         #REGEX ".*d\\.dll" EXCLUDE
+         #REGEX ".pdb" EXCLUDE
          REGEX ".*QtGraphicalEffects.*" EXCLUDE
          REGEX ".*QtMultimedia.*" EXCLUDE
          REGEX ".*QtSensors.*" EXCLUDE
@@ -1117,14 +1137,14 @@ if (NOT MSVC)
    set_target_properties(inspectorplugin
       PROPERTIES
       COMPILE_FLAGS
-         "-fPIC -D_GNU_SOURCE -D_REENTRANT -DHAVE_CONFIG_H -DQT_PLUGIN -DQT_SVG_LIB -DQT_SHARED -DQT_NO_DEBUG -include ${PROJECT_SOURCE_DIR}/all.h"
+         "-fPIC -D_GNU_SOURCE -D_REENTRANT -DHAVE_CONFIG_H -DQT_PLUGIN -DQT_SVG_LIB -DQT_SHARED -DQT_DEBUG -include ${PROJECT_SOURCE_DIR}/all.h"
       )
 else (NOT MSVC)
    # x86 archictecture does not support position-independent code, the -fPIC option is not relevant for this processor.
    set_target_properties (
       inspectorplugin
       PROPERTIES
-         COMPILE_FLAGS "${PCH_INCLUDE} -D_GNU_SOURCE -D_REENTRANT -DHAVE_CONFIG_H -DQT_PLUGIN -DQT_SVG_LIB -DQT_SHARED -DQT_NO_DEBUG"
+         COMPILE_FLAGS "${PCH_INCLUDE} -D_GNU_SOURCE -D_REENTRANT -DHAVE_CONFIG_H -DQT_PLUGIN -DQT_SVG_LIB -DQT_SHARED -DQT_DEBUG"
       )
 endif (NOT MSVC)
 
-- 
2.17.1.windows.2

