Skip to content

Commit

Permalink
Add rosidl_find_package_idl helper function (#754)
Browse files Browse the repository at this point in the history
* Create rosidl_find_package_idl helper function.

Signed-off-by: Mike Purvis <mpurvis@clearpathrobotics.com>
  • Loading branch information
mikepurvis authored Aug 21, 2023
1 parent 1fab290 commit f47565c
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 10 deletions.
43 changes: 43 additions & 0 deletions rosidl_cmake/cmake/rosidl_find_package_idl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2023 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Get the absolute path of an IDL file stored in a package's share
# directory, checking if the package's find module set a GNUInstallDirs
# pkgname_DATADIR variable pointing to a separate location from the
# default pkgname_DIR.
#
# :param var: A name of a variable to store the idl file absolute path.
# :param pkg_name: Name of the package, assumed to have already been
# find_package'd.
# :type pkg_name: string
# :param idl_name: The filename of the idl file to look for.
# :type idl_name: string
#
# @public
#
function(rosidl_find_package_idl var pkg_name idl_file)
set(_candidates
"${${pkg_name}_DATADIR}/${idl_file}"
"${${pkg_name}_DIR}/../${idl_file}"
)
foreach(_try ${_candidates})
if(EXISTS "${_try}")
normalize_path(_norm "${_try}")
set("${var}" "${_norm}" PARENT_SCOPE)
return()
endif()
endforeach()
message(FATAL_ERROR "Unable to find ${idl_file} in any of ${_candidates} for ${pkg_name}.")
set("${var}" "-NOTFOUND" PARENT_SCOPE)
endfunction()
3 changes: 1 addition & 2 deletions rosidl_cmake/cmake/rosidl_generate_interfaces.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ macro(rosidl_generate_interfaces target)
"'${_dep}' has not been found before using find_package()")
endif()
foreach(_idl_file ${${_dep}_IDL_FILES})
set(_abs_idl_file "${${_dep}_DIR}/../${_idl_file}")
normalize_path(_abs_idl_file "${_abs_idl_file}")
rosidl_find_package_idl(_abs_idl_file "${_dep}" "${_idl_file}")
list(APPEND _dep_files "${_abs_idl_file}")
endforeach()
endforeach()
Expand Down
1 change: 1 addition & 0 deletions rosidl_cmake/rosidl_cmake-extras.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ endmacro()

include("${rosidl_cmake_DIR}/rosidl_export_typesupport_libraries.cmake")
include("${rosidl_cmake_DIR}/rosidl_export_typesupport_targets.cmake")
include("${rosidl_cmake_DIR}/rosidl_find_package_idl.cmake")
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

find_package(rcutils REQUIRED)
find_package(rosidl_cmake REQUIRED)
find_package(rosidl_runtime_c REQUIRED)
find_package(rosidl_typesupport_interface REQUIRED)

Expand Down Expand Up @@ -43,8 +44,7 @@ set(_dependency_files "")
set(_dependencies "")
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
foreach(_idl_file ${${_pkg_name}_IDL_FILES})
set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}")
normalize_path(_abs_idl_file "${_abs_idl_file}")
rosidl_find_package_idl(_abs_idl_file "${_pkg_name}" "${_idl_file}")
list(APPEND _dependency_files "${_abs_idl_file}")
list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}")
endforeach()
Expand Down
1 change: 1 addition & 0 deletions rosidl_generator_c/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<buildtool_export_depend>python3</buildtool_export_depend>
<buildtool_export_depend>rosidl_pycommon</buildtool_export_depend>

<build_export_depend>rosidl_cmake</build_export_depend>
<build_export_depend>rosidl_generator_type_description</build_export_depend>
<build_export_depend>rosidl_typesupport_interface</build_export_depend>
<build_export_depend>rcutils</build_export_depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

find_package(rosidl_cmake REQUIRED)
find_package(rosidl_runtime_cpp REQUIRED)

set(_output_path
Expand Down Expand Up @@ -47,8 +48,7 @@ set(_dependency_files "")
set(_dependencies "")
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
foreach(_idl_file ${${_pkg_name}_IDL_FILES})
set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}")
normalize_path(_abs_idl_file "${_abs_idl_file}")
rosidl_find_package_idl(_abs_idl_file "${_pkg_name}" "${_idl_file}")
list(APPEND _dependency_files "${_abs_idl_file}")
list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}")
endforeach()
Expand Down
1 change: 1 addition & 0 deletions rosidl_generator_cpp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<buildtool_export_depend>python3</buildtool_export_depend>
<buildtool_export_depend>rosidl_pycommon</buildtool_export_depend>

<build_export_depend>rosidl_cmake</build_export_depend>
<!-- This is needed for the rosidl_message_type_support_t struct and visibility macros -->
<build_export_depend>rosidl_generator_c</build_export_depend>
<build_export_depend>rosidl_runtime_cpp</build_export_depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ if(NOT TARGET ${rosidl_generate_interfaces_TARGET}__rosidl_generator_c)
"'rosidl_typesupport_introspection_c' extension.")
endif()

find_package(rosidl_cmake REQUIRED)
find_package(rosidl_runtime_c REQUIRED)
find_package(rosidl_typesupport_interface REQUIRED)
find_package(rosidl_typesupport_introspection_c REQUIRED)
Expand All @@ -41,8 +42,7 @@ set(_dependency_files "")
set(_dependencies "")
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
foreach(_idl_file ${${_pkg_name}_IDL_FILES})
set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}")
normalize_path(_abs_idl_file "${_abs_idl_file}")
rosidl_find_package_idl(_abs_idl_file "${_pkg_name}" "${_idl_file}")
list(APPEND _dependency_files "${_abs_idl_file}")
list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}")
endforeach()
Expand Down
1 change: 1 addition & 0 deletions rosidl_typesupport_introspection_c/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<buildtool_export_depend>rosidl_generator_c</buildtool_export_depend>
<buildtool_export_depend>rosidl_pycommon</buildtool_export_depend>

<build_export_depend>rosidl_cmake</build_export_depend>
<build_export_depend>rosidl_runtime_c</build_export_depend>
<build_export_depend>rosidl_typesupport_interface</build_export_depend>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ if(NOT TARGET ${rosidl_generate_interfaces_TARGET}__rosidl_generator_cpp)
"'rosidl_typesupport_introspection_cpp' extension.")
endif()

find_package(rosidl_cmake REQUIRED)
find_package(rosidl_runtime_c REQUIRED)
find_package(rosidl_typesupport_interface REQUIRED)
find_package(rosidl_typesupport_introspection_cpp REQUIRED)
Expand All @@ -41,8 +42,7 @@ set(_dependency_files "")
set(_dependencies "")
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
foreach(_idl_file ${${_pkg_name}_IDL_FILES})
set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}")
normalize_path(_abs_idl_file "${_abs_idl_file}")
rosidl_find_package_idl(_abs_idl_file "${_pkg_name}" "${_idl_file}")
list(APPEND _dependency_files "${_abs_idl_file}")
list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}")
endforeach()
Expand Down
1 change: 1 addition & 0 deletions rosidl_typesupport_introspection_cpp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<buildtool_export_depend>rosidl_generator_cpp</buildtool_export_depend>
<buildtool_export_depend>rosidl_pycommon</buildtool_export_depend>

<build_export_depend>rosidl_cmake</build_export_depend>
<build_export_depend>rosidl_runtime_c</build_export_depend>
<build_export_depend>rosidl_runtime_cpp</build_export_depend>

Expand Down

0 comments on commit f47565c

Please sign in to comment.