@@ -63,20 +63,34 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
6363 #
6464 find_program (BUF_COMMAND buf)
6565 if (NOT BUF_COMMAND)
66+
67+ set (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD ${CMAKE_HOST_SYSTEM_PROCESSOR} )
68+ if (CMAKE_HOST_WIN32 )
69+ if (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD STREQUAL "AMD64" )
70+ set (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD x86_64)
71+ elseif (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD STREQUAL "ARM64" )
72+ set (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD arm64)
73+ else ()
74+ message (FATAL_ERROR "Unknown Windows platform to correct buf download URL: ${HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD} " )
75+ endif ()
76+ endif ()
77+
78+ set (BUF_DOWNLOAD_URL https://github.com/bufbuild/buf/releases/latest/download/buf-${CMAKE_HOST_SYSTEM_NAME} -${HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD}${CMAKE_HOST_EXECUTABLE_SUFFIX} )
79+
6680 file (
6781 DOWNLOAD
68- https://github.com/bufbuild/buf/releases/latest/download/buf- ${CMAKE_HOST_SYSTEM_NAME} - ${CMAKE_HOST_SYSTEM_PROCESSOR }
69- ${CMAKE_CURRENT_BINARY_DIR} /buf_latest
82+ ${BUF_DOWNLOAD_URL }
83+ ${CMAKE_CURRENT_BINARY_DIR} /buf_latest${CMAKE_HOST_EXECUTABLE_SUFFIX}
7084 STATUS buf_status
7185 )
7286 list (GET buf_status 0 buf_status_code)
7387 list (GET buf_status 1 buf_status_string)
7488
7589 if (NOT buf_status_code EQUAL 0)
76- message (FATAL_ERROR "No local `buf` program found (try setting PATH?) and failed to download: ${buf_status_string} " )
90+ message (FATAL_ERROR "No local `buf` program found (try setting PATH?) and failed to download: ${buf_status_string} for ${BUF_DOWNLOAD_URL} " )
7791 endif ()
7892
79- set (BUF_COMMAND ${CMAKE_CURRENT_BINARY_DIR} /buf_latest)
93+ set (BUF_COMMAND ${CMAKE_CURRENT_BINARY_DIR} /buf_latest${CMAKE_HOST_EXECUTABLE_SUFFIX} )
8094 file (CHMOD ${BUF_COMMAND} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
8195 endif ()
8296
@@ -113,6 +127,16 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
113127 )
114128 endif ()
115129
130+ # List of names of non-compilable generated code
131+ # The Switch component generates protobuf which uses `switch` as a namespace.
132+ # This needs to be processed below.
133+ set (VIAMCPPSDK_SWITCH_REPLACE_PATHS
134+ ${PROTO_GEN_DIR} /component /switch/v1/switch.grpc.pb.cc
135+ ${PROTO_GEN_DIR} /component /switch/v1/switch.grpc.pb.h
136+ ${PROTO_GEN_DIR} /component /switch/v1/switch.pb.cc
137+ ${PROTO_GEN_DIR} /component /switch/v1/switch.pb.h
138+ )
139+
116140 add_custom_command (
117141 OUTPUT
118142 # Unfortunately, there isn't a good way to know in advance what
@@ -201,6 +225,10 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
201225 ${PROTO_GEN_DIR} /component /servo/v1/servo.grpc.pb.h
202226 ${PROTO_GEN_DIR} /component /servo/v1/servo.pb.cc
203227 ${PROTO_GEN_DIR} /component /servo/v1/servo.pb.h
228+ ${PROTO_GEN_DIR} /component /switch/v1/switch.grpc.pb.cc
229+ ${PROTO_GEN_DIR} /component /switch/v1/switch.grpc.pb.h
230+ ${PROTO_GEN_DIR} /component /switch/v1/switch.pb.cc
231+ ${PROTO_GEN_DIR} /component /switch/v1/switch.pb.h
204232 ${PROTO_GEN_DIR} /google/api/annotations.pb.cc
205233 ${PROTO_GEN_DIR} /google/api/annotations.pb.h
206234 ${PROTO_GEN_DIR} /google/api/httpbody.pb.cc
@@ -245,6 +273,9 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
245273 COMMAND ${BUF_COMMAND} generate ${BUF_GOOGLE_API_SOURCE} --template buf.gen.yaml --path google/rpc --path google/api
246274 COMMAND ${BUF_COMMAND} generate ${BUF_VIAM_GOUTILS_SOURCE} --template buf.gen.yaml
247275 COMMAND ${BUF_COMMAND} generate ${BUF_VIAM_API_SOURCE} --template buf.gen.yaml --path ${BUF_PROTO_COMPONENTS_JOINED}
276+
277+ # After generating the protos, include a step to invoke a search-and-replace for switch -> switch_ in the Switch component files
278+ COMMAND ${CMAKE_COMMAND} "-DSWITCH_REPLACE_PATHS=\" ${VIAMCPPSDK_SWITCH_REPLACE_PATHS} \" " -P ${CMAKE_CURRENT_SOURCE_DIR} /viamcppsdk_replace_switch.cmake
248279 MAIN_DEPENDENCY buf.gen.yaml
249280 )
250281
@@ -328,6 +359,8 @@ target_sources(viamapi
328359 ${PROTO_GEN_DIR} /component /sensor/v1/sensor.pb.cc
329360 ${PROTO_GEN_DIR} /component /servo/v1/servo.grpc.pb.cc
330361 ${PROTO_GEN_DIR} /component /servo/v1/servo.pb.cc
362+ ${PROTO_GEN_DIR} /component /switch/v1/switch.grpc.pb.cc
363+ ${PROTO_GEN_DIR} /component /switch/v1/switch.pb.cc
331364 ${PROTO_GEN_DIR} /google/api/annotations.pb.cc
332365 ${PROTO_GEN_DIR} /google/api/http.pb.cc
333366 ${PROTO_GEN_DIR} /google/api/httpbody.pb.cc
@@ -390,6 +423,8 @@ target_sources(viamapi
390423 ${PROTO_GEN_DIR} /../../viam/api/component /sensor/v1/sensor.pb.h
391424 ${PROTO_GEN_DIR} /../../viam/api/component /servo/v1/servo.grpc.pb.h
392425 ${PROTO_GEN_DIR} /../../viam/api/component /servo/v1/servo.pb.h
426+ ${PROTO_GEN_DIR} /../../viam/api/component /switch/v1/switch.grpc.pb.h
427+ ${PROTO_GEN_DIR} /../../viam/api/component /switch/v1/switch.pb.h
393428 ${PROTO_GEN_DIR} /../../viam/api/google/api/annotations.pb.h
394429 ${PROTO_GEN_DIR} /../../viam/api/google/api/http.pb.h
395430 ${PROTO_GEN_DIR} /../../viam/api/google/api/httpbody.pb.h
0 commit comments