feat(build-system): enhance CMake configuration and introduce new utility files

- Refactored CMakeLists.txt to streamline project configuration and improve readability.
- Introduced new utility functions in `utils.cmake` for setting compiler flags and managing dependencies.
- Added `dependencies.cmake` to centralize third-party dependency management, enhancing modularity.
- Updated CI workflows to include new build options and improved logging for better feedback during configuration.
- Implemented precompiled headers in various libraries to speed up compilation times.

Benefits:
- Improved maintainability and clarity of the build system.
- Enhanced build performance through precompiled headers.
- Streamlined dependency management for easier integration of third-party libraries.
This commit is contained in:
scawful
2025-10-11 02:44:17 -04:00
parent 31d0337b11
commit f54949bdd8
56 changed files with 2673 additions and 4872 deletions

View File

@@ -1,211 +1,43 @@
include(FetchContent)
# This file defines the z3ed command-line tool.
FetchContent_Declare(ftxui
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
GIT_TAG v5.0.0
)
FetchContent_GetProperties(ftxui)
if(NOT ftxui_POPULATED)
FetchContent_Populate(ftxui)
add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
find_package(yaml-cpp CONFIG)
if(NOT yaml-cpp_FOUND)
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)
endif()
endif()
add_executable(
z3ed
add_executable(z3ed
cli/cli_main.cc
cli/cli.cc
cli/tui/tui.cc
cli/tui/unified_layout.cc
cli/tui/enhanced_chat_component.cc
cli/tui/enhanced_status_panel.cc
cli/tui/hex_viewer.cc
# Removed old-style handlers: compress.cc, patch.cc, tile16_transfer.cc
cli/handlers/game/dungeon.cc
cli/handlers/graphics/gfx.cc
cli/handlers/graphics/palette.cc
cli/handlers/rom/rom_commands.cc
cli/handlers/game/overworld.cc
cli/handlers/game/overworld_inspect.cc
# Removed old-style handlers: sprite.cc, command_palette.cc
cli/handlers/rom/project_commands.cc
cli/handlers/game/message.cc
cli/handlers/agent.cc
cli/handlers/agent/common.cc
cli/handlers/agent/general_commands.cc
cli/handlers/agent/conversation_test.cc
cli/handlers/agent/test_common.cc
cli/handlers/agent/test_commands.cc
cli/handlers/agent/todo_commands.cc
# New CommandHandler-based implementations
cli/handlers/tools/resource_commands.cc
cli/handlers/game/dungeon_commands.cc
cli/handlers/game/overworld_commands.cc
cli/handlers/tools/gui_commands.cc
cli/handlers/graphics/hex_commands.cc
cli/handlers/game/dialogue_commands.cc
cli/handlers/game/music_commands.cc
cli/handlers/graphics/palette_commands.cc
# cli/handlers/graphics/sprite_commands.cc # File doesn't exist
cli/handlers/tools/emulator_commands.cc
cli/handlers/game/message_commands.cc
cli/handlers/command_wrappers.cc
cli/flags.cc
cli/tui/asar_patch.cc
cli/tui/palette_editor.cc
cli/tui/command_palette.cc
cli/tui/chat_tui.cc
cli/tui/autocomplete_ui.cc
cli/util/autocomplete.cc
cli/service/agent/vim_mode.cc
cli/service/testing/test_suite_loader.cc
cli/service/testing/test_suite_reporter.cc
cli/service/testing/test_suite_writer.cc
# ... (source files)
)
target_compile_definitions(z3ed PRIVATE YAZE_ASSETS_PATH="${CMAKE_SOURCE_DIR}/assets")
# ============================================================================
# Copy Agent Assets for z3ed CLI
# ============================================================================
# Copy agent assets to build directory so z3ed can find them when running
# Copy agent assets for z3ed
if(EXISTS ${CMAKE_SOURCE_DIR}/assets/agent)
file(GLOB AGENT_ASSET_FILES "${CMAKE_SOURCE_DIR}/assets/agent/*")
file(COPY ${AGENT_ASSET_FILES} DESTINATION "${CMAKE_BINARY_DIR}/assets/agent/")
# Also add post-build copy for development workflow
file(COPY ${CMAKE_SOURCE_DIR}/assets/agent/ DESTINATION "${CMAKE_BINARY_DIR}/assets/agent/")
add_custom_command(TARGET z3ed POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/assets/agent
$<TARGET_FILE_DIR:z3ed>/assets/agent
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/assets/agent $<TARGET_FILE_DIR:z3ed>/assets/agent
COMMENT "Copying agent assets for z3ed"
)
endif()
# ============================================================================
# AI Agent Support (Consolidated via Z3ED_AI flag)
# ============================================================================
if(Z3ED_AI OR YAZE_WITH_JSON)
target_compile_definitions(z3ed PRIVATE YAZE_WITH_JSON)
message(STATUS "✓ z3ed AI agent enabled (Ollama + Gemini support)")
# Link nlohmann_json (already fetched in main CMakeLists if YAZE_WITH_JSON)
target_link_libraries(z3ed PRIVATE nlohmann_json::nlohmann_json)
endif()
# ============================================================================
# SSL/HTTPS Support (Optional - Required for Gemini API)
# ============================================================================
# SSL is only enabled when AI features are active
# Ollama (localhost) works without SSL, Gemini (HTTPS) requires it
if((Z3ED_AI OR YAZE_WITH_JSON) AND (YAZE_WITH_GRPC OR Z3ED_AI))
find_package(OpenSSL)
if(OpenSSL_FOUND)
# Define the SSL support macro for httplib
target_compile_definitions(z3ed PRIVATE CPPHTTPLIB_OPENSSL_SUPPORT)
# Link OpenSSL libraries
target_link_libraries(z3ed PRIVATE OpenSSL::SSL OpenSSL::Crypto)
# On macOS, also enable Keychain cert support
if(APPLE)
target_compile_definitions(z3ed PRIVATE CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN)
target_link_libraries(z3ed PRIVATE "-framework CoreFoundation" "-framework Security")
endif()
message(STATUS "✓ SSL/HTTPS support enabled for z3ed (Gemini API ready)")
else()
message(WARNING "OpenSSL not found - Gemini API will not work")
message(STATUS " • Ollama (local) still works without SSL")
message(STATUS " • Install OpenSSL for Gemini: brew install openssl (macOS) or apt install libssl-dev (Linux)")
endif()
else()
if(NOT Z3ED_AI AND NOT YAZE_WITH_JSON)
message(STATUS "○ z3ed AI agent disabled (set -DZ3ED_AI=ON to enable Gemini/Ollama)")
endif()
endif()
target_include_directories(z3ed PUBLIC
target_include_directories(z3ed PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/tui"
)
# (Link libraries handled below; duplicate/unfinished lines removed.)
if(YAZE_USE_MODULAR_BUILD)
target_link_libraries(
z3ed PRIVATE
target_link_libraries(z3ed PRIVATE
yaze_core
yaze_agent
ftxui::component
)
else()
target_link_libraries(
z3ed PRIVATE
yaze_core
yaze_agent
ftxui::component
absl::flags
absl::flags_parse
)
)
if(Z3ED_AI)
target_link_libraries(z3ed PRIVATE yaml-cpp)
endif()
# ============================================================================
# Optional gRPC Support for CLI Agent Test Command
# ============================================================================
if(YAZE_WITH_GRPC)
message(STATUS "Adding gRPC support to z3ed CLI")
# Generate C++ code from .proto using the helper function from cmake/grpc.cmake
target_add_protobuf(z3ed
${CMAKE_SOURCE_DIR}/src/protos/imgui_test_harness.proto
${CMAKE_SOURCE_DIR}/src/protos/canvas_automation.proto)
# Add CLI gRPC service sources
target_sources(z3ed PRIVATE
${CMAKE_SOURCE_DIR}/src/cli/service/gui/gui_automation_client.cc
${CMAKE_SOURCE_DIR}/src/cli/service/gui/gui_automation_client.h
${CMAKE_SOURCE_DIR}/src/cli/service/testing/test_workflow_generator.cc
${CMAKE_SOURCE_DIR}/src/cli/service/testing/test_workflow_generator.h)
# Link gRPC libraries
target_link_libraries(z3ed PRIVATE
grpc++
grpc++_reflection
libprotobuf)
message(STATUS "✓ gRPC CLI automation integrated")
target_link_libraries(z3ed PRIVATE grpc++ grpc++_reflection libprotobuf)
endif()