What does INCLUDE_DIRS variable in the catkin_package macro do?

I am experimenting with build options in exercise 2.4 in advanced C++ and noticed that the solution sets INCLUDE_DIRS to ‘include/${PROJECT_NAME}/’

In other examples, INCLUDE_DIRS to ‘include’

What does INCLUDE_DIRS set? - The only explanation I found was – INCLUDE_DIRS - The exported include paths (i.e. cflags) for the package – doesn’t clear things up.

David

Hi @davef,

In CMake, INCLUDE_DIRS is a variable used to specify the directories where CMake should look for header files when building a project.

If we have something like this, for example:

set(INCLUDE_DIRS /path/to/include/dir)

This is going to tell g++ (the compiler) to search for header files on this /path/to/include/dir directory, for example.

If in your file you have:

#include "davef.h"

g++ will try to find davef.h at /path/to/include/dir, in the example provided.

When you build your project using g++ , it would be equivalent to running

g++ -I/path/to/include/dir ...

where ... represents other compiler flags and source files.

Thanks,
This leads to two follow-up questions.

  1. In the case of
project(my_robot_manager)
set(INCLUDE_DIRS include)

Is include/ automatically appended to the project name making the full search path

my_package/include/
  1. Are the following three statements doing the same thing?
catkin_package(
  INCLUDE_DIRS include
)
include_directories(
  include
)
set(INCLUDE_DIRS /path/to/include/dir)

dave

Edit: I searched for

include_directories vs catkin_package(INCLUDE_DIRS

in Google and Generative AI gave a good response. I think what was confusing me was that the catkin_package() macro is just syntactical sugar for preexisting functionality in CMake.

Edit2:

Something else that is pretty handy is to add messages to your cmake file with

message(STATUS "XXXXXXX " ${PROJECT_NAME})

Then build with the following command

catkin_make | grep XXXXXXX
1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.