9

I am writing a minimal Find*.cmake for OpenNI. To find the header files I wrote

find_path(OPENNI_INCLUDE_PATH XnOS.h)

which is working as expected (OPENNI_INCLUDE_PATH has the value /usr/include/ni). However, in my files I have to include the headers with

#include <ni/XnOS.h>

How can I get rid of the ni prefix, so I can write

#include <XnOS.h>

The problem with the first include is that a XnCppWrapper.h gets included and this file includes again some Xn*.h headers, but without the ni prefix. This results in a compiler error.

Masala
  • 401
  • 8
  • 14
  • Are all of the files in the first form? I mean you could adjust the OPENNI_INCLUDE_PATH variable to be the parent of what is returned by find_path() and use that instead. – drescherjm Mar 21 '14 at 12:15
  • I think, I don't get your suggestion. Do you mean that I should strap ni from /usr/include/ni? This doesn't solve the include problem. – Masala Mar 21 '14 at 12:23
  • I mean if ni is in /usr/include then OPENNI_INCLUDE_PATH should be /usr/include instead of /usr/include/ni. This way you do not need to generate some script process that changes your c++ source files and headers looking for includes to remove the path. Although I do know if this was the case /usr/include will allready be in your includes so the OPENNI_INCLUDE_PATH would be redundant. – drescherjm Mar 21 '14 at 12:31
  • Although you could always set(OPENNI_INCLUDE_PATH ${OPENNI_INCLUDE_PATH};${OPENNI_INCLUDE_PATH}/..) – drescherjm Mar 21 '14 at 12:36
  • You are right, ni is in /usr/include. Unfortunatley it doesn't change a thing if I change OPENNI_INCLUDE_PATH to be /usr/include. In either case I have to write #include in my files, which results in the above described compilation error. – Masala Mar 21 '14 at 12:37
  • If /usr/include is in your includes "#include – drescherjm Mar 21 '14 at 12:39
  • It results in a compilation error, because in the file XnOs.h is again an include that doesn't have the ni/ prefix. Then the compiler complains that it can not find the file. – Masala Mar 21 '14 at 12:42
  • Then try to include both paths like I said 3 posts ago. – drescherjm Mar 21 '14 at 12:43
  • That was no solution. I get the same compilation error. – Masala Mar 21 '14 at 12:49
  • If both /usr/include/ni and /usr/include are in your includes you should not get an error. Something else must be happening. – drescherjm Mar 21 '14 at 12:52

1 Answers1

13

Always have the path you use for find_path match the one in your #include statements.

If you want to #include <ni/XnOS.h> you should write

find_path(OPENNI_INCLUDE_PATH ni/XnOS.h)

If instead you want to #include <XnOS.h>, use

find_path(OPENNI_INCLUDE_PATH XnOS.h)

Just be sure to make up your mind beforehand which one you want to use and stick to it. Mixing several include paths for the same library is a sure way to unnecessarily overcomplicate the build environment.

ComicSansMS
  • 51,484
  • 14
  • 155
  • 166
  • In my cmake file I have `find_path(OPENNI_INCLUDE_PATH XnOS.h)` and I want to include the header with `#include `, but it doesn't work this way. – Masala Mar 21 '14 at 13:27
  • @Masala Then you probably have a bug in your CMake script somewhere. Use [`message`](http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:message) to verify that the value returned by `find_path` matches your expectation. Also be sure to double-check that your targets actually use that value as an include directory. – ComicSansMS Mar 21 '14 at 13:31
  • You were right, the mistake was in the main cmake file and not in the find module. – Masala Mar 21 '14 at 13:36