Skip to content

Commit b7d0ede

Browse files
committed
Fix CMakeLists
1 parent f7770b4 commit b7d0ede

2 files changed

Lines changed: 45 additions & 44 deletions

File tree

.github/workflows/build-winxp.yml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,23 @@ jobs:
7171
export CMAKE_PREFIX_PATH="$MXE_PREFIX"
7272
export PKG_CONFIG_PATH="$MXE_PREFIX/lib/pkgconfig"
7373
74-
# Make your vendored headers work (#include <SDL_net.h>, json headers etc.)
75-
export CPPFLAGS="-I$MXE_PREFIX/include -I$MXE_PREFIX/include/SDL -I$GITHUB_WORKSPACE/deps/include/SDL_net -I$GITHUB_WORKSPACE/deps/include"
74+
# IMPORTANT (Option 1):
75+
# Use MXE's jsoncpp headers (v1.9.1) instead of repo headers (v1.9.7),
76+
# to match the jsoncpp library we link against.
77+
export CPPFLAGS="-I$MXE_PREFIX/include/jsoncpp -I$MXE_PREFIX/include -I$MXE_PREFIX/include/SDL -I$GITHUB_WORKSPACE/deps/include/SDL_net -I$GITHUB_WORKSPACE/deps/include"
7678
export CFLAGS="$CPPFLAGS"
7779
export CXXFLAGS="$CPPFLAGS"
7880
81+
echo "=== DEBUG: jsoncpp version headers present ==="
82+
ls -la "$MXE_PREFIX/include/jsoncpp/json/version.h" || true
83+
ls -la "$GITHUB_WORKSPACE/deps/include/json/version.h" || true
84+
7985
echo "=== DEBUG: key libs present in MXE_PREFIX/lib ==="
80-
ls -la "$MXE_PREFIX/lib" | grep -Ei "json|sdl|jpeg|png|webp|smpeg|modplug|ws2|iphlp|winmm|dxguid" || true
81-
82-
# Force link libs without touching CMakeLists.txt
83-
# - jsoncpp: fixes Json::Value / Json::CharReader undefined references
84-
# - ws2_32/iphlpapi: fixes SDL_net winsock + GetAdaptersInfo
85-
# - winmm: fixes midiOut* symbols from SDL_mixer
86-
# - dxguid: fixes DirectDraw IID_* symbols from SDL
87-
# - jpeg/png/webp/smpeg/modplug: fixes SDL_image/SDL_mixer optional codec symbols when linked statically
88-
export LDFLAGS="-L$MXE_PREFIX/lib \
89-
-ljsoncpp \
90-
-lws2_32 -liphlpapi -lwinmm -ldxguid \
91-
-ljpeg -lpng -lwebp \
92-
-lsmpeg -lmodplug"
86+
ls -la "$MXE_PREFIX/lib" | grep -Ei "json|sdl|jpeg|png|webp|smpeg|modplug|vorbis|ogg|ws2|iphlp|winmm|dxguid" || true
87+
88+
# NOTE (Option A):
89+
# Do NOT force -l... libs via LDFLAGS here.
90+
# The corrected src/CMakeLists.txt links required libs with correct ordering.
9391
9492
mkdir -p build
9593
cd build

src/CMakeLists.txt

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,13 @@ if ( EMBED_ASSETS )
613613
endif ()
614614

615615
install ( 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+
617621
if ( 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
655658
if ( 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} )
663664
else()
664665
set ( JSONCPP_LINK jsoncpp )
665666
endif()
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)
668669
target_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
678681
if ( APPLE AND CREATE_BUNDLE )
679682
include ( PostprocessBundle )

0 commit comments

Comments
 (0)