GNOME Bugzilla – Bug 747582
Clang command line options are relative to the wrong directory
Last modified: 2015-04-11 00:33:12 UTC
Command line arguments of the form -Isomething are relative to the builddir, but clang interprets them as relative to the directory that has the source file, which is wrong in case of out of tree builds or in case of non-recursive makefile. Unfortunately I did not find how to convince clang to resolve relative paths differently, which means that builder would have to parse through the different options for relative -I and resolve them manually.
(In reply to Giovanni Campagna from comment #0) > Command line arguments of the form -Isomething are relative to the builddir, > but clang interprets them as relative to the directory that has the source > file, which is wrong in case of out of tree builds or in case of > non-recursive makefile. > > Unfortunately I did not find how to convince clang to resolve relative paths > differently, which means that builder would have to parse through the > different options for relative -I and resolve them manually. Ugh. Sounds fun. Builder mostly uses non-recursive automake and things work fine though?
No, non-recursive automake makes it worse. In builder it mostly works because stuff happens to be in the same directory (and automake has -I. by default, or it gets included with ""). But if you look eg. at libide/clang/ide-clang-service.c you get a fatal error including "ide-build-system.h", because -Ilibide/ does not work.
Aha! Lovely. I'll see what I can do.
This was a fun one! Thanks for reporting, I tested using the gnome-builder tree both in and out of tree and things seem to work well. Go ahead and let me know how it works for you on any other projects.
Created attachment 301273 [details] [review] makecache: add support for out-of-tree, non-recursive automake When attempting to resolve the CFLAGS, resolve relative paths so that clang can find the files appropriately. Clang expects that the CFLAGS are relative to the source file.
Review of attachment 301273 [details] [review]: You're an awesome person, did I ever tell you? ::: libide/autotools/ide-makecache.c @@ +767,3 @@ + */ + + if (g_str_has_prefix (part2, "./")) Almost. For config.h, automake uses -I., so this needs to be has_prefix("./") or == "." Indeed, after the patch it fails only with config.h, everything else works. (Test case: src/gedit/gedit-menu-stack-switcher.c in gnome-builder) Also you should probably use g_build_filename() instead of g_strdup_printf()
Created attachment 301339 [details] [review] makecache: operate on all relative paths Not just those starting with ./ Relative paths can start with ., .., or just a directory name. The only distinguisher is that they don't start with /
With this it works on all files in gnome-builder, and it works in libgweather, which uses recursive automake and -I.. to find config.h.