Enhance CMake configuration for PNG support and introduce vcpkg.json

- Updated CMakeLists.txt to conditionally enable PNG support based on the presence of the PNG library, improving compatibility for minimal builds.
- Added vcpkg.json to manage project dependencies, including zlib, libpng, sdl2, and abseil, streamlining package management.
- Modified CI workflow in ci.yml to simplify CMake configuration commands for better readability.
- Enhanced CMake scripts to ensure proper handling of dependencies in both minimal and regular builds, improving build reliability.
This commit is contained in:
scawful
2025-09-25 09:56:32 -04:00
parent 163aa9e121
commit d26f58be2f
8 changed files with 72 additions and 19 deletions

View File

@@ -166,16 +166,9 @@ jobs:
- name: Configure CMake (Windows)
if: runner.os == 'Windows'
shell: cmd
run: |
cmake -B ${{ github.workspace }}/build ^
-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} ^
-DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake ^
-DVCPKG_TARGET_TRIPLET=${{ matrix.vcpkg_triplet }} ^
-DYAZE_MINIMAL_BUILD=ON ^
-DYAZE_ENABLE_ROM_TESTS=OFF ^
-DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF ^
-G "${{ matrix.cmake_generator }}" ^
-A ${{ matrix.cmake_generator_platform }}
cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=${{ matrix.vcpkg_triplet }} -DYAZE_MINIMAL_BUILD=ON -DYAZE_ENABLE_ROM_TESTS=OFF -DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF -G "${{ matrix.cmake_generator }}" -A ${{ matrix.cmake_generator_platform }}
# Build
- name: Build

View File

@@ -26,8 +26,13 @@ option(YAZE_ENABLE_EXPERIMENTAL_TESTS "Enable experimental/unstable tests" ON)
option(YAZE_MINIMAL_BUILD "Minimal build for CI (disable optional features)" OFF)
set(YAZE_TEST_ROM_PATH "${CMAKE_BINARY_DIR}/bin/zelda3.sfc" CACHE STRING "Path to test ROM file")
# libpng features in bitmap.cc
add_definitions("-DYAZE_LIB_PNG=1")
# libpng features in bitmap.cc - conditional for minimal builds
if(PNG_FOUND)
add_definitions("-DYAZE_LIB_PNG=1")
else()
add_definitions("-DYAZE_LIB_PNG=0")
message(STATUS "Building without PNG support for minimal build")
endif()
# Modern CMake standards
set(CMAKE_CXX_STANDARD 23)

View File

@@ -1,7 +1,15 @@
if (MINGW)
if (MINGW OR WIN32)
add_subdirectory(src/lib/abseil-cpp)
elseif(YAZE_MINIMAL_BUILD)
# For CI builds, always use submodule to avoid dependency issues
add_subdirectory(src/lib/abseil-cpp)
else()
find_package(absl)
# Try system package first, fallback to submodule
find_package(absl QUIET)
if(NOT absl_FOUND)
message(STATUS "System Abseil not found, using submodule")
add_subdirectory(src/lib/abseil-cpp)
endif()
endif()
set(ABSL_PROPAGATE_CXX_STD ON)
set(ABSL_CXX_STANDARD 17)

View File

@@ -12,5 +12,23 @@ if(WIN32 OR MINGW)
add_definitions("-DSDL_MAIN_HANDLED")
endif()
# libpng
find_package(PNG REQUIRED)
# libpng and ZLIB dependencies
if(WIN32 AND NOT YAZE_MINIMAL_BUILD)
# Use vcpkg on Windows
find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED)
elseif(YAZE_MINIMAL_BUILD)
# For CI builds, try to find but don't require
find_package(ZLIB QUIET)
find_package(PNG QUIET)
if(NOT ZLIB_FOUND OR NOT PNG_FOUND)
message(STATUS "PNG/ZLIB not found in minimal build, some features may be disabled")
set(PNG_FOUND FALSE)
set(PNG_LIBRARIES "")
set(PNG_INCLUDE_DIRS "")
endif()
else()
# Regular builds require these dependencies
find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED)
endif()

View File

@@ -119,21 +119,29 @@ if (YAZE_BUILD_LIB)
${CMAKE_SOURCE_DIR}/incl/
${CMAKE_SOURCE_DIR}/src/
${ASAR_INCLUDE_DIRS}
${PNG_INCLUDE_DIRS}
${SDL2_INCLUDE_DIR}
${PROJECT_BINARY_DIR}
)
# Conditionally add PNG include dirs if available
if(PNG_FOUND)
target_include_directories(yaze_c PUBLIC ${PNG_INCLUDE_DIRS})
endif()
target_link_libraries(
yaze_c PRIVATE
asar-static
${ABSL_TARGETS}
${SDL_TARGETS}
${PNG_LIBRARIES}
${CMAKE_DL_LIBS}
ImGuiTestEngine
ImGui
)
# Conditionally link PNG if available
if(PNG_FOUND)
target_link_libraries(yaze_c PRIVATE ${PNG_LIBRARIES})
endif()
if (YAZE_INSTALL_LIB)
install(TARGETS yaze_c

View File

@@ -45,11 +45,15 @@ target_include_directories(
${CMAKE_SOURCE_DIR}/incl/
${CMAKE_SOURCE_DIR}/src/
${CMAKE_SOURCE_DIR}/src/lib/imgui_test_engine
${PNG_INCLUDE_DIRS}
${SDL2_INCLUDE_DIR}
${PROJECT_BINARY_DIR}
)
# Conditionally add PNG include dirs if available
if(PNG_FOUND)
target_include_directories(yaze PUBLIC ${PNG_INCLUDE_DIRS})
endif()
# Conditionally link nfd if available
if(YAZE_HAS_NFD)
target_link_libraries(yaze PRIVATE nfd)
@@ -63,12 +67,16 @@ target_link_libraries(
asar-static
${ABSL_TARGETS}
${SDL_TARGETS}
${PNG_LIBRARIES}
${CMAKE_DL_LIBS}
ImGui
ImGuiTestEngine
)
# Conditionally link PNG if available
if(PNG_FOUND)
target_link_libraries(yaze PUBLIC ${PNG_LIBRARIES})
endif()
if (APPLE)
target_link_libraries(yaze PUBLIC ${COCOA_LIBRARY})
endif()

View File

@@ -1,6 +1,7 @@
#include "project.h"
#include <fstream>
#include <sstream>
#include <string>
#include "app/gui/icons.h"

12
vcpkg.json Normal file
View File

@@ -0,0 +1,12 @@
{
"name": "yaze",
"version": "0.3.0",
"description": "Yet Another Zelda3 Editor",
"dependencies": [
"zlib",
"libpng",
"sdl2",
"abseil"
],
"builtin-baseline": "c8696863d371ab7f46e213d8f5ca923c4aef2a00"
}