catkin: When are the install directives in CMakeLists.txt effective?
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 usecatkin_install_python
? If we work only with Ubuntu, is it unnecessary?
Note that this is essentially a duplicate of #q331276. There are probably others.
@gvdhoorn Partially. I'm also asking the necessity of installation, if the package works without doing that.
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.