feat: Update CMake configuration for Abseil and gRPC, enhance modular build support, and add CLI flag handling
This commit is contained in:
@@ -1,34 +1,45 @@
|
||||
# Normalize Abseil's hardware AES flags when targeting macOS ARM64 only.
|
||||
if(APPLE AND DEFINED CMAKE_OSX_ARCHITECTURES AND CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
|
||||
set(ABSL_RANDOM_HWAES_X64_FLAGS "" CACHE STRING "" FORCE)
|
||||
set(ABSL_RANDOM_HWAES_ARM64_FLAGS "-march=armv8-a+crypto" CACHE STRING "" FORCE)
|
||||
endif()
|
||||
# Abseil release to use when fetching from source
|
||||
set(YAZE_ABSL_GIT_TAG "20240116.2" CACHE STRING "Abseil release tag used when fetching from source")
|
||||
|
||||
if (MINGW OR WIN32 OR YAZE_FORCE_BUNDLED_ABSL)
|
||||
add_subdirectory(src/lib/abseil-cpp)
|
||||
elseif(YAZE_MINIMAL_BUILD)
|
||||
# For CI builds, always use submodule to avoid dependency issues
|
||||
add_subdirectory(src/lib/abseil-cpp)
|
||||
else()
|
||||
# Try system package first, fallback to submodule
|
||||
find_package(absl QUIET)
|
||||
if(NOT absl_FOUND)
|
||||
message(STATUS "System Abseil not found, using submodule")
|
||||
add_subdirectory(src/lib/abseil-cpp)
|
||||
# Attempt to use the system package unless the build explicitly requests the
|
||||
# bundled (fetched) copy or we're on platforms where prebuilt packages are often
|
||||
# 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)
|
||||
if(absl_FOUND)
|
||||
message(STATUS "Using system-provided Abseil package")
|
||||
else()
|
||||
set(_yaze_use_fetched_absl TRUE)
|
||||
message(STATUS "System Abseil not found. Fetching release ${YAZE_ABSL_GIT_TAG}.")
|
||||
endif()
|
||||
endif()
|
||||
set(ABSL_PROPAGATE_CXX_STD ON)
|
||||
set(ABSL_CXX_STANDARD 23)
|
||||
set(ABSL_USE_GOOGLETEST_HEAD ON)
|
||||
set(ABSL_ENABLE_INSTALL ON)
|
||||
|
||||
# Silence C++23 deprecation warnings for Abseil int128
|
||||
if(MSVC)
|
||||
add_definitions(-DSILENCE_CXX23_DEPRECATIONS)
|
||||
else()
|
||||
add_definitions(-D_SILENCE_CXX23_DEPRECATION_WARNING)
|
||||
if(_yaze_use_fetched_absl)
|
||||
include(FetchContent)
|
||||
FetchContent_GetProperties(absl)
|
||||
if(NOT absl_POPULATED)
|
||||
FetchContent_Declare(
|
||||
absl
|
||||
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
|
||||
GIT_TAG ${YAZE_ABSL_GIT_TAG}
|
||||
GIT_SHALLOW TRUE
|
||||
GIT_PROGRESS TRUE
|
||||
USES_TERMINAL_DOWNLOAD TRUE
|
||||
)
|
||||
set(ABSL_PROPAGATE_CXX_STD ON CACHE BOOL "" FORCE)
|
||||
set(ABSL_BUILD_TESTING OFF CACHE BOOL "" FORCE)
|
||||
set(ABSL_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(absl)
|
||||
message(STATUS "Fetched Abseil ${YAZE_ABSL_GIT_TAG}")
|
||||
endif()
|
||||
endif()
|
||||
# Define base Abseil targets
|
||||
|
||||
if(NOT TARGET absl::strings)
|
||||
message(FATAL_ERROR "Abseil was not found or failed to configure correctly.")
|
||||
endif()
|
||||
|
||||
# Canonical list of Abseil targets that the rest of the project links against.
|
||||
set(
|
||||
ABSL_TARGETS
|
||||
absl::strings
|
||||
@@ -61,20 +72,20 @@ set(
|
||||
absl::utility
|
||||
)
|
||||
|
||||
# Add int128 only on non-Windows platforms to avoid C++23 deprecation issues
|
||||
# Only expose absl::int128 when it's supported without warnings.
|
||||
if(NOT WIN32)
|
||||
list(APPEND ABSL_TARGETS absl::int128)
|
||||
message(STATUS "Including absl::int128 (non-Windows platform)")
|
||||
message(STATUS "Including absl::int128 target")
|
||||
else()
|
||||
message(STATUS "Excluding absl::int128 on Windows to avoid C++23 deprecation issues")
|
||||
message(STATUS "Skipping absl::int128 target on Windows")
|
||||
endif()
|
||||
|
||||
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(NOT _absl_opts STREQUAL "NOTFOUND")
|
||||
set(_absl_filtered_opts "")
|
||||
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)
|
||||
@@ -88,11 +99,17 @@ if(APPLE AND DEFINED CMAKE_OSX_ARCHITECTURES AND CMAKE_OSX_ARCHITECTURES STREQUA
|
||||
if(_absl_opt STREQUAL "-maes" OR _absl_opt STREQUAL "-msse4.1")
|
||||
continue()
|
||||
endif()
|
||||
list(APPEND _absl_filtered_opts "${_absl_opt}")
|
||||
list(APPEND _absl_filtered_opts ${_absl_opt})
|
||||
endforeach()
|
||||
set_target_properties(${_absl_target} PROPERTIES COMPILE_OPTIONS "${_absl_filtered_opts}")
|
||||
set_property(TARGET ${_absl_target} PROPERTY COMPILE_OPTIONS ${_absl_filtered_opts})
|
||||
endif()
|
||||
target_compile_options(${_absl_target} PRIVATE "-Xarch_arm64" "-march=armv8-a+crypto")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# Silence C++23 deprecation warnings for Abseil int128
|
||||
if(MSVC)
|
||||
add_definitions(-DSILENCE_CXX23_DEPRECATIONS)
|
||||
else()
|
||||
add_definitions(-D_SILENCE_CXX23_DEPRECATION_WARNING)
|
||||
endif()
|
||||
|
||||
@@ -22,7 +22,8 @@ set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH FALSE)
|
||||
# Add compiler flags for Clang 15+ compatibility
|
||||
# gRPC v1.62.0 requires C++17 (std::result_of removed in C++20)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
add_compile_options(-Wno-error=missing-template-arg-list-after-template-kw)
|
||||
add_compile_options(-Wno-error=missing-template-arg-list-after-template-kw)
|
||||
add_compile_definitions(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
|
||||
endif()
|
||||
|
||||
# Save YAZE's C++ standard and temporarily set to C++17 for gRPC
|
||||
@@ -46,6 +47,12 @@ set(gRPC_BUILD_GRPC_RUBY_PLUGIN OFF CACHE BOOL "" FORCE)
|
||||
set(gRPC_BENCHMARK_PROVIDER "none" CACHE STRING "" FORCE)
|
||||
set(gRPC_ZLIB_PROVIDER "package" CACHE STRING "" FORCE)
|
||||
|
||||
# Skip install rule generation inside gRPC's dependency graph. This avoids
|
||||
# configure-time checks that require every transitive dependency (like Abseil
|
||||
# compatibility shims) to participate in install export sets, which we do not
|
||||
# need for the editor builds.
|
||||
set(CMAKE_SKIP_INSTALL_RULES ON CACHE BOOL "" FORCE)
|
||||
|
||||
# Let gRPC fetch and build its own protobuf and abseil
|
||||
set(gRPC_PROTOBUF_PROVIDER "module" CACHE STRING "" FORCE)
|
||||
set(gRPC_ABSL_PROVIDER "module" CACHE STRING "" FORCE)
|
||||
@@ -59,7 +66,7 @@ set(protobuf_WITH_ZLIB ON CACHE BOOL "" FORCE)
|
||||
|
||||
# Abseil configuration
|
||||
set(ABSL_PROPAGATE_CXX_STD ON CACHE BOOL "" FORCE)
|
||||
set(ABSL_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
set(ABSL_ENABLE_INSTALL ON CACHE BOOL "" FORCE)
|
||||
set(ABSL_BUILD_TESTING OFF CACHE BOOL "" FORCE)
|
||||
|
||||
# Declare gRPC - use v1.62.0 which fixes health_check_client incomplete type bug
|
||||
@@ -150,7 +157,7 @@ function(target_add_protobuf target)
|
||||
"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc"
|
||||
"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h"
|
||||
)
|
||||
target_include_directories(${target} PRIVATE
|
||||
target_include_directories(${target} PUBLIC
|
||||
$<BUILD_INTERFACE:${_gRPC_PROTO_GENS_DIR}>
|
||||
$<BUILD_INTERFACE:${_gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR}>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user