[CMake] check_include_files() can't "find" header because it can't compile test app

Alexander Neundorf a.neundorf-work at gmx.net
Mon Sep 14 16:22:14 EDT 2009


On Sunday 13 September 2009, Casey Jones wrote:
> Hello, I'm trying to link a Qt4 library into my program as an optional
> dependency.  I can get it to find and link the library with a
> FindFoo.cmake. But when I use check_include_files( foo.h HAVE_FOO_H ) it
> says it can't find the header.  So looking in CMakeError.log it says it
> found foo.h but since it includes Qt headers like:
> #include <QString>
> instead of
> #include <qt4/QtCore/QString>
> it can't compile the test program.
>
> Is there a way to have check_include_files() not compile the test program
> and just make sure the header exists?  

You could just use find_path(FOO_INCLUDE_DIR foo.h ...), usually this is good. 
enough.
Or you can set the cmake variable CMAKE_REQUIRED_INCLUDES before calling the 
check_include_files() macro so that it lists all necessary include dirs 
(should be ${QT_QTCORE_INCLUDE_DIR} or something like this)

> Or is there some other way to create the config.h.in and config.h?

You don't *have* to compile anything in order to create a config.h from a 
config.h.in.
configure_file() reads the config.h.in and replaces all cmake variables with 
their values in that file and writes the output file. 
It doesn't matter where these values come from, whether a 
check_include_files() or if you just set them.

Alex


More information about the CMake mailing list