Legacy protobuf is annoying.

Took 4 minutes
This commit is contained in:
Lukas Brübach 2025-10-04 21:31:54 +02:00
parent fdf08780b3
commit e5f23f1906

View file

@ -165,33 +165,47 @@ set(PROTO_FILES
session_event.proto session_event.proto
) )
if(${Protobuf_VERSION} VERSION_LESS "3.21.0.0") # Common output directory for generated files
message(STATUS "Using Protobuf Legacy Mode")
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/pb) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/pb)
set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/pb") set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/pb")
if(${Protobuf_VERSION} VERSION_LESS "3.21.0.0")
message(STATUS "Using Protobuf Legacy Mode")
include_directories(${PROTOBUF_INCLUDE_DIRS}) include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories(${PROTO_BINARY_DIR}) # pb/ folder include_directories(${PROTO_BINARY_DIR}) # expose pb/ folder
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_FILES}) # Generate protobuf cpp/h files directly into pb/
set(PROTO_SRCS)
set(PROTO_HDRS)
foreach (f ${PROTO_FILES})
get_filename_component(fname ${f} NAME_WE)
set(src_cpp ${PROTO_BINARY_DIR}/${fname}.pb.cc)
set(src_h ${PROTO_BINARY_DIR}/${fname}.pb.h)
# Move files at build time using a custom command
foreach (f ${PROTO_SRCS} ${PROTO_HDRS})
get_filename_component(fname ${f} NAME)
add_custom_command( add_custom_command(
TARGET cockatrice_protocol POST_BUILD OUTPUT ${src_cpp} ${src_h}
COMMAND ${CMAKE_COMMAND} -E copy ${f} ${PROTO_BINARY_DIR}/${fname} COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
--cpp_out=${PROTO_BINARY_DIR}
-I ${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/${f}
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/${f}
COMMENT "Generating ${fname}.pb.cc / .pb.h"
) )
list(APPEND PROTO_SRCS ${src_cpp})
list(APPEND PROTO_HDRS ${src_h})
endforeach () endforeach ()
add_library(cockatrice_protocol ${PROTO_SRCS} ${PROTO_HDRS}) add_library(cockatrice_protocol ${PROTO_SRCS} ${PROTO_HDRS})
set(cockatrice_protocol_LIBS ${PROTOBUF_LIBRARIES}) set(cockatrice_protocol_LIBS ${PROTOBUF_LIBRARIES})
if(UNIX) if(UNIX)
set(cockatrice_protocol_LIBS ${cockatrice_protocol_LIBS} -lpthread) set(cockatrice_protocol_LIBS ${cockatrice_protocol_LIBS} -lpthread)
endif(UNIX) endif(UNIX)
target_link_libraries(cockatrice_protocol ${cockatrice_protocol_LIBS}) target_link_libraries(cockatrice_protocol ${cockatrice_protocol_LIBS})
target_include_directories(cockatrice_protocol PUBLIC ${PROTO_BINARY_DIR}) target_include_directories(cockatrice_protocol PUBLIC ${PROTO_BINARY_DIR})
# ubuntu uses an outdated package for protobuf, 3.1.0 is required # ubuntu uses an outdated package for protobuf, 3.1.0 is required
if(${Protobuf_VERSION} VERSION_LESS "3.1.0") if(${Protobuf_VERSION} VERSION_LESS "3.1.0")
# remove unused parameter and misleading indentation warnings when compiling to avoid errors # remove unused parameter and misleading indentation warnings when compiling to avoid errors
@ -204,7 +218,6 @@ if(${Protobuf_VERSION} VERSION_LESS "3.21.0.0")
else() else()
add_library(cockatrice_protocol ${PROTO_FILES}) add_library(cockatrice_protocol ${PROTO_FILES})
target_link_libraries(cockatrice_protocol PUBLIC protobuf::libprotobuf) target_link_libraries(cockatrice_protocol PUBLIC protobuf::libprotobuf)
set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/pb")
target_include_directories(cockatrice_protocol PUBLIC "${PROTOBUF_INCLUDE_DIRS}" PUBLIC ${CMAKE_CURRENT_BINARY_DIR} PUBLIC ${PROTO_BINARY_DIR}) target_include_directories(cockatrice_protocol PUBLIC "${PROTOBUF_INCLUDE_DIRS}" PUBLIC ${CMAKE_CURRENT_BINARY_DIR} PUBLIC ${PROTO_BINARY_DIR})
protobuf_generate( protobuf_generate(