target_include_directories and system headers

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

target_include_directories and system headers

Jim Lloyd
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 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.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: target_include_directories and system headers

Nils Gladitz-2
On Thu, Jun 28, 2018 at 7:12 AM Jim Lloyd <[hidden email]> wrote:
[...]
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.

Specifically the paragraph close to the end starting with "When the INTERFACE_INCLUDE_DIRECTORIES of an imported target...".

Basically include directories inherited from imported targets are implicitly "SYSTEM" by default.

Nils

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: target_include_directories and system headers

Jim Lloyd
Thank you Nils, that is exactly the information I needed. Simply setting `set(CMAKE_NO_SYSTEM_FROM_IMPORTED ON)` achieves the workaround I wanted.


On Wed, Jun 27, 2018 at 11:03 PM, Nils Gladitz <[hidden email]> wrote:
On Thu, Jun 28, 2018 at 7:12 AM Jim Lloyd <[hidden email]> wrote:
[...]
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.

Specifically the paragraph close to the end starting with "When the INTERFACE_INCLUDE_DIRECTORIES of an imported target...".

Basically include directories inherited from imported targets are implicitly "SYSTEM" by default.

Nils


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake