ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

catkin: When are the install directives in CMakeLists.txt effective?

asked 2021-10-25 00:08:38 -0500

akihiko gravatar image

updated 2021-10-26 09:08:01 -0500

lucasw gravatar image

I tested a simple catkin package, and have some questions about the install directives in CMakeLists.txt.

My environment is:

  • OS: Ubuntu 18.04
  • ROS: melodic
  • catkin system: python-catkin-tools

The package consists of:

~/catkin_ws/src/test_hoge1:

  • CMakeLists.txt
  • package.xml
  • scripts/
    • test2_node.py
  • src/
    • test1_node.cpp

So, there are two noes in the package (one is made with C++ and the other is a Python script).

The first version of CMakeLists.txt is:

cmake_minimum_required(VERSION 3.0.2)
project(test_hoge1)
find_package(catkin REQUIRED
  roscpp
  rospy
  std_msgs)

catkin_package(
)

include_directories(
${catkin_INCLUDE_DIRS}
)
add_executable(${PROJECT_NAME}_test1_node src/test1_node.cpp)
set_target_properties(${PROJECT_NAME}_test1_node PROPERTIES OUTPUT_NAME test1_node PREFIX "")
add_dependencies(${PROJECT_NAME}_test1_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(${PROJECT_NAME}_test1_node
  ${catkin_LIBRARIES}
)

After executing $ catkin build --this, the following (executable-related) files were produced:

  • ./devel/lib/test_hoge1/test1_node (symbolic link to the below file)
  • ./devel/.private/test_hoge1/lib/test_hoge1/test1_node

Running nodes by rosrun,

$ rosrun test_hoge1 test1_node
#--> ./devel/lib/test_hoge1/test1_node is executed.
$ rosrun test_hoge1 test2_node.py
#--> ./src/test_hoge1/scripts/test2_node.py is executed.

Then I added the following directives into CMakeLists.txt:

catkin_install_python(PROGRAMS
  scripts/test2_node.py
  DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
install(TARGETS ${PROJECT_NAME}_test1_node
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

catkin build --this produced the following:

  • ./build/test_hoge1/catkin_generated/installspace/test2_node.py
  • ./devel/lib/test_hoge1/test1_node (symbolic link to the below file)
  • ./devel/.private/test_hoge1/lib/test_hoge1/test1_node

test2_node.py is a copy (not a symbolic link) of the script in src/scripts/, so it is a snapshot at building the package.

However executing the script by $ rosrun test_hoge1 test2_node.py still uses ./src/test_hoge1/scripts/test2_node.py.

Based on those experiments, my questions are:

  • The install directive (for C++ nodes) in CMakeLists.txt looks doing nothing. When is it effective? Or, if we work only with Ubuntu, is it unnecessary?
  • Although the catkin_install_python directive copies the scripts as their snapshots, rosrun executes the original scripts. This behavior is confusing. Did I make some mistakes in CMakeLists.txt, or is it a designed behavior? If it is the normal behavior, When and why do we need to use catkin_install_python? If we work only with Ubuntu, is it unnecessary?
edit retag flag offensive close merge delete

Comments

Note that this is essentially a duplicate of #q331276. There are probably others.

gvdhoorn gravatar image gvdhoorn  ( 2021-10-25 02:37:46 -0500 )edit

@gvdhoorn Partially. I'm also asking the necessity of installation, if the package works without doing that.

akihiko gravatar image akihiko  ( 2021-10-25 02:51:05 -0500 )edit

As you should know by now, asking multiple questions in a single post goes against best-practice for a Q&A site like ROS Answers.

gvdhoorn gravatar image gvdhoorn  ( 2021-10-25 03:35:12 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2021-10-25 01:53:36 -0500

gvdhoorn gravatar image

updated 2021-10-25 03:38:29 -0500

When are the install directives in CMakeLists.txt effective?

Seeing as you are using catkin_tools, I believe this can all be explained by quoting the relevant documentation (this section specifically):

Without any additional arguments, packages are not “installed” using the standard CMake install() targets. Addition of the --install option will configure a workspace so that it creates an install space and write the products of all install targets to that FHS tree. The contents of the install space, which, by default, is located in a directory named install will look like the following:

$ ls ./install
_setup_util.py bin            env.sh         etc            include
lib            setup.bash     setup.sh       setup.zsh      share

This is a sub section of the documentation of the config verb.

To configure your workspace such that catkin_tools will also create an install space, you'd run:

catkin config --install

after that, you'd need to:

catkin clean -y

and then a final:

catkin build

provided all your packages have correct build scripts, you should now see all install(..)-ed artefacts in the install space.

So to answer your question: packages will only be installed (to the install space) when your workspace has been configured for it.

edit flag offensive delete link more

Comments

Thanks for answering. Although this is explaining how to install the files (and where), it doesn't mention why the installation is necessary (what are the benefits, and what are the disadvantages if we do not do it). Could you add that to you answer, please?

akihiko gravatar image akihiko  ( 2021-10-25 02:51:12 -0500 )edit

Could you add that to you answer, please?

No, I won't.

As I wrote above, asking multiple questions in a single post goes against best-practice.

Why things should be installed is only tangentially related to when they get installed, which was the main question as evidenced by the title of your post.

gvdhoorn gravatar image gvdhoorn  ( 2021-10-25 03:36:20 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-10-25 00:08:38 -0500

Seen: 356 times

Last updated: Oct 25 '21