Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generation of protobuf files #74

Merged
merged 1 commit into from
May 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if(NOT ZMQ_FOUND)
return()
endif()

find_package(Protobuf 3.0.0)
find_package(Protobuf CONFIG 3.0.0)
if(NOT Protobuf_FOUND)
message(STATUS "protobuf not found")
return()
Expand All @@ -20,27 +20,13 @@ set(proto_source_files
model/messages.proto
)

# generate proto file for C++
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${proto_source_files})
file(RELATIVE_PATH PROTO_HDRS_REL ${CMAKE_CURRENT_SOURCE_DIR} ${PROTO_HDRS})

# generate proto file for Python
FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/model PROTOMODEL_PATH)
FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/model/ns3gym/ns3gym PROTOBINDING_PATH)
FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${proto_source_files} proto_source_file_native)
EXECUTE_PROCESS(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --proto_path=${PROTOMODEL_PATH} --python_out=${PROTOBINDING_PATH}
${proto_source_file_native} RESULT_VARIABLE rv)
IF(${rv})
MESSAGE("Generation of ns3gym Protobuf Python messages failed. Source file: ${proto_native}")
ENDIF()

set(source_files
helper/opengym-helper.cc
model/container.cc
model/opengym_env.cc
model/opengym_interface.cc
model/spaces.cc
${PROTO_SRCS}
${proto_source_files}
)

set(header_files
Expand All @@ -49,7 +35,6 @@ set(header_files
model/opengym_env.h
model/opengym_interface.h
model/spaces.h
${PROTO_HDRS_REL}
)

build_lib(
Expand All @@ -59,13 +44,21 @@ build_lib(
LIBRARIES_TO_LINK
${libcore}
${ZMQ_LIBRARIES}
${Protobuf_LIBRARIES}
protobuf::libprotobuf
TEST_SOURCES
test/opengym-test-suite.cc
)

# add location of generated messages.pb.h to include directories
target_include_directories(
${libopengym-obj}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
protobuf_generate(
TARGET ${libopengym-obj}
IMPORT_DIRS model/
LANGUAGE cpp
PROTOC_OUT_DIR ${CMAKE_OUTPUT_DIRECTORY}/include
)

protobuf_generate(
TARGET ${libopengym-obj}
IMPORT_DIRS model/
LANGUAGE python
PROTOC_OUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/model/ns3gym/ns3gym
)