- Qbs Manual
- Module Providers
- Qbs 1.18.2

Custom Modules and Items ◦ How-tos

# Module Providers

There are use cases for which a pre-defined module is not flexible enough. For instance, the overall set of modules related to a certain task might depend on some information present on the local platform.

Note: Module providers are an advanced concept that you will rarely need to use directly. Reading this section is not required for most people's everyday work.

## How Qbs Uses Module Providers

If Qbs encounters a Depends item whose name does not match a known module, it checks whether such a module can be generated. This procedure works as follows:

1. All search paths are scanned for a file called `module-providers/<name>/provider.qbs`, where `<name>` is the name of the dependency as specified in the `Depends` item. Multi-component names such as "a.b" are turned into nested directories, and each of them is scanned, starting with the deepest path. For instance, if the dependency's name is `a.b`, then Qbs will look for `a/b/provider.qbs` and then `a/provider.qbs`.
2. If such a file is found, it needs to contain a ModuleProvider item. This item is instantiated, which potentially leads to the creation of one or more modules, and Qbs retrieves the search paths to find these modules from the item. The details are described in the ModuleProvider documentation.
3. If a matching module provider was found and provided new search paths, a second attempt will be made to locate the dependency using the new paths. The search for a matching module provider ends as soon as one was found, regardless of whether it created any modules or not.
4. If no matching module provider was found in any of the search paths, Qbs will fall back to a generic module provider, which creates a module that attempts to locate the dependency via `pkg-config`. This fallback mechanism can be disabled in the respective Depends item or globally via the --no-fallback-module-provider option.

## Parameterizing Module Providers

You can pass information to module providers from the command line, via profiles or from within a product, in a similar way as you would do for modules. For instance, the following invocation of Qbs passes information to two module providers `a` and `b`:

     $ qbs moduleProviders.a.p1:true moduleProviders.a.p2:true moduleProviders.b.p:false

Qbs will set the properties of the respective module providers accordingly. In the above example, module provider `a` needs to declare two boolean properties `p1` and `p2`, and they will be set to `true` and `false`, respectively.

Custom Modules and Items ◦ How-tos