Skip to content

Commit

Permalink
Separate ros2_standalone cmake project to resolve libraries conflict (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
msz-rai authored Sep 23, 2023
1 parent b7528ac commit 222f8e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
14 changes: 0 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@ set(RGL_BUILD_PCL_EXTENSION OFF CACHE BOOL
"Enables building PCL extension.")
set(RGL_BUILD_ROS2_EXTENSION OFF CACHE BOOL
"Enables building ROS2 extension. It requires installed and sourced ROS2.")
set(RGL_BUILD_ROS2_EXTENSION_STANDALONE OFF CACHE BOOL
"Enables building ROS2 extension in standalone mode. It requires installed and sourced ROS2.")

if (RGL_BUILD_ROS2_EXTENSION_STANDALONE)
set(RGL_BUILD_ROS2_EXTENSION ON)
endif()

# Include ros2_standalone
# Needs to be added before add_subdirectory(external) to prevent overriding OS libraries by RGL
# E.g., RGL populate spdlog using FetchContent (statically linked object) which overrides spdlog installed on OS (shared object)
# It causes the standalone build not to find spdlog which looks for shared objects only
if(RGL_BUILD_ROS2_EXTENSION_STANDALONE)
add_subdirectory(ros2_standalone)
endif()

# Hide automatically generated CTest targets
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
Expand Down
6 changes: 5 additions & 1 deletion ros2_standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# This file is based on https://github.com/RobotecAI/ros2cs/blob/develop/src/ros2cs/ros2cs_core/CMakeLists.txt

cmake_minimum_required(VERSION 3.18)

project(RobotecGPULidar_ros2_standalone)

find_program(PATCHELF "patchelf")
if(UNIX)
if(NOT PATCHELF)
Expand Down Expand Up @@ -172,7 +176,7 @@ macro(install_standalone_dependencies)
string(SUBSTRING "${_remainingPath}" 0 ${_lastDotPos} _tempPos)
get_filename_component(_libPathFilename "${_tempPos}" NAME)
get_filename_component(_resolvedFilename "${_resolvedFile}" NAME)
install(CODE "execute_process(COMMAND ln -s ${_resolvedFilename} ${_libPathFilename} WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/ros2_standalone ERROR_QUIET)")
install(CODE "execute_process(COMMAND ln -s ${_resolvedFilename} ${_libPathFilename} WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${INSTALL_DESTINATION_DIR} ERROR_QUIET)")
set(_remainingPath "${_tempPos}")
endwhile()
endif()
Expand Down
16 changes: 10 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def main():
parser.add_argument("--with-ros2", action='store_true',
help="Build RGL with ROS2 extension")
parser.add_argument("--with-ros2-standalone", action='store_true',
help="Build RGL with ROS2 extension in standalone mode")
help="Build RGL with ROS2 extension and install all dependent ROS2 libraries additionally")
parser.add_argument("--cmake", type=str, default="",
help="Pass arguments to cmake. Usage: --cmake=\"args...\"")
if on_linux():
Expand Down Expand Up @@ -121,12 +121,13 @@ def is_cuda_version_ok():
os.environ["Path"] = os.environ["Path"] + ";" + os.path.join(os.getcwd(), args.build_dir)

# Build
if args.with_ros2_standalone:
args.with_ros2 = True
cmake_args = [
f"-DCMAKE_TOOLCHAIN_FILE={os.path.join(cfg.VCPKG_INSTALL_DIR, 'scripts', 'buildsystems', 'vcpkg.cmake') if args.with_pcl else ''}",
f"-DVCPKG_TARGET_TRIPLET={cfg.VCPKG_TRIPLET}",
f"-DVCPKG_TARGET_TRIPLET={cfg.VCPKG_TRIPLET if args.with_pcl else ''}",
f"-DRGL_BUILD_PCL_EXTENSION={'ON' if args.with_pcl else 'OFF'}",
f"-DRGL_BUILD_ROS2_EXTENSION={'ON' if args.with_ros2 else 'OFF'}",
f"-DRGL_BUILD_ROS2_EXTENSION_STANDALONE={'ON' if args.with_ros2_standalone else 'OFF'}"
]

if on_linux():
Expand All @@ -138,8 +139,6 @@ def is_cuda_version_ok():
linker_rpath_flags.append(f"-Wl,-rpath={rpath}")
cmake_args.append(f"-DCMAKE_SHARED_LINKER_FLAGS=\"{' '.join(linker_rpath_flags)}\"")

cmake_args.append(f"-DCMAKE_INSTALL_PREFIX={os.path.join(os.getcwd(), args.build_dir)}")

# Append user args, possibly overwriting
cmake_args.append(args.cmake)

Expand All @@ -148,7 +147,12 @@ def is_cuda_version_ok():
run_subprocess_command(f"cmake --build {args.build_dir} -- {args.build_args}")

if args.with_ros2_standalone:
run_subprocess_command(f"cmake --install {args.build_dir}")
# Build RobotecGPULidar_ros2_standalone project to find and install all dependent ROS2 libraries and their dependencies
# It cannot be added as a subdirectory of RobotecGPULidar project because there is a conflict in the same libraries required by RGL and ROS2
# RGL takes them from vcpkg as statically linked objects while ROS2 standalone required them as a shared objects
ros2_standalone_cmake_args = f"-DCMAKE_INSTALL_PREFIX={os.path.join(os.getcwd(), args.build_dir)}"
run_subprocess_command(f"cmake ros2_standalone -B {args.build_dir}/ros2_standalone -G {cfg.CMAKE_GENERATOR} {ros2_standalone_cmake_args}")
run_subprocess_command(f"cmake --install {args.build_dir}/ros2_standalone")


def on_linux():
Expand Down

0 comments on commit 222f8e8

Please sign in to comment.