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:
118
cmake/dependencies.cmake
Normal file
118
cmake/dependencies.cmake
Normal file
@@ -0,0 +1,118 @@
|
||||
# This file centralizes the management of all third-party dependencies.
|
||||
# It provides functions to find or fetch dependencies and creates alias targets
|
||||
# for consistent usage throughout the project.
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
# ============================================================================
|
||||
# Helper function to add a dependency
|
||||
# ============================================================================
|
||||
function(yaze_add_dependency name)
|
||||
set(options)
|
||||
set(oneValueArgs GIT_REPOSITORY GIT_TAG URL)
|
||||
set(multiValueArgs)
|
||||
cmake_parse_arguments(DEP "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(TARGET yaze::${name})
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Try to find the package via find_package first
|
||||
find_package(${name} QUIET)
|
||||
|
||||
if(${name}_FOUND)
|
||||
message(STATUS "Found ${name} via find_package")
|
||||
if(TARGET ${name}::${name})
|
||||
add_library(yaze::${name} ALIAS ${name}::${name})
|
||||
else()
|
||||
# Handle cases where find_package doesn't create an imported target
|
||||
# This is a simplified approach; more logic may be needed for specific packages
|
||||
add_library(yaze::${name} INTERFACE IMPORTED)
|
||||
target_include_directories(yaze::${name} INTERFACE ${${name}_INCLUDE_DIRS})
|
||||
target_link_libraries(yaze::${name} INTERFACE ${${name}_LIBRARIES})
|
||||
endif()
|
||||
return()
|
||||
endif()
|
||||
|
||||
# If not found, use FetchContent
|
||||
message(STATUS "Could not find ${name}, fetching from source.")
|
||||
FetchContent_Declare(
|
||||
${name}
|
||||
GIT_REPOSITORY ${DEP_GIT_REPOSITORY}
|
||||
GIT_TAG ${DEP_GIT_TAG}
|
||||
)
|
||||
|
||||
FetchContent_GetProperties(${name})
|
||||
if(NOT ${name}_POPULATED)
|
||||
FetchContent_Populate(${name})
|
||||
add_subdirectory(${${name}_SOURCE_DIR} ${${name}_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
if(TARGET ${name})
|
||||
add_library(yaze::${name} ALIAS ${name})
|
||||
elseif(TARGET ${name}::${name})
|
||||
add_library(yaze::${name} ALIAS ${name}::${name})
|
||||
else()
|
||||
message(FATAL_ERROR "Failed to create target for ${name}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# ============================================================================
|
||||
# Dependency Declarations
|
||||
# ============================================================================
|
||||
|
||||
# gRPC (must come before Abseil - provides its own compatible Abseil)
|
||||
if(YAZE_WITH_GRPC)
|
||||
include(cmake/grpc.cmake)
|
||||
endif()
|
||||
|
||||
# Abseil (only if gRPC didn't provide it)
|
||||
if(NOT YAZE_WITH_GRPC)
|
||||
include(cmake/absl.cmake)
|
||||
endif()
|
||||
|
||||
# SDL2
|
||||
include(cmake/sdl2.cmake)
|
||||
|
||||
# Asar
|
||||
include(cmake/asar.cmake)
|
||||
|
||||
# Google Test
|
||||
if(YAZE_BUILD_TESTS)
|
||||
include(cmake/gtest.cmake)
|
||||
endif()
|
||||
|
||||
# ImGui
|
||||
include(cmake/imgui.cmake)
|
||||
|
||||
# FTXUI (for z3ed)
|
||||
if(YAZE_BUILD_Z3ED)
|
||||
FetchContent_Declare(ftxui
|
||||
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
|
||||
GIT_TAG v5.0.0
|
||||
)
|
||||
FetchContent_MakeAvailable(ftxui)
|
||||
endif()
|
||||
|
||||
# yaml-cpp (always available for configuration files)
|
||||
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)
|
||||
|
||||
FetchContent_Declare(yaml-cpp
|
||||
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
|
||||
GIT_TAG 0.8.0
|
||||
)
|
||||
FetchContent_MakeAvailable(yaml-cpp)
|
||||
|
||||
# nlohmann_json (header only)
|
||||
if(YAZE_WITH_JSON)
|
||||
set(JSON_BuildTests OFF CACHE INTERNAL "Disable nlohmann_json tests")
|
||||
add_subdirectory(${CMAKE_SOURCE_DIR}/third_party/json ${CMAKE_BINARY_DIR}/third_party/json EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
# httplib (header only)
|
||||
# No action needed here as it's included directly.
|
||||
|
||||
@@ -98,15 +98,22 @@ set(ABSL_PROPAGATE_CXX_STD ON CACHE BOOL "" FORCE)
|
||||
set(ABSL_ENABLE_INSTALL ON CACHE BOOL "" FORCE)
|
||||
set(ABSL_BUILD_TESTING OFF CACHE BOOL "" FORCE)
|
||||
|
||||
# Declare gRPC - use v1.67.1 which fixes MSVC template issues and is compatible with modern compilers
|
||||
# v1.67.1 includes:
|
||||
# - MSVC/Visual Studio compatibility fixes (template instantiation errors)
|
||||
# Disable x86-specific optimizations for ARM64 macOS builds
|
||||
if(APPLE AND CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
|
||||
set(ABSL_USE_EXTERNAL_GOOGLETEST OFF CACHE BOOL "" FORCE)
|
||||
set(ABSL_BUILD_TEST_HELPERS OFF CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
|
||||
# Declare gRPC - use v1.75.1 which includes ARM64 macOS fixes and is compatible with modern compilers
|
||||
# v1.75.1 includes:
|
||||
# - ARM64 macOS compilation fixes (Abseil randen_hwaes)
|
||||
# - MSVC/Visual Studio compatibility fixes
|
||||
# - Clang 18+ compatibility
|
||||
# - Abseil compatibility updates
|
||||
# - Updated Abseil and Protobuf dependencies
|
||||
FetchContent_Declare(
|
||||
grpc
|
||||
GIT_REPOSITORY https://github.com/grpc/grpc.git
|
||||
GIT_TAG v1.67.1
|
||||
GIT_TAG v1.75.1
|
||||
GIT_PROGRESS TRUE
|
||||
GIT_SHALLOW TRUE
|
||||
USES_TERMINAL_DOWNLOAD TRUE
|
||||
@@ -142,7 +149,76 @@ file(MAKE_DIRECTORY ${_gRPC_PROTO_GENS_DIR})
|
||||
get_target_property(_PROTOBUF_INCLUDE_DIRS libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
|
||||
list(GET _PROTOBUF_INCLUDE_DIRS 0 _gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR)
|
||||
|
||||
message(STATUS "gRPC setup complete")
|
||||
# Export Abseil targets from gRPC's bundled abseil for use by the rest of the project
|
||||
# This ensures version compatibility between gRPC and our project
|
||||
set(
|
||||
ABSL_TARGETS
|
||||
absl::strings
|
||||
absl::str_format
|
||||
absl::flags
|
||||
absl::flags_parse
|
||||
absl::flags_usage
|
||||
absl::flags_commandlineflag
|
||||
absl::flags_marshalling
|
||||
absl::flags_private_handle_accessor
|
||||
absl::flags_program_name
|
||||
absl::flags_config
|
||||
absl::flags_reflection
|
||||
absl::status
|
||||
absl::statusor
|
||||
absl::examine_stack
|
||||
absl::stacktrace
|
||||
absl::base
|
||||
absl::config
|
||||
absl::core_headers
|
||||
absl::failure_signal_handler
|
||||
absl::flat_hash_map
|
||||
absl::cord
|
||||
absl::hash
|
||||
absl::synchronization
|
||||
absl::time
|
||||
absl::symbolize
|
||||
absl::container_memory
|
||||
absl::memory
|
||||
absl::utility
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
# Only expose absl::int128 when it's supported without warnings
|
||||
if(NOT WIN32)
|
||||
list(APPEND ABSL_TARGETS absl::int128)
|
||||
set(ABSL_TARGETS ${ABSL_TARGETS} PARENT_SCOPE)
|
||||
endif()
|
||||
|
||||
# Fix Abseil ARM64 macOS compile flags (remove x86-specific flags)
|
||||
if(APPLE AND DEFINED CMAKE_OSX_ARCHITECTURES AND CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
|
||||
foreach(_absl_target IN ITEMS absl_random_internal_randen_hwaes absl_random_internal_randen_hwaes_impl)
|
||||
if(TARGET ${_absl_target})
|
||||
get_target_property(_absl_opts ${_absl_target} COMPILE_OPTIONS)
|
||||
if(_absl_opts AND NOT _absl_opts STREQUAL "NOTFOUND")
|
||||
set(_absl_filtered_opts)
|
||||
set(_absl_skip_next FALSE)
|
||||
foreach(_absl_opt IN LISTS _absl_opts)
|
||||
if(_absl_skip_next)
|
||||
set(_absl_skip_next FALSE)
|
||||
continue()
|
||||
endif()
|
||||
if(_absl_opt STREQUAL "-Xarch_x86_64")
|
||||
set(_absl_skip_next TRUE)
|
||||
continue()
|
||||
endif()
|
||||
if(_absl_opt STREQUAL "-maes" OR _absl_opt STREQUAL "-msse4.1")
|
||||
continue()
|
||||
endif()
|
||||
list(APPEND _absl_filtered_opts ${_absl_opt})
|
||||
endforeach()
|
||||
set_property(TARGET ${_absl_target} PROPERTY COMPILE_OPTIONS ${_absl_filtered_opts})
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
message(STATUS "gRPC setup complete (includes bundled Abseil)")
|
||||
|
||||
function(target_add_protobuf target)
|
||||
if(NOT TARGET ${target})
|
||||
|
||||
70
cmake/utils.cmake
Normal file
70
cmake/utils.cmake
Normal file
@@ -0,0 +1,70 @@
|
||||
# This file contains utility functions for the yaze build system.
|
||||
|
||||
# ============================================================================
|
||||
# yaze_add_compiler_flags
|
||||
#
|
||||
# Sets standard compiler flags for C++ and C.
|
||||
# Also handles platform-specific and compiler-specific flags.
|
||||
# ============================================================================
|
||||
function(yaze_add_compiler_flags)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
if(YAZE_SUPPRESS_WARNINGS)
|
||||
if(MSVC)
|
||||
add_compile_options(/w)
|
||||
else()
|
||||
add_compile_options(-w)
|
||||
endif()
|
||||
message(STATUS "✓ Warnings suppressed (use -v preset suffix for verbose builds)")
|
||||
else()
|
||||
message(STATUS "○ Verbose warnings enabled")
|
||||
endif()
|
||||
|
||||
# Common interface target for shared settings
|
||||
add_library(yaze_common INTERFACE)
|
||||
target_compile_features(yaze_common INTERFACE cxx_std_23)
|
||||
|
||||
# Platform-specific definitions
|
||||
if(YAZE_PLATFORM_LINUX)
|
||||
target_compile_definitions(yaze_common INTERFACE linux stricmp=strcasecmp)
|
||||
elseif(YAZE_PLATFORM_MACOS)
|
||||
target_compile_definitions(yaze_common INTERFACE MACOS)
|
||||
elseif(YAZE_PLATFORM_WINDOWS)
|
||||
target_compile_definitions(yaze_common INTERFACE WINDOWS)
|
||||
endif()
|
||||
|
||||
# Compiler-specific settings
|
||||
if(MSVC)
|
||||
target_compile_options(yaze_common INTERFACE
|
||||
/EHsc
|
||||
/W4 /permissive-
|
||||
/bigobj
|
||||
/utf-8
|
||||
)
|
||||
target_compile_definitions(yaze_common INTERFACE
|
||||
_CRT_SECURE_NO_WARNINGS
|
||||
_CRT_NONSTDC_NO_WARNINGS
|
||||
SILENCE_CXX23_DEPRECATIONS
|
||||
_SILENCE_CXX23_DEPRECATION_WARNING
|
||||
_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS
|
||||
NOMINMAX
|
||||
WIN32_LEAN_AND_MEAN
|
||||
strncasecmp=_strnicmp
|
||||
strcasecmp=_stricmp
|
||||
)
|
||||
else()
|
||||
target_compile_options(yaze_common INTERFACE
|
||||
-Wall -Wextra -Wpedantic
|
||||
-Wno-deprecated-declarations
|
||||
-Wno-c++23-compat
|
||||
)
|
||||
target_compile_definitions(yaze_common INTERFACE
|
||||
_SILENCE_CXX23_DEPRECATION_WARNING
|
||||
_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
Reference in New Issue
Block a user