Skip to content

adding conan build in the tutorial #4152

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

Draft
wants to merge 1 commit into
base: develop2
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tutorial/consuming_packages/the_flexibility_of_conanfile_py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,42 @@ demonstrates how to import bindings for the library depending on the graphics AP
tools<conan_tools_env_virtualrunenv>` without the need to copy them to the local
folder.


Use the build() method and ``conan build`` command
--------------------------------------------------
Comment on lines +398 to +399
Copy link
Contributor

Choose a reason for hiding this comment

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

I think explaining the build method would be a good addition to this lesson but I would introduce it in a different way.
Instead of saying that if you have a recipe that implements this and showing it with conan new (that we introduce in the creating packages section), just continue the story as another advantage of the conanfile.py vs the txt one and explain users how to add a build method, just adding this to the conanfile.py they already have:

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

then do the conan build and also adding links here to the local development section to give it a bit more visibility.


If you have a recipe that implements a ``build()`` method, then it is possible to automatically call
the full ``conan install + cmake <configure> + cmake <build>`` flow with a single command. Though this
might not be the typical developer flow, it can be a convenient shortcut in some cases.

You can try it with:

.. code-block:: bash

$ mkdir myproj && cd myproj
$ conan new cmake_lib
$ conan build .


The ``conan new`` command creates a simple project containing a ``conanfile.py``, a ``CMakeLists.txt`` and some C++ code.
If you inspect the ``conanfile.py``, you can see it contains a ``build()`` method, with the instructions how to
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
If you inspect the ``conanfile.py``, you can see it contains a ``build()`` method, with the instructions how to
If you inspect the ``conanfile.py``, you can see that it contains a ``build()`` method, with the instructions on how to

configure and build this project, using some Conan helpers such as ``cmake.configure()`` and ``cmake.build()``.

It is not important to fully understand the ``build()`` method now, it will explained later in the tutorial.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
It is not important to fully understand the ``build()`` method now, it will explained later in the tutorial.
It is not important to fully understand the ``build()`` method now, it will be explained later in the tutorial.

The ``conan build .`` command will automatically call ``conan install .`` (``conan build`` can receive all the same
arguments, profiles, settings, etc. as ``install``) to install the dependencies and call the ``generarators``,
and after it finishes, it will call the ``build()`` method, which in turns call the CMake configure and build steps,
doing a local build of the project.

.. note::

**Best practices**

The ``conan build`` command does not intend to replace or change the typical developer flow using CMake and
other build tools, and using their IDEs. It is just a convenient shortcut for cases in which we want to locally
build a project easily without having to type several commands or use the IDE.


.. seealso::

- :ref:`Using "cmake_layout" + "CMakeToolchain" + "CMakePresets feature" to build your project<examples-tools-cmake-toolchain-build-project-presets>`.
Expand Down