diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c5dc2f4..8dda3fb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/ros2_standalone/CMakeLists.txt b/ros2_standalone/CMakeLists.txt index 49883831..4b99247d 100644 --- a/ros2_standalone/CMakeLists.txt +++ b/ros2_standalone/CMakeLists.txt @@ -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) @@ -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() diff --git a/setup.py b/setup.py index 76dbb172..1551e25e 100755 --- a/setup.py +++ b/setup.py @@ -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(): @@ -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(): @@ -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) @@ -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():