[CMake] CheckIncludeFiles: how to use?

Alexander Neundorf a.neundorf-work at gmx.net
Fri Jul 3 12:05:42 EDT 2009


On Thursday 02 July 2009, Marcel Loose wrote:
> Hi David,
>
> That indeed seems to do the trick. The diagnostics are somewhat vague,
> though, if not to say incorrect.
>
> -- Looking for include files var
> -- Looking for include files var - found
> -- var = 1
>
> I think the line
>     MESSAGE(STATUS "Looking for include files ${VARIABLE}")
> should read
>     MESSAGE(STATUS "Looking for include files ${INCLUDE}")

Hmm, well, maybe.

> Also, the variable var is not cached; there's no trace whatsoever in the
> CMakeCache.txt file of either stdio.h, unistd.h or var.

That's what I get with the attached CMakeLists.txt:
...
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for include files HAVE_STDIO_AND_STRING_H
-- Looking for include files HAVE_STDIO_AND_STRING_H - found
-- HAVE_UNISTD_H: 1
-- HAVE_STDIO_AND_STRING_H 1
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/src/tests/cif/bH
hammer:~/src/tests/cif/bH$ grep HAVE_STDIO CMakeCache.txt
//Have include HAVE_STDIO_AND_STRING_H
HAVE_STDIO_AND_STRING_H:INTERNAL=1

So, if the variable has a useful name the output is not that bad. It is also 
cached.

> Seems to me that check_include_file() is preferred over
> check_include_files(). Any idea what's the use of the latter?

E.g. it's necessary if you have to include a header B if you want to use 
header A, then you need to be able to specify two header files.

Alex
-------------- next part --------------
cmake_minimum_required(VERSION 2.6)

include(CheckIncludeFile)
include(CheckIncludeFiles)

check_include_file(unistd.h HAVE_UNISTD_H)

check_include_files("stdio.h;string.h" HAVE_STDIO_AND_STRING_H)

message(STATUS "HAVE_UNISTD_H: ${HAVE_UNISTD_H}")

message(STATUS "HAVE_STDIO_AND_STRING_H ${HAVE_STDIO_AND_STRING_H}")


More information about the CMake mailing list