@@ -615,64 +615,68 @@ endif ()
615615install ( TARGETS openxcom ${install_dest} DESTINATION ${CMAKE_INSTALL_BINDIR} )
616616
617617# --- Windows / MinGW / MXE link setup (safe for Linux/macOS) ------------------
618- set (system_libs "" )
619- set (WIN32_LIBS "" )
620-
621- if ( WIN32 )
622- # Base Windows libs (MinGW understands these names too)
623- set ( system_libs
624- advapi32
625- shell32
626- shlwapi
627- wininet
628- urlmon
629- )
630-
631- # Tools (crash handler etc.)
632- set ( WIN32_LIBS imagehlp dbghelp )
633-
634- # Keep export-all-symbols behavior
635- set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--export-all-symbols" )
636-
637- if ( MINGW )
638- # SDL apps that use WIN32 subsystem need SDLmain to provide WinMain
639- # Typical MinGW order: mingw32, SDLmain, SDL
640- list (APPEND system_libs mingw32 SDLmain SDL)
641-
642- # Put subsystem/static flags as link options (not as "libraries")
643- target_link_options (openxcom PRIVATE -mwindows -static )
644-
645- # Required deps for static SDL_net / SDL_image / audio / etc.
646- target_link_libraries ( openxcom PRIVATE PRIVATE
647- ws2_32 iphlpapi # SDL_net (Winsock + GetAdaptersInfo)
648- winmm # SDL_mixer MIDI on Windows
649- dxguid # DirectDraw IID_* symbols
650- jpeg png webp # SDL_image codecs
651- smpeg modplug # SDL_mixer optional codecs (if enabled in your MXE build)
652- vorbis ogg # vorbisfile needs these when static
653- )
654- endif ()
655- endif ()
656618
657619# jsoncpp: on MinGW/MXE force picking it from the toolchain prefix if available
658620if ( MINGW )
659621 find_library (JSONCPP_LIB jsoncpp PATHS "${CMAKE_PREFIX_PATH} /lib" NO_DEFAULT_PATH )
660- endif ()
622+ endif ()
661623
662624if ( MINGW AND JSONCPP_LIB )
663625 set ( JSONCPP_LINK ${JSONCPP_LIB} )
664- else ()
626+ else ()
665627 set ( JSONCPP_LINK jsoncpp )
666- endif ()
628+ endif ()
629+
630+ # Win32 system libs + tools
631+ set (WIN32_SYSTEM_LIBS "" )
632+ set (WIN32_TOOLS_LIBS "" )
667633
668- # Final link line (works on Linux/macOS because WIN32 vars stay empty there)
669- target_link_libraries ( openxcom PRIVATE
670- ${system_libs}
634+ if ( WIN32 )
635+ set (WIN32_SYSTEM_LIBS advapi32 shell32 shlwapi wininet urlmon)
636+ set (WIN32_TOOLS_LIBS imagehlp dbghelp)
637+
638+ # keep export-all-symbols behavior
639+ set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--export-all-symbols" )
640+
641+ if ( MINGW )
642+ # subsystem/static flags as link options (not as "libraries")
643+ target_link_options (openxcom PRIVATE -mwindows -static )
644+
645+ # SDL WinMain glue (WinXP/MinGW)
646+ # (SDL itself comes from PKG_DEPS_LDFLAGS)
647+ list (APPEND WIN32_SYSTEM_LIBS mingw32 SDLmain)
648+ endif ()
649+ endif ()
650+
651+ # IMPORTANT: order matters with static linking!
652+ # Put libraries that *depend on others* first, and their dependencies later.
653+ target_link_libraries (openxcom PRIVATE
671654 ${PKG_DEPS_LDFLAGS}
672655 ${JSONCPP_LINK}
656+
657+ # These use vorbis/ogg → dependencies AFTER
673658 vorbisfile
659+ vorbis
660+ ogg
661+
662+ # SDL_net uses ws2_32/iphlpapi → dependencies AFTER SDL_net
674663 SDL_net
675- ${WIN32_LIBS}
664+ ws2_32
665+ iphlpapi
666+
667+ # Common Windows multimedia / GUID deps used by SDL_* stacks
668+ winmm
669+ dxguid
670+
671+ # SDL_image/SDL_mixer optional codec deps (only if your MXE build enables them)
672+ jpeg
673+ png
674+ webp
675+ smpeg
676+ modplug
677+
678+ ${WIN32_SYSTEM_LIBS}
679+ ${WIN32_TOOLS_LIBS}
676680)
677681
678682# ---------------------------------------------------------------------------
0 commit comments