How to fix CMake "target_include_directories called with invalid arguments"

Problem:

In your CMakeLists.txt, you want to add an include directory such as /usr/include/mylibrary for the executable myexe using code like:

target_include_directories( myexe /usr/include/mylib )

But when you try to configure the build using cmake . or make, you see an error message like

CMake Error at CMakeLists.txt:8 (target_include_directories):
  target_include_directories called with invalid arguments


-- Configuring incomplete, errors occurred!

Solution

You need to add PUBLIC between the target name (myexe) and the include directory/directories:

target_include_directories( myexe PUBLIC /usr/include/mylib )