c-family: add -fsearch-include-path

The C++ modules code has a -fmodule-header (or -x c++-{user,system}-header)
option to specify looking up headers to compile to header units on the usual
include paths.  I'd like to have the same functionality for full C++20
modules such as module std, which I proposed to live on the include path at
bits/std.cc.  But this behavior doesn't seem necessarily connected to
modules, so I'm proposing a general C/C++ option to specify the behavior of
looking in the include path for the input files specified on the command
line.

Other ideas for the name of the option are very welcome.

The libcpp change is to allow -fsearch-include-path{,=user} to find files in
the current working directory, like -include.  This can be handy for a quick
compile of both std.cc and a file that imports it, e.g.

g++ -std=c++20 -fmodules -fsearch-include-path bits/std.cc importer.cc

gcc/ChangeLog:

	* doc/cppopts.texi: Document -fsearch-include-path.
	* doc/invoke.texi: Mention it for modules.

gcc/c-family/ChangeLog:

	* c.opt: Add -fsearch-include-path.
	* c-opts.cc (c_common_post_options): Handle it.

gcc/cp/ChangeLog:

	* module.cc (module_preprocess_options): Don't override it.

libcpp/ChangeLog:

	* internal.h (search_path_head): Declare.
	* files.cc (search_path_head): No longer static.
	* init.cc (cpp_read_main_file): Use it.
This commit is contained in:
Jason Merrill
2024-05-16 21:43:20 -04:00
parent 7db55c0ba1
commit dbfbd3aa2c
8 changed files with 50 additions and 12 deletions

View File

@@ -744,14 +744,12 @@ cpp_read_main_file (cpp_reader *pfile, const char *fname, bool injecting)
/* Set the default target (if there is none already). */
deps_add_default_target (deps, fname);
auto main_search = CPP_OPTION (pfile, main_search);
bool angle = main_search == CMS_system;
cpp_dir *start_dir = (main_search < CMS_user ? &pfile->no_search_path
: search_path_head (pfile, fname, angle, IT_CMDLINE));
pfile->main_file
= _cpp_find_file (pfile, fname,
CPP_OPTION (pfile, preprocessed) ? &pfile->no_search_path
: CPP_OPTION (pfile, main_search) == CMS_user
? pfile->quote_include
: CPP_OPTION (pfile, main_search) == CMS_system
? pfile->bracket_include : &pfile->no_search_path,
/*angle=*/0, _cpp_FFK_NORMAL, 0);
= _cpp_find_file (pfile, fname, start_dir, angle, _cpp_FFK_NORMAL, 0);
if (_cpp_find_failed (pfile->main_file))
return NULL;