SPlatten
SPlatten

Reputation: 5760

cmake v2.8.19.2 include folder from outside project

I am trying to build a library using cmake version 2.8.10.2

A header is included from a directory outside of the project, I’ve tried adding the path to the directory using:

add_subdirectory($ENV{PRJ2}/path/)

I’ve check the path is correct but when building I get:

fatal error: header_name.h: No such file or directory

It’s driving me crazy…

Upvotes: 0

Views: 68

Answers (1)

ErniBrown
ErniBrown

Reputation: 1372

add_subdirectory adds a folder to the cmake project, searching for the CMakeLists.txt file in it and loading the configuration. If you want to add headers from a directory to a project you should use include_directories (link here)

Consider that using a directory out of the main folder of the project is not convenient. I suggest you two possibilities:

  • If you are using some headers that are not part of another project (for example you developed by yourself for other reasons and want to add them to your project), then move them inside one of your project folders
  • If the headers are from another library/project add them using the find_package system. I was not able to find a good guide for the 2.x versions of cmake, but I strongly suggest you to move to 3.x

Upvotes: 1

Related Questions