Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake find_path include directory prefix

Tags:

c++

cmake

openni

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.

like image 568
Masala Avatar asked Mar 21 '14 12:03

Masala


1 Answers

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.

like image 116
ComicSansMS Avatar answered Sep 20 '22 16:09

ComicSansMS