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,26 +1,59 @@
set(YAZE_SRC_FILES "")
foreach (file
app/rom.cc
${YAZE_APP_CORE_SRC}
${YAZE_APP_EMU_SRC}
${YAZE_APP_GFX_SRC}
${YAZE_APP_ZELDA3_SRC}
${YAZE_APP_EDITOR_SRC}
${YAZE_UTIL_SRC}
${YAZE_GUI_SRC})
list(APPEND YAZE_SRC_FILES ${CMAKE_SOURCE_DIR}/src/${file})
endforeach()
# This file defines the yaze test suites and configures test discovery with labels.
# Only build test executable if tests are enabled
if(YAZE_BUILD_TESTS AND NOT YAZE_BUILD_TESTS STREQUAL "OFF")
if(YAZE_BUILD_TESTS)
# Base list of test sources for all builds
set(YAZE_TEST_BASE_SOURCES
# Helper function to create and configure a test executable for a suite of tests.
# This function adds the executable, links common dependencies, discovers the
# tests using gtest_discover_tests, and assigns a label to all discovered tests.
function(yaze_add_test_suite suite_name label is_gui_test)
set(sources ${ARGN})
add_executable(${suite_name} yaze_test.cc ${sources})
target_include_directories(${suite_name} PUBLIC
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/incl
${CMAKE_SOURCE_DIR}/test
${PROJECT_BINARY_DIR}
)
target_link_libraries(${suite_name} PRIVATE
yaze_test_support
gmock_main
gtest_main
absl::failure_signal_handler
absl::flags
absl::flags_parse
)
# Link ImGui Test Engine for GUI tests
if(is_gui_test AND YAZE_ENABLE_UI_TESTS)
target_link_libraries(${suite_name} PRIVATE ${IMGUI_TEST_ENGINE_TARGET})
target_compile_definitions(${suite_name} PRIVATE ${IMGUI_TEST_ENGINE_DEFINITIONS})
endif()
if(WIN32)
message(STATUS "Configuring Windows stack size for ${suite_name} to 16MB")
if(MSVC)
target_link_options(${suite_name} PRIVATE /STACK:16777216)
else()
target_link_options(${suite_name} PRIVATE -Wl,--stack,16777216)
endif()
endif()
include(GoogleTest)
gtest_discover_tests(${suite_name})
# Get the list of tests discovered for the target and apply the label.
get_target_property(suite_tests ${suite_name} TESTS)
if(suite_tests)
set_tests_properties(${suite_tests} PROPERTIES LABELS "${label}")
endif()
endfunction()
# --- Stable Test Suite (Valid Contracts) ---
set(STABLE_TEST_SOURCES
test_editor.cc
test_editor.h
testing.h
test_utils.h
test_utils.cc
# Unit Tests
unit/core/asar_wrapper_test.cc
unit/core/hex_test.cc
@@ -38,165 +71,68 @@ if(YAZE_BUILD_TESTS AND NOT YAZE_BUILD_TESTS STREQUAL "OFF")
unit/zelda3/dungeon_component_unit_test.cc
unit/zelda3/dungeon/room_object_encoding_test.cc
unit/zelda3/dungeon/room_manipulation_test.cc
# dungeon_object_renderer_mock_test.cc - REMOVED (ObjectRenderer obsolete)
# CLI Services (for catalog serialization tests)
../src/cli/service/resources/resource_catalog.cc
cli/service/resources/command_context_test.cc
# Integration Tests
integration/asar_integration_test.cc
integration/asar_rom_test.cc
integration/dungeon_editor_test.cc
integration/dungeon_editor_test.h
integration/dungeon_editor_v2_test.cc
integration/dungeon_editor_v2_test.h
integration/editor/tile16_editor_test.cc
integration/editor/editor_integration_test.cc
integration/editor/editor_integration_test.h
integration/ai/ai_gui_controller_test.cc
integration/ai/test_ai_tile_placement.cc
integration/ai/test_gemini_vision.cc
# E2E Tests
e2e/rom_dependent/e2e_rom_test.cc
e2e/zscustomoverworld/zscustomoverworld_upgrade_test.cc
# Integration Tests (Zelda3)
integration/zelda3/overworld_integration_test.cc
integration/zelda3/dungeon_editor_system_integration_test.cc
# dungeon_object_renderer_integration_test.cc - REMOVED (ObjectRenderer obsolete)
integration/zelda3/room_integration_test.cc
integration/zelda3/dungeon_object_rendering_tests.cc
integration/zelda3/dungeon_room_test.cc
integration/zelda3/sprite_position_test.cc
integration/zelda3/message_test.cc
)
yaze_add_test_suite(yaze_test_stable "stable" OFF ${STABLE_TEST_SOURCES})
# Sources only for full development builds
set(YAZE_TEST_DEV_SOURCES
test_utils.cc
# E2E Tests (included in development builds)
e2e/canvas_selection_test.cc
e2e/framework_smoke_test.cc
e2e/dungeon_editor_smoke_test.cc
# Benchmarks
# --- ROM Dependent Test Suite ---
if(YAZE_ENABLE_ROM_TESTS)
set(ROM_DEPENDENT_TEST_SOURCES
integration/asar_rom_test.cc
e2e/rom_dependent/e2e_rom_test.cc
e2e/zscustomoverworld/zscustomoverworld_upgrade_test.cc
)
yaze_add_test_suite(yaze_test_rom_dependent "rom_dependent" OFF ${ROM_DEPENDENT_TEST_SOURCES})
target_compile_definitions(yaze_test_rom_dependent PRIVATE
YAZE_ENABLE_ROM_TESTS=1
YAZE_TEST_ROM_PATH="${YAZE_TEST_ROM_PATH}"
)
endif()
# --- Experimental & GUI Test Suites ---
if(YAZE_ENABLE_UI_TESTS)
set(GUI_TEST_SOURCES
test_utils.cc
e2e/framework_smoke_test.cc
e2e/dungeon_editor_smoke_test.cc
e2e/canvas_selection_test.cc
integration/ai/ai_gui_controller_test.cc
)
yaze_add_test_suite(yaze_test_gui "gui;experimental" ON ${GUI_TEST_SOURCES})
# Add a single test entry to run the entire GUI suite headlessly
add_test(
NAME headless_gui_suite
COMMAND $<TARGET_FILE:yaze_test_gui> -nogui
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
set_tests_properties(headless_gui_suite PROPERTIES LABELS "headless_gui;experimental")
endif()
set(EXPERIMENTAL_TEST_SOURCES
integration/ai/test_ai_tile_placement.cc
integration/ai/test_gemini_vision.cc
)
yaze_add_test_suite(yaze_test_experimental "experimental" OFF ${EXPERIMENTAL_TEST_SOURCES})
# --- Benchmark Test Suite ---
set(BENCHMARK_TEST_SOURCES
benchmarks/gfx_optimization_benchmarks.cc
)
yaze_add_test_suite(yaze_test_benchmark "benchmark" OFF ${BENCHMARK_TEST_SOURCES})
if(YAZE_MINIMAL_BUILD)
# CI/Minimal build: use simplified test executable and base sources
add_executable(
yaze_test
yaze_test_ci.cc
${YAZE_TEST_BASE_SOURCES}
)
else()
# Development build: use full-featured test executable and all sources
add_executable(
yaze_test
yaze_test.cc
${YAZE_TEST_BASE_SOURCES}
${YAZE_TEST_DEV_SOURCES}
)
endif()
# Configure test executable only when tests are enabled
target_include_directories(
yaze_test PUBLIC
${CMAKE_SOURCE_DIR}/src/app/
${CMAKE_SOURCE_DIR}/src/lib/
${CMAKE_SOURCE_DIR}/incl/
${CMAKE_SOURCE_DIR}/src/
${CMAKE_SOURCE_DIR}/test/
${CMAKE_SOURCE_DIR}/src/lib/imgui_test_engine
${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
${SDL2_INCLUDE_DIR}
${PNG_INCLUDE_DIRS}
${PROJECT_BINARY_DIR}
)
target_link_libraries(
yaze_test
${SDL_TARGETS}
asar-static
${ABSL_TARGETS}
${PNG_LIBRARIES}
${OPENGL_LIBRARIES}
${CMAKE_DL_LIBS}
gmock_main
gmock
gtest_main
gtest
)
# Link core library for essential functionality (BPS, ASAR, etc.)
if(YAZE_BUILD_LIB)
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 TARGET yaze_emulator)
target_link_libraries(yaze_test yaze_emulator)
endif()
else()
target_link_libraries(yaze_test yaze_core)
endif()
endif()
if(TARGET yaze_test_support)
target_link_libraries(yaze_test yaze_test_support)
endif()
# Conditionally link ImGuiTestEngine only when UI tests are enabled
if(YAZE_ENABLE_UI_TESTS)
target_link_libraries(yaze_test ${IMGUI_TEST_ENGINE_TARGET})
target_compile_definitions(yaze_test PRIVATE ${IMGUI_TEST_ENGINE_DEFINITIONS})
endif()
# ROM Testing Configuration
if(YAZE_ENABLE_ROM_TESTS)
target_compile_definitions(yaze_test PRIVATE
YAZE_ENABLE_ROM_TESTS=1
YAZE_TEST_ROM_PATH="${YAZE_TEST_ROM_PATH}"
)
endif()
# Platform-specific definitions
if(UNIX AND NOT APPLE)
target_compile_definitions(yaze_test PRIVATE "linux" "stricmp=strcasecmp")
elseif(APPLE)
target_compile_definitions(yaze_test PRIVATE "MACOS" "stricmp=strcasecmp")
elseif(WIN32)
target_compile_definitions(yaze_test PRIVATE "WINDOWS")
# Increase stack size on Windows to prevent stack overflow during tests
# Use 16MB stack to handle deep call stacks in tests and test discovery
message(STATUS "Configuring Windows stack size for yaze_test to 16MB")
if(MSVC)
target_link_options(yaze_test PRIVATE /STACK:16777216) # 16MB stack
message(STATUS " Using MSVC linker flag: /STACK:16777216")
elseif(MINGW OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_options(yaze_test PRIVATE -Wl,--stack,16777216) # 16MB stack
message(STATUS " Using MinGW/GNU linker flag: -Wl,--stack,16777216")
else()
# Fallback for other compilers
target_link_options(yaze_test PRIVATE -Wl,--stack,16777216)
message(STATUS " Using fallback linker flag: -Wl,--stack,16777216")
endif()
endif()
endif()
include(test.cmake)
endif()

View File

@@ -6,7 +6,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "app/rom.h"
#include "cli/handlers/mock_rom.h"
#include "mocks/mock_rom.h"
namespace yaze {
namespace cli {
@@ -16,11 +16,12 @@ class CommandContextTest : public ::testing::Test {
protected:
void SetUp() override {
// Initialize mock ROM for testing
auto status = InitializeMockRom(mock_rom_);
ASSERT_OK(status);
std::vector<uint8_t> test_data(1024, 0); // 1KB of empty data
auto status = mock_rom_.SetTestData(test_data);
ASSERT_TRUE(status.ok());
}
Rom mock_rom_;
yaze::test::MockRom mock_rom_;
};
TEST_F(CommandContextTest, LoadsRomFromConfig) {
@@ -30,7 +31,7 @@ TEST_F(CommandContextTest, LoadsRomFromConfig) {
CommandContext context(config);
auto rom_or = context.GetRom();
ASSERT_OK(rom_or);
ASSERT_TRUE(rom_or.ok());
EXPECT_TRUE(rom_or.value()->is_loaded());
}
@@ -41,7 +42,7 @@ TEST_F(CommandContextTest, UsesExternalRomContext) {
CommandContext context(config);
auto rom_or = context.GetRom();
ASSERT_OK(rom_or);
ASSERT_TRUE(rom_or.ok());
EXPECT_EQ(rom_or.value(), &mock_rom_);
}
@@ -64,10 +65,10 @@ TEST_F(CommandContextTest, EnsuresLabelsLoaded) {
CommandContext context(config);
auto rom_or = context.GetRom();
ASSERT_OK(rom_or);
ASSERT_TRUE(rom_or.ok());
auto status = context.EnsureLabelsLoaded(rom_or.value());
EXPECT_OK(status);
EXPECT_TRUE(status.ok());
}
TEST_F(CommandContextTest, GetFormatReturnsConfigFormat) {
@@ -107,11 +108,11 @@ TEST_F(ArgumentParserTest, ParsesIntArguments) {
ArgumentParser parser(args);
auto room_or = parser.GetInt("room");
ASSERT_OK(room_or);
ASSERT_TRUE(room_or.ok());
EXPECT_EQ(room_or.value(), 0x12);
auto count_or = parser.GetInt("count");
ASSERT_OK(count_or);
ASSERT_TRUE(count_or.ok());
EXPECT_EQ(count_or.value(), 42);
}
@@ -120,11 +121,11 @@ TEST_F(ArgumentParserTest, ParsesHexArguments) {
ArgumentParser parser(args);
auto addr_or = parser.GetHex("address");
ASSERT_OK(addr_or);
ASSERT_TRUE(addr_or.ok());
EXPECT_EQ(addr_or.value(), 0x1234);
auto value_or = parser.GetHex("value");
ASSERT_OK(value_or);
ASSERT_TRUE(value_or.ok());
EXPECT_EQ(value_or.value(), 0xFF);
}
@@ -150,7 +151,7 @@ TEST_F(ArgumentParserTest, ValidatesRequiredArguments) {
ArgumentParser parser(args);
auto status = parser.RequireArgs({"type"});
EXPECT_OK(status);
EXPECT_TRUE(status.ok());
status = parser.RequireArgs({"type", "missing"});
EXPECT_FALSE(status.ok());
@@ -175,11 +176,11 @@ class OutputFormatterTest : public ::testing::Test {
TEST_F(OutputFormatterTest, CreatesFromString) {
auto json_formatter = OutputFormatter::FromString("json");
ASSERT_OK(json_formatter);
ASSERT_TRUE(json_formatter.ok());
EXPECT_TRUE(json_formatter.value().IsJson());
auto text_formatter = OutputFormatter::FromString("text");
ASSERT_OK(text_formatter);
ASSERT_TRUE(text_formatter.ok());
EXPECT_TRUE(text_formatter.value().IsText());
auto invalid_formatter = OutputFormatter::FromString("invalid");
@@ -188,7 +189,7 @@ TEST_F(OutputFormatterTest, CreatesFromString) {
TEST_F(OutputFormatterTest, GeneratesValidJson) {
auto formatter_or = OutputFormatter::FromString("json");
ASSERT_OK(formatter_or);
ASSERT_TRUE(formatter_or.ok());
auto formatter = std::move(formatter_or.value());
formatter.BeginObject("Test");
@@ -217,7 +218,7 @@ TEST_F(OutputFormatterTest, GeneratesValidJson) {
TEST_F(OutputFormatterTest, GeneratesValidText) {
auto formatter_or = OutputFormatter::FromString("text");
ASSERT_OK(formatter_or);
ASSERT_TRUE(formatter_or.ok());
auto formatter = std::move(formatter_or.value());
formatter.BeginObject("Test Object");
@@ -247,7 +248,7 @@ TEST_F(OutputFormatterTest, GeneratesValidText) {
TEST_F(OutputFormatterTest, EscapesJsonStrings) {
auto formatter_or = OutputFormatter::FromString("json");
ASSERT_OK(formatter_or);
ASSERT_TRUE(formatter_or.ok());
auto formatter = std::move(formatter_or.value());
formatter.BeginObject("Test");
@@ -265,7 +266,7 @@ TEST_F(OutputFormatterTest, EscapesJsonStrings) {
TEST_F(OutputFormatterTest, HandlesEmptyObjects) {
auto formatter_or = OutputFormatter::FromString("json");
ASSERT_OK(formatter_or);
ASSERT_TRUE(formatter_or.ok());
auto formatter = std::move(formatter_or.value());
formatter.BeginObject("Empty");
@@ -277,7 +278,7 @@ TEST_F(OutputFormatterTest, HandlesEmptyObjects) {
TEST_F(OutputFormatterTest, HandlesEmptyArrays) {
auto formatter_or = OutputFormatter::FromString("json");
ASSERT_OK(formatter_or);
ASSERT_TRUE(formatter_or.ok());
auto formatter = std::move(formatter_or.value());
formatter.BeginObject("Test");

View File

@@ -18,9 +18,12 @@
#include "app/core/window.h"
#include "app/core/controller.h"
#include "app/gfx/backend/sdl2_renderer.h"
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
#include "e2e/canvas_selection_test.h"
#include "e2e/framework_smoke_test.h"
#include "e2e/dungeon_editor_smoke_test.h"
#endif
// #include "test_editor.h" // Not used in main
@@ -306,6 +309,7 @@ int main(int argc, char* argv[]) {
yaze::core::Controller controller;
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
// Register smoke test
ImGuiTest* smoke_test = IM_REGISTER_TEST(engine, "E2ETest", "FrameworkSmokeTest");
smoke_test->TestFunc = E2ETest_FrameworkSmokeTest;
@@ -319,6 +323,7 @@ int main(int argc, char* argv[]) {
ImGuiTest* dungeon_test = IM_REGISTER_TEST(engine, "E2ETest", "DungeonEditorSmokeTest");
dungeon_test->TestFunc = E2ETest_DungeonEditorV2SmokeTest;
dungeon_test->UserData = &controller;
#endif
// Main loop
bool done = false;