diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c316d60..2e5e6bae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -164,6 +164,7 @@ jobs: -DCMAKE_C_COMPILER=${{ matrix.cc }} \ -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} \ -DCMAKE_POLICY_VERSION_MINIMUM=3.16 \ + -DYAZE_USE_MODULAR_BUILD=ON \ -DYAZE_MINIMAL_BUILD=ON \ -DYAZE_ENABLE_ROM_TESTS=OFF \ -DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF \ @@ -175,7 +176,7 @@ jobs: if: runner.os == 'Windows' shell: cmd run: | - cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_POLICY_VERSION_MINIMUM=3.16 -DYAZE_MINIMAL_BUILD=ON -DYAZE_ENABLE_ROM_TESTS=OFF -DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF -DYAZE_ENABLE_UI_TESTS=OFF -Wno-dev -G "${{ matrix.cmake_generator }}" -A ${{ matrix.cmake_generator_platform }} + cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_POLICY_VERSION_MINIMUM=3.16 -DYAZE_USE_MODULAR_BUILD=ON -DYAZE_MINIMAL_BUILD=ON -DYAZE_ENABLE_ROM_TESTS=OFF -DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF -DYAZE_ENABLE_UI_TESTS=OFF -Wno-dev -G "${{ matrix.cmake_generator }}" -A ${{ matrix.cmake_generator_platform }} # Build - name: Build @@ -353,6 +354,7 @@ jobs: -DCMAKE_CXX_FLAGS="-fsanitize=address -fno-omit-frame-pointer" \ -DCMAKE_C_FLAGS="-fsanitize=address -fno-omit-frame-pointer" \ -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address" \ + -DYAZE_USE_MODULAR_BUILD=ON \ -DYAZE_MINIMAL_BUILD=ON \ -DYAZE_ENABLE_ROM_TESTS=OFF \ -DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF \ @@ -397,6 +399,7 @@ jobs: run: | cmake -B ${{ github.workspace }}/build \ -DCMAKE_BUILD_TYPE=Debug \ + -DYAZE_USE_MODULAR_BUILD=ON \ -DCMAKE_CXX_FLAGS="--coverage" \ -DCMAKE_C_FLAGS="--coverage" \ -DCMAKE_EXE_LINKER_FLAGS="--coverage" \ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 548e6100..057f575c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -248,6 +248,7 @@ jobs: -GNinja \ -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \ -DCMAKE_POLICY_VERSION_MINIMUM=3.16 \ + -DYAZE_USE_MODULAR_BUILD=ON \ -DYAZE_BUILD_TESTS=ON \ -DYAZE_BUILD_EMU=OFF \ -DYAZE_BUILD_Z3ED=ON \ @@ -267,6 +268,7 @@ jobs: -GNinja \ -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \ -DCMAKE_POLICY_VERSION_MINIMUM=3.16 \ + -DYAZE_USE_MODULAR_BUILD=ON \ -DYAZE_BUILD_TESTS=ON \ -DYAZE_BUILD_EMU=OFF \ -DYAZE_BUILD_Z3ED=ON \ @@ -296,6 +298,7 @@ jobs: '-A','${{ matrix.cmake_generator_platform }}', '-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}', '-DCMAKE_POLICY_VERSION_MINIMUM=3.16', + '-DYAZE_USE_MODULAR_BUILD=ON', '-DYAZE_BUILD_TESTS=ON', '-DYAZE_BUILD_EMU=OFF', '-DYAZE_BUILD_Z3ED=ON', diff --git a/CMakeLists.txt b/CMakeLists.txt index 76fa7d11..3bb63222 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ option(YAZE_ENABLE_ROM_TESTS "Enable tests that require ROM files" OFF) option(YAZE_ENABLE_EXPERIMENTAL_TESTS "Enable experimental/unstable tests" ON) option(YAZE_ENABLE_UI_TESTS "Enable ImGui Test Engine UI testing" ON) option(YAZE_MINIMAL_BUILD "Minimal build for CI (disable optional features)" OFF) +option(YAZE_USE_MODULAR_BUILD "Use modularized library build system for faster builds" OFF) # Optional JSON support (required for Gemini and structured agent responses) option(YAZE_WITH_JSON "Enable JSON support for AI integrations" OFF) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index efcc32db..5b104b49 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -87,6 +87,32 @@ if(YAZE_BUILD_APP OR YAZE_BUILD_Z3ED) include(cli/agent.cmake) endif() +if(YAZE_USE_MODULAR_BUILD) + message(STATUS "Using modular build system") + + if(YAZE_BUILD_LIB OR YAZE_BUILD_APP OR YAZE_BUILD_Z3ED) + include(app/gfx/gfx.cmake) + include(app/gui/gui.cmake) + include(app/zelda3/zelda3.cmake) + include(app/core/core.cmake) + include(app/editor/editor.cmake) + + include(util/util.cmake) + include(app/gfx/gfx_library.cmake) + include(app/gui/gui_library.cmake) + include(app/zelda3/zelda3_library.cmake) + + if(YAZE_BUILD_EMU AND NOT YAZE_WITH_GRPC) + include(app/emu/emu_library.cmake) + endif() + + include(app/core/core_library.cmake) + include(app/editor/editor_library.cmake) + endif() +else() + message(STATUS "Using traditional monolithic build system") +endif() + if (YAZE_BUILD_APP) include(app/app.cmake) endif() @@ -165,29 +191,116 @@ endif() # Yaze Core Library (for testing and C API) if (YAZE_BUILD_LIB) - # Create core library for testing (includes editor and zelda3 components needed by tests) - set(YAZE_CORE_SOURCES - app/rom.cc - ${YAZE_APP_CORE_SRC} - ${YAZE_APP_GFX_SRC} - ${YAZE_APP_EDITOR_SRC} - ${YAZE_APP_ZELDA3_SRC} - ${YAZE_APP_EMU_SRC} - ${YAZE_GUI_SRC} - ${YAZE_UTIL_SRC} - # cli/service/gui_automation_client.cc # Moved to yaze_c - cli/service/testing/test_workflow_generator.cc - ) - - # Create full library for C API + # Sources shared by the C API library set(YAZE_C_SOURCES ./yaze.cc cli/service/gui/gui_automation_client.cc ) - - # Create the core library (static for testing) - add_library(yaze_core STATIC ${YAZE_CORE_SOURCES}) - + + if(YAZE_USE_MODULAR_BUILD) + # Aggregate modular libraries into an interface target for backward compatibility + if(NOT TARGET yaze_core) + add_library(yaze_core INTERFACE) + endif() + + target_include_directories( + yaze_core INTERFACE + ${CMAKE_SOURCE_DIR}/src/lib/ + ${CMAKE_SOURCE_DIR}/src/app/ + ${CMAKE_SOURCE_DIR}/src/lib/asar/src + ${CMAKE_SOURCE_DIR}/src/lib/asar/src/asar + ${CMAKE_SOURCE_DIR}/src/lib/asar/src/asar-dll-bindings/c + ${CMAKE_SOURCE_DIR}/incl/ + ${CMAKE_SOURCE_DIR}/src/ + ${CMAKE_SOURCE_DIR}/src/lib/imgui + ${CMAKE_SOURCE_DIR}/src/lib/imgui_test_engine + ${SDL2_INCLUDE_DIR} + ${PROJECT_BINARY_DIR} + ) + + target_link_libraries( + yaze_core INTERFACE + yaze_util + yaze_gfx + yaze_gui + yaze_zelda3 + yaze_core_lib + yaze_editor + ImGui + ) + + if(TARGET yaze_agent) + target_link_libraries(yaze_core INTERFACE yaze_agent) + endif() + + if(YAZE_BUILD_EMU AND NOT YAZE_WITH_GRPC AND TARGET yaze_emulator) + target_link_libraries(yaze_core INTERFACE yaze_emulator) + endif() + + if(YAZE_ENABLE_UI_TESTS AND TARGET ImGuiTestEngine) + target_link_libraries(yaze_core INTERFACE ImGuiTestEngine) + endif() + + if(YAZE_WITH_GRPC) + target_link_libraries(yaze_core INTERFACE + grpc++ + grpc++_reflection + libprotobuf) + endif() + else() + # Create core library for testing (includes editor and zelda3 components needed by tests) + set(YAZE_CORE_SOURCES + app/rom.cc + ${YAZE_APP_CORE_SRC} + ${YAZE_APP_GFX_SRC} + ${YAZE_APP_EDITOR_SRC} + ${YAZE_APP_ZELDA3_SRC} + ${YAZE_APP_EMU_SRC} + ${YAZE_GUI_SRC} + ${YAZE_UTIL_SRC} + # cli/service/gui_automation_client.cc # Moved to yaze_c + cli/service/testing/test_workflow_generator.cc + ) + + add_library(yaze_core STATIC ${YAZE_CORE_SOURCES}) + + target_include_directories( + yaze_core PUBLIC + ${CMAKE_SOURCE_DIR}/src/lib/ + ${CMAKE_SOURCE_DIR}/src/app/ + ${CMAKE_SOURCE_DIR}/src/lib/asar/src + ${CMAKE_SOURCE_DIR}/src/lib/asar/src/asar + ${CMAKE_SOURCE_DIR}/src/lib/asar/src/asar-dll-bindings/c + ${CMAKE_SOURCE_DIR}/incl/ + ${CMAKE_SOURCE_DIR}/src/ + ${CMAKE_SOURCE_DIR}/src/lib/imgui + ${CMAKE_SOURCE_DIR}/src/lib/imgui_test_engine + ${SDL2_INCLUDE_DIR} + ${PROJECT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ) + + target_link_libraries( + yaze_core PUBLIC + asar-static + yaze_agent + ${ABSL_TARGETS} + ${SDL_TARGETS} + ${CMAKE_DL_LIBS} + ImGui + ) + + if(YAZE_WITH_GRPC) + target_add_protobuf(yaze_core + ${CMAKE_SOURCE_DIR}/src/app/core/proto/imgui_test_harness.proto) + + target_link_libraries(yaze_core PRIVATE + grpc++ + grpc++_reflection + libprotobuf) + endif() + endif() + # Create the full C API library (static for CI, shared for release) if(YAZE_MINIMAL_BUILD) add_library(yaze_c STATIC ${YAZE_C_SOURCES}) @@ -195,44 +308,6 @@ if (YAZE_BUILD_LIB) add_library(yaze_c SHARED ${YAZE_C_SOURCES}) endif() - # Configure core library (for testing) - target_include_directories( - yaze_core PUBLIC - ${CMAKE_SOURCE_DIR}/src/lib/ - ${CMAKE_SOURCE_DIR}/src/app/ - ${CMAKE_SOURCE_DIR}/src/lib/asar/src - ${CMAKE_SOURCE_DIR}/src/lib/asar/src/asar - ${CMAKE_SOURCE_DIR}/src/lib/asar/src/asar-dll-bindings/c - ${CMAKE_SOURCE_DIR}/incl/ - ${CMAKE_SOURCE_DIR}/src/ - ${CMAKE_SOURCE_DIR}/src/lib/imgui - ${CMAKE_SOURCE_DIR}/src/lib/imgui_test_engine - ${SDL2_INCLUDE_DIR} - ${PROJECT_BINARY_DIR} - ${CMAKE_CURRENT_BINARY_DIR} - ) - - target_link_libraries( - yaze_core PUBLIC - asar-static - yaze_agent - ${ABSL_TARGETS} - ${SDL_TARGETS} - ${CMAKE_DL_LIBS} - ImGui - ) - - if(YAZE_WITH_GRPC) - target_add_protobuf(yaze_core - ${CMAKE_SOURCE_DIR}/src/app/core/proto/imgui_test_harness.proto) - - target_link_libraries(yaze_core PRIVATE - grpc++ - grpc++_reflection - libprotobuf) - endif() - - # Configure full C API library target_include_directories( yaze_c PUBLIC ${CMAKE_SOURCE_DIR}/src/lib/ @@ -246,19 +321,41 @@ if (YAZE_BUILD_LIB) ${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}) - target_include_directories(yaze_core PUBLIC ${PNG_INCLUDE_DIRS}) + if(NOT YAZE_USE_MODULAR_BUILD) + target_include_directories(yaze_core PUBLIC ${PNG_INCLUDE_DIRS}) + endif() + endif() + + if(YAZE_USE_MODULAR_BUILD) + target_link_libraries( + yaze_c PRIVATE + yaze_util + yaze_gfx + yaze_gui + yaze_zelda3 + yaze_core_lib + yaze_editor + ImGui + ) + + if(TARGET yaze_agent) + target_link_libraries(yaze_c PRIVATE yaze_agent) + endif() + + if(YAZE_BUILD_EMU AND NOT YAZE_WITH_GRPC AND TARGET yaze_emulator) + target_link_libraries(yaze_c PRIVATE yaze_emulator) + endif() + else() + target_link_libraries( + yaze_c PRIVATE + yaze_core + ImGui + ) endif() - target_link_libraries( - yaze_c PRIVATE - yaze_core - ImGui - ) - if(YAZE_WITH_GRPC) target_add_protobuf(yaze_c ${CMAKE_SOURCE_DIR}/src/app/core/proto/imgui_test_harness.proto) @@ -269,18 +366,18 @@ if (YAZE_BUILD_LIB) libprotobuf) endif() - # Conditionally link ImGui Test Engine and set definitions if(YAZE_ENABLE_UI_TESTS AND TARGET ImGuiTestEngine) target_link_libraries(yaze_c PRIVATE ImGuiTestEngine) target_compile_definitions(yaze_c PRIVATE YAZE_ENABLE_IMGUI_TEST_ENGINE=1) else() target_compile_definitions(yaze_c PRIVATE YAZE_ENABLE_IMGUI_TEST_ENGINE=0) endif() - - # Conditionally link PNG if available + if(PNG_FOUND) target_link_libraries(yaze_c PRIVATE ${PNG_LIBRARIES}) - target_link_libraries(yaze_core PRIVATE ${PNG_LIBRARIES}) + if(NOT YAZE_USE_MODULAR_BUILD) + target_link_libraries(yaze_core PRIVATE ${PNG_LIBRARIES}) + endif() endif() if (YAZE_INSTALL_LIB) diff --git a/src/app/app.cmake b/src/app/app.cmake index 2f5d2e11..b87b8fdc 100644 --- a/src/app/app.cmake +++ b/src/app/app.cmake @@ -98,7 +98,26 @@ else() target_compile_definitions(yaze PRIVATE YAZE_ENABLE_NFD=0) endif() -target_link_libraries(yaze PRIVATE yaze_core) +if(YAZE_USE_MODULAR_BUILD) + target_link_libraries(yaze PRIVATE + yaze_util + yaze_gfx + yaze_gui + yaze_zelda3 + yaze_core_lib + yaze_editor + ) + + if(TARGET yaze_agent) + target_link_libraries(yaze PRIVATE yaze_agent) + endif() + + if(YAZE_BUILD_EMU AND NOT YAZE_WITH_GRPC AND TARGET yaze_emulator) + target_link_libraries(yaze PRIVATE yaze_emulator) + endif() +else() + target_link_libraries(yaze PRIVATE yaze_core) +endif() # Enable policy framework in main yaze target target_compile_definitions(yaze PRIVATE YAZE_ENABLE_POLICY_FRAMEWORK=1) @@ -224,22 +243,24 @@ if(YAZE_WITH_GRPC) ${CMAKE_SOURCE_DIR}/third_party/json/include) target_compile_definitions(yaze PRIVATE YAZE_WITH_JSON) - # Generate C++ code from .proto using the helper function from cmake/grpc.cmake - target_add_protobuf(yaze - ${CMAKE_SOURCE_DIR}/src/app/core/proto/imgui_test_harness.proto) - - # Add service implementation sources - target_sources(yaze PRIVATE - ${CMAKE_SOURCE_DIR}/src/app/core/service/imgui_test_harness_service.cc - ${CMAKE_SOURCE_DIR}/src/app/core/service/imgui_test_harness_service.h - ${CMAKE_SOURCE_DIR}/src/app/core/service/screenshot_utils.cc - ${CMAKE_SOURCE_DIR}/src/app/core/service/screenshot_utils.h - ${CMAKE_SOURCE_DIR}/src/app/core/service/widget_discovery_service.cc - ${CMAKE_SOURCE_DIR}/src/app/core/service/widget_discovery_service.h - ${CMAKE_SOURCE_DIR}/src/app/core/testing/test_recorder.cc - ${CMAKE_SOURCE_DIR}/src/app/core/testing/test_recorder.h - ${CMAKE_SOURCE_DIR}/src/app/core/testing/test_script_parser.cc - ${CMAKE_SOURCE_DIR}/src/app/core/testing/test_script_parser.h) + if(NOT YAZE_USE_MODULAR_BUILD) + # Generate C++ code from .proto using the helper function from cmake/grpc.cmake + target_add_protobuf(yaze + ${CMAKE_SOURCE_DIR}/src/app/core/proto/imgui_test_harness.proto) + + # Add service implementation sources + target_sources(yaze PRIVATE + ${CMAKE_SOURCE_DIR}/src/app/core/service/imgui_test_harness_service.cc + ${CMAKE_SOURCE_DIR}/src/app/core/service/imgui_test_harness_service.h + ${CMAKE_SOURCE_DIR}/src/app/core/service/screenshot_utils.cc + ${CMAKE_SOURCE_DIR}/src/app/core/service/screenshot_utils.h + ${CMAKE_SOURCE_DIR}/src/app/core/service/widget_discovery_service.cc + ${CMAKE_SOURCE_DIR}/src/app/core/service/widget_discovery_service.h + ${CMAKE_SOURCE_DIR}/src/app/core/testing/test_recorder.cc + ${CMAKE_SOURCE_DIR}/src/app/core/testing/test_recorder.h + ${CMAKE_SOURCE_DIR}/src/app/core/testing/test_script_parser.cc + ${CMAKE_SOURCE_DIR}/src/app/core/testing/test_script_parser.h) + endif() # Link gRPC libraries target_link_libraries(yaze PRIVATE diff --git a/src/app/core/core_library.cmake b/src/app/core/core_library.cmake new file mode 100644 index 00000000..92711dfc --- /dev/null +++ b/src/app/core/core_library.cmake @@ -0,0 +1,92 @@ +# ============================================================================== +# Yaze Core Library +# ============================================================================== +# This library contains core application functionality: +# - ROM management +# - Project management +# - Controller/Window management +# - Asar wrapper for assembly +# - Platform-specific utilities (file dialogs, fonts, clipboard) +# - Widget state capture for testing +# - Emulator interface +# +# Dependencies: yaze_util, yaze_gfx, asar, SDL2 +# ============================================================================== + +add_library(yaze_core_lib STATIC + app/rom.cc + ${YAZE_APP_CORE_SRC} +) + +target_include_directories(yaze_core_lib PUBLIC + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/src/app + ${CMAKE_SOURCE_DIR}/src/lib + ${CMAKE_SOURCE_DIR}/src/lib/imgui + ${CMAKE_SOURCE_DIR}/src/lib/asar/src + ${CMAKE_SOURCE_DIR}/src/lib/asar/src/asar + ${CMAKE_SOURCE_DIR}/src/lib/asar/src/asar-dll-bindings/c + ${CMAKE_SOURCE_DIR}/incl + ${SDL2_INCLUDE_DIR} + ${PROJECT_BINARY_DIR} +) + +target_link_libraries(yaze_core_lib PUBLIC + yaze_util + yaze_gfx + yaze_common + asar-static + ${ABSL_TARGETS} + ${SDL_TARGETS} + ${CMAKE_DL_LIBS} +) + +target_sources(yaze_core_lib PRIVATE + ${CMAKE_SOURCE_DIR}/src/cli/service/testing/test_workflow_generator.cc +) + +if(YAZE_WITH_GRPC) + target_add_protobuf(yaze_core_lib + ${CMAKE_SOURCE_DIR}/src/app/core/proto/imgui_test_harness.proto) + + target_sources(yaze_core_lib PRIVATE + ${CMAKE_SOURCE_DIR}/src/app/core/service/imgui_test_harness_service.cc + ${CMAKE_SOURCE_DIR}/src/app/core/service/imgui_test_harness_service.h + ${CMAKE_SOURCE_DIR}/src/app/core/service/screenshot_utils.cc + ${CMAKE_SOURCE_DIR}/src/app/core/service/screenshot_utils.h + ${CMAKE_SOURCE_DIR}/src/app/core/service/widget_discovery_service.cc + ${CMAKE_SOURCE_DIR}/src/app/core/service/widget_discovery_service.h + ${CMAKE_SOURCE_DIR}/src/app/core/testing/test_recorder.cc + ${CMAKE_SOURCE_DIR}/src/app/core/testing/test_recorder.h + ${CMAKE_SOURCE_DIR}/src/app/core/testing/test_script_parser.cc + ${CMAKE_SOURCE_DIR}/src/app/core/testing/test_script_parser.h + ) + + target_link_libraries(yaze_core_lib PUBLIC + grpc++ + grpc++_reflection + libprotobuf + ) +endif() + +# Platform-specific libraries +if(APPLE) + target_link_libraries(yaze_core_lib PUBLIC ${COCOA_LIBRARY}) +endif() + +set_target_properties(yaze_core_lib PROPERTIES + POSITION_INDEPENDENT_CODE ON + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" +) + +# Platform-specific compile definitions +if(UNIX AND NOT APPLE) + target_compile_definitions(yaze_core_lib PRIVATE linux stricmp=strcasecmp) +elseif(APPLE) + target_compile_definitions(yaze_core_lib PRIVATE MACOS) +elseif(WIN32) + target_compile_definitions(yaze_core_lib PRIVATE WINDOWS) +endif() + +message(STATUS "✓ yaze_core_lib library configured") diff --git a/src/app/editor/editor_library.cmake b/src/app/editor/editor_library.cmake new file mode 100644 index 00000000..f6c273eb --- /dev/null +++ b/src/app/editor/editor_library.cmake @@ -0,0 +1,73 @@ +# ============================================================================== +# Yaze Editor Library +# ============================================================================== +# This library contains all editor functionality: +# - Editor manager and coordination +# - Dungeon editor (room selector, object editor, renderer) +# - Overworld editor (map, tile16, entities) +# - Sprite editor +# - Music editor +# - Message editor +# - Assembly editor +# - Graphics/palette editors +# - System editors (settings, commands, extensions) +# - Testing infrastructure +# +# Dependencies: yaze_core_lib, yaze_gfx, yaze_gui, yaze_zelda3, ImGui +# ============================================================================== + +add_library(yaze_editor STATIC ${YAZE_APP_EDITOR_SRC}) + +target_include_directories(yaze_editor PUBLIC + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/src/lib + ${CMAKE_SOURCE_DIR}/src/lib/imgui + ${CMAKE_SOURCE_DIR}/src/lib/imgui_test_engine + ${CMAKE_SOURCE_DIR}/incl + ${SDL2_INCLUDE_DIR} + ${PROJECT_BINARY_DIR} +) + +target_link_libraries(yaze_editor PUBLIC + yaze_core_lib + yaze_gfx + yaze_gui + yaze_zelda3 + yaze_util + yaze_common + ImGui +) + +# Conditionally link ImGui Test Engine +if(YAZE_ENABLE_UI_TESTS AND TARGET ImGuiTestEngine) + target_link_libraries(yaze_editor PUBLIC ImGuiTestEngine) + target_compile_definitions(yaze_editor PRIVATE YAZE_ENABLE_IMGUI_TEST_ENGINE=1) +else() + target_compile_definitions(yaze_editor PRIVATE YAZE_ENABLE_IMGUI_TEST_ENGINE=0) +endif() + +# Conditionally link gRPC if enabled +if(YAZE_WITH_GRPC) + target_link_libraries(yaze_editor PRIVATE + grpc++ + grpc++_reflection + libprotobuf + ) +endif() + +set_target_properties(yaze_editor PROPERTIES + POSITION_INDEPENDENT_CODE ON + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" +) + +# Platform-specific compile definitions +if(UNIX AND NOT APPLE) + target_compile_definitions(yaze_editor PRIVATE linux stricmp=strcasecmp) +elseif(APPLE) + target_compile_definitions(yaze_editor PRIVATE MACOS) +elseif(WIN32) + target_compile_definitions(yaze_editor PRIVATE WINDOWS) +endif() + +message(STATUS "✓ yaze_editor library configured") diff --git a/src/app/editor/graphics/graphics_editor.cc b/src/app/editor/graphics/graphics_editor.cc index 1d4dc8cb..61b47810 100644 --- a/src/app/editor/graphics/graphics_editor.cc +++ b/src/app/editor/graphics/graphics_editor.cc @@ -20,7 +20,7 @@ #include "app/gui/modules/asset_browser.h" #include "app/gui/style.h" #include "app/rom.h" -#include "gfx/performance_profiler.h" +#include "app/gfx/performance_profiler.h" #include "imgui/imgui.h" #include "imgui/misc/cpp/imgui_stdlib.h" #include "imgui_memory_editor.h" diff --git a/src/app/emu/emu_library.cmake b/src/app/emu/emu_library.cmake new file mode 100644 index 00000000..57f15f8e --- /dev/null +++ b/src/app/emu/emu_library.cmake @@ -0,0 +1,47 @@ +# ============================================================================== +# Yaze Emulator Library +# ============================================================================== +# This library contains SNES emulation functionality: +# - CPU (65C816) implementation +# - PPU (Picture Processing Unit) for graphics +# - APU (Audio Processing Unit) with SPC700 and DSP +# - DMA controller +# - Memory management +# +# Dependencies: yaze_util, SDL2 +# ============================================================================== + +add_library(yaze_emulator STATIC ${YAZE_APP_EMU_SRC}) + +target_include_directories(yaze_emulator PUBLIC + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/src/app + ${CMAKE_SOURCE_DIR}/src/lib + ${CMAKE_SOURCE_DIR}/incl + ${SDL2_INCLUDE_DIR} + ${PROJECT_BINARY_DIR} +) + +target_link_libraries(yaze_emulator PUBLIC + yaze_util + yaze_common + ${ABSL_TARGETS} + ${SDL_TARGETS} +) + +set_target_properties(yaze_emulator PROPERTIES + POSITION_INDEPENDENT_CODE ON + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" +) + +# Platform-specific compile definitions +if(UNIX AND NOT APPLE) + target_compile_definitions(yaze_emulator PRIVATE linux stricmp=strcasecmp) +elseif(APPLE) + target_compile_definitions(yaze_emulator PRIVATE MACOS) +elseif(WIN32) + target_compile_definitions(yaze_emulator PRIVATE WINDOWS) +endif() + +message(STATUS "✓ yaze_emulator library configured") diff --git a/src/app/gfx/gfx_library.cmake b/src/app/gfx/gfx_library.cmake new file mode 100644 index 00000000..9201215d --- /dev/null +++ b/src/app/gfx/gfx_library.cmake @@ -0,0 +1,53 @@ +# ============================================================================== +# Yaze Graphics Library +# ============================================================================== +# This library contains all graphics-related functionality: +# - Bitmap manipulation +# - SNES tile/palette handling +# - Compression/decompression +# - Arena memory management +# - Atlas rendering +# - Performance profiling +# +# Dependencies: yaze_util, SDL2, Abseil +# ============================================================================== + +add_library(yaze_gfx STATIC ${YAZE_APP_GFX_SRC}) + +target_include_directories(yaze_gfx PUBLIC + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/src/lib + ${CMAKE_SOURCE_DIR}/incl + ${SDL2_INCLUDE_DIR} + ${PROJECT_BINARY_DIR} +) + +target_link_libraries(yaze_gfx PUBLIC + yaze_util + yaze_common + ${ABSL_TARGETS} + ${SDL_TARGETS} +) + +# Conditionally add PNG support +if(PNG_FOUND) + target_include_directories(yaze_gfx PUBLIC ${PNG_INCLUDE_DIRS}) + target_link_libraries(yaze_gfx PUBLIC ${PNG_LIBRARIES}) +endif() + +set_target_properties(yaze_gfx PROPERTIES + POSITION_INDEPENDENT_CODE ON + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" +) + +# Platform-specific compile definitions +if(UNIX AND NOT APPLE) + target_compile_definitions(yaze_gfx PRIVATE linux stricmp=strcasecmp) +elseif(APPLE) + target_compile_definitions(yaze_gfx PRIVATE MACOS) +elseif(WIN32) + target_compile_definitions(yaze_gfx PRIVATE WINDOWS) +endif() + +message(STATUS "✓ yaze_gfx library configured") diff --git a/src/app/gui/canvas.h b/src/app/gui/canvas.h index d7b2b277..806cd6e6 100644 --- a/src/app/gui/canvas.h +++ b/src/app/gui/canvas.h @@ -1,7 +1,7 @@ #ifndef YAZE_GUI_CANVAS_H #define YAZE_GUI_CANVAS_H -#include "gfx/tilemap.h" +#include "app/gfx/tilemap.h" #define IMGUI_DEFINE_MATH_OPERATORS #include diff --git a/src/app/gui/canvas/canvas_context_menu.cc b/src/app/gui/canvas/canvas_context_menu.cc index bbbabfa7..0ce91e92 100644 --- a/src/app/gui/canvas/canvas_context_menu.cc +++ b/src/app/gui/canvas/canvas_context_menu.cc @@ -9,7 +9,7 @@ #include "app/gui/enhanced_palette_editor.h" #include "app/gui/bpp_format_ui.h" #include "app/gui/icons.h" -#include "gui/canvas/canvas_modals.h" +#include "app/gui/canvas/canvas_modals.h" #include "imgui/imgui.h" namespace yaze { diff --git a/src/app/gui/canvas/canvas_context_menu.h b/src/app/gui/canvas/canvas_context_menu.h index 7e5dd7fc..f73156c4 100644 --- a/src/app/gui/canvas/canvas_context_menu.h +++ b/src/app/gui/canvas/canvas_context_menu.h @@ -9,7 +9,7 @@ #include "app/gfx/bitmap.h" #include "app/gfx/snes_palette.h" #include "app/gui/icons.h" -#include "gui/canvas/canvas_modals.h" +#include "app/gui/canvas/canvas_modals.h" #include "canvas_usage_tracker.h" #include "imgui/imgui.h" diff --git a/src/app/gui/canvas/canvas_modals.h b/src/app/gui/canvas/canvas_modals.h index a28cc22a..2baf2814 100644 --- a/src/app/gui/canvas/canvas_modals.h +++ b/src/app/gui/canvas/canvas_modals.h @@ -7,7 +7,7 @@ #include "app/gfx/bitmap.h" #include "app/gfx/snes_palette.h" #include "app/gfx/bpp_format_manager.h" -#include "gui/canvas_utils.h" +#include "app/gui/canvas_utils.h" #include "imgui/imgui.h" namespace yaze { diff --git a/src/app/gui/gui_library.cmake b/src/app/gui/gui_library.cmake new file mode 100644 index 00000000..20d7c83a --- /dev/null +++ b/src/app/gui/gui_library.cmake @@ -0,0 +1,49 @@ +# ============================================================================== +# Yaze GUI Library +# ============================================================================== +# This library contains all GUI-related functionality: +# - Canvas system +# - ImGui widgets and utilities +# - Input handling +# - Theme management +# - Color utilities +# - Background rendering +# +# Dependencies: yaze_gfx, yaze_util, ImGui, SDL2 +# ============================================================================== + +add_library(yaze_gui STATIC ${YAZE_GUI_SRC}) + +target_include_directories(yaze_gui PUBLIC + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/src/lib + ${CMAKE_SOURCE_DIR}/src/lib/imgui + ${CMAKE_SOURCE_DIR}/incl + ${SDL2_INCLUDE_DIR} + ${PROJECT_BINARY_DIR} +) + +target_link_libraries(yaze_gui PUBLIC + yaze_gfx + yaze_util + yaze_common + ImGui + ${SDL_TARGETS} +) + +set_target_properties(yaze_gui PROPERTIES + POSITION_INDEPENDENT_CODE ON + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" +) + +# Platform-specific compile definitions +if(UNIX AND NOT APPLE) + target_compile_definitions(yaze_gui PRIVATE linux stricmp=strcasecmp) +elseif(APPLE) + target_compile_definitions(yaze_gui PRIVATE MACOS) +elseif(WIN32) + target_compile_definitions(yaze_gui PRIVATE WINDOWS) +endif() + +message(STATUS "✓ yaze_gui library configured") diff --git a/src/app/gui/modules/text_editor.h b/src/app/gui/modules/text_editor.h index e26686a5..27f9344e 100644 --- a/src/app/gui/modules/text_editor.h +++ b/src/app/gui/modules/text_editor.h @@ -12,7 +12,7 @@ #include #include -#include "imgui.h" +#include "imgui/imgui.h" class TextEditor { public: diff --git a/src/app/gui/style.cc b/src/app/gui/style.cc index 088fc610..4ee7ab5d 100644 --- a/src/app/gui/style.cc +++ b/src/app/gui/style.cc @@ -5,9 +5,9 @@ #include "app/core/platform/file_dialog.h" #include "app/gui/theme_manager.h" #include "app/gui/background_renderer.h" -#include "core/platform/font_loader.h" -#include "gui/color.h" -#include "gui/icons.h" +#include "app/core/platform/font_loader.h" +#include "app/gui/color.h" +#include "app/gui/icons.h" #include "imgui/imgui.h" #include "imgui/imgui_internal.h" #include "util/log.h" diff --git a/src/app/zelda3/zelda3_library.cmake b/src/app/zelda3/zelda3_library.cmake new file mode 100644 index 00000000..b0f64aa3 --- /dev/null +++ b/src/app/zelda3/zelda3_library.cmake @@ -0,0 +1,45 @@ +# ============================================================================== +# Yaze Zelda3 Library +# ============================================================================== +# This library contains all Zelda3-specific game logic: +# - Overworld system (maps, tiles, sprites) +# - Dungeon system (rooms, objects, sprites) +# - Screen modules (title, inventory, dungeon map) +# - Sprite management +# - Music/tracker system +# +# Dependencies: yaze_gfx, yaze_util +# ============================================================================== + +add_library(yaze_zelda3 STATIC ${YAZE_APP_ZELDA3_SRC}) + +target_include_directories(yaze_zelda3 PUBLIC + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/src/lib + ${CMAKE_SOURCE_DIR}/incl + ${PROJECT_BINARY_DIR} +) + +target_link_libraries(yaze_zelda3 PUBLIC + yaze_gfx + yaze_util + yaze_common + ${ABSL_TARGETS} +) + +set_target_properties(yaze_zelda3 PROPERTIES + POSITION_INDEPENDENT_CODE ON + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" +) + +# Platform-specific compile definitions +if(UNIX AND NOT APPLE) + target_compile_definitions(yaze_zelda3 PRIVATE linux stricmp=strcasecmp) +elseif(APPLE) + target_compile_definitions(yaze_zelda3 PRIVATE MACOS) +elseif(WIN32) + target_compile_definitions(yaze_zelda3 PRIVATE WINDOWS) +endif() + +message(STATUS "✓ yaze_zelda3 library configured") diff --git a/src/cli/agent.cmake b/src/cli/agent.cmake index e3a77cfd..4915f4e8 100644 --- a/src/cli/agent.cmake +++ b/src/cli/agent.cmake @@ -1,3 +1,69 @@ +include(FetchContent) + +function(_yaze_ensure_yaml_cpp _out_target) + if(TARGET yaml-cpp::yaml-cpp) + set(${_out_target} yaml-cpp::yaml-cpp PARENT_SCOPE) + return() + endif() + + if(TARGET yaml-cpp) + set(${_out_target} yaml-cpp PARENT_SCOPE) + return() + endif() + + find_package(yaml-cpp CONFIG QUIET) + + if(TARGET yaml-cpp::yaml-cpp) + set(${_out_target} yaml-cpp::yaml-cpp PARENT_SCOPE) + return() + elseif(TARGET yaml-cpp) + set(${_out_target} yaml-cpp PARENT_SCOPE) + return() + endif() + + message(STATUS "yaml-cpp not found via package config, fetching from source") + + FetchContent_Declare(yaml-cpp + GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git + GIT_TAG 0.8.0 + ) + + FetchContent_GetProperties(yaml-cpp) + if(NOT yaml-cpp_POPULATED) + FetchContent_Populate(yaml-cpp) + + set(_yaml_cpp_cmakelists "${yaml-cpp_SOURCE_DIR}/CMakeLists.txt") + if(EXISTS "${_yaml_cpp_cmakelists}") + file(READ "${_yaml_cpp_cmakelists}" _yaml_cpp_cmake_contents) + if(_yaml_cpp_cmake_contents MATCHES "cmake_minimum_required\\(VERSION 3\\.4\\)") + string(REPLACE "cmake_minimum_required(VERSION 3.4)" + "cmake_minimum_required(VERSION 3.5)" + _yaml_cpp_cmake_contents "${_yaml_cpp_cmake_contents}") + file(WRITE "${_yaml_cpp_cmakelists}" "${_yaml_cpp_cmake_contents}") + endif() + endif() + + set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Disable yaml-cpp tests" FORCE) + set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "Disable yaml-cpp contrib" FORCE) + set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "Disable yaml-cpp tools" FORCE) + set(YAML_CPP_INSTALL OFF CACHE BOOL "Disable yaml-cpp install" FORCE) + set(YAML_CPP_FORMAT_SOURCE OFF CACHE BOOL "Disable yaml-cpp format target" FORCE) + + add_subdirectory(${yaml-cpp_SOURCE_DIR} ${yaml-cpp_BINARY_DIR} EXCLUDE_FROM_ALL) + + if(NOT TARGET yaml-cpp) + message(FATAL_ERROR "yaml-cpp target was not created after fetching") + endif() + + # Ensure the fetched target exposes its public headers + target_include_directories(yaml-cpp PUBLIC ${yaml-cpp_SOURCE_DIR}/include) + endif() + + set(${_out_target} yaml-cpp PARENT_SCOPE) +endfunction() + +_yaze_ensure_yaml_cpp(YAZE_YAML_CPP_TARGET) + set(YAZE_AGENT_SOURCES cli/handlers/agent/tool_commands.cc cli/service/agent/conversational_agent_service.cc @@ -20,13 +86,14 @@ endif() add_library(yaze_agent STATIC ${YAZE_AGENT_SOURCES}) -target_link_libraries(yaze_agent - PUBLIC - yaze_common - ${ABSL_TARGETS} - yaml-cpp +set(_yaze_agent_link_targets + yaze_common + ${ABSL_TARGETS} + ${YAZE_YAML_CPP_TARGET} ) +target_link_libraries(yaze_agent PUBLIC ${_yaze_agent_link_targets}) + target_include_directories(yaze_agent PUBLIC ${CMAKE_SOURCE_DIR}/src @@ -36,6 +103,13 @@ target_include_directories(yaze_agent ${CMAKE_SOURCE_DIR}/src/lib ) +if(YAZE_YAML_CPP_TARGET) + get_target_property(_yaze_yaml_include_dirs ${YAZE_YAML_CPP_TARGET} INTERFACE_INCLUDE_DIRECTORIES) + if(_yaze_yaml_include_dirs) + target_include_directories(yaze_agent PUBLIC ${_yaze_yaml_include_dirs}) + endif() +endif() + if(SDL2_INCLUDE_DIR) target_include_directories(yaze_agent PUBLIC ${SDL2_INCLUDE_DIR}) endif() diff --git a/src/cli/z3ed.cmake b/src/cli/z3ed.cmake index 151c1b2e..ce7a53d0 100644 --- a/src/cli/z3ed.cmake +++ b/src/cli/z3ed.cmake @@ -118,15 +118,31 @@ target_include_directories( ${PROJECT_BINARY_DIR} ) -target_link_libraries( - z3ed PRIVATE - yaze_core - ftxui::component - ftxui::screen - ftxui::dom - absl::flags - absl::flags_parse -) +if(YAZE_USE_MODULAR_BUILD) + target_link_libraries( + z3ed PRIVATE + yaze_util + yaze_gfx + yaze_zelda3 + yaze_core_lib + yaze_agent + ftxui::component + ftxui::screen + ftxui::dom + absl::flags + absl::flags_parse + ) +else() + target_link_libraries( + z3ed PRIVATE + yaze_core + ftxui::component + ftxui::screen + ftxui::dom + absl::flags + absl::flags_parse + ) +endif() # ============================================================================ # Optional gRPC Support for CLI Agent Test Command diff --git a/src/util/util.cmake b/src/util/util.cmake new file mode 100644 index 00000000..9810b416 --- /dev/null +++ b/src/util/util.cmake @@ -0,0 +1,47 @@ +# ============================================================================== +# Yaze Utility Library +# ============================================================================== +# This library contains low-level utilities used throughout the codebase: +# - BPS patch handling +# - Command-line flag parsing +# - Hexadecimal utilities +# +# This library has no dependencies on GUI, graphics, or game-specific code, +# making it the foundation of the dependency hierarchy. +# ============================================================================== + +set(YAZE_UTIL_SRC + util/bps.cc + util/flag.cc + util/hex.cc +) + +add_library(yaze_util STATIC ${YAZE_UTIL_SRC}) + +target_include_directories(yaze_util PUBLIC + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/incl + ${PROJECT_BINARY_DIR} +) + +target_link_libraries(yaze_util PUBLIC + yaze_common + ${ABSL_TARGETS} +) + +set_target_properties(yaze_util PROPERTIES + POSITION_INDEPENDENT_CODE ON + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" +) + +# Platform-specific compile definitions +if(UNIX AND NOT APPLE) + target_compile_definitions(yaze_util PRIVATE linux stricmp=strcasecmp) +elseif(APPLE) + target_compile_definitions(yaze_util PRIVATE MACOS) +elseif(WIN32) + target_compile_definitions(yaze_util PRIVATE WINDOWS) +endif() + +message(STATUS "✓ yaze_util library configured") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cfe46cf5..1ea4215b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -253,7 +253,26 @@ endif() # Link core library for essential functionality (BPS, ASAR, etc.) if(YAZE_BUILD_LIB) - target_link_libraries(yaze_test yaze_core) + if(YAZE_USE_MODULAR_BUILD) + target_link_libraries(yaze_test + yaze_util + yaze_gfx + yaze_gui + yaze_zelda3 + yaze_core_lib + yaze_editor + ) + + if(TARGET yaze_agent) + target_link_libraries(yaze_test yaze_agent) + endif() + + if(YAZE_BUILD_EMU AND NOT YAZE_WITH_GRPC AND TARGET yaze_emulator) + target_link_libraries(yaze_test yaze_emulator) + endif() + else() + target_link_libraries(yaze_test yaze_core) + endif() endif() # Conditionally link ImGuiTestEngine only when UI tests are enabled