Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix protobuf compilation warning in gRPC example #830

Merged
merged 2 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 1 addition & 82 deletions cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
@@ -1,85 +1,4 @@
macro(check_append_cxx_compiler_flag OUTPUT_VAR)
foreach(CHECK_FLAG ${ARGN})
check_cxx_compiler_flag(${CHECK_FLAG}
"check_cxx_compiler_flag_${CHECK_FLAG}")
if(check_cxx_compiler_flag_${CHECK_FLAG})
list(APPEND ${OUTPUT_VAR} ${CHECK_FLAG})
endif()
endforeach()
endmacro()

if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET)
if(MSVC)
unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE)
set(PATCH_PROTOBUF_SOURCES_OPTIONS /wd4244 /wd4251 /wd4267 /wd4309)

if(MSVC_VERSION GREATER_EQUAL 1922)
# see
# https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=vs-2019#improvements_162
# for detail
list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd5054)
endif()

if(MSVC_VERSION GREATER_EQUAL 1925)
list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4996)
endif()

if(MSVC_VERSION LESS 1910)
list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4800)
endif()
else()
unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE)
include(CheckCXXCompilerFlag)
check_append_cxx_compiler_flag(
PATCH_PROTOBUF_SOURCES_OPTIONS -Wno-type-limits
-Wno-deprecated-declarations -Wno-unused-parameter)
endif()
set(PATCH_PROTOBUF_SOURCES_OPTIONS_SET TRUE)
if(PATCH_PROTOBUF_SOURCES_OPTIONS)
set(PATCH_PROTOBUF_SOURCES_OPTIONS
${PATCH_PROTOBUF_SOURCES_OPTIONS}
CACHE INTERNAL
"Options to disable warning of generated protobuf sources" FORCE)
endif()
endif()

function(patch_protobuf_sources)
if(PATCH_PROTOBUF_SOURCES_OPTIONS)
foreach(PROTO_SRC ${ARGN})
unset(PROTO_SRC_OPTIONS)
get_source_file_property(PROTO_SRC_OPTIONS ${PROTO_SRC} COMPILE_OPTIONS)
if(PROTO_SRC_OPTIONS)
list(APPEND PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
else()
set(PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
endif()

set_source_files_properties(
${PROTO_SRC} PROPERTIES COMPILE_OPTIONS "${PROTO_SRC_OPTIONS}")
endforeach()
unset(PROTO_SRC)
unset(PROTO_SRC_OPTIONS)
endif()
endfunction()

function(patch_protobuf_targets)
if(PATCH_PROTOBUF_SOURCES_OPTIONS)
foreach(PROTO_TARGET ${ARGN})
unset(PROTO_TARGET_OPTIONS)
get_target_property(PROTO_TARGET_OPTIONS ${PROTO_TARGET} COMPILE_OPTIONS)
if(PROTO_TARGET_OPTIONS)
list(APPEND PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
else()
set(PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
endif()

set_target_properties(
${PROTO_TARGET} PROPERTIES COMPILE_OPTIONS "${PROTO_TARGET_OPTIONS}")
endforeach()
unset(PROTO_TARGET)
unset(PROTO_TARGET_OPTIONS)
endif()
endfunction()
include(${PROJECT_SOURCE_DIR}/cmake/proto-options-patch.cmake)

set(PROTO_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third_party/opentelemetry-proto")

Expand Down
82 changes: 82 additions & 0 deletions cmake/proto-options-patch.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
macro(check_append_cxx_compiler_flag OUTPUT_VAR)
foreach(CHECK_FLAG ${ARGN})
check_cxx_compiler_flag(${CHECK_FLAG}
"check_cxx_compiler_flag_${CHECK_FLAG}")
if(check_cxx_compiler_flag_${CHECK_FLAG})
list(APPEND ${OUTPUT_VAR} ${CHECK_FLAG})
endif()
endforeach()
endmacro()

if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET)
if(MSVC)
unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE)
set(PATCH_PROTOBUF_SOURCES_OPTIONS /wd4244 /wd4251 /wd4267 /wd4309)

if(MSVC_VERSION GREATER_EQUAL 1922)
# see
# https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=vs-2019#improvements_162
# for detail
list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd5054)
endif()

if(MSVC_VERSION GREATER_EQUAL 1925)
list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4996)
endif()

if(MSVC_VERSION LESS 1910)
list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4800)
endif()
else()
unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE)
include(CheckCXXCompilerFlag)
check_append_cxx_compiler_flag(
PATCH_PROTOBUF_SOURCES_OPTIONS -Wno-type-limits
-Wno-deprecated-declarations -Wno-unused-parameter)
endif()
set(PATCH_PROTOBUF_SOURCES_OPTIONS_SET TRUE)
if(PATCH_PROTOBUF_SOURCES_OPTIONS)
set(PATCH_PROTOBUF_SOURCES_OPTIONS
${PATCH_PROTOBUF_SOURCES_OPTIONS}
CACHE INTERNAL
"Options to disable warning of generated protobuf sources" FORCE)
endif()
endif()

function(patch_protobuf_sources)
if(PATCH_PROTOBUF_SOURCES_OPTIONS)
foreach(PROTO_SRC ${ARGN})
unset(PROTO_SRC_OPTIONS)
get_source_file_property(PROTO_SRC_OPTIONS ${PROTO_SRC} COMPILE_OPTIONS)
if(PROTO_SRC_OPTIONS)
list(APPEND PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
else()
set(PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
endif()

set_source_files_properties(
${PROTO_SRC} PROPERTIES COMPILE_OPTIONS "${PROTO_SRC_OPTIONS}")
endforeach()
unset(PROTO_SRC)
unset(PROTO_SRC_OPTIONS)
endif()
endfunction()

function(patch_protobuf_targets)
if(PATCH_PROTOBUF_SOURCES_OPTIONS)
foreach(PROTO_TARGET ${ARGN})
unset(PROTO_TARGET_OPTIONS)
get_target_property(PROTO_TARGET_OPTIONS ${PROTO_TARGET} COMPILE_OPTIONS)
if(PROTO_TARGET_OPTIONS)
list(APPEND PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
else()
set(PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
endif()

set_target_properties(
${PROTO_TARGET} PROPERTIES COMPILE_OPTIONS "${PROTO_TARGET_OPTIONS}")
endforeach()
unset(PROTO_TARGET)
unset(PROTO_TARGET_OPTIONS)
endif()
endfunction()
6 changes: 4 additions & 2 deletions examples/grpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ add_custom_command(
${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--grpc_out=${CMAKE_CURRENT_BINARY_DIR}"
"--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" "--proto_path=${proto_file_path}"
--plugin=protoc-gen-grpc="${gRPC_CPP_PLUGIN_EXECUTABLE}" "${proto_file}")
# DEPENDS "${proto_file}")

# hw_grpc_proto
add_library(example_grpc_proto ${example_grpc_srcs} ${example_grpc_hdrs}
${example_proto_srcs} ${example_proto_hdrs})

include(${PROJECT_SOURCE_DIR}/cmake/proto-options-patch.cmake)
patch_protobuf_targets(example_grpc_proto)

include_directories(
${CMAKE_SOURCE_DIR}/exporters/ostream/include ${CMAKE_SOURCE_DIR}/ext/include
${CMAKE_SOURCE_DIR}/api/include/ ${CMAKE_SOURCE_DIR/})
Expand All @@ -45,4 +46,5 @@ foreach(_target client server)
gRPC::grpc++_reflection
opentelemetry_trace
opentelemetry_exporter_ostream_span)
patch_protobuf_targets(${_target})
endforeach()