From 34cc5934e22f9699309439c153661608c05a646d Mon Sep 17 00:00:00 2001 From: badlogic Date: Fri, 5 Aug 2022 12:32:21 +0200 Subject: [PATCH 1/3] [sdl] Fix build on Windows, set working dir for VS debugger --- spine-sdl/CMakeLists.txt | 10 ++++++---- spine-sdl/example/main.c | 1 + spine-sdl/example/main.cpp | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/spine-sdl/CMakeLists.txt b/spine-sdl/CMakeLists.txt index e0109f838..b2ada59fb 100644 --- a/spine-sdl/CMakeLists.txt +++ b/spine-sdl/CMakeLists.txt @@ -16,20 +16,22 @@ FetchContent_MakeAvailable(SDL) include_directories(src) add_library(spine-sdl-c STATIC src/spine-sdl-c.c src/spine-sdl-c.h src/stb_image.h) -target_link_libraries(spine-sdl-c LINK_PUBLIC SDL2 spine-c) +target_link_libraries(spine-sdl-c LINK_PUBLIC SDL2-static spine-c) install(TARGETS spine-sdl-c DESTINATION dist/lib) install(FILES src/spine-sdl-c.h src/stb_image.h DESTINATION dist/include) add_library(spine-sdl-cpp STATIC src/spine-sdl-cpp.cpp src/spine-sdl-cpp.h src/stb_image.h) -target_link_libraries(spine-sdl-cpp LINK_PUBLIC SDL2 spine-cpp) +target_link_libraries(spine-sdl-cpp LINK_PUBLIC SDL2-static spine-cpp) install(TARGETS spine-sdl-cpp DESTINATION dist/lib) install(FILES src/spine-sdl-cpp.h src/stb_image.h DESTINATION dist/include) add_executable(spine-sdl-c-example example/main.c) -target_link_libraries(spine-sdl-c-example SDL2 spine-sdl-c) +target_link_libraries(spine-sdl-c-example SDL2-static spine-sdl-c) +set_property(TARGET spine-sdl-c-example PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/spine-sdl") add_executable(spine-sdl-cpp-example example/main.cpp) -target_link_libraries(spine-sdl-cpp-example SDL2 spine-sdl-cpp) +target_link_libraries(spine-sdl-cpp-example SDL2-static spine-sdl-cpp) +set_property(TARGET spine-sdl-cpp-example PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/spine-sdl") # copy data to build directory add_custom_command(TARGET spine-sdl-c-example PRE_BUILD diff --git a/spine-sdl/example/main.c b/spine-sdl/example/main.c index 8992a0ef1..77512e131 100644 --- a/spine-sdl/example/main.c +++ b/spine-sdl/example/main.c @@ -29,6 +29,7 @@ #include #include +#undef main int main() { if (SDL_Init(SDL_INIT_VIDEO)) { diff --git a/spine-sdl/example/main.cpp b/spine-sdl/example/main.cpp index 50083a6b8..18c3052f0 100644 --- a/spine-sdl/example/main.cpp +++ b/spine-sdl/example/main.cpp @@ -29,8 +29,9 @@ #include #include +#undef main -int main() { +int main(int argc, char **argv) { if (SDL_Init(SDL_INIT_VIDEO)) { printf("Error: %s", SDL_GetError()); return -1; From e2b980c8797064ca25e5b80304bbee8bedb5ce2f Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Fri, 5 Aug 2022 12:34:35 +0200 Subject: [PATCH 2/3] [sdl] Update README for Windows examples. --- spine-sdl/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spine-sdl/README.md b/spine-sdl/README.md index 7ee7a30c1..e5fb5839e 100644 --- a/spine-sdl/README.md +++ b/spine-sdl/README.md @@ -38,9 +38,7 @@ The Spine SFML example works on Windows, Linux and Mac OS X. For a spine-c based 6. Click `Browse Build` and select the `spine-runtimes/spine-sdl/build` directory. You can create the `build` folder directly in the file dialog via `New Folder`. 7. Click `Configure`. Then click `Generate`. This will create a Visual Studio solution file called `spine.sln` in `spine-runtimes/spine-sdl/build` and also download the SDL dependencies. 8. Open the `spine.sln` file in Visual Studio -9. Right click the `spine-sfml-example` project in the solution explorer and select `Set as Startup Project` from the context menu -10. Right click the `spine-sfml-example` project in the solution explorer and select `Properties` from the context menu -11. Select `Debugging` in the left-hand list, then set `Working Directory` to `$(OutputPath)` +9. Right click the `spine-sdl-example-c` or `spine-sdl-example-cpp` project in the solution explorer and select `Set as Startup Project` from the context menus 12. Click `Local Windows Debugger` to run the example The entire example code is contained in [main.cpp](example/main.cpp#L61) From 92ebbbfc4854304515215b5306c099eb86273f99 Mon Sep 17 00:00:00 2001 From: badlogic Date: Sat, 6 Aug 2022 14:09:40 +0200 Subject: [PATCH 3/3] [sdl] Fix up CMake, compilation on Linux. --- CMakeLists.txt | 4 ++-- spine-sdl/src/spine-sdl-c.c | 1 - spine-sdl/src/spine-sdl-c.h | 5 ++--- spine-sdl/src/spine-sdl-cpp.h | 4 +--- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e2e1ff5b..42ef2411f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,8 @@ if(MSVC) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") set (CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}") else() - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wunused-value -Wno-c++11-long-long -Wno-variadic-macros -Wextra -pedantic -Wnonportable-include-path -Wshadow -std=c89") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wunused-value -Wno-c++11-long-long -Wno-variadic-macros -Wextra -Wnon-virtual-dtor -pedantic -Wnonportable-include-path -Wshadow -std=c++11 -fno-exceptions -fno-rtti") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wunused-value -Wno-variadic-macros -Wextra -pedantic -Wshadow -std=c89") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wunused-value -Wno-variadic-macros -Wextra -Wnon-virtual-dtor -pedantic -Wshadow -std=c++11 -fno-exceptions -fno-rtti") if (${SPINE_SANITIZE}) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=undefined") diff --git a/spine-sdl/src/spine-sdl-c.c b/spine-sdl/src/spine-sdl-c.c index 4f99357bb..83555998a 100644 --- a/spine-sdl/src/spine-sdl-c.c +++ b/spine-sdl/src/spine-sdl-c.c @@ -30,7 +30,6 @@ #include "spine-sdl-c.h" #include #include -#include #define STB_IMAGE_IMPLEMENTATION diff --git a/spine-sdl/src/spine-sdl-c.h b/spine-sdl/src/spine-sdl-c.h index b8cbf2b63..7d48cca66 100644 --- a/spine-sdl/src/spine-sdl-c.h +++ b/spine-sdl/src/spine-sdl-c.h @@ -32,13 +32,12 @@ #include +#include + #ifdef __cplusplus extern "C" { #endif -struct SDL_Renderer; -struct SDL_Texture; -struct SDL_Vertex; _SP_ARRAY_DECLARE_TYPE(spSdlVertexArray, struct SDL_Vertex) typedef struct spSkeletonDrawable { diff --git a/spine-sdl/src/spine-sdl-cpp.h b/spine-sdl/src/spine-sdl-cpp.h index a2843f5d4..c47b6bc61 100644 --- a/spine-sdl/src/spine-sdl-cpp.h +++ b/spine-sdl/src/spine-sdl-cpp.h @@ -31,9 +31,7 @@ #define SPINE_SDL #include - -struct SDL_Renderer; -struct SDL_Vertex; +#include namespace spine { class SkeletonDrawable {