[CMake] Which to use: find_file and find_library; or check_include_file and check_library_exists

Alexander Neundorf a.neundorf-work at gmx.net
Tue Apr 21 15:37:02 EDT 2009


On Tuesday 21 April 2009, Marcel Loose wrote:
> Hi all,
>
> I was wondering what is the preferred way to look for a library and/or a
> header file. I noticed that most (if not all) pre-packaged cmake modules
> use find_file and find_library.
>
> Is there a reason that they do not use check_include_file and
> check_library_exists?
>
> If writing my own cmake modules, should I use find_file and
> find_library, or check_include_file and check_library_exists?

They do different things.
FIND_XXX() returns the full path to the file, which is necessary for use with 
cmake.
check_include_file() tries to compile a small file with given 
libraries/include dirs, and tests whether that succeeds. So you cannot use 
that to find the location of a library or header.
You can use check_library_exists() to check whether e.g. the C library 
supports some functions, or whether a header exists in one of the standard 
include directories.

Alex


More information about the CMake mailing list