Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for qbs build helper and qbs toolchain #1978

Merged
merged 22 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7c7c2ec
Add documentation for qbs build helper
Jan 11, 2021
a8200c8
Add documentation for qbs toolchain
Jan 11, 2021
4e8d013
Add documentation for attributes of qbs build helper
Jan 11, 2021
badd931
Update reference/build_helpers/qbs.rst
danimtb Jan 13, 2021
d3c1771
Update reference/build_helpers/qbs.rst
danimtb Jan 13, 2021
c2251ad
Update creating_packages/toolchains/qbs.rst
danimtb Jan 13, 2021
c053b7d
Update creating_packages/toolchains/qbs.rst
danimtb Jan 13, 2021
8f2a988
Update creating_packages/toolchains/qbs.rst
danimtb Jan 13, 2021
50b4296
Update creating_packages/toolchains/qbs.rst
danimtb Jan 13, 2021
d6ff2bd
Update creating_packages/toolchains/qbs.rst
danimtb Jan 13, 2021
638362d
Update creating_packages/toolchains/qbs.rst
danimtb Jan 13, 2021
e1131fa
Update creating_packages/toolchains/qbs.rst
danimtb Jan 13, 2021
a692e6e
Update creating_packages/toolchains/qbs.rst
danimtb Jan 13, 2021
22b79d9
Update creating_packages/toolchains/qbs.rst
danimtb Jan 13, 2021
dd57116
Update creating_packages/toolchains/qbs.rst
danimtb Jan 13, 2021
e5d87d8
Update creating_packages/toolchains/qbs.rst
danimtb Jan 13, 2021
fdd2b28
Update creating_packages/toolchains/qbs.rst
danimtb Jan 13, 2021
4fb7dda
Update creating_packages/toolchains/qbs.rst
danimtb Jan 13, 2021
6fe4d47
Merge remote-tracking branch 'refs/remotes/psy-kai/develop' into develop
Jan 13, 2021
c27f411
Fixed copy & paste error
Jan 13, 2021
c91aba9
Removed project name to simplify line
Jan 13, 2021
b7ea033
Referenced rst files
Jan 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 68 additions & 0 deletions creating_packages/toolchains/qbs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
.. _conan-qbs-toolchain:

QbsToolchain
==============

.. warning::

This is an **experimental** feature subject to breaking changes in future releases.


The ``QbsToolchain`` can be used in the ``generate()`` method:


.. code:: python

from conans import ConanFile
from conan.tools.meson import QbsToolchain
Psy-Kai marked this conversation as resolved.
Show resolved Hide resolved

class App(ConanFile):
settings = "os", "arch", "compiler", "build_type"
requires = "hello/0.1"
options = {"shared": [True, False]}
default_options = {"shared": False}

def generate(self):
tc = QbsToolchain(self)
tc.generate()


The ``QbsToolchain`` will generate the following file during ``conan install``
danimtb marked this conversation as resolved.
Show resolved Hide resolved
command (or before calling the ``build()`` method when the package is being
built in the cache): ``conan_toolchain.qbs``. This file will contain a qbs profile
danimtb marked this conversation as resolved.
Show resolved Hide resolved
named ``conan_toolchain_profile``.
danimtb marked this conversation as resolved.
Show resolved Hide resolved


``conan_toolchain.qbs`` will contain the definitions of all the Qbs properties
danimtb marked this conversation as resolved.
Show resolved Hide resolved
related to the Conan options and settings for the current package, platform,
etc. This includes the following:

* Detection of compiler
danimtb marked this conversation as resolved.
Show resolved Hide resolved

* Based on the compiler set in environment variable ``CC``
danimtb marked this conversation as resolved.
Show resolved Hide resolved

* Uses detected system compiler based on Conan setting ``compiler`` if environment variable ``CC`` is not set
danimtb marked this conversation as resolved.
Show resolved Hide resolved

* Detection of compiler flags from environment (as defined at https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html)
danimtb marked this conversation as resolved.
Show resolved Hide resolved

* ``ASFLAGS``

* ``CFLAGS``

* ``CPPFLAGS``

* ``CXXFLAGS``

* ``LDFLAGS``

* Detection of sysroot from environment
danimtb marked this conversation as resolved.
Show resolved Hide resolved

* Detection of ``build_type`` from Conan settings
danimtb marked this conversation as resolved.
Show resolved Hide resolved

* Detection of ``arch`` from Conan settings
danimtb marked this conversation as resolved.
Show resolved Hide resolved

* Detection of ``compiler.cxxstd`` from Conan settings
danimtb marked this conversation as resolved.
Show resolved Hide resolved

* Detection of ``fPIC``

* Based on existance/value of a option named ``fPIC``
danimtb marked this conversation as resolved.
Show resolved Hide resolved
159 changes: 159 additions & 0 deletions reference/build_helpers/qbs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
.. _qbs_build_reference:

Qbs
===

If you are using **Qbs** as your build system, you can use the **Qbs** build helper.

.. code-block:: python

from conans import ConanFile, tools, Qbs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is wrong, the right one is from conan.tools.qbs import Qbs.

import os

class ConanFileToolsTest(ConanFile):
...

def build(self):
qbs = Qbs(self)
qbs.build()

Constructor
-----------

.. code-block:: python

class Qbs(object):

def __init__(self, conanfile, project_file=None)

Parameters:
- **conanfile** (Required): Use ``self`` inside a ``conanfile.py``.
- **project_file** (Optional, Defaulted to ``None``): Path to the root project file.

Attributes
----------

use_toolchain_profile
+++++++++++++++++++++

**Defaulted to**: ``conan_toolchain_profile``

Specifies the qbs profile to build the project for.

jobs
++++

**Defaulted to**: ``tools.cpu_count()``

Specifies the number of concurrent build jobs.

Methods
-------

add_configuration()
+++++++++++
danimtb marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: python

def add_configuration(self, name, values)

Add a build configuration to use.

Parameters:
- **name** (Required): Specifies build configuration name.
- **values** (Required): A dict of properties set for this build configuration.


build()
+++++++

.. code-block:: python

def build(self, products=None)

Build Qbs project.

Parameters:
- **products** (Optional, Defaulted to ``None``): Specifies a list of products to build. If ``None`` build all products which have the qbs property ``buildByDefault`` set to ``true``.


build_all()
++++++
danimtb marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: python

def build_all(self)

Build all products of Qbs project, even products which set the qbs property ``buildByDefault`` set to ``false``


install()
+++++++++

.. code-block:: python

def install(self)

Install products.


Example
-------

A typical usage of the Qbs build helper, if you want to be able to both execute :command:`conan create` and also build your package for a
library locally (in your user folder, not in the local cache), could be:

.. code-block:: python

from conans import ConanFile, Qbs

class HelloConan(ConanFile):
name = "hello"
version = "0.1"
settings = "os", "compiler", "build_type", "arch"
generators = "qbs"
exports_sources = "src/*", "*.qbs"
no_copy_source = True
requires = "zlib/1.2.11"

def build(self):
qbs = Qbs(self)
qbs.add_configuration("default", {
"project.Hello.conanBuildInfo", self.build_folder + "/conanbuildinfo.qbs"
Psy-Kai marked this conversation as resolved.
Show resolved Hide resolved
})
qbs.build()

def package(self):
self.copy("*.h", dst="include", src="src")
self.copy("*.lib", dst="lib", keep_path=False)
self.copy("*.dll", dst="bin", keep_path=False)
self.copy("*.dylib*", dst="lib", keep_path=False)
self.copy("*.so", dst="lib", keep_path=False)
self.copy("*.a", dst="lib", keep_path=False)

def package_info(self):
self.cpp_info.libs = ["hello"]

Note the ``qbs`` generator, which generates the *conanbuildinfo.qbs* file, to process
dependencies information. Setting ``no_copy_source = True`` helps qbs to pick the right project file
and not get confused by the generated files.

The *hello.qbs* could be as simple as:

.. code-block:: text

Project {
readonly property path conanBuildInfo

references: conanBuildInfo

DynamicLibrary {
name: "hello"
version: "0.1.0"
files: "src/hello.cpp"
cpp.cxxLanguageVersion: "c++11"

Depends { name: "cpp" }
Depends { name: "zlib" }
}
}