Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does cmake look to find packages?

Tags:

c++

ubuntu

cmake

In Ubuntu 14.04, I am compiling a C++ program, which depends on the following packages: CUDA and OpenNI. In the CMakeListst.txt file for this program, there is the following:

find_package(CUDA)
find_package(OpenNI)

And the output to cmake is:

Found CUDA: /usr/local/cuda (found version "6.5") 
-- Could NOT find OpenNI (missing:  OpenNI_LIBRARY OpenNI_INCLUDE_DIR)

So, it seems that CUDA was found, but OpenNI was not. Now, I have definitely installed OpenNI, but perhaps not in the standard location. Whereas the CUDA files are in usr/local/cuda as stated, my OpenNI files are in ~/Libraries/OpenNI.

My question is: How do I tell cmake where to look for to define the OpenNI_LIBRARY and OpenNI_INCLUDE_DIR variables? Is there a file somewhere which cmake has paths defined for all these variables, which I might need to manually edit?

like image 899
Karnivaurus Avatar asked Nov 18 '14 21:11

Karnivaurus


Video Answer


2 Answers

Even if this is a quite old question: If you call cmake with --debug-find it will tell you where it looks for a package that you requested through a find_package() call in your CMake script.

My personal preference, especially for packages residing in their very own dedicated location, is to define an environment variable <package_name>_DIR, which points to the package's configuration file (assuming that the lib provides one). See the find_package() documentation about the search procedure for more details.

like image 134
user2169513 Avatar answered Sep 26 '22 03:09

user2169513


It looks in CMAKE_MODULE_PATH.

Append to this path using expressions like this

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

like image 30
Jens Munk Avatar answered Sep 22 '22 03:09

Jens Munk