shithub: choc

Download patch

ref: ba625b652bafb6bd16026756532266574b36ecc6
parent: 622340e47976299e6107997d92197b351258d8c5
author: Alex Mayfield <alexmax2742@gmail.com>
date: Sat Jun 9 14:39:30 EDT 2018

Add MSYS2 support

This required proper ordering of libraries in the main build script
and coming up with a workaround in the SDL2 finder to ensure -lmingw32
always came first in the link order.

--- a/cmake/FindSDL2.cmake
+++ b/cmake/FindSDL2.cmake
@@ -26,8 +26,8 @@
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 # Currently works with the following generators:
-# - Unix Makefiles
-# - Ninja
+# - Unix Makefiles (Linux, MSYS2)
+# - Ninja (Linux, MSYS2)
 # - Visual Studio
 
 # Cache variable that allows you to point CMake at a directory containing
@@ -91,7 +91,24 @@
                           IMPORTED_LOCATION "${SDL2_LIBRARY}")
 
     # SDL2main imported target.
-    add_library(SDL2::SDL2main UNKNOWN IMPORTED)
-    set_target_properties(SDL2::SDL2main PROPERTIES
-                          IMPORTED_LOCATION "${SDL2_MAIN_LIBRARY}")
+    if(MINGW)
+        # Gross hack to get mingw32 first in the linker order.
+        add_library(SDL2::_SDL2main_detail UNKNOWN IMPORTED)
+        set_target_properties(SDL2::_SDL2main_detail PROPERTIES
+                              IMPORTED_LOCATION "${SDL2_MAIN_LIBRARY}")
+
+        # Ensure that SDL2main comes before SDL2 in the linker order.  CMake
+        # isn't smart enough to keep proper ordering for indirect dependencies
+        # so we have to spell it out here.
+        target_link_libraries(SDL2::_SDL2main_detail INTERFACE SDL2::SDL2)
+
+        add_library(SDL2::SDL2main INTERFACE IMPORTED)
+        set_target_properties(SDL2::SDL2main PROPERTIES
+                              IMPORTED_LIBNAME mingw32)
+        target_link_libraries(SDL2::SDL2main INTERFACE SDL2::_SDL2main_detail)
+    else()
+        add_library(SDL2::SDL2main UNKNOWN IMPORTED)
+        set_target_properties(SDL2::SDL2main PROPERTIES
+                              IMPORTED_LOCATION "${SDL2_MAIN_LIBRARY}")
+    endif()
 endif()
--- a/cmake/FindSDL2_mixer.cmake
+++ b/cmake/FindSDL2_mixer.cmake
@@ -26,8 +26,8 @@
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 # Currently works with the following generators:
-# - Unix Makefiles
-# - Ninja
+# - Unix Makefiles (Linux, MSYS2)
+# - Ninja (Linux, MSYS2)
 # - Visual Studio
 
 # Cache variable that allows you to point CMake at a directory containing
--- a/cmake/FindSDL2_net.cmake
+++ b/cmake/FindSDL2_net.cmake
@@ -26,8 +26,8 @@
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 # Currently works with the following generators:
-# - Unix Makefiles
-# - Ninja
+# - Unix Makefiles (Linux, MSYS2)
+# - Ninja (Linux, MSYS2)
 # - Visual Studio
 
 # Cache variable that allows you to point CMake at a directory containing
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -105,7 +105,7 @@
 set(SOURCE_FILES ${COMMON_SOURCE_FILES} ${GAME_SOURCE_FILES})
 set(SOURCE_FILES_WITH_DEH ${SOURCE_FILES} ${DEHACKED_SOURCE_FILES})
 
-set(EXTRA_LIBS textscreen pcsound opl SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net)
+set(EXTRA_LIBS SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net textscreen pcsound opl)
 if(SAMPLERATE_FOUND)
     list(APPEND EXTRA_LIBS samplerate::samplerate)
 endif()
@@ -197,7 +197,7 @@
 
 target_include_directories("${PROGRAM_PREFIX}setup"
                            PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../")
-target_link_libraries("${PROGRAM_PREFIX}setup" setup textscreen SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net)
+target_link_libraries("${PROGRAM_PREFIX}setup" SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net setup textscreen)
 
 if(MSVC)
     set_target_properties("${PROGRAM_PREFIX}setup" PROPERTIES
@@ -207,9 +207,9 @@
 add_executable(midiread midifile.c z_native.c i_system.c m_argv.c m_misc.c)
 target_compile_definitions(midiread PRIVATE "-DTEST")
 target_include_directories(midiread PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../")
-target_link_libraries(midiread PRIVATE SDL2::SDL2)
+target_link_libraries(midiread SDL2::SDL2main SDL2::SDL2)
 
 add_executable(mus2mid mus2mid.c memio.c z_native.c i_system.c m_argv.c m_misc.c)
 target_compile_definitions(mus2mid PRIVATE "-DSTANDALONE")
 target_include_directories(mus2mid PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../")
-target_link_libraries(mus2mid PRIVATE SDL2::SDL2)
+target_link_libraries(mus2mid SDL2::SDL2main SDL2::SDL2)