@@ -613,8 +613,13 @@ if ( EMBED_ASSETS )
613613endif ()
614614
615615install ( TARGETS openxcom ${install_dest} DESTINATION ${CMAKE_INSTALL_BINDIR} )
616- # Base Windows libs: use -lxxx style so it works on MinGW; MSVC doesn't care.
616+
617+ # --- Windows / MinGW / MXE link setup (safe for Linux/macOS) ------------------
618+ set (system_libs "" )
619+ set (WIN32_LIBS "" )
620+
617621if ( WIN32 )
622+ # Base Windows libs (MinGW understands these names too)
618623 set ( system_libs
619624 advapi32
620625 shell32
@@ -626,45 +631,41 @@ if ( WIN32 )
626631 # Tools (crash handler etc.)
627632 set ( WIN32_LIBS imagehlp dbghelp )
628633
629- # Export all symbols (as you had)
634+ # Keep export- all- symbols behavior
630635 set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--export-all-symbols" )
631636
632- # MinGW specific (MXE/WinXP build)
633637 if ( MINGW )
634- # Use GUI subsystem + static link
635- set ( system_libs ${system_libs} mingw32 -mwindows -static )
636-
637- # SDL_mixer uses winmm for MIDI on Windows
638- set ( system_libs ${system_libs} winmm )
639-
640- # SDL (DirectX IDs) and SDL_net dependencies
641- set ( system_libs ${system_libs} dxguid ws2_32 iphlpapi )
642-
643- # SDL_image codecs (static build needs explicit deps)
644- set ( system_libs ${system_libs} jpeg png webp )
645-
646- # SDL_mixer optional deps often pulled in by static build
647- set ( system_libs ${system_libs} modplug smpeg )
648-
649- # vorbisfile needs vorbis + ogg when static
650- set ( system_libs ${system_libs} vorbis ogg )
651- endif ()
652- endif ()
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
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 ()
653656
654657# jsoncpp: on MinGW/MXE force picking it from the toolchain prefix if available
655658if ( MINGW )
656659 find_library (JSONCPP_LIB jsoncpp PATHS "${CMAKE_PREFIX_PATH} /lib" NO_DEFAULT_PATH )
657- if ( JSONCPP_LIB )
658- set ( JSONCPP_LINK ${JSONCPP_LIB} )
659- else ()
660- # fallback: still try -ljsoncpp
661- set ( JSONCPP_LINK jsoncpp )
662- endif ()
660+ endif ()
661+
662+ if ( MINGW AND JSONCPP_LIB )
663+ set ( JSONCPP_LINK ${JSONCPP_LIB} )
663664else ()
664665 set ( JSONCPP_LINK jsoncpp )
665666endif ()
666667
667- # Final link line (works on Linux/macOS because WIN32 vars are empty there)
668+ # Final link line (works on Linux/macOS because WIN32 vars stay empty there)
668669target_link_libraries ( openxcom
669670 ${system_libs}
670671 ${PKG_DEPS_LDFLAGS}
@@ -674,6 +675,8 @@ target_link_libraries ( openxcom
674675 ${WIN32_LIBS}
675676)
676677
678+ # ---------------------------------------------------------------------------
679+
677680# Pack libraries into bundle and link executable appropriately
678681if ( APPLE AND CREATE_BUNDLE )
679682 include ( PostprocessBundle )
0 commit comments