refactor(build): enhance MSVC whole-archive linking for protobuf

- Updated CMake configurations across core, net, agent, and z3ed to conditionally apply /WHOLEARCHIVE linking for libprotobuf based on the compiler ID.
- Added status messages to indicate when /WHOLEARCHIVE linking is skipped for clang-cl, improving clarity in build logs.

Benefits:
- Improves compatibility and clarity in the build process for Windows environments using different compilers.
- Ensures that necessary symbols are included when using MSVC, enhancing build reliability.
This commit is contained in:
scawful
2025-10-13 23:11:06 -04:00
parent 7bb0f257ce
commit cafa50b355
5 changed files with 23 additions and 11 deletions

View File

@@ -148,9 +148,11 @@ if(YAZE_WITH_GRPC)
)
# On Windows, force whole-archive linking for protobuf to ensure all symbols are included
if(MSVC)
target_link_options(yaze_core_lib PUBLIC /WHOLEARCHIVE:$<TARGET_FILE:libprotobuf>)
endif()
if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_link_options(yaze_core_lib PUBLIC /WHOLEARCHIVE:$<TARGET_FILE:libprotobuf>)
elseif(MSVC)
message(STATUS "○ Skipping /WHOLEARCHIVE for libprotobuf in yaze_core_lib (clang-cl)")
endif()
message(STATUS " - gRPC test harness + ROM service enabled")
endif()

View File

@@ -87,8 +87,10 @@ if(YAZE_WITH_GRPC)
)
# On Windows, force whole-archive linking for protobuf to ensure all symbols are included
if(MSVC)
if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_link_options(yaze_net PUBLIC /WHOLEARCHIVE:$<TARGET_FILE:libprotobuf>)
elseif(MSVC)
message(STATUS "○ Skipping /WHOLEARCHIVE for libprotobuf in yaze_net (clang-cl)")
endif()
message(STATUS " - gRPC ROM service enabled")

View File

@@ -164,8 +164,10 @@ if(YAZE_WITH_GRPC)
)
# On Windows, force whole-archive linking for protobuf to ensure all symbols are included
if(MSVC)
if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_link_options(yaze_agent PUBLIC /WHOLEARCHIVE:$<TARGET_FILE:libprotobuf>)
elseif(MSVC)
message(STATUS "○ Skipping /WHOLEARCHIVE for libprotobuf (clang-cl)")
endif()
# Note: YAZE_WITH_GRPC is defined globally via add_compile_definitions in root CMakeLists.txt

View File

@@ -42,7 +42,9 @@ if(YAZE_WITH_GRPC)
target_link_libraries(z3ed PRIVATE grpc++ grpc++_reflection libprotobuf)
# On Windows, force whole-archive linking for protobuf to ensure all symbols are included
if(MSVC)
target_link_options(z3ed PRIVATE /WHOLEARCHIVE:$<TARGET_FILE:libprotobuf>)
endif()
endif()
if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_link_options(z3ed PRIVATE /WHOLEARCHIVE:$<TARGET_FILE:libprotobuf>)
elseif(MSVC)
message(STATUS "○ Skipping /WHOLEARCHIVE for libprotobuf in z3ed (clang-cl)")
endif()
endif()

View File

@@ -49,7 +49,11 @@ if(YAZE_BUILD_TESTS)
target_link_options(${suite_name} PRIVATE /STACK:16777216)
# Force whole-archive linking for protobuf to ensure all symbols are included
if(YAZE_WITH_GRPC)
target_link_options(${suite_name} PRIVATE /WHOLEARCHIVE:$<TARGET_FILE:libprotobuf>)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_link_options(${suite_name} PRIVATE /WHOLEARCHIVE:$<TARGET_FILE:libprotobuf>)
else()
message(STATUS "○ Skipping /WHOLEARCHIVE for libprotobuf in ${suite_name} (clang-cl)")
endif()
endif()
else()
target_link_options(${suite_name} PRIVATE -Wl,--stack,16777216)
@@ -153,4 +157,4 @@ if(YAZE_BUILD_TESTS)
)
yaze_add_test_suite(yaze_test_benchmark "benchmark" OFF ${BENCHMARK_TEST_SOURCES})
endif()
endif()