Skip to content

Commit

Permalink
check proto version
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Jul 2, 2024
1 parent fe321f6 commit 3667195
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/struct_pb/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@ endif()
set(TEST_PROTO main.cpp)

if (Protobuf_FOUND)
add_definitions(-DSTRUCT_PB_WITH_PROTO)
message(STATUS "Found Protobuf: ${Protobuf_VERSION}")
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(PROTO_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/)
file(GLOB PROTO_FILES ${PROTO_SRC_DIR}/*.proto)
if(${Protobuf_VERSION} GREATER_EQUAL 3.21)
message(STATUS "Gen proto files")
add_definitions(-DSTRUCT_PB_WITH_PROTO)
message(STATUS "Found Protobuf: ${Protobuf_VERSION}")
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(PROTO_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/)
file(GLOB PROTO_FILES ${PROTO_SRC_DIR}/*.proto)

protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_FILES})
# message(STATUS "Proto source files: ${PROTO_SRCS}")
# message(STATUS "Proto header files: ${PROTO_HDRS}")
add_executable(struct_pb_test ${PROTO_SRCS} ${TEST_PROTO})
target_link_libraries(struct_pb_test PRIVATE protobuf::libprotobuf)
add_test(NAME struct_pb_test COMMAND struct_pb_test)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_FILES})
# message(STATUS "Proto source files: ${PROTO_SRCS}")
# message(STATUS "Proto header files: ${PROTO_HDRS}")
add_executable(struct_pb_test ${PROTO_SRCS} ${TEST_PROTO})
target_link_libraries(struct_pb_test PRIVATE protobuf::libprotobuf)
add_test(NAME struct_pb_test COMMAND struct_pb_test)
endif()
else()
add_executable(struct_pb_test ${TEST_PROTO})
add_test(NAME struct_pb_test COMMAND struct_pb_test)
Expand Down

0 comments on commit 3667195

Please sign in to comment.