- Qbs Manual
- QbsProbes
- ConanfileProbe
- Qbs 2.6.1

# ConanfileProbe

Extracts information about dependencies from a Conan recipe file. More...

- List of all members, including inherited members
- ConanfileProbe is part of List of All Items.

## Properties

- additionalArguments : stringList
- conanfilePath : path
- dependencies : var
- executable : path
- generatedFilesPath : path
- generators : stringList
- json : var
- options : var
- packageReference : string
- settings : var
- verbose : var

## Detailed Description

The `ConanfileProbe` interfaces Qbs to the Conan package manager. It runs conan install on a Conan recipe file such as `conanfile.py` or `conanfile.txt` and extracts all available meta information about package dependencies using the json generator. The output may be used to set up Profile items or module properties in products. `ConanfileProbe` can also be used to run other Conan generators and to retrieve their output.

## Examples

In the following examples we assume that our project contains a `conanfile.py`. This file describes all dependencies of our project. The dependency packages are expected to export meta information to be consumed by our project.

### Using ConanfileProbe with Conan Module Provider

Conan 2.6 has a built-in QbsDeps generator that creates JSON files suitable for consumption by the conan module provider. Use it to access dependencies.

     import qbs.Probes

     Project {
         Probes.ConanfileProbe {
             id: conanProbe
             conanfilePath: project.sourceDirectory + "/conanfile.py"
             generators: "QbsDeps"
         }

         CppApplication {
             type: "application"
             files: "main.cpp"
             qbsModuleProviders: "conan"
             moduleProviders.conan.installDirectory: conanProbe.generatedFilesPath
             Depends { name: "mylib" }
         }
     }

### Including Files Generated by Conan

Note: This example does not apply to Conan 2.0, or newer.

Conan 1 has a built-in qbs generator that creates a project file containing dummy products. This is the easiest way to access dependencies, but also the least flexible one. It requires each Conan package to export correct meta information and works only if the dependency is a library.

     import qbs.Probes

     Project {
         Probes.ConanfileProbe {
             id: conan
             conanfilePath: project.sourceDirectory + "/conanfile.py"
             generators: "qbs"
         }

         references: conan.generatedFilesPath + "/conanbuildinfo.qbs"

         CppApplication {
             type: "application"
             files: "main.cpp"
             Depends { name: "mylib" }
         }
     }

### Setting Module Properties in Products

Note: This example does not apply to Conan 2.0, or newer.

When a product depends on a Conan package that does not have a dedicated module, package meta information may be directly fed into the cpp module.

This approach is very flexible.

     import qbs.Probes

     CppApplication {
         Probes.ConanfileProbe {
             id: conan
             conanfilePath: product.sourceDirectory + "/conanfile.py"
             options: ({opt1: "True"; opt2: "TheValue"})
         }
         cpp.includePaths: conan.dependencies["myLib"].include_paths
         cpp.libraryPaths: conan.dependencies["myLib"].lib_paths
         cpp.dynamicLibraries: conan.dependencies["mylib"].libs
     }

### Setting Up a Profile

Note: This example does not apply to Conan 2.0, or newer.

When multiple products depend on one or more Conan packages, the dependency information may be combined in a Profile. This is especially useful when Qbs modules are available for some of the packages, but some of their properties need to be initialized. Otherwise, it would have to be done manually in global profiles.

     import qbs.Probes

     Project {
         Probes.ConanfileProbe {
             id: conan
             conanfilePath: project.sourceDirectory + "/conanfile.py"
         }
         Profile {
             name: "arm-gcc"
             cpp.toolchainInstallPath: conan.dependencies["arm-none-eabi-gcc"].rootpath + "/bin"
             cpp.toolchainPrefix: "arm-linux-gnueabi-"
             qbs.toolchainType: "gcc"
         }
     }

This allows fully automated dependency management, including compiler toolchains and is very useful when teams work in heterougeneous environments.

## Property Documentation

additionalArguments : stringList

Additional command line arguments that are appended to the `conan install` command.

Default: []

conanfilePath : path

Path to a `conanfile.py` or `conanfile.txt` that is used by this probe.

This property cannot be set at the same time as packageReference.

Default: Undefined

dependencies : var `[read-only]`

This property contains the same information as json.dependencies, but instead of an array, `dependencies` is a map with package names as keys for convenient access.

Note: This property does not apply to Conan 2.0, or newer.

Default: Undefined

executable : path

The name of or the path to the Conan executable.

Default: "conan.exe" on Windows, "conan" otherwise

generatedFilesPath : path `[read-only]`

The path of the folder where Conan generators store their files. Each instance of this probe creates a unique folder under Project.buildDirectory. The folder name is a hash of the arguments supplied to `conan install`.

Default: Undefined

generators : stringList

Conan generators to be executed by this probe.

When using Conan 2.x, QbsDeps generator is added by default.

When using Conan 1.x, the JSON generator is always enabled.

All generated files are written to the generatedFilesPath folder.

`\autodetected`

See also Available generators.

json : var `[read-only]`

The parsed output of Conan's JSON generator as a JavaScript object.

Note: This property does not apply to Conan 2.0, or newer.

Default: Undefined

options : var

Options applied to `conan install` via the `-o` flag. This property is an object in the form `key:value`.

Example:

     options: ({someOpt: "True", someOtherOpt: "TheValue"})

Default: Undefined

packageReference : string

Reference of a Conan package in the form `name/version@user/channel`. Use this property if you want to probe an existing package in the local cache or on a remote.

This property cannot be set at the same time as conanfilePath.

Default: Undefined

settings : var

Settings applied to `conan install` via the `-s` flag. This property is an object in the form `key:value`.

Example:

     settings: ({os: "Linux", compiler: "gcc"})

Default: Undefined

verbose : var

Set to `true` to print all output of `conan install`. If this property is `false` only error output will be printed.

Default: `false`