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

How to use precompiled headers with non-standard locations of includes? #1415

Closed
adamryczkowski opened this issue Feb 22, 2017 · 8 comments
Closed

Comments

@adamryczkowski
Copy link

adamryczkowski commented Feb 22, 2017

Consider the following example:

meson.build:

project('c++ pch test', 'cpp')
inc = include_directories('include')
exe = executable('prog', 'prog.cc', cpp_pch : ['pch/prog.hh'], include_directories : inc)

prog.cc is the same as the example in the meson code:

void func() {
    std::cout << "This is a function that fails to compile if iostream is not included."
              << std::endl;
}
int main(int argc, char **argv) {
    return 0;
}

In header in subdirectory include/myheader.h single line, but in real life it would be much more complex:

#include<iostream>

And the precompiled header pch/prog.hh

#include"myheader.h"

The building fails with the following message:

[0/1] Regenerating build files
The Meson build system
Version: 0.39.0.dev1
Source dir: /home/Adama-docs/Adam/MyDocs/praca/IMGW/dev/meson/test cases/common/14 cpp pch
Build dir: /home/Adama-docs/Adam/MyDocs/praca/IMGW/dev/meson/test cases/common/14 cpp pch/build
Build type: native build
Project name: c++ pch test
Native cpp compiler: c++ (gcc 5.4.1)
Build machine cpu family: x86_64
Build machine cpu: x86_64
Build targets in project: 1
[1/3] Precompiling header ../pch/prog.hh
FAILED: prog@exe/prog.hh.gch 
c++  '-pipe' '-Wall' '-Winvalid-pch' '-Wnon-virtual-dtor' '-O0' '-g' '-MMD' '-MQ' 'prog@exe/prog.hh.gch' '-MF' 'prog@exe/prog.hh.gch.d' -o 'prog@exe/prog.hh.gch' -c ../pch/prog.hh
../pch/prog.hh:1:21: fatal error: myheader.h: No such file or directory
compilation terminated.
ninja: build stopped: subcommand failed.

It looks as if the compiler is ignoring my include directories. What did I do wrong?

@adamryczkowski adamryczkowski changed the title How to use preconfigured files with non-standard locations of includes? How to use precompiled headers with non-standard locations of includes? Feb 23, 2017
@adamryczkowski
Copy link
Author

It is similar (possibly even a duplicate) of #999 . But it doesn't make it solved. Can anyone tell me, is there any walkaround to this issue?

My build use a lot of custom meta programming compile-time libraries, that take over 3s just to parse.

@adamryczkowski
Copy link
Author

Bump?... I understand you might be busy; Can you at least give me an idea, whether such a thing as pch of non-standard includes are on the roadmap and eventually will be supported?

@jpakkane
Copy link
Member

The fact that paths are not set up is a bug and we should fix that at some point. Unfortunately this ties into a different issue with PCH, that including non-system dependencies (i.e. ones that are part of the project and you edit) is a bit tricky due to potential staleness issues.

The workaround currently is that you put the includes you want to precompile in the header file explicitly. This has the added bonus that it gives you one unambiguous location for what to put in each pch. But yes, eventually we should support your use case as well.

@adamryczkowski
Copy link
Author

Thank you very much for your answer.

Do you mean replacing prog.hh with

#include"../include/myheader.h"

It works in this test case, but fails if myheader.h calls several other non-standard includes (which is my case, 55 other header files. As I said, the library I am using is compile-time oriented).

Do you have any workaround in my case? Maybe a custom compiler parameter that will manually point the right include directory? Or, theoretically I should be able to compile with a "custom compiler" that is a simple wrapper around the gcc that simply adds the missing -I parameter to the invocation.

@jpakkane
Copy link
Member

What I meant is that you put the following in your pch/prog.hh:

#pragma once
#include<boost/foobar.hpp>
#include<algorithm>
... etc ...

Meson will then precompile those external headers. This works with external dependencies (Boost, Qt, others) just fine, just not with header files that you write yourself. So if you are doing heavy template metaprogramming development yourself, you can't (currently) precompile those headers (but since they change all the time, you probably don't even want to).

The downside is that you need to write all headers you want to precompile into that header which might be duplicating information if you already have it in some other header.

@adamryczkowski
Copy link
Author

Thank you very much for the answer.
I link against a third party template-heavy library, and I don't expect it to change more often then few times a year.

Do you have any form of estimate when pre-compiling of custom headers will be implemented? Just order of magnitude will be fine, i.e. days, weeks, months or years.

Thanks

@nicolas17
Copy link

Meson will then precompile those external headers. This works with external dependencies (Boost, Qt, others) just fine, just not with header files that you write yourself.

Why does this not work with headers in the project? It seems to be setting up DEPFILE correctly, such that modifying the custom header will recompile the pch. What's the case where this breaks?

@nioncode
Copy link
Contributor

nioncode commented Feb 9, 2019

Fixed by #4860, please close.

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

No branches or pull requests

5 participants