[CMake] Issue with check_include_file() and GL/glxproto.h

Eric Noulard eric.noulard at gmail.com
Thu Nov 10 17:22:22 EST 2011


2011/11/10 GOUJON Alexandre <ale.goujon at gmail.com>:
> Hi,
>
> It all started when I tried compiling Piglit [1] : cmake checked all the
> dependencies, didn't complain and generated Makefiles but doing 'make'
> caused an error because a header was missing.
>
> So I proposed myself to write a patch and add the check.
> But the following didn't work :
>
> check_include_file(GL/glxproto.h HAVE_GL_GLXPROTO_H)
> if (NOT HAVE_GL_GLXPROTO_H)
>    message(FATAL_ERROR "GL/glxproto.h required. On Ubuntu, you need the
> x11proto-gl-dev package.")
> endif (NOT HAVE_GL_GLXPROTO_H)
>
[...]

> I'm not really familiar with CMake so I may have missed something.
> What I understand is that check_include_file() tries to compile a test which
> includes GL/glxproto.h.
> It seems another header is needed prior to using GL/glxproto.h.

If this is the case then it is a "GL/glxproto.h" design mistake
not CMake mistake.

Until now I did never cross a "public" C or C++ header that needs
a previous include.

A public include file should always include its needed dependencies, right?
Or may be I'm missing some particular use case?

> From my "user" point of view, this approach is quite strange because the
> header is present but "not found".
> If you want to check the usability of the file, I think a comment or a
> better macro name would help.

This is true but the documentation tells you more about the macro
cmake --help-module CheckIncludeFile

says
"an optional third argument is the CFlags to add to the compile line or
       you can use CMAKE_REQUIRED_FLAGS"

which clearly states that it does a compilation.

If you just want to find a file then may be,

find_file

cmake command would be a better choice.

> And, could you add a check like
> IF(${VARIABLE}) message(FATAL_ERROR "${VARIABLE} already defined :
> aborting") ENDIF(${VARIABLE})
> ?

The thing you want is probably

if(DEFINED VARIABLE)
   message(FATAL_ERROR "VARIABLE already defined : <${VARIABLE}> aborting")
endif()


> That is, explicitly abort the macro instead of letting the user testing a
> variable previously defined and not modified by check_include_file.

I think it's not the responsability of check_include_file to do such job
but you can do that in your CMakeLists.txt

>
> IF("${VARIABLE}" MATCHES "^${VARIABLE}$") fails : is it intended ?

I do not understand
In which case does it fail?

-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list