Where does cmake look to find packages?

In Ubuntu 14.04

, I am compiling a program C++

that depends on the following packages: CUDA

and OpenNI

. The file CMakeListst.txt

for this program has the following:

find_package(CUDA)
find_package(OpenNI)

      

And the output to cmake

:

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

      

So it appears to have CUDA

been found, but OpenNI

not. I have definitely installed now OpenNI

, but maybe not in the default location. If the files CUDA

are in usr/local/cuda

as stated, my files OpenNI

are in ~/Libraries/OpenNI

.

My question is, how do I tell cmake

where to look for variable definitions OpenNI_LIBRARY

and OpenNI_INCLUDE_DIR

? Is there a file somewhere that cmake

has paths defined for all of these variables that I might need to manually edit?

+3


source to share


2 answers


There is no single way to tell where the search script will look for the library.

It's a bit unfortunate, but the only way to know for sure is to check the source of the find script itself. Most search scripts rely on find_library

similar commands to find their files, which by default will search in a few places that are obvious candidates (eg /usr/local/

Unixes).

Unfortunately, this in itself is not very far. If you're stuck on a platform like Windows that doesn't have a sensible default location, or you want to avoid polluting your directory tree, you need a different way. Most search scripts allow you to insert the library location in some way.

In my experience, the cleanest way to do this is with environment variables. They are flexible for customization and convenient use. In particular, you can make them permanent by adding them to your user environment, so you don't have to type them in every time you start CMake.



If you check, for example, the find script for the CUDA, which comes with CMake , you will notice that it uses the environment variables CUDA_PATH

, CUDA_LIB_PATH

, CUDA_INC_PATH

and CUDA_BIN_PATH

(along with several others) for this purpose.

An alternative is to directly set the find script result variables in the cache from the command line via the CMake parameter-D

.

Either way, you will need to check the source of the script to see which is the best way.

Tip: Don't try to hardcode your own CMakeLists. While this may seem like a quick fix, it is also very messy, essentially making your build system unmovable. Always reach for solutions that allow the user to customize the build system externally without changing the CMake code.

+2


source


It looks like CMAKE_MODULE_PATH.

Add to this path using expressions like this



(APPEND CMAKE_MODULE_PATH $ {CMAKE_CURRENT_SOURCE_DIR} / cmake)

+1


source







All Articles