chore(cmake): enhance CMake configuration for Abseil and yaml-cpp

- Made ABSL_TARGETS available to the rest of the project via include(), improving modularity.
- Added MSVC-specific compile options for yaml-cpp to address exception handling warnings.

Benefits:
- Streamlined integration of Abseil targets across the project.
- Improved compatibility and reduced warnings for yaml-cpp on MSVC.
This commit is contained in:
scawful
2025-10-11 10:49:40 -04:00
parent a8d49306e5
commit feeb16cb9f
3 changed files with 55 additions and 24 deletions

View File

@@ -43,13 +43,33 @@ endif()
if(NOT TARGET absl::strings)
message(FATAL_ERROR "Abseil was not found or failed to configure correctly.")
else()
message(STATUS "✓ Abseil configured successfully (standalone)")
# Verify critical targets exist
foreach(_check_target IN ITEMS absl::status absl::statusor absl::str_format absl::flags)
if(NOT TARGET ${_check_target})
message(WARNING "Expected Abseil target ${_check_target} not found")
endif()
endforeach()
endif()
# Canonical list of Abseil targets that the rest of the project links against.
# Note: Order matters for some linkers - put base libraries first
set(
ABSL_TARGETS
absl::base
absl::config
absl::core_headers
absl::utility
absl::memory
absl::container_memory
absl::strings
absl::str_format
absl::cord
absl::hash
absl::time
absl::status
absl::statusor
absl::flags
absl::flags_parse
absl::flags_usage
@@ -59,23 +79,12 @@ set(
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
)
# Only expose absl::int128 when it's supported without warnings.
@@ -86,6 +95,8 @@ else()
message(STATUS "Skipping absl::int128 target on Windows")
endif()
# ABSL_TARGETS is now available to the rest of the project via include()
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})

View File

@@ -64,11 +64,25 @@ endfunction()
# gRPC (must come before Abseil - provides its own compatible Abseil)
if(YAZE_WITH_GRPC)
include(cmake/grpc.cmake)
# Verify ABSL_TARGETS was populated by gRPC
list(LENGTH ABSL_TARGETS _absl_count)
if(_absl_count EQUAL 0)
message(FATAL_ERROR "ABSL_TARGETS is empty after including grpc.cmake!")
else()
message(STATUS "gRPC provides ${_absl_count} Abseil targets for linking")
endif()
endif()
# Abseil (only if gRPC didn't provide it)
if(NOT YAZE_WITH_GRPC)
include(cmake/absl.cmake)
# Verify ABSL_TARGETS was populated
list(LENGTH ABSL_TARGETS _absl_count)
if(_absl_count EQUAL 0)
message(FATAL_ERROR "ABSL_TARGETS is empty after including absl.cmake!")
else()
message(STATUS "Abseil provides ${_absl_count} targets for linking")
endif()
endif()
# SDL2
@@ -108,6 +122,11 @@ FetchContent_Declare(yaml-cpp
)
FetchContent_MakeAvailable(yaml-cpp)
# Fix MSVC exception handling warning for yaml-cpp
if(MSVC AND TARGET yaml-cpp)
target_compile_options(yaml-cpp PRIVATE /EHsc)
endif()
# nlohmann_json (header only)
if(YAZE_WITH_JSON)
set(JSON_BuildTests OFF CACHE INTERNAL "Disable nlohmann_json tests")

View File

@@ -151,10 +151,22 @@ list(GET _PROTOBUF_INCLUDE_DIRS 0 _gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR)
# 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
# Note: Order matters for some linkers - put base libraries first
set(
ABSL_TARGETS
absl::base
absl::config
absl::core_headers
absl::utility
absl::memory
absl::container_memory
absl::strings
absl::str_format
absl::cord
absl::hash
absl::time
absl::status
absl::statusor
absl::flags
absl::flags_parse
absl::flags_usage
@@ -164,32 +176,21 @@ set(
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()
# ABSL_TARGETS is now available to the rest of the project via include()
# 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)