[CMake] target_include_directories and system headers

Jim Lloyd jim.lloyd at etagen.com
Thu Jun 28 01:11:52 EDT 2018


I am cross compiling to ARM using the g++ 7.2 compilers provided with the
Xilinx SDK.

This compiler was built using old assumptions about system headers being
pure C, such
that when compiled from a .cpp source, the header is wrapped in an `extern
"C" {}`. This causes true C++ headers to fail when compiling templates,
with 'error: template with C linkage'.

I have filed a bug against the ARM gcc compiler, but I would like to be
able to workaround the bug with CMake if possible. And as I read the
documentation, I am beginning to think that there may be a bug in CMake too.

As I read the documentation for target_include_directories, the `-isystem`
option for specifying an include directory is triggered by the SYSTEM
option, and therefore should not be used when SYSTEM is not specified. But
it seems to me that `-isystem` may be used even if SYSTEM is not specified.

For example, the yaml-cpp <https://github.com/jbeder/yaml-cpp> project
declares its include directories like this:

if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
    target_include_directories(yaml-cpp
        PUBLIC $<BUILD_INTERFACE:${YAML_CPP_SOURCE_DIR}/include>
               $<INSTALL_INTERFACE:${INCLUDE_INSTALL_ROOT_DIR}>
        PRIVATE $<BUILD_INTERFACE:${YAML_CPP_SOURCE_DIR}/src>)
endif()

But if I make a trivial project that simply includes yaml-cpp as a
dependency, the generated compile commands use `-isystem` to include the
yaml-cpp headers.

Is this a bug in CMake?

Also, is there any way I may be able to work around this problem with CMake
3.10? I would be happy to globally force the use of `-I` for all include
directories.

Thanks,

Jim Lloyd
EtaGen Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180627/4bec2eba/attachment.html>


More information about the CMake mailing list