├── README.md ├── py-py ├── __pycache__ │ └── msg_pb2.cpython-36.pyc ├── pb_zmq_sub.py ├── zmq_pub.py ├── CMakeLists.txt ├── zmq_sub.py ├── msg.proto ├── pb_zmq_pub.py └── msg_pb2.py ├── cpp-py ├── msg.proto ├── subscriber.py ├── CMakeLists.txt └── publisher.cpp ├── cpp-cpp ├── src │ ├── proto │ │ ├── my_msg.proto │ │ ├── CMakeLists.txt │ │ └── msg.proto │ ├── CMakeLists.txt │ ├── msg.proto │ ├── publisher.cpp │ ├── my_publisher.cpp │ ├── my_subscriber.cpp │ └── subscriber.cpp └── CMakeLists.txt ├── .gitignore └── cmake ├── FindZMQ.cmake ├── FindPnC.cmake ├── FindMosek.cmake ├── FindGurobi.cmake ├── FindPythonAnaconda.cmake ├── FindGFlags.cmake ├── FindEigen.cmake └── FindProtobuf.cmake /README.md: -------------------------------------------------------------------------------- 1 | # zmq-protobuf 2 | Examples of communication protocol between python and c++ using zmq & protobuf 3 | -------------------------------------------------------------------------------- /py-py/__pycache__/msg_pb2.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/junhyeokahn/zmq-protobuf/HEAD/py-py/__pycache__/msg_pb2.cpython-36.pyc -------------------------------------------------------------------------------- /cpp-py/msg.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package RL; 4 | 5 | message DataSet { 6 | uint32 count = 1; 7 | repeated float joint_position = 2; 8 | repeated float joint_velocity = 3; 9 | } 10 | -------------------------------------------------------------------------------- /cpp-cpp/src/proto/my_msg.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message JointPosition 4 | { 5 | int32 count = 1; 6 | repeated float q = 2; 7 | } 8 | 9 | message JointVelocity 10 | { 11 | int32 count = 1; 12 | repeated float qdot = 2; 13 | } 14 | -------------------------------------------------------------------------------- /cpp-cpp/src/proto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROTOBUF_GENERATE_CPP(PROTO_SRC PROTO_HEADER msg.proto) 2 | ADD_LIBRARY(proto ${PROTO_HEADER} ${PROTO_SRC}) 3 | 4 | PROTOBUF_GENERATE_CPP(MY_PROTO_SRC MY_PROTO_HEADER my_msg.proto) 5 | ADD_LIBRARY(my_proto ${MY_PROTO_HEADER} ${MY_PROTO_SRC}) 6 | -------------------------------------------------------------------------------- /py-py/pb_zmq_sub.py: -------------------------------------------------------------------------------- 1 | import zmq 2 | import sys 3 | import google.protobuf.text_format 4 | # protoc output for testmsg.proto: 5 | from msg_pb2 import * 6 | 7 | context = zmq.Context() 8 | socket = context.socket(zmq.SUB) 9 | socket.connect("tcp://localhost:5556") 10 | socket.setsockopt_string(zmq.SUBSCRIBE, "") 11 | 12 | c = Container() 13 | 14 | while True: 15 | 16 | msg = socket.recv() 17 | c.ParseFromString(msg) 18 | print(str(c)) 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | tags 35 | build 36 | 37 | -------------------------------------------------------------------------------- /cpp-py/subscriber.py: -------------------------------------------------------------------------------- 1 | import zmq 2 | import sys 3 | import os 4 | import time 5 | 6 | sys.path.append(os.getcwd() + '/build') 7 | 8 | from msg_pb2 import * 9 | 10 | context = zmq.Context() 11 | socket = context.socket(zmq.SUB) 12 | socket.connect("tcp://127.0.0.1:5557") 13 | socket.setsockopt_string(zmq.SUBSCRIBE, "") 14 | time.sleep(1) 15 | 16 | msg = DataSet() 17 | 18 | while True: 19 | 20 | encoded_msg = socket.recv() 21 | msg.ParseFromString(encoded_msg) 22 | print(str(msg)) 23 | -------------------------------------------------------------------------------- /py-py/zmq_pub.py: -------------------------------------------------------------------------------- 1 | # 2 | # Weather update server 3 | # Binds PUB socket to tcp://*:5556 4 | # Publishes random weather updates 5 | # 6 | 7 | import zmq 8 | from random import randrange 9 | 10 | 11 | context = zmq.Context() 12 | socket = context.socket(zmq.PUB) 13 | socket.bind("tcp://*:5556") 14 | 15 | while True: 16 | zipcode = randrange(1, 100000) 17 | temperature = randrange(-80, 135) 18 | relhumidity = randrange(10, 60) 19 | 20 | socket.send_string("%i %i %i" % (zipcode, temperature, relhumidity)) 21 | -------------------------------------------------------------------------------- /cpp-cpp/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(proto) 2 | 3 | add_executable(pub "publisher.cpp") 4 | target_link_libraries(pub proto ${Protobuf_LIBRARIES} 5 | ${ZMQ_LIBRARIES}) 6 | 7 | add_executable(sub "subscriber.cpp") 8 | target_link_libraries(sub proto ${Protobuf_LIBRARIES} 9 | ${ZMQ_LIBRARIES}) 10 | 11 | add_executable(my_pub "my_publisher.cpp") 12 | target_link_libraries(my_pub my_proto ${Protobuf_LIBRARIES} 13 | ${ZMQ_LIBRARIES}) 14 | 15 | add_executable(my_sub "my_subscriber.cpp") 16 | target_link_libraries(my_sub my_proto ${Protobuf_LIBRARIES} 17 | ${ZMQ_LIBRARIES}) 18 | -------------------------------------------------------------------------------- /py-py/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5.1) 2 | project(py-py) 3 | set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 4 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cpp-cpp/cmake") 5 | set (CMAKE_CXX_STANDARD 14) 6 | 7 | find_package(Protobuf) 8 | 9 | #message(${ZMQ_INCLUDE_DIRS}) 10 | #message(${ZMQ_LIBRARIES}) 11 | #message(${Protobuf_INCLUDE_DIRS}) 12 | #message(${Protobuf_LIBRARIES}) 13 | #message(${Protobuf_PROTOC_LIBRARIES}) 14 | #message(${Protobuf_LITE_LIBRARIES}) 15 | 16 | include_directories(${Protobuf_INCLUDE_DIR}) 17 | 18 | PROTOBUF_GENERATE_PYTHON(PROTO_PY msg.proto) 19 | add_custom_target(myTarget ALL DEPENDS ${PROTO_PY}) 20 | #add_custom_target(myTarget ${PROTO_PY}) 21 | -------------------------------------------------------------------------------- /py-py/zmq_sub.py: -------------------------------------------------------------------------------- 1 | # 2 | # Weather update client 3 | # Connects SUB socket to tcp://localhost:5556 4 | # Collects weather updates and finds avg temp in zipcode 5 | # 6 | 7 | import sys 8 | import zmq 9 | 10 | 11 | # Socket to talk to server 12 | context = zmq.Context() 13 | socket = context.socket(zmq.SUB) 14 | socket.connect("tcp://localhost:5556") 15 | socket.setsockopt_string(zmq.SUBSCRIBE, "") 16 | 17 | # Process 5 updates 18 | total_temp = 0 19 | for update_nbr in range(5): 20 | string = socket.recv_string() 21 | zipcode, temperature, relhumidity = string.split() 22 | print("============") 23 | print(update_nbr) 24 | print(zipcode) 25 | print(temperature) 26 | print(relhumidity) 27 | -------------------------------------------------------------------------------- /cmake/FindZMQ.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find ZMQ 2 | # Once done this will define 3 | # ZMQ_FOUND - System has ZMQ 4 | # ZMQ_INCLUDE_DIRS - The ZMQ include directories 5 | # ZMQ_LIBRARIES - The libraries needed to use ZMQ 6 | # ZMQ_DEFINITIONS - Compiler switches required for using ZMQ 7 | 8 | find_path ( ZMQ_INCLUDE_DIR zmq.h ) 9 | find_library ( ZMQ_LIBRARY NAMES zmq ) 10 | 11 | set ( ZMQ_LIBRARIES ${ZMQ_LIBRARY} ) 12 | set ( ZMQ_INCLUDE_DIRS ${ZMQ_INCLUDE_DIR} ) 13 | set ( ZMQ_FOUND TRUE ) 14 | 15 | include ( FindPackageHandleStandardArgs ) 16 | # handle the QUIETLY and REQUIRED arguments and set ZMQ_FOUND to TRUE 17 | # if all listed variables are TRUE 18 | find_package_handle_standard_args ( ZMQ DEFAULT_MSG ZMQ_LIBRARY ZMQ_INCLUDE_DIR ) 19 | -------------------------------------------------------------------------------- /cpp-cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5.1) 2 | project(cpp-cpp) 3 | set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 4 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 5 | set (CMAKE_CXX_STANDARD 14) 6 | 7 | find_package(ZMQ) 8 | find_package(Protobuf) 9 | 10 | #message(${ZMQ_INCLUDE_DIRS}) 11 | #message(${ZMQ_LIBRARIES}) 12 | #message(${Protobuf_INCLUDE_DIRS}) 13 | #message(${Protobuf_LIBRARIES}) 14 | #message(${Protobuf_PROTOC_LIBRARIES}) 15 | #message(${Protobuf_LITE_LIBRARIES}) 16 | 17 | include_directories(${ZMQ_INCLUDE_DIRS}) 18 | include_directories(${Protobuf_INCLUDE_DIR}) 19 | 20 | include_directories("${PROJECT_SOURCE_DIR}") 21 | include_directories("${PROJECT_SOURCE_DIR}/src") 22 | include_directories("${PROJECT_SOURCE_DIR}/include") 23 | 24 | add_subdirectory(src) 25 | -------------------------------------------------------------------------------- /py-py/msg.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package pb; 4 | 5 | enum ValueType { 6 | // the following tags correspond to hal.h: hal_type_t; 7 | HAL_BIT = 0; 8 | HAL_FLOAT = 1; 9 | HAL_S32 = 2; 10 | HAL_U32 = 3; 11 | } 12 | 13 | enum ContainerType { 14 | MT_TEST1 = 0; 15 | MT_TEST2 = 1; 16 | MT_TEST3 = 2; 17 | } 18 | message Pin { 19 | ValueType type = 1; 20 | string name = 2; 21 | 22 | // One of the following must be filled in, 23 | // depending on type. 24 | bool halbit = 5; 25 | double halfloat = 6; 26 | sfixed32 hals32 = 7; 27 | fixed32 halu32 = 8; 28 | } 29 | 30 | message Container { 31 | ContainerType type = 1; 32 | repeated string note = 2; // error text 'lines' 33 | repeated Pin pin = 3; 34 | } 35 | -------------------------------------------------------------------------------- /py-py/pb_zmq_pub.py: -------------------------------------------------------------------------------- 1 | import zmq 2 | import time 3 | import sys 4 | import binascii 5 | import google.protobuf.text_format 6 | 7 | # protoc output for testmsg.proto: 8 | from msg_pb2 import * 9 | 10 | context = zmq.Context() 11 | socket = context.socket(zmq.PUB) 12 | socket.bind("tcp://*:5556") 13 | 14 | i = 0 15 | # create example protobuf message: 16 | c = Container() 17 | c.type = MT_TEST1 18 | c.note.append("beipacktext zeile 1") 19 | c.note.append("beipacktext zeile 2") 20 | 21 | p = c.pin.add() 22 | p.name = "pi" 23 | p.type = HAL_FLOAT 24 | p.halfloat = 3.14 25 | 26 | p = c.pin.add() 27 | p.name = "e" 28 | p.type = HAL_FLOAT 29 | p.halfloat = 2.71828 30 | 31 | print (c.ByteSize()) 32 | print (str(c)) 33 | serialized_msg = c.SerializeToString() 34 | 35 | while True: 36 | 37 | i += 1 38 | print(i) 39 | socket.send(serialized_msg) 40 | time.sleep(1) 41 | -------------------------------------------------------------------------------- /cpp-py/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5.1) 2 | project(cpp-py) 3 | set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 4 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake") 5 | set (CMAKE_CXX_STANDARD 14) 6 | 7 | find_package(ZMQ) 8 | find_package(Protobuf) 9 | 10 | message(${ZMQ_INCLUDE_DIRS}) 11 | message(${ZMQ_LIBRARIES}) 12 | message(${Protobuf_INCLUDE_DIRS}) 13 | message(${Protobuf_LIBRARIES}) 14 | message(${Protobuf_PROTOC_LIBRARIES}) 15 | message(${Protobuf_LITE_LIBRARIES}) 16 | 17 | include_directories(${ZMQ_INCLUDE_DIRS}) 18 | include_directories(${Protobuf_INCLUDE_DIR}) 19 | include_directories("${PROJECT_SOURCE_DIR}") 20 | 21 | PROTOBUF_GENERATE_CPP(PROTO_SRC PROTO_HEADER msg.proto) 22 | ADD_LIBRARY(proto ${PROTO_HEADER} ${PROTO_SRC}) 23 | 24 | PROTOBUF_GENERATE_PYTHON(PROTO_PY msg.proto) 25 | add_custom_target(myTarget ALL DEPENDS ${PROTO_PY}) 26 | 27 | add_executable(pub "publisher.cpp") 28 | target_link_libraries(pub proto 29 | ${Protobuf_LIBRARIES} 30 | ${ZMQ_LIBRARIES}) 31 | -------------------------------------------------------------------------------- /cpp-py/publisher.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | zmq::context_t context (1); 12 | zmq::socket_t publisher (context, ZMQ_PUB); 13 | publisher.bind("tcp://127.0.0.1:5557"); 14 | std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 15 | 16 | int i (0); 17 | while(true) { 18 | std::string encoded_msg; 19 | RL::DataSet msg; 20 | msg.set_count(i); 21 | msg.add_joint_position(1.1); 22 | msg.add_joint_position(2.1); 23 | msg.add_joint_velocity(-1.1); 24 | msg.add_joint_velocity(-2.1); 25 | 26 | msg.SerializeToString(&encoded_msg); 27 | 28 | zmq::message_t zmq_msg(encoded_msg.size()); 29 | memcpy ((void *) zmq_msg.data(), encoded_msg.c_str(), 30 | encoded_msg.size()); 31 | publisher.send(zmq_msg); 32 | 33 | ++i; 34 | } 35 | 36 | std::cout << "pub done" << std::endl; 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /cmake/FindPnC.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find PNC 2 | # Once done this will define 3 | # PNC_FOUND - System has Gurobi 4 | # PNC_INCLUDE_DIRS - The Gurobi include directories 5 | # PNC_LIBRARIES - The libraries needed to use Gurobi 6 | 7 | find_path(PNC_INCLUDE_DIR 8 | NAMES Configuration.h 9 | PATHS "/usr/local/include/PnC" 10 | ) 11 | find_library(PNC_UTILS_LIBRARY 12 | NAMES myUtils 13 | PATHS "/usr/local/lib" 14 | ) 15 | find_library(DRACO_PNC_LIBRARY 16 | NAMES DracoPnC 17 | PATHS "/usr/local/lib" 18 | ) 19 | 20 | include(FindPackageHandleStandardArgs) 21 | 22 | if(PNC_INCLUDE_DIR) 23 | set(PNC_INCLUDE_DIRS "${PNC_INCLUDE_DIR}" ) 24 | set(PNC_LIBRARIES "${DRACO_PNC_LIBRARY};${PNC_UTILS_LIBRARY}" ) 25 | set(PNC_FOUND TRUE) 26 | message("-- Found PnC: TRUE") 27 | else() 28 | message("-- Found PnC: FALSE, Build without PnC") 29 | endif() 30 | 31 | mark_as_advanced( PNC_INCLUDE_DIR 32 | DRACO_PNC_LIBRARY 33 | PNC_UTILS_LIBRARY ) 34 | -------------------------------------------------------------------------------- /cpp-cpp/src/msg.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | // Simple messages. 4 | message ZmqPBExampleRequest { 5 | string request_string = 1; 6 | int32 request_number = 2; 7 | } 8 | 9 | message ZmqPBExampleResponse { 10 | string response_string = 1; 11 | int32 response_number = 2; 12 | } 13 | 14 | // RPC wrapper messages. 15 | message ZmqPBExampleRPCRequest { 16 | string service = 1; 17 | string method = 2; 18 | bytes protobuf = 3; 19 | } 20 | 21 | message ZmqPBExampleRPCResponse { 22 | bytes protobuf = 1; 23 | string error = 2; 24 | } 25 | 26 | enum RPCError { 27 | NO_SERVICE = 0; 28 | NO_METHOD = 1; 29 | BAD_REQUEST = 2; 30 | } 31 | 32 | // our specific rpc call request and response messages 33 | message RPCAddRequest { 34 | uint32 term1 = 1; 35 | uint32 term2 = 2; 36 | } 37 | 38 | message RPCAddResponse { 39 | uint32 sum = 1; 40 | } 41 | 42 | message RPCReverseRequest { 43 | string to_reverse = 1; 44 | } 45 | 46 | message RPCReverseResponse { 47 | string reversed = 1; 48 | } 49 | 50 | // weather buffer 51 | message ZmqPBExampleWeather { 52 | uint32 zipcode = 1; 53 | uint32 temperature = 2; 54 | uint32 relhumidity = 3; 55 | } 56 | 57 | // worker requests and responses 58 | message ZmqPBExampleWorkerRequest { 59 | string string_in = 1; 60 | } 61 | 62 | message ZmqPBExampleWorkerResponse { 63 | string string_out = 1; 64 | } 65 | -------------------------------------------------------------------------------- /cpp-cpp/src/proto/msg.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | // Simple messages. 4 | message ZmqPBExampleRequest { 5 | string request_string = 1; 6 | int32 request_number = 2; 7 | } 8 | 9 | message ZmqPBExampleResponse { 10 | string response_string = 1; 11 | int32 response_number = 2; 12 | } 13 | 14 | // RPC wrapper messages. 15 | message ZmqPBExampleRPCRequest { 16 | string service = 1; 17 | string method = 2; 18 | bytes protobuf = 3; 19 | } 20 | 21 | message ZmqPBExampleRPCResponse { 22 | bytes protobuf = 1; 23 | string error = 2; 24 | } 25 | 26 | enum RPCError { 27 | NO_SERVICE = 0; 28 | NO_METHOD = 1; 29 | BAD_REQUEST = 2; 30 | } 31 | 32 | // our specific rpc call request and response messages 33 | message RPCAddRequest { 34 | uint32 term1 = 1; 35 | uint32 term2 = 2; 36 | } 37 | 38 | message RPCAddResponse { 39 | uint32 sum = 1; 40 | } 41 | 42 | message RPCReverseRequest { 43 | string to_reverse = 1; 44 | } 45 | 46 | message RPCReverseResponse { 47 | string reversed = 1; 48 | } 49 | 50 | // weather buffer 51 | message ZmqPBExampleWeather { 52 | uint32 zipcode = 1; 53 | uint32 temperature = 2; 54 | uint32 relhumidity = 3; 55 | } 56 | 57 | // worker requests and responses 58 | message ZmqPBExampleWorkerRequest { 59 | string string_in = 1; 60 | } 61 | 62 | message ZmqPBExampleWorkerResponse { 63 | string string_out = 1; 64 | } 65 | -------------------------------------------------------------------------------- /cmake/FindMosek.cmake: -------------------------------------------------------------------------------- 1 | # Try to find MOSEK 2 | # Once done this will define 3 | # MOSEK_FOUND - system has MOSEK 4 | # MOSEK_INCLUDE_DIRS - the MOSEK include directories 5 | # MOSEK_LIBRARIES - Link these to use MOSEK 6 | 7 | set (MOSEK_HOME $ENV{MOSEK_HOME}) 8 | 9 | find_path(MOSEK_INCLUDE_DIR 10 | NAMES mosek.h 11 | PATHS "${MOSEK_HOME}/h" 12 | ) 13 | 14 | find_library(MOSEK_LIBRARY 15 | NAMES mosek64 16 | PATHS "${MOSEK_HOME}/bin" 17 | ) 18 | 19 | find_library(MOSEK_LIBRARY_EXTENSION 20 | NAMES mosek64.8.1 21 | PATHS "${MOSEK_HOME}/bin" 22 | ) 23 | 24 | find_library(FUSION_LIBRARY 25 | NAMES fusion64 26 | fusion64.8.1 27 | PATHS "${MOSEK_HOME/bin}" 28 | ) 29 | 30 | find_library(FUSION_LIBRARY_EXTENSION 31 | NAMES fusion64.8.1 32 | PATHS "${MOSEK_HOME/bin}" 33 | ) 34 | 35 | 36 | include(FindPackageHandleStandardArgs) 37 | 38 | if(MOSEK_INCLUDE_DIR) 39 | set(MOSEK_INCLUDE_DIRS "${MOSEK_INCLUDE_DIR}") 40 | set(MOSEK_LIBRARIES "${MOSEK_LIBRARY};${MOSEK_LIBRARY_EXTENSION};${FUSION_LIBRARY};${FUSION_LIBRARY_EXTENSION}") 41 | set(MOSEK_FOUND TRUE) 42 | message("-- Found Mosek: TRUE") 43 | else() 44 | message("-- Found Mosek: FALSE, Build without Mosek") 45 | endif() 46 | 47 | mark_as_advanced(MOSEK_HOME 48 | MOSEK_INCLUDE_DIR 49 | MOSEK_LIBRARY 50 | FUSION_LIBRARY 51 | ) 52 | -------------------------------------------------------------------------------- /cmake/FindGurobi.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find GUROBI 2 | # Once done this will define 3 | # GUROBI_FOUND - System has Gurobi 4 | # GUROBI_INCLUDE_DIRS - The Gurobi include directories 5 | # GUROBI_LIBRARIES - The libraries needed to use Gurobi 6 | 7 | set (GUROBI_HOME $ENV{GUROBI_HOME}) 8 | 9 | find_path(GUROBI_INCLUDE_DIR 10 | NAMES gurobi_c++.h 11 | PATHS "${GUROBI_HOME}/include" 12 | ) 13 | 14 | find_library(GUROBI_LIBRARY 15 | NAMES gurobi 16 | gurobi45 17 | gurobi46 18 | gurobi50 19 | gurobi51 20 | gurobi52 21 | gurobi55 22 | gurobi56 23 | gurobi60 24 | gurobi65 25 | gurobi70 26 | gurobi80 27 | PATHS "${GUROBI_HOME}/lib" 28 | ) 29 | 30 | find_library(GUROBI_CXX_LIBRARY 31 | NAMES gurobi_c++ 32 | PATHS "$ENV{GUROBI_HOME}/lib" 33 | ) 34 | 35 | include(FindPackageHandleStandardArgs) 36 | 37 | if(GUROBI_INCLUDE_DIR) 38 | set(GUROBI_INCLUDE_DIRS "${GUROBI_INCLUDE_DIR}" ) 39 | set(GUROBI_LIBRARIES "${GUROBI_LIBRARY};${GUROBI_CXX_LIBRARY}" ) 40 | set(GUROBI_FOUND TRUE) 41 | message("-- Found Gurobi: TRUE") 42 | else() 43 | message("-- Found Gurobi: FALSE, Build without Gurobi") 44 | endif() 45 | 46 | mark_as_advanced(GUROBI_HOME 47 | GUROBI_INCLUDE_DIR 48 | GUROBI_LIBRARY 49 | GUROBI_CXX_LIBRARY 50 | ) 51 | -------------------------------------------------------------------------------- /cpp-cpp/src/publisher.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include "build/src/proto/msg.pb.h" 6 | 7 | #include 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | // publish 12 | zmq::context_t context (1); 13 | zmq::socket_t publisher (context, ZMQ_PUB); 14 | publisher.bind("tcp://127.0.0.1:5557"); 15 | 16 | while(1) 17 | { 18 | // encoded_message : protobuf all 19 | // serialized_update : protobuf one segment 20 | // message : zmq 21 | // update : my msg 22 | using namespace google::protobuf::io; 23 | std::string encoded_message; 24 | ZeroCopyOutputStream* raw_output = 25 | new StringOutputStream(&encoded_message); 26 | CodedOutputStream* coded_output = new CodedOutputStream(raw_output); 27 | 28 | int num_updates = 10; 29 | 30 | // prefix the stream with the number of updates 31 | coded_output->WriteLittleEndian32(num_updates); 32 | int update_nbr; 33 | 34 | // create a bunch of updates, serialize them and add them 35 | // to the stream 36 | for(update_nbr = 0; update_nbr < num_updates; update_nbr++) { 37 | 38 | ZmqPBExampleWeather update; 39 | update.set_zipcode( 78731 ); 40 | update.set_temperature( 78 ); 41 | update.set_relhumidity( 10 ); 42 | 43 | std::string serialized_update; 44 | update.SerializeToString(&serialized_update); 45 | 46 | coded_output->WriteVarint32(serialized_update.size()); 47 | coded_output->WriteString(serialized_update); 48 | } 49 | // clean up 50 | delete coded_output; 51 | delete raw_output; 52 | 53 | zmq::message_t message(encoded_message.size()); 54 | memcpy ((void *) message.data(), encoded_message.c_str(), 55 | encoded_message.size()); 56 | 57 | publisher.send(message); 58 | } 59 | 60 | std::cout << "done pub" << std::endl; 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /cpp-cpp/src/my_publisher.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | #include 7 | #include 8 | #include "build/src/proto/my_msg.pb.h" 9 | 10 | #include "zmq.hpp" 11 | 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | using namespace google::protobuf::io; 16 | // publish 17 | zmq::context_t context (1); 18 | zmq::socket_t publisher (context, ZMQ_PUB); 19 | publisher.bind("tcp://127.0.0.1:5557"); 20 | std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 21 | 22 | uint32_t idx(0); 23 | // sending (jpos, jvel) 2 times 24 | while(1) { 25 | std::string encoded_message; 26 | 27 | ZeroCopyOutputStream* raw_output = 28 | new StringOutputStream(&encoded_message); 29 | CodedOutputStream* coded_output = new CodedOutputStream(raw_output); 30 | 31 | coded_output->WriteLittleEndian32(2); 32 | JointPosition pos_msg; 33 | pos_msg.set_count(idx); 34 | pos_msg.add_q(2.1); 35 | pos_msg.add_q(2.2); 36 | std::string pos_msg_serialized; 37 | pos_msg.SerializeToString(&pos_msg_serialized); 38 | 39 | coded_output->WriteVarint32(pos_msg_serialized.size()); 40 | coded_output->WriteString(pos_msg_serialized); 41 | 42 | JointVelocity vel_msg; 43 | vel_msg.set_count(idx); 44 | vel_msg.add_qdot(-1.1); 45 | vel_msg.add_qdot(-2.1); 46 | vel_msg.add_qdot(-3.1); 47 | std::string vel_msg_serialized; 48 | vel_msg.SerializeToString(&vel_msg_serialized); 49 | 50 | coded_output->WriteVarint32(vel_msg_serialized.size()); 51 | coded_output->WriteString(vel_msg_serialized); 52 | 53 | delete coded_output; 54 | delete raw_output; 55 | 56 | zmq::message_t message(encoded_message.size()); 57 | memcpy ((void *) message.data(), encoded_message.c_str(), 58 | encoded_message.size()); 59 | publisher.send(message); 60 | 61 | ++idx; 62 | } 63 | 64 | std::cout << "done pub" << std::endl; 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /cpp-cpp/src/my_subscriber.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include "build/src/proto/my_msg.pb.h" 8 | 9 | #include 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | using namespace google::protobuf::io; 14 | 15 | zmq::context_t context (1); 16 | zmq::socket_t subscriber (context, ZMQ_SUB); 17 | subscriber.connect("tcp://127.0.0.1:5557"); 18 | subscriber.setsockopt(ZMQ_SUBSCRIBE, NULL, 0); 19 | std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 20 | 21 | while (1) { 22 | zmq::message_t update; 23 | subscriber.recv(&update); 24 | 25 | ZeroCopyInputStream* raw_input = 26 | new ArrayInputStream(update.data(), update.size()); 27 | CodedInputStream* coded_input = new CodedInputStream(raw_input); 28 | 29 | uint32_t num_msg; 30 | coded_input->ReadLittleEndian32(&num_msg); 31 | 32 | std::string serialized_msg; 33 | uint32_t serialized_size; 34 | JointPosition jpos_msg; 35 | coded_input->ReadVarint32(&serialized_size); 36 | coded_input->ReadString(&serialized_msg, serialized_size); 37 | jpos_msg.ParseFromString(serialized_msg); 38 | std::cout << "joint position" << std::endl; 39 | std::cout << "count : " << jpos_msg.count() << std::endl; 40 | for (int i = 0; i < jpos_msg.q_size(); ++i) { 41 | std::cout << i << " th q : " << jpos_msg.q(i) << std::endl; 42 | } 43 | 44 | std::string serialized_msg_2; 45 | uint32_t serialized_size2; 46 | JointVelocity jvel_msg; 47 | coded_input->ReadVarint32(&serialized_size2); 48 | coded_input->ReadString(&serialized_msg_2, serialized_size2); 49 | jvel_msg.ParseFromString(serialized_msg_2); 50 | std::cout << "joint velocity" << std::endl; 51 | std::cout << "count : " << jvel_msg.count() << std::endl; 52 | for (int i = 0; i < jvel_msg.qdot_size(); ++i) { 53 | std::cout << i << " th qdot : " << jvel_msg.qdot(i) << std::endl; 54 | } 55 | 56 | delete raw_input; 57 | delete coded_input; 58 | if (jvel_msg.count() == 12) { 59 | break; 60 | } 61 | } 62 | 63 | std::cout << "done sub" << std::endl; 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /cpp-cpp/src/subscriber.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include "build/src/proto/msg.pb.h" 6 | 7 | #include 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | using namespace google::protobuf::io; 12 | 13 | zmq::context_t context (1); 14 | zmq::socket_t subscriber (context, ZMQ_SUB); 15 | subscriber.connect("tcp://127.0.0.1:5557"); 16 | subscriber.setsockopt(ZMQ_SUBSCRIBE, NULL, 0); 17 | 18 | int update_nbr; 19 | for (update_nbr = 0; update_nbr < 10; update_nbr++) { 20 | // encoded_message : protobuf all 21 | // serialized_update : protobuf one segment 22 | // message : zmq 23 | // update : my msg 24 | 25 | zmq::message_t update; 26 | subscriber.recv(&update); 27 | 28 | // use protocol buffer's io stuff to package up a bunch of stuff into 29 | // one stream of serialized messages. the first part of the stream 30 | // is the number of messages. next, each message is preceeded by its 31 | // size in bytes. 32 | ZeroCopyInputStream* raw_input = 33 | new ArrayInputStream(update.data(), update.size()); 34 | CodedInputStream* coded_input = new CodedInputStream(raw_input); 35 | 36 | // find out how many updates are in this message 37 | uint32_t num_updates; 38 | coded_input->ReadLittleEndian32(&num_updates); 39 | std::cout << "received update " << update_nbr << std::endl; 40 | 41 | // now for each message in the stream, find the size and parse it ... 42 | for(int i = 0; i < num_updates; i++) { 43 | 44 | std::cout << "\titem: " << i << std::endl; 45 | 46 | std::string serialized_update; 47 | uint32_t serialized_size; 48 | ZmqPBExampleWeather weather_update; 49 | 50 | // the message size 51 | coded_input->ReadVarint32(&serialized_size); 52 | // the serialized message data 53 | coded_input->ReadString(&serialized_update, serialized_size); 54 | 55 | // parse it 56 | weather_update.ParseFromString(serialized_update); 57 | std::cout << "\t\tzip: " << weather_update.zipcode() << std::endl; 58 | std::cout << "\t\ttemperature: " << weather_update.temperature() << 59 | std::endl; 60 | std::cout << "\t\trelative humidity: " << 61 | weather_update.relhumidity() << std::endl; 62 | } 63 | 64 | delete coded_input; 65 | delete raw_input; 66 | } 67 | 68 | std::cout << "done sub" << std::endl; 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /cmake/FindPythonAnaconda.cmake: -------------------------------------------------------------------------------- 1 | # tested on OSX Yosemite and Ubuntu 14.04 LTS 2 | # handle anaconda dependencies 3 | cmake_minimum_required(VERSION 3.7) 4 | 5 | option(ANACONDA_PYTHON_VERBOSE "Anaconda dependency info" OFF) 6 | 7 | if(NOT CMAKE_FIND_ANACONDA_PYTHON_INCLUDED) 8 | set(CMAKE_FIND_ANACONDA_PYTHON_INCLUDED 1) 9 | 10 | # find anaconda installation 11 | set(_cmd conda info --root) 12 | execute_process( 13 | COMMAND ${_cmd} 14 | RESULT_VARIABLE _r 15 | OUTPUT_VARIABLE _o 16 | ERROR_VARIABLE _e 17 | OUTPUT_STRIP_TRAILING_WHITESPACE 18 | ERROR_STRIP_TRAILING_WHITESPACE 19 | ) 20 | 21 | if(ANACONDA_PYTHON_VERBOSE) 22 | message("Executing conda info --root") 23 | message("_r = ${_r}") 24 | message("_o = ${_o}") 25 | message("_e = ${_e}") 26 | endif() 27 | 28 | IF(IS_DIRECTORY ${_o}) 29 | set(ANACONDA_PYTHON_FOUND True) 30 | endif() 31 | 32 | if(ANACONDA_PYTHON_FOUND) 33 | set( ANACONDA_PYTHON_DIR ${_o} ) 34 | message( "-- Found anaconda root directory ${ANACONDA_PYTHON_DIR}" ) 35 | 36 | # find python version 37 | # 38 | set(_cmd python --version) 39 | execute_process( 40 | COMMAND ${_cmd} 41 | RESULT_VARIABLE _r 42 | OUTPUT_VARIABLE _o 43 | ERROR_VARIABLE _e 44 | OUTPUT_STRIP_TRAILING_WHITESPACE 45 | ERROR_STRIP_TRAILING_WHITESPACE 46 | ) 47 | 48 | if(ANACONDA_PYTHON_VERBOSE) 49 | message("Executing python --version") 50 | message("_r = ${_r}") 51 | message("_o = ${_o}") 52 | message("_e = ${_e}") 53 | endif() 54 | 55 | if(_e) 56 | set (_o = ${_e}) 57 | endif() 58 | 59 | string (REGEX MATCH "Python ([0-9]+)[.]([0-9]+)[.]([0-9]+)" _py_version_found "${_o}") 60 | #message("_py_version_found = ${_py_version_found}") 61 | #message("CMAKE_MATCH_0 = ${CMAKE_MATCH_0}") 62 | set( _py_version_major ${CMAKE_MATCH_1} ) 63 | set( _py_version_minor ${CMAKE_MATCH_2} ) 64 | set( _py_version_patch ${CMAKE_MATCH_3} ) 65 | set( ANACONDA_PYTHON_VERSION ${_py_version_major}.${_py_version_minor} ) 66 | 67 | if( ${_py_version_major} MATCHES 2 ) 68 | set( _py_ext "") 69 | else() 70 | set( _py_ext "m") 71 | endif() 72 | 73 | set(_py_id "python${ANACONDA_PYTHON_VERSION}${_py_ext}") 74 | 75 | if( NOT DEFINED ENV{CONDA_DEFAULT_ENV} ) 76 | set( env_CONDA_DEFAULT_ENV "root" ) 77 | message( "-- Could not find anaconda environment setting; using default root" ) 78 | else() 79 | set( env_CONDA_DEFAULT_ENV $ENV{CONDA_DEFAULT_ENV} ) 80 | endif() 81 | 82 | message( "-- Using anaconda ${env_CONDA_DEFAULT_ENV} environment" ) 83 | if( env_CONDA_DEFAULT_ENV STREQUAL "root" ) 84 | set(PYTHON_INCLUDE_DIR "${ANACONDA_PYTHON_DIR}/include/${_py_id}" CACHE INTERNAL "") 85 | set(PYTHON_LIBRARY "${ANACONDA_PYTHON_DIR}/lib/lib${_py_id}${CMAKE_SHARED_LIBRARY_SUFFIX}" CACHE INTERNAL "") 86 | set(PYTHON_EXECUTABLE "${ANACONDA_PYTHON_DIR}/bin/${_py_id}" CACHE INTERNAL "") 87 | else() 88 | set(PYTHON_INCLUDE_DIR "${ANACONDA_PYTHON_DIR}/envs/${env_CONDA_DEFAULT_ENV}/include/${_py_id}" CACHE INTERNAL "") 89 | set(PYTHON_LIBRARY "${ANACONDA_PYTHON_DIR}/envs/${env_CONDA_DEFAULT_ENV}/lib/lib${_py_id}${CMAKE_SHARED_LIBRARY_SUFFIX}" CACHE INTERNAL "") 90 | set(PYTHON_EXECUTABLE "${ANACONDA_PYTHON_DIR}/envs/${env_CONDA_DEFAULT_ENV}/bin/${_py_id}" CACHE INTERNAL "") 91 | endif() 92 | 93 | set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}") 94 | set(PYTHON_LIBRARIES "${PYTHON_LIBRARY}") 95 | set(PYTHON_EXECUTABLES "${PYTHON_EXECUTABLE}") 96 | 97 | set(FOUND_PYTHONLIBS TRUE) 98 | else() 99 | message( "Not found: anaconda root directory..." ) 100 | message( "Trying system python install..." ) 101 | FindPythonLibs() 102 | endif() 103 | 104 | message( "-- PYTHON_INCLUDE_DIR = ${PYTHON_INCLUDE_DIR}") 105 | message( "-- PYTHON_LIBRARY = ${PYTHON_LIBRARY}") 106 | message( "-- PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}") 107 | endif() 108 | -------------------------------------------------------------------------------- /cmake/FindGFlags.cmake: -------------------------------------------------------------------------------- 1 | # -*- mode: cmake -*- 2 | # vi: set ft=cmake : 3 | 4 | # Copyright (c) 2018, Massachusetts Institute of Technology. 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions are met: 9 | # 10 | # * Redistributions of source code must retain the above copyright notice, this 11 | # list of conditions and the following disclaimer. 12 | # 13 | # * Redistributions in binary form must reproduce the above copyright notice, 14 | # this list of conditions and the following disclaimer in the documentation 15 | # and/or other materials provided with the distribution. 16 | # 17 | # * Neither the name of the copyright holder nor the names of its contributors 18 | # may be used to endorse or promote products derived from this software 19 | # without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | 33 | function(_gflags_find_library _NAME) 34 | string(TOUPPER ${_NAME} _NAME_UPPER) 35 | 36 | set(_LIBRARY_VAR GFLAGS_${_NAME_UPPER}_LIBRARY) 37 | set(_TARGET gflags_${_NAME}) 38 | 39 | if(_NAME MATCHES static$) 40 | set(_SHARED_STATIC STATIC) 41 | else() 42 | set(_SHARED_STATIC SHARED) 43 | endif() 44 | 45 | if(_NAME MATCHES ^nothreads) 46 | set(_NOTHREADS _nothreads) 47 | else() 48 | set(_NOTHREADS) 49 | endif() 50 | 51 | find_library(${_LIBRARY_VAR} 52 | NAMES ${CMAKE_${_SHARED_STATIC}_LIBRARY_PREFIX}gflags${_NOTHREADS}${CMAKE_${_SHARED_STATIC}_LIBRARY_SUFFIX} 53 | HINTS "${PC_GFLAGS_LIBRARY_DIRS}" 54 | ) 55 | 56 | set(GFlags_${_NAME}_FIND_QUIETLY ON) 57 | find_package_handle_standard_args(GFlags_${_NAME} 58 | REQUIRED_VARS GFLAGS_INCLUDE_DIR ${_LIBRARY_VAR} 59 | ) 60 | 61 | if(GFlags_${_NAME}_FOUND) 62 | set(GFlags_${_NAME}_FOUND ON PARENT_SCOPE) 63 | mark_as_advanced(${_LIBRARY_VAR}) 64 | 65 | add_library(${_TARGET} ${_SHARED_STATIC} IMPORTED) 66 | set_target_properties(${_TARGET} PROPERTIES 67 | IMPORTED_LOCATION "${${_LIBRARY_VAR}}" 68 | INTERFACE_INCLUDE_DIRECTORIES "${GFLAGS_INCLUDE_DIRS}" 69 | ) 70 | 71 | if(_NAME MATCHES static$) 72 | set_target_properties(${_TARGET} PROPERTIES 73 | IMPORTED_LINK_INTERFACE_LANGUAGES CXX 74 | INTERFACE_COMPILE_DEFINITIONS GFLAGS_IS_A_DLL=0 75 | ) 76 | else() 77 | if(WIN32) 78 | set_target_properties(${_TARGET} PROPERTIES 79 | INTERFACE_COMPILE_DEFINITIONS GFLAGS_IS_A_DLL=1 80 | ) 81 | else() 82 | set_target_properties(${_TARGET} PROPERTIES 83 | INTERFACE_COMPILE_DEFINITIONS GFLAGS_IS_A_DLL=0 84 | ) 85 | endif() 86 | endif() 87 | 88 | if(_NAME STREQUAL static) 89 | find_package(Threads QUIET) 90 | 91 | if(Threads_FOUND) 92 | set_target_properties(${_TARGET} PROPERTIES 93 | INTERFACE_LINK_LIBRARIES $ 94 | ) 95 | endif() 96 | endif() 97 | endif() 98 | endfunction() 99 | 100 | if(NOT GFlags_FIND_COMPONENTS) 101 | set(GFlags_FIND_COMPONENTS nothreads_shared) 102 | set(GFlags_FIND_REQUIRED_nothreads_shared ${GFlags_FIND_REQUIRED}) 103 | endif() 104 | 105 | find_package(PkgConfig QUIET) 106 | 107 | set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON) 108 | pkg_check_modules(PC_GFLAGS QUIET gflags) 109 | 110 | if(GFLAGS_VERSION_STRING) 111 | set(GFLAGS_VERSION_STRING "${PC_GFLAGS_VERSION}") 112 | else() 113 | set(GFLAGS_VERSION_STRING) 114 | endif() 115 | 116 | find_path(GFLAGS_INCLUDE_DIR NAMES gflags/gflags.h 117 | HINTS "${PC_GFLAGS_INCLUDE_DIRS}" 118 | ) 119 | 120 | foreach(_GFLAGS_COMPONENT ${GFlags_FIND_COMPONENTS}) 121 | _gflags_find_library(${_GFLAGS_COMPONENT}) 122 | endforeach() 123 | 124 | if(GFLAGS_NOTHREADS_SHARED_LIBRARY) 125 | set(GFLAGS_LIBRARY gflags_nothreads_shared) 126 | elseif(GFLAGS_NOTHREADS_STATIC_LIBRARY) 127 | set(GFLAGS_LIBRARY gflags_nothreads_static) 128 | elseif(GFLAGS_SHARED_LIBRARY) 129 | set(GFLAGS_LIBRARY gflags_shared) 130 | elseif(GFLAGS_STATIC_LIBRARY) 131 | set(GFLAGS_LIBRARY gflags_static) 132 | else() 133 | set(GFLAGS_LIBRARY) 134 | endif() 135 | 136 | include(FindPackageHandleStandardArgs) 137 | 138 | find_package_handle_standard_args(GFlags 139 | REQUIRED_VARS GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY 140 | VERSION_VAR GFLAGS_VERSION_STRING 141 | HANDLE_COMPONENTS 142 | ) 143 | 144 | if(GFLAGS_FOUND) 145 | set(GFLAGS_INCLUDE_DIRS "${GFLAGS_INCLUDE_DIR}") 146 | set(GFLAGS_LIBRARIES "${GFLAGS_LIBRARY}") 147 | mark_as_advanced(GFLAGS_INCLUDE_DIR) 148 | endif() 149 | -------------------------------------------------------------------------------- /py-py/msg_pb2.py: -------------------------------------------------------------------------------- 1 | # Generated by the protocol buffer compiler. DO NOT EDIT! 2 | # source: msg.proto 3 | 4 | import sys 5 | _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) 6 | from google.protobuf.internal import enum_type_wrapper 7 | from google.protobuf import descriptor as _descriptor 8 | from google.protobuf import message as _message 9 | from google.protobuf import reflection as _reflection 10 | from google.protobuf import symbol_database as _symbol_database 11 | # @@protoc_insertion_point(imports) 12 | 13 | _sym_db = _symbol_database.Default() 14 | 15 | 16 | 17 | 18 | DESCRIPTOR = _descriptor.FileDescriptor( 19 | name='msg.proto', 20 | package='pb', 21 | syntax='proto3', 22 | serialized_options=None, 23 | serialized_pb=_b('\n\tmsg.proto\x12\x02pb\"r\n\x03Pin\x12\x1b\n\x04type\x18\x01 \x01(\x0e\x32\r.pb.ValueType\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x0e\n\x06halbit\x18\x05 \x01(\x08\x12\x10\n\x08halfloat\x18\x06 \x01(\x01\x12\x0e\n\x06hals32\x18\x07 \x01(\x0f\x12\x0e\n\x06halu32\x18\x08 \x01(\x07\"P\n\tContainer\x12\x1f\n\x04type\x18\x01 \x01(\x0e\x32\x11.pb.ContainerType\x12\x0c\n\x04note\x18\x02 \x03(\t\x12\x14\n\x03pin\x18\x03 \x03(\x0b\x32\x07.pb.Pin*A\n\tValueType\x12\x0b\n\x07HAL_BIT\x10\x00\x12\r\n\tHAL_FLOAT\x10\x01\x12\x0b\n\x07HAL_S32\x10\x02\x12\x0b\n\x07HAL_U32\x10\x03*9\n\rContainerType\x12\x0c\n\x08MT_TEST1\x10\x00\x12\x0c\n\x08MT_TEST2\x10\x01\x12\x0c\n\x08MT_TEST3\x10\x02\x62\x06proto3') 24 | ) 25 | 26 | _VALUETYPE = _descriptor.EnumDescriptor( 27 | name='ValueType', 28 | full_name='pb.ValueType', 29 | filename=None, 30 | file=DESCRIPTOR, 31 | values=[ 32 | _descriptor.EnumValueDescriptor( 33 | name='HAL_BIT', index=0, number=0, 34 | serialized_options=None, 35 | type=None), 36 | _descriptor.EnumValueDescriptor( 37 | name='HAL_FLOAT', index=1, number=1, 38 | serialized_options=None, 39 | type=None), 40 | _descriptor.EnumValueDescriptor( 41 | name='HAL_S32', index=2, number=2, 42 | serialized_options=None, 43 | type=None), 44 | _descriptor.EnumValueDescriptor( 45 | name='HAL_U32', index=3, number=3, 46 | serialized_options=None, 47 | type=None), 48 | ], 49 | containing_type=None, 50 | serialized_options=None, 51 | serialized_start=215, 52 | serialized_end=280, 53 | ) 54 | _sym_db.RegisterEnumDescriptor(_VALUETYPE) 55 | 56 | ValueType = enum_type_wrapper.EnumTypeWrapper(_VALUETYPE) 57 | _CONTAINERTYPE = _descriptor.EnumDescriptor( 58 | name='ContainerType', 59 | full_name='pb.ContainerType', 60 | filename=None, 61 | file=DESCRIPTOR, 62 | values=[ 63 | _descriptor.EnumValueDescriptor( 64 | name='MT_TEST1', index=0, number=0, 65 | serialized_options=None, 66 | type=None), 67 | _descriptor.EnumValueDescriptor( 68 | name='MT_TEST2', index=1, number=1, 69 | serialized_options=None, 70 | type=None), 71 | _descriptor.EnumValueDescriptor( 72 | name='MT_TEST3', index=2, number=2, 73 | serialized_options=None, 74 | type=None), 75 | ], 76 | containing_type=None, 77 | serialized_options=None, 78 | serialized_start=282, 79 | serialized_end=339, 80 | ) 81 | _sym_db.RegisterEnumDescriptor(_CONTAINERTYPE) 82 | 83 | ContainerType = enum_type_wrapper.EnumTypeWrapper(_CONTAINERTYPE) 84 | HAL_BIT = 0 85 | HAL_FLOAT = 1 86 | HAL_S32 = 2 87 | HAL_U32 = 3 88 | MT_TEST1 = 0 89 | MT_TEST2 = 1 90 | MT_TEST3 = 2 91 | 92 | 93 | 94 | _PIN = _descriptor.Descriptor( 95 | name='Pin', 96 | full_name='pb.Pin', 97 | filename=None, 98 | file=DESCRIPTOR, 99 | containing_type=None, 100 | fields=[ 101 | _descriptor.FieldDescriptor( 102 | name='type', full_name='pb.Pin.type', index=0, 103 | number=1, type=14, cpp_type=8, label=1, 104 | has_default_value=False, default_value=0, 105 | message_type=None, enum_type=None, containing_type=None, 106 | is_extension=False, extension_scope=None, 107 | serialized_options=None, file=DESCRIPTOR), 108 | _descriptor.FieldDescriptor( 109 | name='name', full_name='pb.Pin.name', index=1, 110 | number=2, type=9, cpp_type=9, label=1, 111 | has_default_value=False, default_value=_b("").decode('utf-8'), 112 | message_type=None, enum_type=None, containing_type=None, 113 | is_extension=False, extension_scope=None, 114 | serialized_options=None, file=DESCRIPTOR), 115 | _descriptor.FieldDescriptor( 116 | name='halbit', full_name='pb.Pin.halbit', index=2, 117 | number=5, type=8, cpp_type=7, label=1, 118 | has_default_value=False, default_value=False, 119 | message_type=None, enum_type=None, containing_type=None, 120 | is_extension=False, extension_scope=None, 121 | serialized_options=None, file=DESCRIPTOR), 122 | _descriptor.FieldDescriptor( 123 | name='halfloat', full_name='pb.Pin.halfloat', index=3, 124 | number=6, type=1, cpp_type=5, label=1, 125 | has_default_value=False, default_value=float(0), 126 | message_type=None, enum_type=None, containing_type=None, 127 | is_extension=False, extension_scope=None, 128 | serialized_options=None, file=DESCRIPTOR), 129 | _descriptor.FieldDescriptor( 130 | name='hals32', full_name='pb.Pin.hals32', index=4, 131 | number=7, type=15, cpp_type=1, label=1, 132 | has_default_value=False, default_value=0, 133 | message_type=None, enum_type=None, containing_type=None, 134 | is_extension=False, extension_scope=None, 135 | serialized_options=None, file=DESCRIPTOR), 136 | _descriptor.FieldDescriptor( 137 | name='halu32', full_name='pb.Pin.halu32', index=5, 138 | number=8, type=7, cpp_type=3, label=1, 139 | has_default_value=False, default_value=0, 140 | message_type=None, enum_type=None, containing_type=None, 141 | is_extension=False, extension_scope=None, 142 | serialized_options=None, file=DESCRIPTOR), 143 | ], 144 | extensions=[ 145 | ], 146 | nested_types=[], 147 | enum_types=[ 148 | ], 149 | serialized_options=None, 150 | is_extendable=False, 151 | syntax='proto3', 152 | extension_ranges=[], 153 | oneofs=[ 154 | ], 155 | serialized_start=17, 156 | serialized_end=131, 157 | ) 158 | 159 | 160 | _CONTAINER = _descriptor.Descriptor( 161 | name='Container', 162 | full_name='pb.Container', 163 | filename=None, 164 | file=DESCRIPTOR, 165 | containing_type=None, 166 | fields=[ 167 | _descriptor.FieldDescriptor( 168 | name='type', full_name='pb.Container.type', index=0, 169 | number=1, type=14, cpp_type=8, label=1, 170 | has_default_value=False, default_value=0, 171 | message_type=None, enum_type=None, containing_type=None, 172 | is_extension=False, extension_scope=None, 173 | serialized_options=None, file=DESCRIPTOR), 174 | _descriptor.FieldDescriptor( 175 | name='note', full_name='pb.Container.note', index=1, 176 | number=2, type=9, cpp_type=9, label=3, 177 | has_default_value=False, default_value=[], 178 | message_type=None, enum_type=None, containing_type=None, 179 | is_extension=False, extension_scope=None, 180 | serialized_options=None, file=DESCRIPTOR), 181 | _descriptor.FieldDescriptor( 182 | name='pin', full_name='pb.Container.pin', index=2, 183 | number=3, type=11, cpp_type=10, label=3, 184 | has_default_value=False, default_value=[], 185 | message_type=None, enum_type=None, containing_type=None, 186 | is_extension=False, extension_scope=None, 187 | serialized_options=None, file=DESCRIPTOR), 188 | ], 189 | extensions=[ 190 | ], 191 | nested_types=[], 192 | enum_types=[ 193 | ], 194 | serialized_options=None, 195 | is_extendable=False, 196 | syntax='proto3', 197 | extension_ranges=[], 198 | oneofs=[ 199 | ], 200 | serialized_start=133, 201 | serialized_end=213, 202 | ) 203 | 204 | _PIN.fields_by_name['type'].enum_type = _VALUETYPE 205 | _CONTAINER.fields_by_name['type'].enum_type = _CONTAINERTYPE 206 | _CONTAINER.fields_by_name['pin'].message_type = _PIN 207 | DESCRIPTOR.message_types_by_name['Pin'] = _PIN 208 | DESCRIPTOR.message_types_by_name['Container'] = _CONTAINER 209 | DESCRIPTOR.enum_types_by_name['ValueType'] = _VALUETYPE 210 | DESCRIPTOR.enum_types_by_name['ContainerType'] = _CONTAINERTYPE 211 | _sym_db.RegisterFileDescriptor(DESCRIPTOR) 212 | 213 | Pin = _reflection.GeneratedProtocolMessageType('Pin', (_message.Message,), dict( 214 | DESCRIPTOR = _PIN, 215 | __module__ = 'msg_pb2' 216 | # @@protoc_insertion_point(class_scope:pb.Pin) 217 | )) 218 | _sym_db.RegisterMessage(Pin) 219 | 220 | Container = _reflection.GeneratedProtocolMessageType('Container', (_message.Message,), dict( 221 | DESCRIPTOR = _CONTAINER, 222 | __module__ = 'msg_pb2' 223 | # @@protoc_insertion_point(class_scope:pb.Container) 224 | )) 225 | _sym_db.RegisterMessage(Container) 226 | 227 | 228 | # @@protoc_insertion_point(module_scope) 229 | -------------------------------------------------------------------------------- /cmake/FindEigen.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find GUROBI 2 | # Once done this will define 3 | # EIGEN_FOUND: TRUE iff Eigen is found. 4 | # EIGEN_INCLUDE_DIRS: Include directories for Eigen. 5 | # EIGEN_VERSION: Extracted from Eigen/src/Core/util/Macros.h 6 | 7 | macro(EIGEN_REPORT_NOT_FOUND REASON_MSG) 8 | unset(EIGEN_FOUND) 9 | unset(EIGEN_INCLUDE_DIRS) 10 | unset(FOUND_INSTALLED_EIGEN_CMAKE_CONFIGURATION) 11 | # Make results of search visible in the CMake GUI if Eigen has not 12 | # been found so that user does not have to toggle to advanced view. 13 | mark_as_advanced(CLEAR EIGEN_INCLUDE_DIR) 14 | # Note _FIND_[REQUIRED/QUIETLY] variables defined by FindPackage() 15 | # use the camelcase library name, not uppercase. 16 | if (Eigen_FIND_QUIETLY) 17 | message(STATUS "Failed to find Eigen - " ${REASON_MSG} ${ARGN}) 18 | elseif (Eigen_FIND_REQUIRED) 19 | message(FATAL_ERROR "Failed to find Eigen - " ${REASON_MSG} ${ARGN}) 20 | else() 21 | # Neither QUIETLY nor REQUIRED, use no priority which emits a message 22 | # but continues configuration and allows generation. 23 | message("-- Failed to find Eigen - " ${REASON_MSG} ${ARGN}) 24 | endif () 25 | return() 26 | endmacro(EIGEN_REPORT_NOT_FOUND) 27 | 28 | # Protect against any alternative find_package scripts for this library having 29 | # been called previously (in a client project) which set EIGEN_FOUND, but not 30 | # the other variables we require / set here which could cause the search logic 31 | # here to fail. 32 | unset(EIGEN_FOUND) 33 | 34 | # ----------------------------------------------------------------- 35 | # By default, if the user has expressed no preference for using an exported 36 | # Eigen CMake configuration over performing a search for the installed 37 | # components, and has not specified any hints for the search locations, then 38 | # prefer an exported configuration if available. 39 | if (NOT DEFINED EIGEN_PREFER_EXPORTED_EIGEN_CMAKE_CONFIGURATION 40 | AND NOT EIGEN_INCLUDE_DIR_HINTS) 41 | message(STATUS "No preference for use of exported Eigen CMake configuration " 42 | "set, and no hints for include directory provided. " 43 | "Defaulting to preferring an installed/exported Eigen CMake configuration " 44 | "if available.") 45 | set(EIGEN_PREFER_EXPORTED_EIGEN_CMAKE_CONFIGURATION TRUE) 46 | endif() 47 | 48 | if (EIGEN_PREFER_EXPORTED_EIGEN_CMAKE_CONFIGURATION) 49 | # Try to find an exported CMake configuration for Eigen. 50 | # 51 | # We search twice, s/t we can invert the ordering of precedence used by 52 | # find_package() for exported package build directories, and installed 53 | # packages (found via CMAKE_SYSTEM_PREFIX_PATH), listed as items 6) and 7) 54 | # respectively in [1]. 55 | # 56 | # By default, exported build directories are (in theory) detected first, and 57 | # this is usually the case on Windows. However, on OS X & Linux, the install 58 | # path (/usr/local) is typically present in the PATH environment variable 59 | # which is checked in item 4) in [1] (i.e. before both of the above, unless 60 | # NO_SYSTEM_ENVIRONMENT_PATH is passed). As such on those OSs installed 61 | # packages are usually detected in preference to exported package build 62 | # directories. 63 | # 64 | # To ensure a more consistent response across all OSs, and as users usually 65 | # want to prefer an installed version of a package over a locally built one 66 | # where both exist (esp. as the exported build directory might be removed 67 | # after installation), we first search with NO_CMAKE_PACKAGE_REGISTRY which 68 | # means any build directories exported by the user are ignored, and thus 69 | # installed directories are preferred. If this fails to find the package 70 | # we then research again, but without NO_CMAKE_PACKAGE_REGISTRY, so any 71 | # exported build directories will now be detected. 72 | # 73 | # To prevent confusion on Windows, we also pass NO_CMAKE_BUILDS_PATH (which 74 | # is item 5) in [1]), to not preferentially use projects that were built 75 | # recently with the CMake GUI to ensure that we always prefer an installed 76 | # version if available. 77 | # 78 | # [1] http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:find_package 79 | find_package(Eigen3 QUIET 80 | NO_MODULE 81 | NO_CMAKE_PACKAGE_REGISTRY 82 | NO_CMAKE_BUILDS_PATH) 83 | if (EIGEN3_FOUND) 84 | message(STATUS "Found installed version of Eigen: ${Eigen3_DIR}") 85 | else() 86 | # Failed to find an installed version of Eigen, repeat search allowing 87 | # exported build directories. 88 | message(STATUS "Failed to find installed Eigen CMake configuration, " 89 | "searching for Eigen build directories exported with CMake.") 90 | # Again pass NO_CMAKE_BUILDS_PATH, as we know that Eigen is exported and 91 | # do not want to treat projects built with the CMake GUI preferentially. 92 | find_package(Eigen3 QUIET 93 | NO_MODULE 94 | NO_CMAKE_BUILDS_PATH) 95 | if (EIGEN3_FOUND) 96 | message(STATUS "Found exported Eigen build directory: ${Eigen3_DIR}") 97 | endif() 98 | endif() 99 | if (EIGEN3_FOUND) 100 | set(FOUND_INSTALLED_EIGEN_CMAKE_CONFIGURATION TRUE) 101 | set(EIGEN_FOUND ${EIGEN3_FOUND}) 102 | set(EIGEN_INCLUDE_DIR "${EIGEN3_INCLUDE_DIR}" CACHE STRING 103 | "Eigen include directory" FORCE) 104 | else() 105 | message(STATUS "Failed to find an installed/exported CMake configuration " 106 | "for Eigen, will perform search for installed Eigen components.") 107 | endif() 108 | endif() 109 | 110 | if (NOT EIGEN_FOUND) 111 | # Search user-installed locations first, so that we prefer user installs 112 | # to system installs where both exist. 113 | list(APPEND EIGEN_CHECK_INCLUDE_DIRS 114 | /usr/local/include 115 | /usr/local/homebrew/include # Mac OS X 116 | /opt/local/var/macports/software # Mac OS X. 117 | /opt/local/include 118 | /usr/include) 119 | # Additional suffixes to try appending to each search path. 120 | list(APPEND EIGEN_CHECK_PATH_SUFFIXES 121 | eigen3 # Default root directory for Eigen. 122 | Eigen/include/eigen3 # Windows (for C:/Program Files prefix) < 3.3 123 | Eigen3/include/eigen3 ) # Windows (for C:/Program Files prefix) >= 3.3 124 | 125 | # Search supplied hint directories first if supplied. 126 | find_path(EIGEN_INCLUDE_DIR 127 | NAMES Eigen/Core 128 | HINTS ${EIGEN_INCLUDE_DIR_HINTS} 129 | PATHS ${EIGEN_CHECK_INCLUDE_DIRS} 130 | PATH_SUFFIXES ${EIGEN_CHECK_PATH_SUFFIXES}) 131 | 132 | if (NOT EIGEN_INCLUDE_DIR OR 133 | NOT EXISTS ${EIGEN_INCLUDE_DIR}) 134 | eigen_report_not_found( 135 | "Could not find eigen3 include directory, set EIGEN_INCLUDE_DIR to " 136 | "path to eigen3 include directory, e.g. /usr/local/include/eigen3.") 137 | endif (NOT EIGEN_INCLUDE_DIR OR 138 | NOT EXISTS ${EIGEN_INCLUDE_DIR}) 139 | 140 | # Mark internally as found, then verify. EIGEN_REPORT_NOT_FOUND() unsets 141 | # if called. 142 | set(EIGEN_FOUND TRUE) 143 | endif() 144 | 145 | # Extract Eigen version from Eigen/src/Core/util/Macros.h 146 | if (EIGEN_INCLUDE_DIR) 147 | set(EIGEN_VERSION_FILE ${EIGEN_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h) 148 | if (NOT EXISTS ${EIGEN_VERSION_FILE}) 149 | eigen_report_not_found( 150 | "Could not find file: ${EIGEN_VERSION_FILE} " 151 | "containing version information in Eigen install located at: " 152 | "${EIGEN_INCLUDE_DIR}.") 153 | else (NOT EXISTS ${EIGEN_VERSION_FILE}) 154 | file(READ ${EIGEN_VERSION_FILE} EIGEN_VERSION_FILE_CONTENTS) 155 | 156 | string(REGEX MATCH "#define EIGEN_WORLD_VERSION [0-9]+" 157 | EIGEN_WORLD_VERSION "${EIGEN_VERSION_FILE_CONTENTS}") 158 | string(REGEX REPLACE "#define EIGEN_WORLD_VERSION ([0-9]+)" "\\1" 159 | EIGEN_WORLD_VERSION "${EIGEN_WORLD_VERSION}") 160 | 161 | string(REGEX MATCH "#define EIGEN_MAJOR_VERSION [0-9]+" 162 | EIGEN_MAJOR_VERSION "${EIGEN_VERSION_FILE_CONTENTS}") 163 | string(REGEX REPLACE "#define EIGEN_MAJOR_VERSION ([0-9]+)" "\\1" 164 | EIGEN_MAJOR_VERSION "${EIGEN_MAJOR_VERSION}") 165 | 166 | string(REGEX MATCH "#define EIGEN_MINOR_VERSION [0-9]+" 167 | EIGEN_MINOR_VERSION "${EIGEN_VERSION_FILE_CONTENTS}") 168 | string(REGEX REPLACE "#define EIGEN_MINOR_VERSION ([0-9]+)" "\\1" 169 | EIGEN_MINOR_VERSION "${EIGEN_MINOR_VERSION}") 170 | 171 | # This is on a single line s/t CMake does not interpret it as a list of 172 | # elements and insert ';' separators which would result in 3.;2.;0 nonsense. 173 | set(EIGEN_VERSION "${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION}") 174 | endif (NOT EXISTS ${EIGEN_VERSION_FILE}) 175 | endif (EIGEN_INCLUDE_DIR) 176 | 177 | # Set standard CMake FindPackage variables if found. 178 | if (EIGEN_FOUND) 179 | set(EIGEN_INCLUDE_DIRS ${EIGEN_INCLUDE_DIR}) 180 | endif (EIGEN_FOUND) 181 | 182 | # Handle REQUIRED / QUIET optional arguments and version. 183 | include(FindPackageHandleStandardArgs) 184 | find_package_handle_standard_args(Eigen 185 | REQUIRED_VARS EIGEN_INCLUDE_DIRS 186 | VERSION_VAR EIGEN_VERSION) 187 | 188 | # Only mark internal variables as advanced if we found Eigen, otherwise 189 | # leave it visible in the standard GUI for the user to set manually. 190 | if (EIGEN_FOUND) 191 | mark_as_advanced(FORCE EIGEN_INCLUDE_DIR 192 | Eigen3_DIR) # Autogenerated by find_package(Eigen3) 193 | endif (EIGEN_FOUND) 194 | -------------------------------------------------------------------------------- /cmake/FindProtobuf.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # FindProtobuf 3 | # ------------ 4 | # 5 | # Locate and configure the Google Protocol Buffers library. 6 | # 7 | # The following variables can be set and are optional: 8 | # 9 | # ``Protobuf_SRC_ROOT_FOLDER`` 10 | # When compiling with MSVC, if this cache variable is set 11 | # the protobuf-default VS project build locations 12 | # (vsprojects/Debug and vsprojects/Release 13 | # or vsprojects/x64/Debug and vsprojects/x64/Release) 14 | # will be searched for libraries and binaries. 15 | # ``Protobuf_IMPORT_DIRS`` 16 | # List of additional directories to be searched for 17 | # imported .proto files. 18 | # ``Protobuf_DEBUG`` 19 | # Show debug messages. 20 | # ``Protobuf_USE_STATIC_LIBS`` 21 | # Set to ON to force the use of the static libraries. 22 | # Default is OFF. 23 | # 24 | # Defines the following variables: 25 | # 26 | # ``Protobuf_FOUND`` 27 | # Found the Google Protocol Buffers library 28 | # (libprotobuf & header files) 29 | # ``Protobuf_VERSION`` 30 | # Version of package found. 31 | # ``Protobuf_INCLUDE_DIRS`` 32 | # Include directories for Google Protocol Buffers 33 | # ``Protobuf_LIBRARIES`` 34 | # The protobuf libraries 35 | # ``Protobuf_PROTOC_LIBRARIES`` 36 | # The protoc libraries 37 | # ``Protobuf_LITE_LIBRARIES`` 38 | # The protobuf-lite libraries 39 | # 40 | # The following :prop_tgt:`IMPORTED` targets are also defined: 41 | # 42 | # ``protobuf::libprotobuf`` 43 | # The protobuf library. 44 | # ``protobuf::libprotobuf-lite`` 45 | # The protobuf lite library. 46 | # ``protobuf::libprotoc`` 47 | # The protoc library. 48 | # ``protobuf::protoc`` 49 | # The protoc compiler. 50 | # 51 | # The following cache variables are also available to set or use: 52 | # 53 | # ``Protobuf_LIBRARY`` 54 | # The protobuf library 55 | # ``Protobuf_PROTOC_LIBRARY`` 56 | # The protoc library 57 | # ``Protobuf_INCLUDE_DIR`` 58 | # The include directory for protocol buffers 59 | # ``Protobuf_PROTOC_EXECUTABLE`` 60 | # The protoc compiler 61 | # ``Protobuf_LIBRARY_DEBUG`` 62 | # The protobuf library (debug) 63 | # ``Protobuf_PROTOC_LIBRARY_DEBUG`` 64 | # The protoc library (debug) 65 | # ``Protobuf_LITE_LIBRARY`` 66 | # The protobuf lite library 67 | # ``Protobuf_LITE_LIBRARY_DEBUG`` 68 | # The protobuf lite library (debug) 69 | # 70 | # Example: 71 | # 72 | # .. code-block:: cmake 73 | # 74 | # find_package(Protobuf REQUIRED) 75 | # include_directories(${Protobuf_INCLUDE_DIRS}) 76 | # include_directories(${CMAKE_CURRENT_BINARY_DIR}) 77 | # protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS foo.proto) 78 | # protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS EXPORT_MACRO DLL_EXPORT foo.proto) 79 | # protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS DESCRIPTORS PROTO_DESCS foo.proto) 80 | # protobuf_generate_python(PROTO_PY foo.proto) 81 | # add_executable(bar bar.cc ${PROTO_SRCS} ${PROTO_HDRS}) 82 | # target_link_libraries(bar ${Protobuf_LIBRARIES}) 83 | # 84 | # .. note:: 85 | # The ``protobuf_generate_cpp`` and ``protobuf_generate_python`` 86 | # functions and :command:`add_executable` or :command:`add_library` 87 | # calls only work properly within the same directory. 88 | # 89 | # .. command:: protobuf_generate_cpp 90 | # 91 | # Add custom commands to process ``.proto`` files to C++:: 92 | # 93 | # protobuf_generate_cpp ( 94 | # [DESCRIPTORS ] [EXPORT_MACRO ] [...]) 95 | # 96 | # ``SRCS`` 97 | # Variable to define with autogenerated source files 98 | # ``HDRS`` 99 | # Variable to define with autogenerated header files 100 | # ``DESCRIPTORS`` 101 | # Variable to define with autogenerated descriptor files, if requested. 102 | # ``EXPORT_MACRO`` 103 | # is a macro which should expand to ``__declspec(dllexport)`` or 104 | # ``__declspec(dllimport)`` depending on what is being compiled. 105 | # ``ARGN`` 106 | # ``.proto`` files 107 | # 108 | # .. command:: protobuf_generate_python 109 | # 110 | # Add custom commands to process ``.proto`` files to Python:: 111 | # 112 | # protobuf_generate_python ( [...]) 113 | # 114 | # ``PY`` 115 | # Variable to define with autogenerated Python files 116 | # ``ARGN`` 117 | # ``.proto`` filess 118 | 119 | function(PROTOBUF_GENERATE_CPP SRCS HDRS) 120 | cmake_parse_arguments(protobuf "" "EXPORT_MACRO;DESCRIPTORS" "" ${ARGN}) 121 | 122 | set(PROTO_FILES "${protobuf_UNPARSED_ARGUMENTS}") 123 | if(NOT PROTO_FILES) 124 | message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files") 125 | return() 126 | endif() 127 | 128 | if(protobuf_EXPORT_MACRO) 129 | set(DLL_EXPORT_DECL "dllexport_decl=${protobuf_EXPORT_MACRO}:") 130 | endif() 131 | 132 | if(PROTOBUF_GENERATE_CPP_APPEND_PATH) 133 | # Create an include path for each file specified 134 | foreach(FIL ${PROTO_FILES}) 135 | get_filename_component(ABS_FIL ${FIL} ABSOLUTE) 136 | get_filename_component(ABS_PATH ${ABS_FIL} PATH) 137 | list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) 138 | if(${_contains_already} EQUAL -1) 139 | list(APPEND _protobuf_include_path -I ${ABS_PATH}) 140 | endif() 141 | endforeach() 142 | else() 143 | set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) 144 | endif() 145 | 146 | if(DEFINED PROTOBUF_IMPORT_DIRS AND NOT DEFINED Protobuf_IMPORT_DIRS) 147 | set(Protobuf_IMPORT_DIRS "${PROTOBUF_IMPORT_DIRS}") 148 | endif() 149 | 150 | if(DEFINED Protobuf_IMPORT_DIRS) 151 | foreach(DIR ${Protobuf_IMPORT_DIRS}) 152 | get_filename_component(ABS_PATH ${DIR} ABSOLUTE) 153 | list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) 154 | if(${_contains_already} EQUAL -1) 155 | list(APPEND _protobuf_include_path -I ${ABS_PATH}) 156 | endif() 157 | endforeach() 158 | endif() 159 | 160 | set(${SRCS}) 161 | set(${HDRS}) 162 | if (protobuf_DESCRIPTORS) 163 | set(${protobuf_DESCRIPTORS}) 164 | endif() 165 | 166 | foreach(FIL ${PROTO_FILES}) 167 | get_filename_component(ABS_FIL ${FIL} ABSOLUTE) 168 | get_filename_component(FIL_WE ${FIL} NAME_WE) 169 | if(NOT PROTOBUF_GENERATE_CPP_APPEND_PATH) 170 | get_filename_component(FIL_DIR ${FIL} DIRECTORY) 171 | if(FIL_DIR) 172 | set(FIL_WE "${FIL_DIR}/${FIL_WE}") 173 | endif() 174 | endif() 175 | 176 | set(_protobuf_protoc_src "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc") 177 | set(_protobuf_protoc_hdr "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h") 178 | list(APPEND ${SRCS} "${_protobuf_protoc_src}") 179 | list(APPEND ${HDRS} "${_protobuf_protoc_hdr}") 180 | 181 | if(protobuf_DESCRIPTORS) 182 | set(_protobuf_protoc_desc "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.desc") 183 | set(_protobuf_protoc_flags "--descriptor_set_out=${_protobuf_protoc_desc}") 184 | list(APPEND ${protobuf_DESCRIPTORS} "${_protobuf_protoc_desc}") 185 | else() 186 | set(_protobuf_protoc_desc "") 187 | set(_protobuf_protoc_flags "") 188 | endif() 189 | 190 | add_custom_command( 191 | OUTPUT "${_protobuf_protoc_src}" 192 | "${_protobuf_protoc_hdr}" 193 | ${_protobuf_protoc_desc} 194 | COMMAND protobuf::protoc 195 | "--cpp_out=${DLL_EXPORT_DECL}${CMAKE_CURRENT_BINARY_DIR}" 196 | ${_protobuf_protoc_flags} 197 | ${_protobuf_include_path} ${ABS_FIL} 198 | DEPENDS ${ABS_FIL} protobuf::protoc 199 | COMMENT "Running C++ protocol buffer compiler on ${FIL}" 200 | VERBATIM ) 201 | endforeach() 202 | 203 | set(${SRCS} "${${SRCS}}" PARENT_SCOPE) 204 | set(${HDRS} "${${HDRS}}" PARENT_SCOPE) 205 | if(protobuf_DESCRIPTORS) 206 | set(${protobuf_DESCRIPTORS} "${${protobuf_DESCRIPTORS}}" PARENT_SCOPE) 207 | endif() 208 | endfunction() 209 | 210 | function(PROTOBUF_GENERATE_PYTHON SRCS) 211 | if(NOT ARGN) 212 | message(SEND_ERROR "Error: PROTOBUF_GENERATE_PYTHON() called without any proto files") 213 | return() 214 | endif() 215 | 216 | if(PROTOBUF_GENERATE_CPP_APPEND_PATH) 217 | # Create an include path for each file specified 218 | foreach(FIL ${ARGN}) 219 | get_filename_component(ABS_FIL ${FIL} ABSOLUTE) 220 | get_filename_component(ABS_PATH ${ABS_FIL} PATH) 221 | list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) 222 | if(${_contains_already} EQUAL -1) 223 | list(APPEND _protobuf_include_path -I ${ABS_PATH}) 224 | endif() 225 | endforeach() 226 | else() 227 | set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) 228 | endif() 229 | 230 | if(DEFINED PROTOBUF_IMPORT_DIRS AND NOT DEFINED Protobuf_IMPORT_DIRS) 231 | set(Protobuf_IMPORT_DIRS "${PROTOBUF_IMPORT_DIRS}") 232 | endif() 233 | 234 | if(DEFINED Protobuf_IMPORT_DIRS) 235 | foreach(DIR ${Protobuf_IMPORT_DIRS}) 236 | get_filename_component(ABS_PATH ${DIR} ABSOLUTE) 237 | list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) 238 | if(${_contains_already} EQUAL -1) 239 | list(APPEND _protobuf_include_path -I ${ABS_PATH}) 240 | endif() 241 | endforeach() 242 | endif() 243 | 244 | set(${SRCS}) 245 | foreach(FIL ${ARGN}) 246 | get_filename_component(ABS_FIL ${FIL} ABSOLUTE) 247 | get_filename_component(FIL_WE ${FIL} NAME_WE) 248 | if(NOT PROTOBUF_GENERATE_CPP_APPEND_PATH) 249 | get_filename_component(FIL_DIR ${FIL} DIRECTORY) 250 | if(FIL_DIR) 251 | set(FIL_WE "${FIL_DIR}/${FIL_WE}") 252 | endif() 253 | endif() 254 | 255 | list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py") 256 | add_custom_command( 257 | OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py" 258 | COMMAND protobuf::protoc --python_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL} 259 | DEPENDS ${ABS_FIL} protobuf::protoc 260 | COMMENT "Running Python protocol buffer compiler on ${FIL}" 261 | VERBATIM ) 262 | endforeach() 263 | 264 | set(${SRCS} ${${SRCS}} PARENT_SCOPE) 265 | endfunction() 266 | 267 | 268 | if(Protobuf_DEBUG) 269 | # Output some of their choices 270 | message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " 271 | "Protobuf_USE_STATIC_LIBS = ${Protobuf_USE_STATIC_LIBS}") 272 | endif() 273 | 274 | 275 | # Backwards compatibility 276 | # Define camel case versions of input variables 277 | foreach(UPPER 278 | PROTOBUF_SRC_ROOT_FOLDER 279 | PROTOBUF_IMPORT_DIRS 280 | PROTOBUF_DEBUG 281 | PROTOBUF_LIBRARY 282 | PROTOBUF_PROTOC_LIBRARY 283 | PROTOBUF_INCLUDE_DIR 284 | PROTOBUF_PROTOC_EXECUTABLE 285 | PROTOBUF_LIBRARY_DEBUG 286 | PROTOBUF_PROTOC_LIBRARY_DEBUG 287 | PROTOBUF_LITE_LIBRARY 288 | PROTOBUF_LITE_LIBRARY_DEBUG 289 | ) 290 | if (DEFINED ${UPPER}) 291 | string(REPLACE "PROTOBUF_" "Protobuf_" Camel ${UPPER}) 292 | if (NOT DEFINED ${Camel}) 293 | set(${Camel} ${${UPPER}}) 294 | endif() 295 | endif() 296 | endforeach() 297 | 298 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 299 | set(_PROTOBUF_ARCH_DIR x64/) 300 | endif() 301 | 302 | 303 | # Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES 304 | if( Protobuf_USE_STATIC_LIBS ) 305 | set( _protobuf_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) 306 | if(WIN32) 307 | set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) 308 | else() 309 | set(CMAKE_FIND_LIBRARY_SUFFIXES .a ) 310 | endif() 311 | endif() 312 | 313 | include(SelectLibraryConfigurations) 314 | 315 | # Internal function: search for normal library as well as a debug one 316 | # if the debug one is specified also include debug/optimized keywords 317 | # in *_LIBRARIES variable 318 | function(_protobuf_find_libraries name filename) 319 | if(${name}_LIBRARIES) 320 | # Use result recorded by a previous call. 321 | return() 322 | elseif(${name}_LIBRARY) 323 | # Honor cache entry used by CMake 3.5 and lower. 324 | set(${name}_LIBRARIES "${${name}_LIBRARY}" PARENT_SCOPE) 325 | else() 326 | find_library(${name}_LIBRARY_RELEASE 327 | NAMES ${filename} 328 | PATHS ${Protobuf_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Release) 329 | mark_as_advanced(${name}_LIBRARY_RELEASE) 330 | 331 | find_library(${name}_LIBRARY_DEBUG 332 | NAMES ${filename}d ${filename} 333 | PATHS ${Protobuf_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Debug) 334 | mark_as_advanced(${name}_LIBRARY_DEBUG) 335 | 336 | select_library_configurations(${name}) 337 | set(${name}_LIBRARY "${${name}_LIBRARY}" PARENT_SCOPE) 338 | set(${name}_LIBRARIES "${${name}_LIBRARIES}" PARENT_SCOPE) 339 | endif() 340 | endfunction() 341 | 342 | # Internal function: find threads library 343 | function(_protobuf_find_threads) 344 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) 345 | find_package(Threads) 346 | if(Threads_FOUND) 347 | list(APPEND Protobuf_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) 348 | set(Protobuf_LIBRARIES "${Protobuf_LIBRARIES}" PARENT_SCOPE) 349 | endif() 350 | endfunction() 351 | 352 | # 353 | # Main. 354 | # 355 | 356 | # By default have PROTOBUF_GENERATE_CPP macro pass -I to protoc 357 | # for each directory where a proto file is referenced. 358 | if(NOT DEFINED PROTOBUF_GENERATE_CPP_APPEND_PATH) 359 | set(PROTOBUF_GENERATE_CPP_APPEND_PATH TRUE) 360 | endif() 361 | 362 | 363 | # Google's provided vcproj files generate libraries with a "lib" 364 | # prefix on Windows 365 | if(MSVC) 366 | set(Protobuf_ORIG_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}") 367 | set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "") 368 | 369 | find_path(Protobuf_SRC_ROOT_FOLDER protobuf.pc.in) 370 | endif() 371 | 372 | # The Protobuf library 373 | _protobuf_find_libraries(Protobuf protobuf) 374 | #DOC "The Google Protocol Buffers RELEASE Library" 375 | 376 | _protobuf_find_libraries(Protobuf_LITE protobuf-lite) 377 | 378 | # The Protobuf Protoc Library 379 | _protobuf_find_libraries(Protobuf_PROTOC protoc) 380 | 381 | # Restore original find library prefixes 382 | if(MSVC) 383 | set(CMAKE_FIND_LIBRARY_PREFIXES "${Protobuf_ORIG_FIND_LIBRARY_PREFIXES}") 384 | endif() 385 | 386 | if(UNIX) 387 | _protobuf_find_threads() 388 | endif() 389 | 390 | # Find the include directory 391 | find_path(Protobuf_INCLUDE_DIR 392 | google/protobuf/service.h 393 | PATHS ${Protobuf_SRC_ROOT_FOLDER}/src 394 | ) 395 | mark_as_advanced(Protobuf_INCLUDE_DIR) 396 | 397 | # Find the protoc Executable 398 | find_program(Protobuf_PROTOC_EXECUTABLE 399 | NAMES protoc 400 | DOC "The Google Protocol Buffers Compiler" 401 | PATHS 402 | ${Protobuf_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Release 403 | ${Protobuf_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Debug 404 | ) 405 | mark_as_advanced(Protobuf_PROTOC_EXECUTABLE) 406 | 407 | if(Protobuf_DEBUG) 408 | message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " 409 | "requested version of Google Protobuf is ${Protobuf_FIND_VERSION}") 410 | endif() 411 | 412 | if(Protobuf_INCLUDE_DIR) 413 | set(_PROTOBUF_COMMON_HEADER ${Protobuf_INCLUDE_DIR}/google/protobuf/stubs/common.h) 414 | 415 | if(Protobuf_DEBUG) 416 | message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " 417 | "location of common.h: ${_PROTOBUF_COMMON_HEADER}") 418 | endif() 419 | 420 | set(Protobuf_VERSION "") 421 | set(Protobuf_LIB_VERSION "") 422 | file(STRINGS ${_PROTOBUF_COMMON_HEADER} _PROTOBUF_COMMON_H_CONTENTS REGEX "#define[ \t]+GOOGLE_PROTOBUF_VERSION[ \t]+") 423 | if(_PROTOBUF_COMMON_H_CONTENTS MATCHES "#define[ \t]+GOOGLE_PROTOBUF_VERSION[ \t]+([0-9]+)") 424 | set(Protobuf_LIB_VERSION "${CMAKE_MATCH_1}") 425 | endif() 426 | unset(_PROTOBUF_COMMON_H_CONTENTS) 427 | 428 | math(EXPR _PROTOBUF_MAJOR_VERSION "${Protobuf_LIB_VERSION} / 1000000") 429 | math(EXPR _PROTOBUF_MINOR_VERSION "${Protobuf_LIB_VERSION} / 1000 % 1000") 430 | math(EXPR _PROTOBUF_SUBMINOR_VERSION "${Protobuf_LIB_VERSION} % 1000") 431 | set(Protobuf_VERSION "${_PROTOBUF_MAJOR_VERSION}.${_PROTOBUF_MINOR_VERSION}.${_PROTOBUF_SUBMINOR_VERSION}") 432 | 433 | if(Protobuf_DEBUG) 434 | message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " 435 | "${_PROTOBUF_COMMON_HEADER} reveals protobuf ${Protobuf_VERSION}") 436 | endif() 437 | 438 | # Check Protobuf compiler version to be aligned with libraries version 439 | execute_process(COMMAND ${Protobuf_PROTOC_EXECUTABLE} --version 440 | OUTPUT_VARIABLE _PROTOBUF_PROTOC_EXECUTABLE_VERSION) 441 | 442 | if("${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}" MATCHES "libprotoc ([0-9.]+)") 443 | set(_PROTOBUF_PROTOC_EXECUTABLE_VERSION "${CMAKE_MATCH_1}") 444 | endif() 445 | 446 | if(Protobuf_DEBUG) 447 | message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " 448 | "${Protobuf_PROTOC_EXECUTABLE} reveals version ${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}") 449 | endif() 450 | 451 | if(NOT "${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}" VERSION_EQUAL "${Protobuf_VERSION}") 452 | message(WARNING "Protobuf compiler version ${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}" 453 | " doesn't match library version ${Protobuf_VERSION}") 454 | endif() 455 | 456 | if(Protobuf_LIBRARY) 457 | if(NOT TARGET protobuf::libprotobuf) 458 | add_library(protobuf::libprotobuf UNKNOWN IMPORTED) 459 | set_target_properties(protobuf::libprotobuf PROPERTIES 460 | INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}") 461 | if(EXISTS "${Protobuf_LIBRARY}") 462 | set_target_properties(protobuf::libprotobuf PROPERTIES 463 | IMPORTED_LOCATION "${Protobuf_LIBRARY}") 464 | endif() 465 | if(EXISTS "${Protobuf_LIBRARY_RELEASE}") 466 | set_property(TARGET protobuf::libprotobuf APPEND PROPERTY 467 | IMPORTED_CONFIGURATIONS RELEASE) 468 | set_target_properties(protobuf::libprotobuf PROPERTIES 469 | IMPORTED_LOCATION_RELEASE "${Protobuf_LIBRARY_RELEASE}") 470 | endif() 471 | if(EXISTS "${Protobuf_LIBRARY_DEBUG}") 472 | set_property(TARGET protobuf::libprotobuf APPEND PROPERTY 473 | IMPORTED_CONFIGURATIONS DEBUG) 474 | set_target_properties(protobuf::libprotobuf PROPERTIES 475 | IMPORTED_LOCATION_DEBUG "${Protobuf_LIBRARY_DEBUG}") 476 | endif() 477 | endif() 478 | endif() 479 | 480 | if(Protobuf_LITE_LIBRARY) 481 | if(NOT TARGET protobuf::libprotobuf-lite) 482 | add_library(protobuf::libprotobuf-lite UNKNOWN IMPORTED) 483 | set_target_properties(protobuf::libprotobuf-lite PROPERTIES 484 | INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}") 485 | if(EXISTS "${Protobuf_LITE_LIBRARY}") 486 | set_target_properties(protobuf::libprotobuf-lite PROPERTIES 487 | IMPORTED_LOCATION "${Protobuf_LITE_LIBRARY}") 488 | endif() 489 | if(EXISTS "${Protobuf_LITE_LIBRARY_RELEASE}") 490 | set_property(TARGET protobuf::libprotobuf-lite APPEND PROPERTY 491 | IMPORTED_CONFIGURATIONS RELEASE) 492 | set_target_properties(protobuf::libprotobuf-lite PROPERTIES 493 | IMPORTED_LOCATION_RELEASE "${Protobuf_LITE_LIBRARY_RELEASE}") 494 | endif() 495 | if(EXISTS "${Protobuf_LITE_LIBRARY_DEBUG}") 496 | set_property(TARGET protobuf::libprotobuf-lite APPEND PROPERTY 497 | IMPORTED_CONFIGURATIONS DEBUG) 498 | set_target_properties(protobuf::libprotobuf-lite PROPERTIES 499 | IMPORTED_LOCATION_DEBUG "${Protobuf_LITE_LIBRARY_DEBUG}") 500 | endif() 501 | endif() 502 | endif() 503 | 504 | if(Protobuf_PROTOC_LIBRARY) 505 | if(NOT TARGET protobuf::libprotoc) 506 | add_library(protobuf::libprotoc UNKNOWN IMPORTED) 507 | set_target_properties(protobuf::libprotoc PROPERTIES 508 | INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}") 509 | if(EXISTS "${Protobuf_PROTOC_LIBRARY}") 510 | set_target_properties(protobuf::libprotoc PROPERTIES 511 | IMPORTED_LOCATION "${Protobuf_PROTOC_LIBRARY}") 512 | endif() 513 | if(EXISTS "${Protobuf_PROTOC_LIBRARY_RELEASE}") 514 | set_property(TARGET protobuf::libprotoc APPEND PROPERTY 515 | IMPORTED_CONFIGURATIONS RELEASE) 516 | set_target_properties(protobuf::libprotoc PROPERTIES 517 | IMPORTED_LOCATION_RELEASE "${Protobuf_PROTOC_LIBRARY_RELEASE}") 518 | endif() 519 | if(EXISTS "${Protobuf_PROTOC_LIBRARY_DEBUG}") 520 | set_property(TARGET protobuf::libprotoc APPEND PROPERTY 521 | IMPORTED_CONFIGURATIONS DEBUG) 522 | set_target_properties(protobuf::libprotoc PROPERTIES 523 | IMPORTED_LOCATION_DEBUG "${Protobuf_PROTOC_LIBRARY_DEBUG}") 524 | endif() 525 | endif() 526 | endif() 527 | 528 | if(Protobuf_PROTOC_EXECUTABLE) 529 | if(NOT TARGET protobuf::protoc) 530 | add_executable(protobuf::protoc IMPORTED) 531 | if(EXISTS "${Protobuf_PROTOC_EXECUTABLE}") 532 | set_target_properties(protobuf::protoc PROPERTIES 533 | IMPORTED_LOCATION "${Protobuf_PROTOC_EXECUTABLE}") 534 | endif() 535 | endif() 536 | endif() 537 | endif() 538 | 539 | include(FindPackageHandleStandardArgs) 540 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Protobuf 541 | REQUIRED_VARS Protobuf_LIBRARIES Protobuf_INCLUDE_DIR 542 | VERSION_VAR Protobuf_VERSION 543 | ) 544 | 545 | if(Protobuf_FOUND) 546 | set(Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIR}) 547 | endif() 548 | 549 | # Restore the original find library ordering 550 | if( Protobuf_USE_STATIC_LIBS ) 551 | set(CMAKE_FIND_LIBRARY_SUFFIXES ${_protobuf_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) 552 | endif() 553 | 554 | # Backwards compatibility 555 | # Define upper case versions of output variables 556 | foreach(Camel 557 | Protobuf_SRC_ROOT_FOLDER 558 | Protobuf_IMPORT_DIRS 559 | Protobuf_DEBUG 560 | Protobuf_INCLUDE_DIRS 561 | Protobuf_LIBRARIES 562 | Protobuf_PROTOC_LIBRARIES 563 | Protobuf_LITE_LIBRARIES 564 | Protobuf_LIBRARY 565 | Protobuf_PROTOC_LIBRARY 566 | Protobuf_INCLUDE_DIR 567 | Protobuf_PROTOC_EXECUTABLE 568 | Protobuf_LIBRARY_DEBUG 569 | Protobuf_PROTOC_LIBRARY_DEBUG 570 | Protobuf_LITE_LIBRARY 571 | Protobuf_LITE_LIBRARY_DEBUG 572 | ) 573 | string(TOUPPER ${Camel} UPPER) 574 | set(${UPPER} ${${Camel}}) 575 | endforeach() 576 | --------------------------------------------------------------------------------