Files
yaze/CMakeLists.txt
scawful f54949bdd8 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.
2025-10-11 02:44:17 -04:00

145 lines
4.4 KiB
CMake

# Yet Another Zelda3 Editor
# by scawful
cmake_minimum_required(VERSION 3.16)
# Set policies for compatibility
cmake_policy(SET CMP0091 NEW)
cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0077 NEW)
project(yaze VERSION 0.3.2
DESCRIPTION "Yet Another Zelda3 Editor"
LANGUAGES CXX C OBJC OBJCXX)
# Enable ccache for faster rebuilds if available
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
message(STATUS "✓ ccache found, enabling for faster builds")
set(CMAKE_CXX_COMPILER_LAUNCHER ccache)
set(CMAKE_C_COMPILER_LAUNCHER ccache)
endif()
# Set project metadata
set(YAZE_VERSION_MAJOR 0)
set(YAZE_VERSION_MINOR 3)
set(YAZE_VERSION_PATCH 2)
# Suppress deprecation warnings from submodules
set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "Suppress deprecation warnings")
# Add cmake directory to module path
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# Include utility functions
include(cmake/utils.cmake)
# Build Flags
set(YAZE_BUILD_APP ON)
set(YAZE_BUILD_LIB ON)
set(YAZE_BUILD_EMU ON)
set(YAZE_BUILD_Z3ED ON)
set(YAZE_BUILD_TESTS ON CACHE BOOL "Build test suite")
set(YAZE_INSTALL_LIB OFF)
# Testing and CI Configuration
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" ON)
option(YAZE_UNITY_BUILD "Enable Unity (Jumbo) builds" OFF)
# Feature Flags
if(YAZE_MINIMAL_BUILD)
# Minimal build for CI: disable features that are slow to build or not essential
set(Z3ED_AI OFF)
set(YAZE_WITH_JSON ON) # JSON is header-only, low impact
set(YAZE_WITH_GRPC OFF)
set(YAZE_ENABLE_UI_TESTS OFF)
message(STATUS "✓ Minimal build enabled for CI")
else()
# Full build for development/release
set(Z3ED_AI ON)
set(YAZE_WITH_JSON ON)
set(YAZE_WITH_GRPC ON)
message(STATUS "✓ All features enabled: JSON, gRPC, AI Agent")
endif()
option(YAZE_SUPPRESS_WARNINGS "Suppress compiler warnings (use -v preset suffix for verbose)" ON)
set(YAZE_TEST_ROM_PATH "${CMAKE_BINARY_DIR}/bin/zelda3.sfc" CACHE STRING "Path to test ROM file")
# Platform detection
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(YAZE_PLATFORM_MACOS ON)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(YAZE_PLATFORM_LINUX ON)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(YAZE_PLATFORM_WINDOWS ON)
endif()
# Setup compiler flags and common interface target
yaze_add_compiler_flags()
# Configure yaze_config.h
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/yaze_config.h.in
${CMAKE_CURRENT_BINARY_DIR}/yaze_config.h
@ONLY
)
# Output directories
include(GNUInstallDirs)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(BUILD_SHARED_LIBS OFF)
# Handle dependencies
include(cmake/dependencies.cmake)
# Project Files
add_subdirectory(src)
# Tools
option(YAZE_BUILD_TOOLS "Build development utility tools" OFF)
if(YAZE_BUILD_TOOLS)
message(STATUS "Building development tools")
add_subdirectory(tools)
endif()
# Tests
if(YAZE_BUILD_TESTS)
add_subdirectory(test)
endif()
# Code quality targets
find_program(CLANG_FORMAT NAMES clang-format clang-format-14 clang-format-15 clang-format-16 clang-format-17 clang-format-18)
if(CLANG_FORMAT)
file(GLOB_RECURSE ALL_SOURCE_FILES
"${CMAKE_SOURCE_DIR}/src/*.cc"
"${CMAKE_SOURCE_DIR}/src/*.h"
"${CMAKE_SOURCE_DIR}/test/*.cc"
"${CMAKE_SOURCE_DIR}/test/*.h")
add_custom_target(format
COMMAND ${CLANG_FORMAT} -i --style=Google ${ALL_SOURCE_FILES}
COMMENT "Running clang-format on source files"
)
add_custom_target(format-check
COMMAND ${CLANG_FORMAT} --dry-run --Werror --style=Google ${ALL_SOURCE_FILES}
COMMENT "Checking code format"
)
endif()
# Packaging configuration
include(cmake/packaging.cmake)
add_custom_target(build_cleaner
COMMAND ${CMAKE_COMMAND} -E echo "Running scripts/build_cleaner.py --dry-run"
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${Python3_EXECUTABLE} scripts/build_cleaner.py --dry-run
COMMENT "Validate CMake source lists and includes"
)