diff --git a/CMakeLists.txt b/CMakeLists.txt index da60e178..4365e462 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,12 +15,14 @@ set(ASSETS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets") option(JAPANESE "Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation)" OFF) option(FIX_BUGS "Fix various bugs in the game" OFF) option(DEBUG_SAVE "Re-enable the ability to drag-and-drop save files onto the window" OFF) + set(BACKEND_RENDERER "SDLTexture" CACHE STRING "Which renderer the game should use: 'OpenGL3' for an OpenGL 3.2 renderer, 'OpenGLES2' for an OpenGL ES 2.0 renderer, 'SDLTexture' for SDL2's hardware-accelerated Texture API, 'SDLSurface' for SDL2's software-rendered Surface API, or 'Software' for a handwritten software renderer") set(BACKEND_AUDIO "SDL2" CACHE STRING "Which audio backend the game should use: 'SDL2' or 'miniaudio'") set(BACKEND_PLATFORM "SDL2" CACHE STRING "Which platform backend the game should use: 'SDL2' or 'GLFW3'") option(LTO "Enable link-time optimisation" OFF) -option(MSVC_LINK_STATIC_RUNTIME "Link the static MSVC runtime library" OFF) +option(PKG_CONFIG_STATIC_LIBS "On platforms with pkg-config, static-link the dependencies (good for Windows builds, so you don't need to bundle DLL files)" OFF) +option(MSVC_LINK_STATIC_RUNTIME "Link the static MSVC runtime library (Visual Studio only)" OFF) option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF) @@ -261,6 +263,10 @@ if(DEBUG_SAVE) target_compile_definitions(CSE2 PRIVATE DEBUG_SAVE) endif() +if(PKG_CONFIG_STATIC_LIBS) + target_link_options(CSE2 PRIVATE "-static") +endif() + if(LTO) include(CheckIPOSupported) @@ -395,6 +401,10 @@ set_target_properties(CSE2 PROPERTIES # Dependencies # ################ +if(NOT FORCE_LOCAL_LIBS) + find_package(PkgConfig QUIET) +endif() + if(BACKEND_PLATFORM MATCHES "GLFW3") find_package(glfw3 REQUIRED) target_link_libraries(CSE2 PRIVATE glfw) @@ -403,9 +413,24 @@ endif() if(BACKEND_PLATFORM MATCHES "SDL2" OR BACKEND_AUDIO MATCHES "SDL2") if(NOT FORCE_LOCAL_LIBS) find_package(SDL2) + + if (PKG_CONFIG_FOUND) + pkg_check_modules(sdl2 QUIET sdl2) + endif() endif() - if(TARGET SDL2::SDL2) + if(sdl2_FOUND) + # pkg-config + if (PKG_CONFIG_STATIC_LIBS) + message(STATUS "Using system SDL2 (pkg-config, static)") + target_compile_options(CSE2 PRIVATE ${sdl2_STATIC_CFLAGS}) + target_link_libraries(CSE2 PRIVATE ${sdl2_STATIC_LIBRARIES}) + else() + message(STATUS "Using system SDL2 (pkg-config, dynamic)") + target_compile_options(CSE2 PRIVATE ${sdl2_CFLAGS}) + target_link_libraries(CSE2 PRIVATE ${sdl2_LIBRARIES}) + endif() + elseif(TARGET SDL2::SDL2) # CMake-generated config (Arch, vcpkg, Raspbian) message(STATUS "Using system SDL2 (CMake, dynamic)") target_link_libraries(CSE2 PRIVATE SDL2::SDL2 SDL2::SDL2main) @@ -423,19 +448,32 @@ if(BACKEND_PLATFORM MATCHES "SDL2" OR BACKEND_AUDIO MATCHES "SDL2") message(STATUS "Using local SDL2") set(SDL_SHARED_ENABLED_BY_DEFAULT OFF) if(MSVC) - set(LIBC ON CACHE INTERNAL "" FORCE) # Needed to prevent possible 'symbol already defined' errors + set(LIBC ON CACHE INTERNAL "" FORCE) # Needed to prevent possible 'symbol already defined' errors endif() - add_subdirectory("external/SDL2" EXCLUDE_FROM_ALL) - target_link_libraries(CSE2 PRIVATE SDL2-static SDL2main) endif() endif() if(NOT FORCE_LOCAL_LIBS) find_package(Freetype) + + if (PKG_CONFIG_FOUND) + pkg_check_modules(freetype2 QUIET freetype2) + endif() endif() -if(FREETYPE_FOUND) - message(STATUS "Using system FreeType") +if(freetype2_FOUND) + # pkg-config + if (PKG_CONFIG_STATIC_LIBS) + message(STATUS "Using system FreeType (pkg-config, static)") + target_compile_options(CSE2 PRIVATE ${freetype2_STATIC_CFLAGS}) + target_link_libraries(CSE2 PRIVATE ${freetype2_STATIC_LIBRARIES}) + else() + message(STATUS "Using system FreeType (pkg-config, dynamic)") + target_compile_options(CSE2 PRIVATE ${freetype2_CFLAGS}) + target_link_libraries(CSE2 PRIVATE ${freetype2_LIBRARIES}) + endif() +elseif(FREETYPE_FOUND) + message(STATUS "Using system FreeType (CMake)") target_include_directories(CSE2 PRIVATE ${FREETYPE_INCLUDE_DIRS}) target_link_libraries(CSE2 PRIVATE ${FREETYPE_LIBRARIES}) else() diff --git a/README.md b/README.md index 4257e355..362b4b7d 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ Branch | Description [accurate](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/accurate) | The main decompilation branch. The code intended to be as close to the original as possible, down to all the bugs and platform-dependencies. [portable](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/portable) | This branch ports the engine to SDL2, and addresses numerous portability issues, allowing it to run on other platforms. [enhanced](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/enhanced) | Based on the portable branch, this adds several enhancements to the engine, and makes it more accessible to modders. -[emscripten](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/emscripten) | Modifies the engine to build with Emscripten, [allowing it to run in web browsers](http://sonicresearch.org/clownacy/cave.html). -[wii](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/wii) | Ports the engine to the Nintendo Wii. +[emscripten](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/emscripten) | Modifies the engine to build with Emscripten, [allowing it to run in web browsers](http://sonicresearch.org/clownacy/cave.html) (no longer maintained). +[wii](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/wii) | Ports the engine to the Nintendo Wii (no longer maintained). # Cave Story Engine 2 (Portable) @@ -38,24 +38,28 @@ Many months of copypasting and tinkering later, here is the result. ## Dependencies -*Note: with CMake, if these are not found, they will be built locally* - * SDL2 * FreeType * FLTK +In CMake builds, if these are not found, they will be built locally. + +In addition, `pkg-config` is required for Makefile builds, and CMake builds that require static-linkage. + ## Building ### CMake This project primarily uses CMake, allowing it to be built with a range of compilers. -In this folder, create another folder called 'build', then switch to the command-line (Visual Studio users should open the [Developer Command Prompt](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs)) and `cd` into it. After that, generate the files for your build system with: +Switch to the terminal (Visual Studio users should open the [Developer Command Prompt](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs)) and `cd` into this folder. After that, generate the files for your build system with: ``` -cmake .. -DCMAKE_BUILD_TYPE=Release +cmake -B build -DCMAKE_BUILD_TYPE=Release ``` +MSYS2 users may want to append `-G"MSYS Makefiles"` to this command, also. + You can also add the following flags: Name | Function @@ -71,7 +75,8 @@ Name | Function `-DBACKEND_AUDIO=SDL2` | Use the SDL2-driven software audio-mixer `-DBACKEND_AUDIO=miniaudio` | Use the miniaudio-driven software audio-mixer `-DLTO=ON` | Enable link-time optimisation -`-DMSVC_LINK_STATIC_RUNTIME=ON` | Link the static MSVC runtime library +`-DPKG_CONFIG_STATIC_LIBS=ON` | On platforms with pkg-config, static-link the dependencies (good for Windows builds, so you don't need to bundle DLL files) +`-DMSVC_LINK_STATIC_RUNTIME=ON` | Link the static MSVC runtime library (Visual Studio only) `-DFORCE_LOCAL_LIBS=ON` | Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones You can pass your own compiler flags with `-DCMAKE_C_FLAGS` and `-DCMAKE_CXX_FLAGS`. @@ -79,16 +84,14 @@ You can pass your own compiler flags with `-DCMAKE_C_FLAGS` and `-DCMAKE_CXX_FLA You can then compile CSE2 with this command: ``` -cmake --build . --config Release +cmake --build build --config Release ``` -If you're a Visual Studio user, you can open the generated `CSE2.sln` file instead. +If you're a Visual Studio user, you can open the generated `CSE2.sln` file instead, which can be found in the `build` folder. Once built, the executables can be found in the `game_english`/`game_japanese` folder, depending on the selected language. -### Makefile - -*Note: this requires pkg-config* +### Makefile \[deprecated - use CMake instead\] Run 'make' in this folder, preferably with some of the following settings: @@ -114,4 +117,4 @@ Once built, the executables can be found in the `game_english`/`game_japanese` f ## Licensing -Being a decompilation, the majority of the code in this project belongs to Daisuke "Pixel" Amaya - not us. We've yet to agree on a license for our own code. +Being a decompilation, the majority of the code in this project belongs to Daisuke "Pixel" Amaya - not us. We've yet to agree on a licence for our own code. diff --git a/src/Backends/Audio/SDL2.cpp b/src/Backends/Audio/SDL2.cpp index bbe2dcb3..e03e3069 100644 --- a/src/Backends/Audio/SDL2.cpp +++ b/src/Backends/Audio/SDL2.cpp @@ -1,5 +1,8 @@ #include "../Audio.h" +#include +#include + #include "SDL.h" #include "../../Organya.h" diff --git a/src/Backends/Audio/miniaudio.cpp b/src/Backends/Audio/miniaudio.cpp index 84849a32..ec685da2 100644 --- a/src/Backends/Audio/miniaudio.cpp +++ b/src/Backends/Audio/miniaudio.cpp @@ -1,5 +1,7 @@ #include "../Audio.h" +#include + #define MINIAUDIO_IMPLEMENTATION #define MA_NO_DECODING #define MA_API static diff --git a/src/Resource.cpp b/src/Resource.cpp index 3e2ac9a9..3aba8a16 100644 --- a/src/Resource.cpp +++ b/src/Resource.cpp @@ -152,6 +152,7 @@ static const struct {"ORG", "ZONBIE", rZonbie, sizeof(rZonbie)}, {"WAVE", "WAVE100", rWave, sizeof(rWave)}, + {"DUMMY", "DUMMY", NULL, 0} // Just here to prevent errors in the event the array is otherwise empty }; const unsigned char* FindResource(const char *name, const char *type, size_t *size) diff --git a/src/WindowsWrapper.h b/src/WindowsWrapper.h index abfeca05..58eda2c1 100644 --- a/src/WindowsWrapper.h +++ b/src/WindowsWrapper.h @@ -1,8 +1,9 @@ #pragma once #ifdef _WIN32 -#include -#include +#define WIN32_LEAN_AND_MEAN +#include +#undef FindResource #else #include