What install command does in cmake?

I am sorry for being so naive. I tried to understand from this cmake website's link But could not understand. I have a sample cmake file, where an executable is generated by

add_executable(${PROJECT_NAME}_node src/filename.cpp)

Then later it installed by the following command

install(TARGETS ${PROJECT_NAME}_node ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} )

This cmake is from ROS so catkin is there. The overall question remains the same. Does someone know, why do we need to install TARGETS/ FILES?

8

3 Answers

INSTALL is useful in, at least, two scenarios:

  • You download some package's source code, generate the binaries, which you want to use in your system. You can INSTALL them under /usr/bin, for example

  • You compile some library which you'll use from another product. It will gather the required files (header files, libraries...), and just those, and put them in a known place, no matter where the library compilation expects them.

You could just copy them, but relying on CMake allows the process to be expressed at a higher level.

It simply installs built binaries on the local system.


If a tool like bash or git has to be installed from sources (e.g. to use its latest version), build it then install it to use.

Building and installing from sources (from private build directory into public system directory) is a normal way if local system does not have required tool, or its package does not exists, or the packaged version is old, or some customization is needed.

You don't need to use the INSTALL function of catkin.

INSTALL function will just copy your final BINARY,LIBRARY,etc to a safer place (ex. main ros package space located at /opt/ros/<your-version>/share,lib,include) to keep the build workspace less crowded and to keep files safe in case your workspace got corrupted.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like