How to add include directories in CMake

It is common in many setups to have additional include directories that need to be used during compilation of C, C++ or CUDA code. These can be both global or relative local directories. Adding include directories to all targets or specific targets is easy in CMake.

  • The directive to add include directories for all targets being compiled by CMake is include_directories. For example, add this to CMakeLists.txt:
include_directories(
    /usr/local/flac
    include
    src
    )
  • The directive to add include directories for a particular target being compiled by CMake is target_include_directories. For example, add this to CMakeLists.txt to compile the target foobar:
target_include_directories(
    foobar PUBLIC
    /usr/local/flac
    include
    src
    )

Tried with: CMake 2.8.7 and Ubuntu 14.04

One thought on “How to add include directories in CMake”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s