sunmat
sunmat

Reputation: 7248

Cmake CHECK_INCLUDE_FILES not finding header file

I'm trying to have Cmake check if the file cxxabi.h is available. This file is from the c++ standard library, at least with g++. My current cmake commands look like this:

include(CheckIncludeFiles)
...
check_include_files(cxxabi.h HAVE_CXXABI)
if(HAVE_CXXABI)
   ...
else(HAVE_CXXABI)
   ...
endif(HAVE_CXXABI)

When this is executed, I get:

 -- Looking for include files HAVE_CXXABI
 -- Looking for include files HAVE_CXXABI - not found.

Although the file is available in /usr/include/c++/4.6.4/ and can properly be found by g++ when I compile a c++ code.

I suspect the macro check_include_files uses the C compiler instead of the C++ one to compile a small program that includes the required file, which of course fails since cxxabi.h is a C++ file.

Any idea how to solve that? (i.e. making the macro use the C++ compiler instead of the C one)

Upvotes: 4

Views: 5008

Answers (2)

Yevgeniy Kolokoltsev
Yevgeniy Kolokoltsev

Reputation: 21

There exists another problem with CHECK_INCLUDE_FILES that I recently discovered with MinGW. The file tested was "ddk/ntapi.h". In the CMakeErr.log for this header I got a multiply messages like "DWORD - does not name a type" and so on for all MS types used in this header. Because of this reason the compilation fails and a requested header appears as "not found", whereas it is not true.

This happens because CheckIncludeFile.cxx contains only the requested header, and some headers in MinGW (and probably in the other APIs) does not include in its body all the list of required headers to be compiled in a standalone program that CMake creates.

The solution for this problem is to add absent basic includes into the CMAKE_REQURED_FLAGS, or as a third variable of CHECK_INCLUDE_FILE_CXX:

CHECK_INCLUDE_FILE_CXX("ddk/ntapi.h" VAR "-include windows.h")

Upvotes: 2

sunmat
sunmat

Reputation: 7248

As edited in my original question:

Problem solved. There is a different macro for C++ headers, check_include_file_cxx, located in CheckIncludeFileCXX.

Upvotes: 7

Related Questions