From fda94f82460014235afc3223b2ed53937e922313 Mon Sep 17 00:00:00 2001 From: Bram Verhulst Date: Sun, 12 Apr 2026 23:26:29 +0200 Subject: [PATCH] Clarify MSVC-only bundled SDL support --- BUILDING.md | 19 +++++++++++++++++++ CMakeLists.txt | 21 +++++++++++++++------ README.md | 5 ++++- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 832c26e..4a4db8b 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -12,6 +12,7 @@ Requirements: - CMake 3.21+ The repository already contains the required prebuilt Windows SDL packages in `Libraries/`. +Those bundled packages are intended for **MSVC / Visual Studio**, not MinGW. Configure and build: @@ -38,6 +39,14 @@ cmake --build build ### 3. Legacy Visual Studio solution The existing `.sln` and `.vcxproj` files are still in the repo and can still be opened directly in Visual Studio. +### CLion with MinGW on Windows +This is a different toolchain from MSVC. The bundled SDL packages in `Libraries/` are the Visual C++ SDL package, so they should not be used with MinGW. + +Use one of these options instead: + +- switch CLion to a Visual Studio toolchain +- or install MinGW-compatible SDL packages and configure CMake with `-DMOTHERLOAD_USE_BUNDLED_WINDOWS_SDL=OFF` + ## Build output The CMake build writes the executable to: @@ -55,6 +64,8 @@ CMake uses the bundled SDL package config files from: - `Libraries/SDLMixer/.../cmake` - `Libraries/SDLTtf/.../cmake` +These are only used for **MSVC** builds. + ### Linux CMake falls back to `pkg-config` and expects these packages to be installed: - `sdl2` @@ -76,6 +87,14 @@ sudo apt install libgl1-mesa-dev ### CMake cannot find SDL packages on Linux Install the SDL development packages listed above. +### CLion / MinGW on Windows fails while linking SDL2main +That usually means the Visual Studio SDL package from `Libraries/` is being used with MinGW. + +Use one of these fixes: + +- use a Visual Studio toolchain in CLion +- or configure CMake with `-DMOTHERLOAD_USE_BUNDLED_WINDOWS_SDL=OFF` and provide MinGW-compatible SDL libraries + ### The game starts but cannot find assets Run the executable from the build output directory, not from the source directory root. The post-build step copies `Resources/` next to the executable. diff --git a/CMakeLists.txt b/CMakeLists.txt index d8ce1fa..8b61f8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,10 +7,18 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") -option(MOTHERLOAD_USE_BUNDLED_WINDOWS_SDL "Use the bundled prebuilt SDL packages on Windows" ON) +option(MOTHERLOAD_USE_BUNDLED_WINDOWS_SDL "Use the bundled prebuilt SDL packages for MSVC builds on Windows" ON) option(MOTHERLOAD_ENABLE_WARNINGS "Enable compiler warnings" ON) -if(WIN32 AND MOTHERLOAD_USE_BUNDLED_WINDOWS_SDL) +if(WIN32 AND MOTHERLOAD_USE_BUNDLED_WINDOWS_SDL AND NOT MSVC) + message(FATAL_ERROR + "MOTHERLOAD_USE_BUNDLED_WINDOWS_SDL=ON only supports MSVC/Visual Studio builds. " + "The bundled SDL package in Libraries/ is the SDL2 Visual C++ build, not a MinGW build. " + "For CLion/MinGW, disable MOTHERLOAD_USE_BUNDLED_WINDOWS_SDL and use MinGW-compatible SDL packages instead." + ) +endif() + +if(MSVC AND MOTHERLOAD_USE_BUNDLED_WINDOWS_SDL) list(PREPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/Libraries/SDLMain/SDL2-2.26.3/cmake" "${CMAKE_SOURCE_DIR}/Libraries/SDLImage/SDL2_image-2.6.3/cmake" @@ -134,6 +142,11 @@ target_include_directories(Motherload "${CMAKE_SOURCE_DIR}/Game" "${CMAKE_SOURCE_DIR}/Engine" ) + +if(TARGET SDL2::SDL2main) + target_link_libraries(Motherload PRIVATE SDL2::SDL2main) +endif() + target_link_libraries(Motherload PRIVATE Engine @@ -143,10 +156,6 @@ target_link_libraries(Motherload SDL2_mixer::SDL2_mixer SDL2_ttf::SDL2_ttf ) - -if(TARGET SDL2::SDL2main) - target_link_libraries(Motherload PRIVATE SDL2::SDL2main) -endif() motherload_enable_warnings(Motherload) source_group(TREE "${CMAKE_SOURCE_DIR}" FILES ${ENGINE_SOURCES} ${GAME_SOURCES}) diff --git a/README.md b/README.md index 00d1c1e..8894f45 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,9 @@ For the longer version, troubleshooting, and platform notes, see [`BUILDING.md`] * Visual Studio 2022 with the Desktop development with C++ workload * CMake 3.21 or newer -The repository already contains prebuilt SDL2 / SDL2_image / SDL2_mixer / SDL2_ttf Windows packages in `Libraries/`, and the CMake build will use those by default. +The repository already contains prebuilt SDL2 / SDL2_image / SDL2_mixer / SDL2_ttf Windows packages in `Libraries/`, and the CMake build will use those by default for **MSVC / Visual Studio** builds. + +If you use **CLion with MinGW**, do **not** use the bundled SDL package. It is the Visual C++ SDL build and is not a proper MinGW dependency set. #### Linux Install the development packages first. @@ -125,6 +127,7 @@ After building, run the generated executable from the build output directory so * The original `.sln` and `.vcxproj` files are still present and can still be used in Visual Studio. * The CMake build creates the same two logical targets as the solution: `Engine` and `Motherload`. * On non-Windows platforms, SDL dependencies are expected to come from the system package manager. +* On Windows, the bundled SDL dependencies are intended for **MSVC**, not MinGW.

(back to top)