Skip to content

Commit

Permalink
Merge pull request #66 from fjanguita/CMakeLists_example
Browse files Browse the repository at this point in the history
CMakeLists example and link to node template added
  • Loading branch information
RPS98 authored Jun 26, 2024
2 parents 38b9a8f + 858a2ff commit 8826887
Showing 1 changed file with 119 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Developing a New Package
------------------------


.. _development_guide_new_pkg_architecture:

Architecture of a New Package
Expand Down Expand Up @@ -420,20 +421,135 @@ In order to compile this tests some lines must be added into a **NEW** ``CMakeLi
endforeach()
endif()
In order to link this ``./tests/CMakeLists.txt`` file into the ``CMakeLists.txt`` file of the package, the following line must be added:
In order to link and run your functional tests alongside with the code style ones, your package's CMakeLists.txt should follow the next structure:

.. code-block:: cmake
# Set the minimum required CMake version
cmake_minimum_required(VERSION 3.5)
# Set the project name
set(PROJECT_NAME as2_node_template)
project(${PROJECT_NAME})
# Default to C++17 if not set
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
# Set Release as default build type if not set
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# find dependencies
set(PROJECT_DEPENDENCIES
ament_cmake
rclcpp
as2_core
as2_msgs
std_msgs
)
foreach(DEPENDENCY ${PROJECT_DEPENDENCIES})
find_package(${DEPENDENCY} REQUIRED)
endforeach()
# Include necessary directories
include_directories(
include
include/${PROJECT_NAME}
)
# Set source files
set(SOURCE_CPP_FILES
src/${PROJECT_NAME}_node.cpp
src/${PROJECT_NAME}.cpp
)
# Create the node executable
add_executable(${PROJECT_NAME}_node ${SOURCE_CPP_FILES})
ament_target_dependencies(${PROJECT_NAME}_node ${PROJECT_DEPENDENCIES})
# Create the dynamic library
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_library(${PROJECT_NAME} SHARED ${SOURCE_CPP_FILES})
ament_target_dependencies(${PROJECT_NAME} ${PROJECT_DEPENDENCIES})
# Set the public include directories for the library
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
# Install the headers
install(
DIRECTORY include/
DESTINATION include
)
# Install the node executable
install(TARGETS
${PROJECT_NAME}_node
DESTINATION lib/${PROJECT_NAME}
)
# Install the shared library
install(
TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
# Export the libraries
ament_export_libraries(${PROJECT_NAME})
# Export the targets
ament_export_targets(export_${PROJECT_NAME})
# Export the include directories
ament_export_include_directories(include)
# Install the launch directory
install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}
)
# Install the config directory
install(DIRECTORY
config
DESTINATION share/${PROJECT_NAME}
)
# Build tests if testing is enabled
if(BUILD_TESTING)
# all other tests
add_subdirectory(tests)
find_package(ament_lint_auto REQUIRED)
file(GLOB_RECURSE EXCLUDE_FILES
build/*
install/*
)
set(AMENT_LINT_AUTO_FILE_EXCLUDE ${EXCLUDE_FILES})
ament_lint_auto_find_test_dependencies()
add_subdirectory(tests)
endif()
# Create the ament package
ament_package()
To run these tests:

.. code-block:: bash
colcon test
------------------------------
Node Template for New Packages
------------------------------

An example node with the proper structure and all the templates can be found `here <https://github.com/aerostack2/as2_node_template>`_.

0 comments on commit 8826887

Please sign in to comment.