Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include_directories(..., is_system: true) appears to be ignored (at least for GCC & Clang) #9219

Open
schmidtw opened this issue Sep 3, 2021 · 5 comments

Comments

@schmidtw
Copy link
Contributor

schmidtw commented Sep 3, 2021

include_directories(..., is_system: true) appears to be ignored for GCC & Clang
Regardless of if is_system is set to true or false, the compiler instruction is always -I instead of what I'd expect (-iquote) if is_system: false is set.

To Reproduce
The below configuration in a meson.build file where you are building a c program helps highlight the issue:

inc = include_directories(['src'],
                          is_system: false)

executable(meson.project_name(),
           ['src/main.c'],
           include_directories: inc,
           install: true)

Run:

meson builddir
cd builddir
ninja --verbose

When you inspect the compile step output you'll see something like this:

gcc -Itest_auth_token.p -I. -I.. -Isrc -I../src -Isubprojects/cutils-2.1.0/include -I../subprojects/cutils-2.1.0/include -fdiagnostics-color=always --coverage -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c99 -g -include xa_config.h -MD -MQ test_auth_token.p/tests_test_auth_token.c.o -MF test_auth_token.p/tests_test_auth_token.c.o.d -o test_auth_token.p/tests_test_auth_token.c.o -c ../tests/test_auth_token.c

Expected behavior

I would expect the compiler output to look like this:

gcc -Itest_auth_token.p -I. -I.. -iquotesrc -iquote../src -Isubprojects/cutils-2.1.0/include -I../subprojects/cutils-2.1.0/include -fdiagnostics-color=always --coverage -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c99 -g -include xa_config.h -MD -MQ test_auth_token.p/tests_test_auth_token.c.o -MF test_auth_token.p/tests_test_auth_token.c.o.d -o test_auth_token.p/tests_test_auth_token.c.o -c ../tests/test_auth_token.c

system parameters

  • Is this a plain native build.
  • Operating System: Fedora 34
  • Python 3.9.6
  • meson --version: 0.59.0
  • ninja --version: 1.10.2
@dcbaker
Copy link
Member

dcbaker commented Sep 3, 2021

We've never set -iquote, If you set is_system you'll get -isystem, otherwise you'll get -I. I think the problem is that is_system is a very badly named option, it's really about using -isystem to get GCC and Clang's "don't show me warnings about external headers" functionality, not about getting the intended behavior of -isystem. Unfortunately no compiler AFAIK has a feature like -ino-warn

@schmidtw
Copy link
Contributor Author

schmidtw commented Sep 3, 2021

ok, that makes sense. I was looking to specify my src directory as the base for all the #include "local.h" headers so I could make the search path not need to backtrack directories.

#include "logging/logging.h"
#include "foobar/foo.h"

vs needing to always use a relative path like this:

#include "../logging/logging.h"
#include "foo.h"

Not a big deal, unless you're moving code around :).

Would normalizing to allow some of the flexibility offered by the following (they appear in gcc and clang to be fairly uniform) would be accepted into meson?

-I dir
-iquote dir
-isystem dir
-idirafter dir

@XutaxKamay
Copy link

XutaxKamay commented May 17, 2022

Sorry for the bump, but
+1 for supporting -iquote (for own headers) if this isn't supported yet.

I actually need it, because, if for example my header is named math.h and I don't want to use system's one, I can use quotes for including my own header and when I want system's one I can include it with <math.h>.

A work-around is just to rename all headers with a prefix, but this could potentially destroy the project.

When including <math.h> it could force to be my own header included first which could confuse the compiler itself and result in errors.

EDIT:
should I make another issue for it?

@kbingham
Copy link
Contributor

Hrm ... I came across this as I was also looking for a way to specify quote include paths, for a common static library, where I want to be able to

#include "common/event_loop.h"

But I don't want that to search system paths...

Perhaps a proposal of adding is_quote to include_directories() alongside https://mesonbuild.com/Reference-manual_functions.html#arguments27 would be interesting, but I'm not sure what other specific use cases it would have.

@vinipsmaker
Copy link

I also have an use for -iquote includes. My project currently is structured as:

  • include: these files are installed to be used by other projects.
  • src: these files are not installed.

So, for headers that I don't want to install in the system (i.e. private headers), I just #include relative to the src directory. That works. No need to change the project build.

However I started to rely heavily on code generators (e.g. re2c, and gperf). Now things break. The generated source doesn't live in src anymore, but somewhere in the build directory, and the private headers won't be found when I #include them. A workaround is to -I, but that can have adverse effects and it's not very robust. -iquote would help tons here.

I like @kbingham's is_quote proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants