Skip to content

Commit f7770b4

Browse files
committed
Fix CMakeLists
1 parent 3e52a7d commit f7770b4

1 file changed

Lines changed: 55 additions & 17 deletions

File tree

src/CMakeLists.txt

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -613,28 +613,66 @@ if ( EMBED_ASSETS )
613613
endif ()
614614

615615
install ( TARGETS openxcom ${install_dest} DESTINATION ${CMAKE_INSTALL_BINDIR} )
616-
# Extra link flags for Windows. They need to be set before the SDL/YAML link flags, otherwise you will get strange link errors ('Undefined reference to WinMain@16')
616+
# Base Windows libs: use -lxxx style so it works on MinGW; MSVC doesn't care.
617617
if ( WIN32 )
618-
set ( basic_windows_libs advapi32.lib shell32.lib shlwapi.lib wininet.lib urlmon.lib )
618+
set ( system_libs
619+
advapi32
620+
shell32
621+
shlwapi
622+
wininet
623+
urlmon
624+
)
625+
626+
# Tools (crash handler etc.)
627+
set ( WIN32_LIBS imagehlp dbghelp )
628+
629+
# Export all symbols (as you had)
630+
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--export-all-symbols" )
631+
632+
# MinGW specific (MXE/WinXP build)
619633
if ( MINGW )
620-
set ( basic_windows_libs ${basic_windows_libs} mingw32 -mwindows )
621-
set ( static_flags -static )
622-
set ( SDLMIXER_LIBRARY "${SDLMIXER_LIBRARY} -lwinmm" )
623-
endif ()
624-
set ( system_libs ${basic_windows_libs} SDLmain ${static_flags} )
625-
endif ()
634+
# Use GUI subsystem + static link
635+
set ( system_libs ${system_libs} mingw32 -mwindows -static )
626636

627-
# backtrace(3) requires libexecinfo on some *BSD systems
628-
if (${CMAKE_SYSTEM_NAME} MATCHES FreeBSD OR ${CMAKE_SYSTEM_NAME} MATCHES NetBSD OR ${CMAKE_SYSTEM_NAME} MATCHES OpenBSD)
629-
set ( system_libs -lexecinfo )
630-
endif ()
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 )
631642

632-
if (WIN32)
633-
set(CMAKE_EXE_LINKER_FLAGS -Wl,--export-all-symbols)
634-
set(WIN32_LIBS imagehlp dbghelp)
635-
endif(WIN32)
643+
# SDL_image codecs (static build needs explicit deps)
644+
set ( system_libs ${system_libs} jpeg png webp )
636645

637-
target_link_libraries ( openxcom ${system_libs} ${PKG_DEPS_LDFLAGS} jsoncpp vorbisfile SDL_net ${WIN32_LIBS} )
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 ()
653+
654+
# jsoncpp: on MinGW/MXE force picking it from the toolchain prefix if available
655+
if ( MINGW )
656+
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 ()
663+
else()
664+
set ( JSONCPP_LINK jsoncpp )
665+
endif()
666+
667+
# Final link line (works on Linux/macOS because WIN32 vars are empty there)
668+
target_link_libraries ( openxcom
669+
${system_libs}
670+
${PKG_DEPS_LDFLAGS}
671+
${JSONCPP_LINK}
672+
vorbisfile
673+
SDL_net
674+
${WIN32_LIBS}
675+
)
638676

639677
# Pack libraries into bundle and link executable appropriately
640678
if ( APPLE AND CREATE_BUNDLE )

0 commit comments

Comments
 (0)