[PATCH] D24933: Enable configuration files in clang

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 1 02:50:00 PST 2017


sepavloff added a comment.

Glad to know that someone is interested in this feature!
Below is actual proposal.

**Adding named configuration files to clang driver**

A configuration file is a collection of driver options, which are inserted into command line before other options specified in the clang invocation. It groups related options together and allows specifying them in simpler, more flexible and less error prone way than just listing the options somewhere in build scripts. Configuration file may be thought as a "macro" that names an option set and is expanded when the driver is called.  This feature must be helpful when a user need to specify many options, cross compilation is likely to be such case.

Configuration file can be specified by either of two methods:

- by command line option `--config <config_file>`, or
- by using special executable file names, such as `armv7l-clang`.

If the option `--config` is used, its argument is treated as a path to configuration file if it contains a directory separator, otherwise the file is searched for in the set of directories described below. If option `--config` is absent and clang executable has name in the form `armv7l-clang`, driver will search for file `armv7l.cfg` in the same set of directories. Similar encoding is already used by clang to specify target.

The set of directories where configuration files are searched for consists of at most three directories, checked in this order:

- user directory (like `~/.llvm`),
- system directory (like `/etc/llvm`),
- the directory where clang executable resides.

User and system directories are optional, they are reserved for distribution or SDK suppliers. By default they are absent, corresponding directories can be specified by cmake arguments `CLANG_CONFIG_FILE_SYSTEM_DIR` and `CLANG_CONFIG_FILE_USER_DIR`. The first found file is used.

Format of configuration file is similar to file used in the construct `@file`, it is a set of options. Configuration file have advantage over this construct:

- it is searched for in well-known places rather than in current directory,
- it may contain comments, long options may be split between lines using trailing backslashes,
- other files may be included by `@file` and they will be resolved relative to the including file,
- the file may be encoded in executable name,
- unused options from configuration file do not produce warnings.


https://reviews.llvm.org/D24933





More information about the cfe-commits mailing list