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

Reformat the visibility file adding and dependency exporting #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions rosidl_adapter_proto/bin/rosidl_adapter_proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ def main(argv=sys.argv[1:]):
proto_files = proto_files,
package_name = package_name
)

# Modify the generated .pb.h to include visibility file
for proto_file in proto_files:
# Just in case if the path contains another <xxx>.proto, e.g.,
# /home/<xxx>.proto/<path-to-proto-file>
proto_file = proto_file.split("/")
msg_type = proto_file[-2]
msg = os.path.splitext(proto_file[-1])[0]

with open(f"{cpp_out_dir}/{package_name}/{msg_type}/{msg}.pb.h", "r") as f:
contents = f.readlines()

# Insert the visibility file on line 6
contents.insert(
6,
f"#include <{package_name}/rosidl_adapter_proto__visibility_control.h>\n")
with open(f"{cpp_out_dir}/{package_name}/{msg_type}/{msg}.pb.h", "w") as f:
f.write("".join(contents))

return rc

Expand Down
27 changes: 17 additions & 10 deletions rosidl_adapter_proto/cmake/rosidl_adapt_proto_interfaces.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,21 @@ configure_file(
@ONLY
)

install(
DIRECTORY ${rosidl_adapter_proto_OUTPUT_DIR}
DESTINATION "include/"
PATTERN "*.h"
)
# Headers inside `build` folder is meant to be used by the current msg
# package. Anything downstream packages should use the headers in `install`
# folder.
include_directories("${CMAKE_CURRENT_BINARY_DIR}/rosidl_adapter_proto")

if(NOT rosidl_generate_interfaces_SKIP_INSTALL)
install(
DIRECTORY ${rosidl_adapter_proto_OUTPUT_DIR}
DESTINATION "include/"
PATTERN "*.h"
)

install(
DIRECTORY ${rosidl_adapter_proto_OUTPUT_DIR}
DESTINATION "share/"
PATTERN "*.proto"
)
install(
DIRECTORY ${rosidl_adapter_proto_OUTPUT_DIR}
DESTINATION "share/"
PATTERN "*.proto"
)
endif()
21 changes: 1 addition & 20 deletions rosidl_adapter_proto/cmake/rosidl_adapter_proto-extras.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ else()
ament_register_extension(
"rosidl_generate_idl_interfaces"
"rosidl_adapter_proto"
"${rosidl_adapter_proto_DIR}/rosidl_adapt_proto_interfaces.cmake")
"rosidl_adapt_proto_interfaces.cmake")

set(rosidl_adapter_proto_BIN
"${rosidl_adapter_proto_DIR}/../../../lib/rosidl_adapter_proto/rosidl_adapter_proto")
Expand All @@ -28,25 +28,6 @@ else()
normalize_path(rosidl_adapter_proto_TEMPLATE_DIR
"${rosidl_adapter_proto_TEMPLATE_DIR}")

include("${rosidl_adapter_proto_DIR}/rosidl_adapt_proto_interfaces.cmake")

add_compile_definitions("ROSIDL_ADAPTER_PROTO_BUILDING_DLL__${PROJECT_NAME}")

# There is no clean way to include additional files into protobuf headers
if(NOT WIN32)
add_compile_options("-include${rosidl_adapter_proto_VISIBILITY_CONTROL_HEADER}")
else()
add_compile_options( "/FI\"${rosidl_adapter_proto_VISIBILITY_CONTROL_HEADER}\"")
endif()

foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
set(_proto_dir "${${_pkg_name}_DIR}/../../../include/${_pkg_name}/rosidl_adapter_proto__visibility_control.h")
normalize_path(_proto_dir "${_proto_dir}")
if(NOT WIN32)
add_compile_options("-include${_proto_dir}")
else()
add_compile_options( "/FI\"${_proto_dir}\"")
endif()
endforeach()

endif()
9 changes: 8 additions & 1 deletion rosidl_typesupport_protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ project(rosidl_typesupport_protobuf)

find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(rosidl_generator_c REQUIRED)

include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/discover-ros-distro-extras.cmake)
if(is_foxy_or_greater)
find_package(rosidl_runtime_c REQUIRED)
ament_export_dependencies(rosidl_runtime_c)
else()
find_package(rosidl_generator_c REQUIRED)
ament_export_dependencies(rosidl_generator_c)
endif()
ament_export_include_directories(include)

ament_python_install_package(${PROJECT_NAME})
Expand Down
1 change: 1 addition & 0 deletions rosidl_typesupport_protobuf/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>rosidl_generator_c</buildtool_depend>
<buildtool_depend>rosidl_runtime_c</buildtool_depend>
<buildtool_export_depend>rosidl_generator_c</buildtool_export_depend>

<export>
Expand Down
10 changes: 2 additions & 8 deletions rosidl_typesupport_protobuf_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,20 @@ endif()
find_package(rmw REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(rosidl_typesupport_protobuf REQUIRED)
find_package(rosidl_generator_c REQUIRED)
if(${is_foxy_or_greater})
find_package(rosidl_runtime_c REQUIRED)
endif()
find_package(rosidl_typesupport_introspection_c REQUIRED)
find_package(rosidl_typesupport_introspection_cpp REQUIRED)

ament_export_dependencies(rmw)
ament_export_dependencies(rosidl_cmake)
ament_export_dependencies(rosidl_generator_c)
if(${is_foxy_or_greater})
ament_export_dependencies(rosidl_runtime_c)
endif()
ament_export_dependencies(rosidl_typesupport_introspection_c)
ament_export_dependencies(rosidl_typesupport_introspection_cpp)
ament_export_dependencies(rosidl_typesupport_interface)
ament_export_dependencies(rosidl_typesupport_protobuf)

ament_export_include_directories(include)

ament_export_dependencies(rosidl_adapter_proto)

ament_python_install_package(${PROJECT_NAME})

add_library(${PROJECT_NAME} SHARED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# rosidl_typesupport_protobuf_c/rosidl_typesupport_protobuf_c-extras.cmake.in

find_package(Protobuf REQUIRED)
find_package(rosidl_adapter_proto REQUIRED)

if(NOT Protobuf_FOUND)
message(STATUS "Could not find Protobuf: skipping rosidl_typesupport_protobuf_c")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ configure_file(
@ONLY
)

ament_export_dependencies(rosidl_typesupport_protobuf rosidl_typesupport_protobuf_c)

# Depend on dependencies
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
ament_target_dependencies(${rosidl_generate_interfaces_TARGET}${_target_suffix}
Expand Down Expand Up @@ -181,5 +183,5 @@ if(NOT rosidl_generate_interfaces_SKIP_INSTALL)
rosidl_export_typesupport_libraries(${_target_suffix}
${rosidl_generate_interfaces_TARGET}${_target_suffix})

ament_export_libraries(${rosidl_generate_interfaces_TARGET}${_target_suffix})
ament_export_libraries(${rosidl_generate_interfaces_TARGET}${_target_suffix} ${Protobuf_LIBRARY})
endif()
11 changes: 8 additions & 3 deletions rosidl_typesupport_protobuf_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()

find_package(ament_cmake REQUIRED)
if(PROTOBUF_STATIC_DISABLE)
ament_package()
message(STATUS "Protobuf static typesupport implementation explicitly disabled - skipping '${PROJECT_NAME}'")
Expand All @@ -54,13 +53,19 @@ find_package(rosidl_generator_c REQUIRED)
ament_export_dependencies(rmw)
ament_export_dependencies(rcutils)
ament_export_dependencies(rosidl_cmake)
ament_export_dependencies(rosidl_generator_c)
ament_export_dependencies(rosidl_generator_cpp)
ament_export_dependencies(rosidl_typesupport_interface)
ament_export_dependencies(rosidl_typesupport_protobuf)
ament_export_dependencies(rosidl_adapter_proto)

ament_export_include_directories(include)

if(${is_foxy_or_greater})
ament_export_dependencies(rosidl_runtime_cpp)
else()
ament_export_dependencies(rosidl_generator_c)
ament_export_dependencies(rosidl_generator_cpp)
endif()

ament_python_install_package(${PROJECT_NAME})

add_library(${PROJECT_NAME} SHARED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# rosidl_typesupport_protobuf_cpp-extras.cmake.in

find_package(Protobuf REQUIRED)
find_package(rosidl_adapter_proto REQUIRED)

if(NOT Protobuf_FOUND)
message(STATUS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,13 @@ set_target_properties(${rosidl_generate_interfaces_TARGET}${_target_suffix}
)

# Include headers from other generators
target_include_directories(${rosidl_generate_interfaces_TARGET}${_target_suffix}
PUBLIC
# This is supposed to be
# `target_include_directories(${rosidl_generate_interfaces_TARGET}${_target_suffix}`
# but there's no way to pass the include folder to the top level target
# ${rosidl_generate_interfaces_TARGET}.
# This include_directories will only be used if message is used in the package
# where it's created
include_directories(
${_output_path}
${Protobuf_INCLUDE_DIR}
${rosidl_adapter_proto_INCLUDE_DIR}
Expand All @@ -156,6 +161,8 @@ ament_target_dependencies(${rosidl_generate_interfaces_TARGET}${_target_suffix}
rosidl_typesupport_interface
)

ament_export_dependencies(rosidl_typesupport_protobuf rosidl_typesupport_protobuf_cpp)

# Depend on dependencies
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
ament_target_dependencies(${rosidl_generate_interfaces_TARGET}${_target_suffix}
Expand Down Expand Up @@ -199,5 +206,5 @@ if(NOT rosidl_generate_interfaces_SKIP_INSTALL)
rosidl_export_typesupport_libraries(${_target_suffix}
${rosidl_generate_interfaces_TARGET}${_target_suffix})

ament_export_libraries(${rosidl_generate_interfaces_TARGET}${_target_suffix})
ament_export_libraries(${rosidl_generate_interfaces_TARGET}${_target_suffix} ${Protobuf_LIBRARY})
endif()