Main trickery¶
Dependency ordering of packages
During the CMake run the main source directory is scanned for packages to build. Each package indicates that it is buildable, and what its dependencies in the package.xml file. Catkin considers the build and buildtool dependencies as specified in the REP 127, topologically sorts the packages and calls add_subdirectory() on each package in order.
Generation of find_package infrastructure
Each package calls catkin_package() which generates find_package files; this is for other packages to use. Each package does a find_package of each other; in this way, packages can build with their dependencies in the same devel space, or already installed on the system. Different versions of these files are created for use in the devel space, and in the installation. The stress-test for this scheme is message generation; different language generators must implement a specific CMake interface which is used by genmsg. See also Finding required packages.
Python path forwarding
A special thunk (via the standard python package pkgutil is generated and put in CMAKE_BINARY_DIR/lib/pythonX.Y/dist-packages/PACKAGENAME/__init__.py, which extends the PYTHONPATH to include CMAKE_SOURCE_DIR/path/to/PACKAGENAME/src. This way the devel space PYTHONPATH only needs to contain CMAKE_BINARY_DIR/lib/pythonX.Y/dist-packages. Caveat: it will also need to contain generated Python code in that folder in devel space. At installation time, this thunk-__init__.py disappears and the static python library source is installed alongside the generated message code in the same directory.
Environment generation
When CMake runs, it knows the locations of the CMAKE_BINARY_DIR and so forth, it generates an environment file (in CMAKE_BINARY_DIR/devel). Projects may extend this environment via catkin_add_env_hooks().