diff --git a/CMakeLists.txt b/CMakeLists.txt index 833c5cce..4b796c13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,12 +106,14 @@ target_include_directories(${app} PRIVATE ${VARTYPES_INCLUDE_DIRS}) list(APPEND libs ${VARTYPES_LIBRARIES}) # Protobuf -find_package(Protobuf REQUIRED) -include_directories(${PROTOBUF_INCLUDE_DIRS}) -list(APPEND libs ${PROTOBUF_LIBRARIES}) +find_package(protobuf CONFIG REQUIRED) +list(APPEND libs protobuf::libprotobuf) -set (Protobuf_IMPORT_DIRS ${Protobuf_INCLUDE_DIR}) -protobuf_generate_cpp(PROTO_CPP PROTO_H +if(protobuf_VERBOSE) + message(STATUS "Using Protocol Buffers ${protobuf_VERSION}") +endif() + +set(PROTOS src/proto/grSim_Commands.proto src/proto/grSim_Packet.proto src/proto/grSim_Replacement.proto @@ -189,8 +191,7 @@ set(HEADERS # files to be compiled set(srcs ${CONFIG_FILES} - ${PROTO_CPP} - ${PROTO_H} + ${PROTOS} ${RESOURCES} ${HEADERS} ${SOURCES} @@ -203,6 +204,15 @@ target_sources(${app} PRIVATE ${srcs}) install(TARGETS ${app} DESTINATION bin) target_link_libraries(${app} ${libs}) +set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") +file(MAKE_DIRECTORY ${PROTO_BINARY_DIR}) +target_include_directories(${app} PUBLIC "$") +protobuf_generate( + TARGET ${app} + IMPORT_DIRS "${CMAKE_CURRENT_LIST_DIR}/src/proto" + PROTOC_OUT_DIR "${PROTO_BINARY_DIR}" +) + if(APPLE AND CMAKE_MACOSX_BUNDLE) # use CMAKE_MACOSX_BUNDLE if you want to build a mac bundle set(MACOSX_BUNDLE_ICON_FILE "${PROJECT_SOURCE_DIR}/resources/icons/grsim.icns") diff --git a/INSTALL.md b/INSTALL.md index 47957903..3e784f33 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -80,7 +80,7 @@ brew install pkg-config brew tap robotology/formulae brew install robotology/formulae/ode brew install qt -brew install protobuf +brew install protobuf@21 ``` If you run into build issues, you may need to run this first: diff --git a/clients/qt/CMakeLists.txt b/clients/qt/CMakeLists.txt index 5ea9473f..6aa15881 100644 --- a/clients/qt/CMakeLists.txt +++ b/clients/qt/CMakeLists.txt @@ -9,26 +9,31 @@ set(libs) find_package(Qt5 COMPONENTS Core Widgets Network REQUIRED) list(APPEND libs Qt5::Core Qt5::Widgets Qt5::Network) +find_package(protobuf CONFIG REQUIRED) +list(APPEND libs protobuf::libprotobuf) -find_package(Protobuf REQUIRED) -include_directories(${PROTOBUF_INCLUDE_DIRS}) -list(APPEND libs ${PROTOBUF_LIBRARIES}) - -protobuf_generate_cpp(PROTO_CPP PROTO_H - ../../src/proto/grSim_Replacement.proto - ../../src/proto/grSim_Commands.proto - ../../src/proto/grSim_Packet.proto -) set(app client) add_executable(${app} MACOSX_BUNDLE - ${PROTO_CPP} - ${PROTO_H} - main.cpp - mainwindow.cpp - mainwindow.h -) + main.cpp + mainwindow.cpp + mainwindow.h + ../../src/proto/grSim_Replacement.proto + ../../src/proto/grSim_Commands.proto + ../../src/proto/grSim_Packet.proto + ) target_link_libraries(${app} ${libs}) +# Set the directory where the generated protobuf files will be placed +set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") +file(MAKE_DIRECTORY ${PROTO_BINARY_DIR}) +target_include_directories(${app} PUBLIC "$") + +# Generate the sources from the .proto files +protobuf_generate( + TARGET ${app} + IMPORT_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../src/proto" + PROTOC_OUT_DIR "${PROTO_BINARY_DIR}" +)