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

Support ROS2 build #5

Merged
merged 11 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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: 36 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ROS_DISTRO: [melodic, melodic_llvm, noetic, noetic_llvm]
ROS_DISTRO: [melodic, melodic_llvm, noetic, noetic_llvm, foxy, foxy_llvm, galactic, galactic_llvm]

steps:
- uses: actions/checkout@v2
Expand All @@ -32,3 +32,38 @@ jobs:
file: ${{github.workspace}}/docker/${{ matrix.ROS_DISTRO }}/Dockerfile
context: .
push: false

build-ros2:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ros_distribution:
- foxy
- galactic
- rolling
include:
# Foxy Fitzroy (June 2020 - May 2023)
- docker_image: rostooling/setup-ros-docker:ubuntu-focal-ros-foxy-ros-base-latest
ros_distribution: foxy
ros_version: 2
# Galactic Geochelone (May 2021 - November 2022)
- docker_image: rostooling/setup-ros-docker:ubuntu-focal-ros-galactic-ros-base-latest
ros_distribution: galactic
ros_version: 2
# Rolling Ridley (June 2020 - Present)
- docker_image: rostooling/setup-ros-docker:ubuntu-focal-ros-rolling-ros-base-latest
ros_distribution: rolling
ros_version: 2
container:
image: ${{ matrix.docker_image }}

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Run action-ros-ci
uses: ros-tooling/action-ros-ci@v0.2
with:
package-name: ndt_omp
target-ros2-distro: ${{ matrix.ros_distribution }}
79 changes: 76 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,79 @@ set(CMAKE_CXX_FLAGS "-std=c++14 -msse -msse2 -msse3 -msse4 -msse4.1 -msse4.2")
# pcl 1.7 causes a segfault when it is built with debug mode
set(CMAKE_BUILD_TYPE "RELEASE")

if($ENV{ROS_VERSION} EQUAL 1)
# ROS1
find_package(catkin REQUIRED COMPONENTS
roscpp
pcl_ros
)

find_package(PCL 1.7 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

message(STATUS "PCL_INCLUDE_DIRS:" ${PCL_INCLUDE_DIRS})
message(STATUS "PCL_LIBRARY_DIRS:" ${PCL_LIBRARY_DIRS})
message(STATUS "PCL_DEFINITIONS:" ${PCL_DEFINITIONS})

find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

###################################
## catkin specific configuration ##
###################################
catkin_package(
INCLUDE_DIRS include
LIBRARIES ndt_omp
)

###########
## Build ##
###########
include_directories(include)
include_directories(
${catkin_INCLUDE_DIRS}
)

add_library(ndt_omp
src/pclomp/voxel_grid_covariance_omp.cpp
src/pclomp/ndt_omp.cpp
src/pclomp/gicp_omp.cpp
)

add_executable(align
apps/align.cpp
)
add_dependencies(align
ndt_omp
)
target_link_libraries(align
${catkin_LIBRARIES}
${PCL_LIBRARIES}
ndt_omp
)

#############
## INSTALL ##
#############

install(
TARGETS
ndt_omp
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)

# install headers
install(DIRECTORY include/pclomp
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION})
else()
# ROS2
find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()

Expand All @@ -25,19 +98,19 @@ find_package(OpenMP)
###########
## Build ##
###########

ament_auto_add_library(ndt_omp SHARED
src/pclomp/voxel_grid_covariance_omp.cpp
src/pclomp/ndt_omp.cpp
src/pclomp/gicp_omp.cpp
)

target_link_libraries(ndt_omp PUBLIC ${PCL_LIBRARIES})
target_link_libraries(ndt_omp ${PCL_LIBRARIES})

if(OpenMP_CXX_FOUND)
target_link_libraries(ndt_omp PUBLIC OpenMP::OpenMP_CXX)
target_link_libraries(ndt_omp OpenMP::OpenMP_CXX)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove PUBLIC?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the docker CI for ROS2 failed with the following error.
And the solution to this error is to remove PUBLIC.
https://stackoverflow.com/questions/59522267/cmake-rejects-a-second-target-link-libraries-talking-about-keyword-vs-plain

Starting >>> ndt_omp
--- stderr: ndt_omp
CMake Warning (dev) at CMakeLists.txt:87 (find_package):
  Policy CMP0074 is not set: find_package uses <PackageName>_ROOT variables.
  Run "cmake --help-policy CMP0074" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  CMake variable PCL_ROOT is set to:

    /usr

  For compatibility, CMake is ignoring the variable.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at CMakeLists.txt:107 (target_link_libraries):
  The plain signature for target_link_libraries has already been used with
  the target "ndt_omp".  All uses of target_link_libraries with a target must
  be either all-keyword or all-plain.

  The uses of the plain signature are here:

   * /opt/ros/foxy/share/ament_cmake_target_dependencies/cmake/ament_target_dependencies.cmake:145 (target_link_libraries)



---
Failed   <<< ndt_omp [9.05s, exited with code 1]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because of ament_auto_add_library?
I feel all-keyword is better if possible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work?
https://github.com/ament/ament_cmake/blob/4ac1ed1153ac774116c273021944eb3ea836495c/ament_cmake_auto/cmake/ament_auto_add_library.cmake#L66

ament_auto_add_library(ndt_omp SHARED PUBLIC
  src/pclomp/voxel_grid_covariance_omp.cpp
  src/pclomp/ndt_omp.cpp
  src/pclomp/gicp_omp.cpp
)

target_link_libraries(ndt_omp PUBLIC ${PCL_LIBRARIES})

if(OpenMP_CXX_FOUND)
  target_link_libraries(ndt_omp PUBLIC OpenMP::OpenMP_CXX)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work? https://github.com/ament/ament_cmake/blob/4ac1ed1153ac774116c273021944eb3ea836495c/ament_cmake_auto/cmake/ament_auto_add_library.cmake#L66

ament_auto_add_library(ndt_omp SHARED PUBLIC
  src/pclomp/voxel_grid_covariance_omp.cpp
  src/pclomp/ndt_omp.cpp
  src/pclomp/gicp_omp.cpp
)

target_link_libraries(ndt_omp PUBLIC ${PCL_LIBRARIES})

if(OpenMP_CXX_FOUND)
  target_link_libraries(ndt_omp PUBLIC OpenMP::OpenMP_CXX)

It doesn't work. 😢

Ah, but since the upstream's style is plain, I think it's okay.

Thanks for letting me know. I'll keep the current code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥺
Okay, thank you!

else()
message(WARNING "OpenMP not found")
endif()

ament_auto_package()
endif()
25 changes: 25 additions & 0 deletions docker/foxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM ros:foxy

RUN apt-get update && apt-get install -y --no-install-recommends \
wget nano build-essential libomp-dev clang lld git\
ros-foxy-geodesy ros-foxy-pcl-ros ros-foxy-nmea-msgs \
ros-foxy-rviz2 ros-foxy-libg2o \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p /root/colcon_ws/src
WORKDIR /root/colcon_ws/src
# Comment it out until the repository supports ROS2 builds.
# RUN git clone https://github.com/SMRT-AIST/fast_gicp.git --recursive --depth=1
# RUN git clone https://github.com/koide3/hdl_graph_slam.git --depth=1

COPY . /root/colcon_ws/src/ndt_omp/

WORKDIR /root/colcon_ws
RUN /bin/bash -c '. /opt/ros/foxy/setup.bash; colcon build'
RUN sed -i "6i source \"/root/colcon_ws/devel/setup.bash\"" /ros_entrypoint.sh

WORKDIR /

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]
27 changes: 27 additions & 0 deletions docker/foxy_llvm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ros:foxy

RUN apt-get update && apt-get install -y --no-install-recommends \
wget nano build-essential libomp-dev clang lld git\
ros-foxy-geodesy ros-foxy-pcl-ros ros-foxy-nmea-msgs \
ros-foxy-rviz2 ros-foxy-libg2o \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p /root/colcon_ws/src
WORKDIR /root/colcon_ws/src
# Comment it out until the repository supports ROS2 builds.
# RUN git clone https://github.com/SMRT-AIST/fast_gicp.git --recursive --depth=1
# RUN git clone https://github.com/koide3/hdl_graph_slam.git --depth=1

COPY . /root/colcon_ws/src/ndt_omp/

RUN update-alternatives --install /usr/bin/ld ld /usr/bin/ld.lld 50

WORKDIR /root/colcon_ws
RUN /bin/bash -c '. /opt/ros/foxy/setup.bash; CC=clang CXX=clang++ colcon build'
RUN sed -i "6i source \"/root/colcon_ws/devel/setup.bash\"" /ros_entrypoint.sh

WORKDIR /

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]
25 changes: 25 additions & 0 deletions docker/galactic/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM ros:galactic

RUN apt-get update && apt-get install -y --no-install-recommends \
wget nano build-essential libomp-dev clang lld git\
ros-galactic-geodesy ros-galactic-pcl-ros ros-galactic-nmea-msgs \
ros-galactic-rviz2 ros-galactic-libg2o \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p /root/colcon_ws/src
WORKDIR /root/colcon_ws/src
RUN git clone https://github.com/SMRT-AIST/fast_gicp.git --recursive --depth=1
# Comment it out until the repository supports ROS2 builds.
# RUN git clone https://github.com/koide3/hdl_graph_slam.git --depth=1

COPY . /root/colcon_ws/src/ndt_omp/

WORKDIR /root/colcon_ws
RUN /bin/bash -c '. /opt/ros/galactic/setup.bash; colcon build'
RUN sed -i "6i source \"/root/colcon_ws/devel/setup.bash\"" /ros_entrypoint.sh

WORKDIR /

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]
27 changes: 27 additions & 0 deletions docker/galactic_llvm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ros:galactic

RUN apt-get update && apt-get install -y --no-install-recommends \
wget nano build-essential libomp-dev clang lld git\
ros-galactic-geodesy ros-galactic-pcl-ros ros-galactic-nmea-msgs \
ros-galactic-rviz2 ros-galactic-libg2o \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p /root/colcon_ws/src
WORKDIR /root/colcon_ws/src
RUN git clone https://github.com/SMRT-AIST/fast_gicp.git --recursive --depth=1
# Comment it out until the repository supports ROS2 builds.
# RUN git clone https://github.com/koide3/hdl_graph_slam.git --depth=1

COPY . /root/colcon_ws/src/ndt_omp/

RUN update-alternatives --install /usr/bin/ld ld /usr/bin/ld.lld 50

WORKDIR /root/colcon_ws
RUN /bin/bash -c '. /opt/ros/galactic/setup.bash; CC=clang CXX=clang++ colcon build'
RUN sed -i "6i source \"/root/colcon_ws/devel/setup.bash\"" /ros_entrypoint.sh

WORKDIR /

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]
5 changes: 2 additions & 3 deletions docker/melodic/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM ros:melodic

RUN apt-get update && apt-get install -y --no-install-recommends \
&& apt-get install -y --no-install-recommends \
wget nano build-essential libomp-dev clang lld\
ros-melodic-geodesy ros-melodic-pcl-ros ros-melodic-nmea-msgs \
ros-melodic-rviz ros-melodic-tf-conversions ros-melodic-libg2o \
Expand All @@ -11,8 +10,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
RUN mkdir -p /root/catkin_ws/src
WORKDIR /root/catkin_ws/src
RUN /bin/bash -c '. /opt/ros/melodic/setup.bash; catkin_init_workspace'
RUN git clone https://github.com/SMRT-AIST/fast_gicp.git --recursive
RUN git clone https://github.com/koide3/hdl_graph_slam.git
RUN git clone https://github.com/SMRT-AIST/fast_gicp.git --recursive --depth=1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RUN git clone https://github.com/koide3/hdl_graph_slam.git --depth=1

COPY . /root/catkin_ws/src/ndt_omp/

Expand Down
5 changes: 2 additions & 3 deletions docker/melodic_llvm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM ros:melodic

RUN apt-get update && apt-get install -y --no-install-recommends \
&& apt-get install -y --no-install-recommends \
wget nano build-essential libomp-dev clang lld\
ros-melodic-geodesy ros-melodic-pcl-ros ros-melodic-nmea-msgs \
ros-melodic-rviz ros-melodic-tf-conversions ros-melodic-libg2o \
Expand All @@ -11,8 +10,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
RUN mkdir -p /root/catkin_ws/src
WORKDIR /root/catkin_ws/src
RUN /bin/bash -c '. /opt/ros/melodic/setup.bash; catkin_init_workspace'
RUN git clone https://github.com/SMRT-AIST/fast_gicp.git --recursive
RUN git clone https://github.com/koide3/hdl_graph_slam.git
RUN git clone https://github.com/SMRT-AIST/fast_gicp.git --recursive --depth=1
RUN git clone https://github.com/koide3/hdl_graph_slam.git --depth=1

COPY . /root/catkin_ws/src/ndt_omp/

Expand Down
5 changes: 2 additions & 3 deletions docker/noetic/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM ros:noetic

RUN apt-get update && apt-get install -y --no-install-recommends \
&& apt-get install -y --no-install-recommends \
wget nano build-essential libomp-dev clang lld git\
ros-noetic-geodesy ros-noetic-pcl-ros ros-noetic-nmea-msgs \
ros-noetic-rviz ros-noetic-tf-conversions ros-noetic-libg2o \
Expand All @@ -11,8 +10,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
RUN mkdir -p /root/catkin_ws/src
WORKDIR /root/catkin_ws/src
RUN /bin/bash -c '. /opt/ros/noetic/setup.bash; catkin_init_workspace'
RUN git clone https://github.com/SMRT-AIST/fast_gicp.git --recursive
RUN git clone https://github.com/koide3/hdl_graph_slam.git
RUN git clone https://github.com/SMRT-AIST/fast_gicp.git --recursive --depth=1
RUN git clone https://github.com/koide3/hdl_graph_slam.git --depth=1

COPY . /root/catkin_ws/src/ndt_omp/

Expand Down
5 changes: 2 additions & 3 deletions docker/noetic_llvm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM ros:noetic

RUN apt-get update && apt-get install -y --no-install-recommends \
&& apt-get install -y --no-install-recommends \
wget nano build-essential libomp-dev clang lld git\
ros-noetic-geodesy ros-noetic-pcl-ros ros-noetic-nmea-msgs \
ros-noetic-rviz ros-noetic-tf-conversions ros-noetic-libg2o \
Expand All @@ -11,8 +10,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
RUN mkdir -p /root/catkin_ws/src
WORKDIR /root/catkin_ws/src
RUN /bin/bash -c '. /opt/ros/noetic/setup.bash; catkin_init_workspace'
RUN git clone https://github.com/SMRT-AIST/fast_gicp.git --recursive
RUN git clone https://github.com/koide3/hdl_graph_slam.git
RUN git clone https://github.com/SMRT-AIST/fast_gicp.git --recursive --depth=1
RUN git clone https://github.com/koide3/hdl_graph_slam.git --depth=1

COPY . /root/catkin_ws/src/ndt_omp/

Expand Down
13 changes: 10 additions & 3 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>ndt_omp</name>
<version>0.0.0</version>
Expand All @@ -8,10 +9,16 @@

<license>BSD</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<depend>libpcl-all-dev</depend>
<buildtool_depend condition="$ROS_VERSION == 1">catkin</buildtool_depend>
<buildtool_depend condition="$ROS_VERSION == 2">ament_cmake_auto</buildtool_depend>

<depend condition="$ROS_VERSION == 1">pcl_ros</depend>
<depend condition="$ROS_VERSION == 1">roscpp</depend>

<depend condition="$ROS_VERSION == 2">libpcl-all-dev</depend>

<export>
<build_type>ament_cmake</build_type>
<build_type condition="$ROS_VERSION == 1">catkin</build_type>
<build_type condition="$ROS_VERSION == 2">ament_cmake</build_type>
</export>
</package>