Skip to content
Open
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
139 changes: 77 additions & 62 deletions webots_ros2_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,62 +30,77 @@ find_package(vision_msgs REQUIRED)
find_package(webots_ros2_msgs REQUIRED)
find_package(tinyxml2_vendor REQUIRED)
find_package(TinyXML2 REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(yaml_cpp_vendor REQUIRED)

if($ENV{ROS_DISTRO} MATCHES "humble")
find_package(Python 3.10 EXACT REQUIRED COMPONENTS Development)
elseif($ENV{ROS_DISTRO} MATCHES "iron")
find_package(Python 3.10 EXACT REQUIRED COMPONENTS Development)
elseif($ENV{ROS_DISTRO} MATCHES "jazzy")
find_package(Python 3.12 EXACT REQUIRED COMPONENTS Development)
elseif($ENV{ROS_DISTRO} MATCHES "kilted")
find_package(Python 3.12 EXACT REQUIRED COMPONENTS Development)
elseif($ENV{ROS_DISTRO} MATCHES "rolling")
find_package(Python 3.12 EXACT REQUIRED COMPONENTS Development)
if($ENV{ROS_DISTRO} MATCHES "humble|iron")
set(PYTHON_VER 3.10)
else()
set(PYTHON_VER 3.12)
endif()
find_package(Python ${PYTHON_VER} EXACT REQUIRED COMPONENTS Development)

add_custom_target(compile-lib-controller ALL
COMMAND ${CMAKE_COMMAND} -E env "WEBOTS_HOME=${CMAKE_CURRENT_SOURCE_DIR}/webots" make release -f Makefile > /dev/null 2>&1
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/webots/src/controller
)

add_custom_target(compile-lib-vehicle ALL
COMMAND ${CMAKE_COMMAND} -E env "WEBOTS_HOME=${CMAKE_CURRENT_SOURCE_DIR}/webots" make release -f Makefile > /dev/null 2>&1
DEPENDS compile-lib-controller
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/webots/projects/default/libraries/vehicle
)
# Configure Webots library paths:
# - Use system-installed Webots.app bundle on macOS
# - Otherwise assume in-tree source build (Linux or macOS)

add_custom_target(compile-generic-window ALL
COMMAND ${CMAKE_COMMAND} -E env "WEBOTS_HOME=${CMAKE_CURRENT_SOURCE_DIR}/webots" make release -f Makefile > /dev/null 2>&1
DEPENDS compile-lib-controller
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/webots/resources/projects/libraries/generic_robot_window
)
if(APPLE AND EXISTS /Applications/Webots.app)
set(WEBOTS_PREBUILT TRUE)
set(WEBOTS_HOME /Applications/Webots.app/Contents)
include_directories(
${WEBOTS_HOME}/include/controller/c
${WEBOTS_HOME}/include/controller/cpp
${Python_INCLUDE_DIRS}
)
link_directories(${WEBOTS_HOME}/lib/controller)
set(WEBOTS_LIB_BASE ${WEBOTS_HOME}/lib/controller)
set(WEBOTS_CONTROLLER_EXEC ${WEBOTS_HOME}/MacOS/webots-controller)
else()
set(WEBOTS_PREBUILT FALSE)
set(WEBOTS_LIB_BASE ${CMAKE_CURRENT_SOURCE_DIR}/webots/lib/controller)
include_directories(
include
webots/include/controller/c
webots/include/controller/cpp
${Python_INCLUDE_DIRS}
)

set(WEBOTS_LIB_BASE webots/lib/controller)
# Build Webots libraries from source
add_custom_target(compile-lib-controller ALL
COMMAND ${CMAKE_COMMAND} -E env "WEBOTS_HOME=${CMAKE_CURRENT_SOURCE_DIR}/webots" make release -f Makefile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/webots/src/controller
)

include_directories(
include
webots/include/controller/c
webots/include/controller/cpp
${Python_INCLUDE_DIRS}
)
add_custom_target(compile-lib-vehicle ALL
COMMAND ${CMAKE_COMMAND} -E env "WEBOTS_HOME=${CMAKE_CURRENT_SOURCE_DIR}/webots" make release -f Makefile
DEPENDS compile-lib-controller
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/webots/projects/default/libraries/vehicle
)

link_directories(${WEBOTS_LIB_BASE})
add_custom_target(compile-generic-window ALL
COMMAND ${CMAKE_COMMAND} -E env "WEBOTS_HOME=${CMAKE_CURRENT_SOURCE_DIR}/webots" make release -f Makefile
DEPENDS compile-lib-controller
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/webots/resources/projects/libraries/generic_robot_window
)
set(WEBOTS_CONTROLLER_EXEC webots/webots-controller)
endif()

set(WEBOTS_LIB
${CMAKE_SHARED_LIBRARY_PREFIX}Controller${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_SHARED_LIBRARY_PREFIX}CppController${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_SHARED_LIBRARY_PREFIX}driver${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_SHARED_LIBRARY_PREFIX}CppDriver${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_SHARED_LIBRARY_PREFIX}car${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_SHARED_LIBRARY_PREFIX}CppCar${CMAKE_SHARED_LIBRARY_SUFFIX}
file(GLOB WEBOTS_LIB_FILES
"${WEBOTS_LIB_BASE}/*Controller${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${WEBOTS_LIB_BASE}/*CppController${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${WEBOTS_LIB_BASE}/*driver${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${WEBOTS_LIB_BASE}/*CppDriver${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${WEBOTS_LIB_BASE}/*car${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${WEBOTS_LIB_BASE}/*CppCar${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
set(WEBOTS_LIB ${WEBOTS_LIB_FILES})

ament_python_install_package(controller
PACKAGE_DIR ${WEBOTS_LIB_BASE}/python/controller)

ament_python_install_package(vehicle
PACKAGE_DIR ${WEBOTS_LIB_BASE}/python/vehicle)
# Only install Python packages if the source directories exist
foreach(pkg IN ITEMS controller vehicle)
if(EXISTS ${WEBOTS_LIB_BASE}/python/${pkg})
ament_python_install_package(${pkg} PACKAGE_DIR ${WEBOTS_LIB_BASE}/python/${pkg})
endif()
endforeach()

ament_python_install_package(${PROJECT_NAME}
PACKAGE_DIR ${PROJECT_NAME})
Expand Down Expand Up @@ -149,9 +164,7 @@ else()
yaml-cpp
)
endif()
add_dependencies(driver
compile-lib-vehicle
)

install(
DIRECTORY include/
DESTINATION include
Expand Down Expand Up @@ -190,9 +203,7 @@ else()
${WEBOTS_LIB}
)
endif()
add_dependencies(${PROJECT_NAME}_imu
compile-lib-vehicle
)

install(TARGETS ${PROJECT_NAME}_imu
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
Expand Down Expand Up @@ -227,9 +238,7 @@ else()
${WEBOTS_LIB}
)
endif()
add_dependencies(${PROJECT_NAME}_rgbd
compile-lib-vehicle
)

install(TARGETS ${PROJECT_NAME}_rgbd
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
Expand Down Expand Up @@ -266,20 +275,26 @@ target_compile_definitions(${PROJECT_NAME}_rgbd PUBLIC "PLUGINLIB__DISABLE_BOOST
pluginlib_export_plugin_description_file(${PROJECT_NAME} webots_ros2_imu.xml)
pluginlib_export_plugin_description_file(${PROJECT_NAME} webots_ros2_rgbd.xml)

# Install ROS 2 nodes
install(PROGRAMS ${PROJECT_NAME}/ros2_supervisor.py
DESTINATION lib/${PROJECT_NAME}
)

# Install scripts
install(
DIRECTORY scripts/
DESTINATION share/${PROJECT_NAME}/scripts
)

# Install webots-controller script
install(
PROGRAMS webots/webots-controller
# Install ROS 2 nodes
install(PROGRAMS ${PROJECT_NAME}/ros2_supervisor.py
DESTINATION lib/${PROJECT_NAME}
)

# Dynamic IMU and RGBD libraries: similar cross-platform treatment applies
# <<< CROSS-PLATFORM CHANGE: add_dependencies only if source build
if(NOT WEBOTS_PREBUILT)
add_dependencies(driver compile-lib-vehicle)
add_dependencies(${PROJECT_NAME}_imu compile-lib-vehicle)
add_dependencies(${PROJECT_NAME}_rgbd compile-lib-vehicle)
endif()

install(PROGRAMS ${WEBOTS_CONTROLLER_EXEC}
DESTINATION share/${PROJECT_NAME}/scripts
)

Expand Down
Loading