From 143bc8713d25a143607366a2b760db86c25acc12 Mon Sep 17 00:00:00 2001
From: freiro <f73b2894@opayq.com>
Date: Sun, 11 Dec 2016 11:49:22 +0100
Subject: [PATCH 1/4] [MSVC] Copy SDL2.dll to build folder

CMake now copies SDL2.dll when compiling citra with citra-qt as a target
on MSVC.
---
 src/citra_qt/CMakeLists.txt | 40 ++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt
index a9dacd5f1..495a9d780 100644
--- a/src/citra_qt/CMakeLists.txt
+++ b/src/citra_qt/CMakeLists.txt
@@ -107,27 +107,27 @@ if(UNIX AND NOT APPLE)
     install(TARGETS citra-qt RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
 endif()
 
-if (Qt5_FOUND AND MSVC)
+if (MSVC)
     include(WindowsCopyFiles)
-
-    set(Qt5_DLL_DIR "${Qt5_DIR}/../../../bin")
-    set(Qt5_PLATFORMS_DIR "${Qt5_DIR}/../../../plugins/platforms/")
     set(DLL_DEST "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/")
-    set(PLATFORMS ${DLL_DEST}platforms/)
-
-    windows_copy_files(citra-qt ${Qt5_DLL_DIR} ${DLL_DEST}
-        icudt*.dll
-        icuin*.dll
-        icuuc*.dll
-        Qt5Core$<$<CONFIG:Debug>:d>.*
-        Qt5Gui$<$<CONFIG:Debug>:d>.*
-        Qt5OpenGL$<$<CONFIG:Debug>:d>.*
-        Qt5Widgets$<$<CONFIG:Debug>:d>.*
-    )
-    windows_copy_files(citra-qt ${Qt5_PLATFORMS_DIR} ${PLATFORMS} qwindows$<$<CONFIG:Debug>:d>.*)
-
-    unset(Qt5_DLL_DIR)
-    unset(Qt5_PLATFORMS_DIR)
+    windows_copy_files(citra-qt ${SDL2_DLL_DIR} ${DLL_DEST} SDL2.dll)
+    if (Qt5_FOUND)
+        set(Qt5_DLL_DIR "${Qt5_DIR}/../../../bin")
+        set(Qt5_PLATFORMS_DIR "${Qt5_DIR}/../../../plugins/platforms/")
+        set(PLATFORMS ${DLL_DEST}platforms/)
+        windows_copy_files(citra-qt ${Qt5_DLL_DIR} ${DLL_DEST}
+            icudt*.dll
+            icuin*.dll
+            icuuc*.dll
+            Qt5Core$<$<CONFIG:Debug>:d>.*
+            Qt5Gui$<$<CONFIG:Debug>:d>.*
+            Qt5OpenGL$<$<CONFIG:Debug>:d>.*
+            Qt5Widgets$<$<CONFIG:Debug>:d>.*
+        )
+        windows_copy_files(citra-qt ${Qt5_PLATFORMS_DIR} ${PLATFORMS} qwindows$<$<CONFIG:Debug>:d>.*)
+        unset(Qt5_DLL_DIR)
+        unset(Qt5_PLATFORMS_DIR)
+        unset(PLATFORMS)
+    endif()
     unset(DLL_DEST)
-    unset(PLATFORMS)
 endif()

From 942f70951d4d52417ff7c8eb6e7638a59ebc0461 Mon Sep 17 00:00:00 2001
From: freiro <f73b2894@opayq.com>
Date: Sun, 11 Dec 2016 15:10:21 +0100
Subject: [PATCH 2/4] Removed redundant Qt check and other fixes

This removes a redundant check and moves part of the code to a separate
function.
---
 src/citra_qt/CMakeLists.txt | 39 ++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt
index 495a9d780..f283545aa 100644
--- a/src/citra_qt/CMakeLists.txt
+++ b/src/citra_qt/CMakeLists.txt
@@ -107,27 +107,26 @@ if(UNIX AND NOT APPLE)
     install(TARGETS citra-qt RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
 endif()
 
-if (MSVC)
+function(copy_msvc_libraries)
     include(WindowsCopyFiles)
     set(DLL_DEST "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/")
     windows_copy_files(citra-qt ${SDL2_DLL_DIR} ${DLL_DEST} SDL2.dll)
-    if (Qt5_FOUND)
-        set(Qt5_DLL_DIR "${Qt5_DIR}/../../../bin")
-        set(Qt5_PLATFORMS_DIR "${Qt5_DIR}/../../../plugins/platforms/")
-        set(PLATFORMS ${DLL_DEST}platforms/)
-        windows_copy_files(citra-qt ${Qt5_DLL_DIR} ${DLL_DEST}
-            icudt*.dll
-            icuin*.dll
-            icuuc*.dll
-            Qt5Core$<$<CONFIG:Debug>:d>.*
-            Qt5Gui$<$<CONFIG:Debug>:d>.*
-            Qt5OpenGL$<$<CONFIG:Debug>:d>.*
-            Qt5Widgets$<$<CONFIG:Debug>:d>.*
-        )
-        windows_copy_files(citra-qt ${Qt5_PLATFORMS_DIR} ${PLATFORMS} qwindows$<$<CONFIG:Debug>:d>.*)
-        unset(Qt5_DLL_DIR)
-        unset(Qt5_PLATFORMS_DIR)
-        unset(PLATFORMS)
-    endif()
-    unset(DLL_DEST)
+
+    set(Qt5_DLL_DIR "${Qt5_DIR}/../../../bin")
+    set(Qt5_PLATFORMS_DIR "${Qt5_DIR}/../../../plugins/platforms/")
+    set(PLATFORMS ${DLL_DEST}platforms/)
+    windows_copy_files(citra-qt ${Qt5_DLL_DIR} ${DLL_DEST}
+        icudt*.dll
+        icuin*.dll
+        icuuc*.dll
+        Qt5Core$<$<CONFIG:Debug>:d>.*
+        Qt5Gui$<$<CONFIG:Debug>:d>.*
+        Qt5OpenGL$<$<CONFIG:Debug>:d>.*
+        Qt5Widgets$<$<CONFIG:Debug>:d>.*
+    )
+    windows_copy_files(citra-qt ${Qt5_PLATFORMS_DIR} ${PLATFORMS} qwindows$<$<CONFIG:Debug>:d>.*)
+endfunction(copy_msvc_libraries)
+
+if (MSVC)
+    copy_msvc_libraries()
 endif()

From 031fc3a46011ea64362549a993e52f0018bfe5b8 Mon Sep 17 00:00:00 2001
From: freiro <f73b2894@opayq.com>
Date: Sun, 11 Dec 2016 15:36:34 +0100
Subject: [PATCH 3/4] Modularization of copy_msvc_libraries cmake funct

Created a new folder in Citra's root called CMakeModules that should
contain cmake functions used by the various CMakeLists.txt.
---
 CMakeLists.txt                    |  1 +
 CMakeModules/CopyMSVCLibsQt.cmake | 19 +++++++++++++++++++
 src/citra_qt/CMakeLists.txt       | 22 ++--------------------
 3 files changed, 22 insertions(+), 20 deletions(-)
 create mode 100644 CMakeModules/CopyMSVCLibsQt.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c02c96840..c7255a998 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,6 @@
 # CMake 3.2 required for cmake to know the right flags for CXX standard on OSX
 cmake_minimum_required(VERSION 3.2)
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules)
 
 function(download_bundled_external remote_path lib_name prefix_var)
     set(prefix "${CMAKE_BINARY_DIR}/externals/${lib_name}")
diff --git a/CMakeModules/CopyMSVCLibsQt.cmake b/CMakeModules/CopyMSVCLibsQt.cmake
new file mode 100644
index 000000000..64b27a807
--- /dev/null
+++ b/CMakeModules/CopyMSVCLibsQt.cmake
@@ -0,0 +1,19 @@
+function(copy_msvc_libraries)
+    include(WindowsCopyFiles)
+    set(DLL_DEST "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/")
+    windows_copy_files(citra-qt ${SDL2_DLL_DIR} ${DLL_DEST} SDL2.dll)
+
+    set(Qt5_DLL_DIR "${Qt5_DIR}/../../../bin")
+    set(Qt5_PLATFORMS_DIR "${Qt5_DIR}/../../../plugins/platforms/")
+    set(PLATFORMS ${DLL_DEST}platforms/)
+    windows_copy_files(citra-qt ${Qt5_DLL_DIR} ${DLL_DEST}
+        icudt*.dll
+        icuin*.dll
+        icuuc*.dll
+        Qt5Core$<$<CONFIG:Debug>:d>.*
+        Qt5Gui$<$<CONFIG:Debug>:d>.*
+        Qt5OpenGL$<$<CONFIG:Debug>:d>.*
+        Qt5Widgets$<$<CONFIG:Debug>:d>.*
+    )
+    windows_copy_files(citra-qt ${Qt5_PLATFORMS_DIR} ${PLATFORMS} qwindows$<$<CONFIG:Debug>:d>.*)
+endfunction(copy_msvc_libraries)
\ No newline at end of file
diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt
index f283545aa..64c4330c1 100644
--- a/src/citra_qt/CMakeLists.txt
+++ b/src/citra_qt/CMakeLists.txt
@@ -1,5 +1,6 @@
 set(CMAKE_AUTOMOC ON)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules)
 
 set(SRCS
             config.cpp
@@ -107,26 +108,7 @@ if(UNIX AND NOT APPLE)
     install(TARGETS citra-qt RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
 endif()
 
-function(copy_msvc_libraries)
-    include(WindowsCopyFiles)
-    set(DLL_DEST "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/")
-    windows_copy_files(citra-qt ${SDL2_DLL_DIR} ${DLL_DEST} SDL2.dll)
-
-    set(Qt5_DLL_DIR "${Qt5_DIR}/../../../bin")
-    set(Qt5_PLATFORMS_DIR "${Qt5_DIR}/../../../plugins/platforms/")
-    set(PLATFORMS ${DLL_DEST}platforms/)
-    windows_copy_files(citra-qt ${Qt5_DLL_DIR} ${DLL_DEST}
-        icudt*.dll
-        icuin*.dll
-        icuuc*.dll
-        Qt5Core$<$<CONFIG:Debug>:d>.*
-        Qt5Gui$<$<CONFIG:Debug>:d>.*
-        Qt5OpenGL$<$<CONFIG:Debug>:d>.*
-        Qt5Widgets$<$<CONFIG:Debug>:d>.*
-    )
-    windows_copy_files(citra-qt ${Qt5_PLATFORMS_DIR} ${PLATFORMS} qwindows$<$<CONFIG:Debug>:d>.*)
-endfunction(copy_msvc_libraries)
-
+include(CopyMSVCLibsQt)
 if (MSVC)
     copy_msvc_libraries()
 endif()

From b7b2627b3746e28fe64c9af74583c8b24edee909 Mon Sep 17 00:00:00 2001
From: freiro <f73b2894@opayq.com>
Date: Tue, 13 Dec 2016 00:01:48 +0100
Subject: [PATCH 4/4] Modularized Qt and SDL file copying Now cmake relies on
 two submodules to copy the libraries in the proper folders

---
 .../{CopyMSVCLibsQt.cmake => CopyCitraQt5Deps.cmake}  |  8 +++-----
 CMakeModules/CopyCitraSDLDeps.cmake                   |  5 +++++
 src/citra/CMakeLists.txt                              | 11 ++++-------
 src/citra_qt/CMakeLists.txt                           |  6 ++++--
 4 files changed, 16 insertions(+), 14 deletions(-)
 rename CMakeModules/{CopyMSVCLibsQt.cmake => CopyCitraQt5Deps.cmake} (74%)
 create mode 100644 CMakeModules/CopyCitraSDLDeps.cmake

diff --git a/CMakeModules/CopyMSVCLibsQt.cmake b/CMakeModules/CopyCitraQt5Deps.cmake
similarity index 74%
rename from CMakeModules/CopyMSVCLibsQt.cmake
rename to CMakeModules/CopyCitraQt5Deps.cmake
index 64b27a807..05f58cf9a 100644
--- a/CMakeModules/CopyMSVCLibsQt.cmake
+++ b/CMakeModules/CopyCitraQt5Deps.cmake
@@ -1,12 +1,10 @@
-function(copy_msvc_libraries)
+function(copy_citra_Qt5_deps target_dir)
     include(WindowsCopyFiles)
     set(DLL_DEST "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/")
-    windows_copy_files(citra-qt ${SDL2_DLL_DIR} ${DLL_DEST} SDL2.dll)
-
     set(Qt5_DLL_DIR "${Qt5_DIR}/../../../bin")
     set(Qt5_PLATFORMS_DIR "${Qt5_DIR}/../../../plugins/platforms/")
     set(PLATFORMS ${DLL_DEST}platforms/)
-    windows_copy_files(citra-qt ${Qt5_DLL_DIR} ${DLL_DEST}
+    windows_copy_files(${target_dir} ${Qt5_DLL_DIR} ${DLL_DEST}
         icudt*.dll
         icuin*.dll
         icuuc*.dll
@@ -16,4 +14,4 @@ function(copy_msvc_libraries)
         Qt5Widgets$<$<CONFIG:Debug>:d>.*
     )
     windows_copy_files(citra-qt ${Qt5_PLATFORMS_DIR} ${PLATFORMS} qwindows$<$<CONFIG:Debug>:d>.*)
-endfunction(copy_msvc_libraries)
\ No newline at end of file
+endfunction(copy_citra_Qt5_deps)
diff --git a/CMakeModules/CopyCitraSDLDeps.cmake b/CMakeModules/CopyCitraSDLDeps.cmake
new file mode 100644
index 000000000..4f9e4aeb9
--- /dev/null
+++ b/CMakeModules/CopyCitraSDLDeps.cmake
@@ -0,0 +1,5 @@
+function(copy_citra_SDL_deps target_dir)
+    include(WindowsCopyFiles)
+    set(DLL_DEST "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/")
+    windows_copy_files(${target_dir} ${SDL2_DLL_DIR} ${DLL_DEST} SDL2.dll)
+endfunction(copy_citra_SDL_deps)
diff --git a/src/citra/CMakeLists.txt b/src/citra/CMakeLists.txt
index f9c488a1a..ecb5d2dfe 100644
--- a/src/citra/CMakeLists.txt
+++ b/src/citra/CMakeLists.txt
@@ -1,3 +1,5 @@
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules)
+
 set(SRCS
             emu_window/emu_window_sdl2.cpp
             citra.cpp
@@ -28,11 +30,6 @@ if(UNIX AND NOT APPLE)
 endif()
 
 if (MSVC)
-    include(WindowsCopyFiles)
-
-    set(DLL_DEST "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/")
-
-    windows_copy_files(citra ${SDL2_DLL_DIR} ${DLL_DEST} SDL2.dll)
-
-    unset(DLL_DEST)
+    include(CopyCitraSDLDeps)
+    copy_citra_SDL_deps(citra)
 endif()
diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt
index 64c4330c1..e1b3566bf 100644
--- a/src/citra_qt/CMakeLists.txt
+++ b/src/citra_qt/CMakeLists.txt
@@ -108,7 +108,9 @@ if(UNIX AND NOT APPLE)
     install(TARGETS citra-qt RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
 endif()
 
-include(CopyMSVCLibsQt)
 if (MSVC)
-    copy_msvc_libraries()
+    include(CopyCitraQt5Deps)
+    include(CopyCitraSDLDeps)
+    copy_citra_Qt5_deps(citra-qt)
+    copy_citra_SDL_deps(citra-qt)
 endif()