chore: Enhance CMake and CI configurations for improved vcpkg integration
- Updated CMakeLists.txt to provide clearer logging and error messages for vcpkg integration, including detailed status reports for toolchain and triplet settings. - Modified CI workflows to utilize manifest mode for vcpkg installations, improving dependency management and build reliability. - Enhanced SDL2 and gRPC configurations to prioritize vcpkg packages, ensuring faster builds and clearer fallback mechanisms. - Improved overall CMake structure for better readability and maintainability, including updated messages for build configurations and warnings.
This commit is contained in:
@@ -6,12 +6,18 @@ set(YAZE_ABSL_GIT_TAG "20240116.2" CACHE STRING "Abseil release tag used when fe
|
||||
# missing the required components (e.g. macOS).
|
||||
set(_yaze_use_fetched_absl ${YAZE_FORCE_BUNDLED_ABSL})
|
||||
if(NOT _yaze_use_fetched_absl)
|
||||
find_package(absl QUIET CONFIG)
|
||||
# Try to find via vcpkg first on Windows
|
||||
if(WIN32 AND DEFINED CMAKE_TOOLCHAIN_FILE)
|
||||
find_package(absl CONFIG QUIET)
|
||||
else()
|
||||
find_package(absl QUIET CONFIG)
|
||||
endif()
|
||||
|
||||
if(absl_FOUND)
|
||||
message(STATUS "Using system-provided Abseil package")
|
||||
message(STATUS "✓ Using system/vcpkg Abseil package")
|
||||
else()
|
||||
set(_yaze_use_fetched_absl TRUE)
|
||||
message(STATUS "System Abseil not found. Fetching release ${YAZE_ABSL_GIT_TAG}.")
|
||||
message(STATUS "○ System Abseil not found. Will fetch release ${YAZE_ABSL_GIT_TAG}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ option(YAZE_USE_VCPKG_GRPC "Use vcpkg pre-compiled gRPC packages (Windows only)"
|
||||
|
||||
if(WIN32 AND YAZE_USE_VCPKG_GRPC)
|
||||
message(STATUS "Attempting to use vcpkg gRPC packages for faster Windows builds...")
|
||||
message(STATUS " Note: This is only for full builds with YAZE_WITH_GRPC=ON")
|
||||
|
||||
# Try to find gRPC via vcpkg
|
||||
find_package(gRPC CONFIG QUIET)
|
||||
@@ -26,7 +27,9 @@ if(WIN32 AND YAZE_USE_VCPKG_GRPC)
|
||||
|
||||
# Verify required targets exist
|
||||
if(NOT TARGET grpc++)
|
||||
message(FATAL_ERROR "gRPC found but grpc++ target missing")
|
||||
message(WARNING "gRPC found but grpc++ target missing - falling back to FetchContent")
|
||||
set(YAZE_GRPC_CONFIGURED FALSE PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT TARGET protoc)
|
||||
|
||||
@@ -1,16 +1,31 @@
|
||||
# SDL2
|
||||
# On Windows, try to use vcpkg first, then fall back to bundled SDL
|
||||
# On Windows with vcpkg, prefer vcpkg packages for faster builds
|
||||
if(WIN32)
|
||||
# Try to find SDL2 via vcpkg first
|
||||
find_package(SDL2 QUIET)
|
||||
if(SDL2_FOUND)
|
||||
# Use vcpkg SDL2
|
||||
set(SDL_TARGETS SDL2::SDL2)
|
||||
list(PREPEND SDL_TARGETS SDL2::SDL2main ws2_32)
|
||||
add_definitions("-DSDL_MAIN_HANDLED")
|
||||
message(STATUS "Using vcpkg SDL2")
|
||||
else()
|
||||
# Fall back to bundled SDL
|
||||
# Try to find SDL2 via vcpkg first if toolchain is available
|
||||
if(DEFINED CMAKE_TOOLCHAIN_FILE AND EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
||||
find_package(SDL2 CONFIG QUIET)
|
||||
if(SDL2_FOUND OR TARGET SDL2::SDL2)
|
||||
# Use vcpkg SDL2
|
||||
if(TARGET SDL2::SDL2)
|
||||
set(SDL_TARGETS SDL2::SDL2)
|
||||
if(TARGET SDL2::SDL2main)
|
||||
list(PREPEND SDL_TARGETS SDL2::SDL2main)
|
||||
endif()
|
||||
list(APPEND SDL_TARGETS ws2_32)
|
||||
add_definitions("-DSDL_MAIN_HANDLED")
|
||||
message(STATUS "✓ Using vcpkg SDL2")
|
||||
|
||||
# Get SDL2 include directories for reference
|
||||
get_target_property(SDL2_INCLUDE_DIR SDL2::SDL2 INTERFACE_INCLUDE_DIRECTORIES)
|
||||
set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Fall back to bundled SDL if vcpkg not available or SDL2 not found
|
||||
if(EXISTS "${CMAKE_SOURCE_DIR}/src/lib/SDL/CMakeLists.txt")
|
||||
message(STATUS "○ vcpkg SDL2 not found, using bundled SDL2")
|
||||
add_subdirectory(src/lib/SDL)
|
||||
set(SDL_TARGETS SDL2-static)
|
||||
set(SDL2_INCLUDE_DIR
|
||||
@@ -19,9 +34,13 @@ if(WIN32)
|
||||
${CMAKE_BINARY_DIR}/src/lib/SDL/include-config-${CMAKE_BUILD_TYPE}
|
||||
)
|
||||
set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
|
||||
list(PREPEND SDL_TARGETS SDL2main ws2_32)
|
||||
if(TARGET SDL2main)
|
||||
list(PREPEND SDL_TARGETS SDL2main)
|
||||
endif()
|
||||
list(APPEND SDL_TARGETS ws2_32)
|
||||
add_definitions("-DSDL_MAIN_HANDLED")
|
||||
message(STATUS "Using bundled SDL2")
|
||||
else()
|
||||
message(FATAL_ERROR "SDL2 not found via vcpkg and bundled SDL2 not available. Please install via vcpkg or ensure submodules are initialized.")
|
||||
endif()
|
||||
elseif(UNIX OR MINGW)
|
||||
# Non-Windows: use bundled SDL
|
||||
@@ -36,7 +55,7 @@ elseif(UNIX OR MINGW)
|
||||
message(STATUS "Using bundled SDL2")
|
||||
else()
|
||||
# Fallback: try to find system SDL
|
||||
find_package(SDL2)
|
||||
find_package(SDL2 REQUIRED)
|
||||
set(SDL_TARGETS SDL2::SDL2)
|
||||
message(STATUS "Using system SDL2")
|
||||
endif()
|
||||
|
||||
@@ -1,40 +1,54 @@
|
||||
# vcpkg configuration reporting for Windows builds
|
||||
# This file is included AFTER vcpkg toolchain has run, so we can only report and validate
|
||||
#
|
||||
# IMPORTANT: vcpkg configuration variables (VCPKG_TARGET_TRIPLET, etc.) must be set:
|
||||
# 1. On the CMake command line: -DVCPKG_TARGET_TRIPLET=x64-windows-static
|
||||
# 2. Via environment variables: set VCPKG_DEFAULT_TRIPLET=x64-windows-static
|
||||
# 3. In vcpkg-configuration.json in the project root
|
||||
|
||||
# vcpkg configuration for Windows builds
|
||||
# Windows-specific macro definitions to avoid conflicts
|
||||
add_definitions("-DMICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS=0")
|
||||
|
||||
# vcpkg settings
|
||||
set(VCPKG_CRT_LINKAGE dynamic)
|
||||
set(VCPKG_LIBRARY_LINKAGE dynamic)
|
||||
# Determine what triplet is being used (for reporting)
|
||||
set(_vcpkg_triplet "unknown")
|
||||
if(DEFINED VCPKG_TARGET_TRIPLET)
|
||||
set(_vcpkg_triplet "${VCPKG_TARGET_TRIPLET}")
|
||||
elseif(DEFINED ENV{VCPKG_DEFAULT_TRIPLET})
|
||||
set(_vcpkg_triplet "$ENV{VCPKG_DEFAULT_TRIPLET}")
|
||||
endif()
|
||||
|
||||
# Enable vcpkg manifest mode for automatic dependency management
|
||||
set(VCPKG_MANIFEST_MODE ON)
|
||||
# Detect installed directory
|
||||
set(_vcpkg_installed "${CMAKE_BINARY_DIR}/vcpkg_installed")
|
||||
if(DEFINED VCPKG_INSTALLED_DIR)
|
||||
set(_vcpkg_installed "${VCPKG_INSTALLED_DIR}")
|
||||
endif()
|
||||
|
||||
# Auto-detect target architecture and set vcpkg triplet
|
||||
if(NOT DEFINED VCPKG_TARGET_TRIPLET)
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|aarch64")
|
||||
set(VCPKG_TARGET_TRIPLET "arm64-windows" CACHE STRING "vcpkg target triplet")
|
||||
set(VCPKG_TARGET_ARCHITECTURE arm64)
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|x86_64")
|
||||
set(VCPKG_TARGET_TRIPLET "x64-windows" CACHE STRING "vcpkg target triplet")
|
||||
set(VCPKG_TARGET_ARCHITECTURE x64)
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|x86")
|
||||
set(VCPKG_TARGET_TRIPLET "x86-windows" CACHE STRING "vcpkg target triplet")
|
||||
set(VCPKG_TARGET_ARCHITECTURE x86)
|
||||
# Detect manifest mode
|
||||
set(_vcpkg_manifest "ON (auto)")
|
||||
if(DEFINED VCPKG_MANIFEST_MODE)
|
||||
if(VCPKG_MANIFEST_MODE)
|
||||
set(_vcpkg_manifest "ON")
|
||||
else()
|
||||
# Fallback to x64 if architecture detection fails
|
||||
set(VCPKG_TARGET_TRIPLET "x64-windows" CACHE STRING "vcpkg target triplet")
|
||||
set(VCPKG_TARGET_ARCHITECTURE x64)
|
||||
message(WARNING "Could not detect target architecture, defaulting to x64")
|
||||
set(_vcpkg_manifest "OFF")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Set vcpkg installation directory if not already set
|
||||
if(NOT DEFINED VCPKG_INSTALLED_DIR)
|
||||
set(VCPKG_INSTALLED_DIR "${CMAKE_BINARY_DIR}/vcpkg_installed" CACHE PATH "vcpkg installed directory")
|
||||
# Report vcpkg configuration
|
||||
message(STATUS "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
||||
message(STATUS "vcpkg Post-Toolchain Report:")
|
||||
message(STATUS " ├─ Active triplet: ${_vcpkg_triplet}")
|
||||
message(STATUS " ├─ Manifest mode: ${_vcpkg_manifest}")
|
||||
message(STATUS " └─ Installed directory: ${_vcpkg_installed}")
|
||||
message(STATUS "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
||||
|
||||
# Validation warnings
|
||||
if(_vcpkg_triplet STREQUAL "unknown")
|
||||
message(WARNING "vcpkg triplet not detected! Build may fail.")
|
||||
message(WARNING "Set VCPKG_TARGET_TRIPLET on command line or VCPKG_DEFAULT_TRIPLET env var")
|
||||
endif()
|
||||
|
||||
message(STATUS "vcpkg configuration:")
|
||||
message(STATUS " Target architecture: ${VCPKG_TARGET_ARCHITECTURE}")
|
||||
message(STATUS " Target triplet: ${VCPKG_TARGET_TRIPLET}")
|
||||
message(STATUS " Installed directory: ${VCPKG_INSTALLED_DIR}")
|
||||
message(STATUS " Manifest mode: ${VCPKG_MANIFEST_MODE}")
|
||||
# Ensure manifest file exists
|
||||
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/vcpkg.json")
|
||||
message(WARNING "vcpkg.json manifest not found in ${CMAKE_SOURCE_DIR}")
|
||||
message(WARNING "vcpkg dependency installation may fail!")
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user