Skip to content

Commit

Permalink
Automatic deploy (build number 18)
Browse files Browse the repository at this point in the history
  • Loading branch information
ConanCI bot committed Mar 6, 2024
1 parent 55518cf commit fe3e872
Show file tree
Hide file tree
Showing 579 changed files with 4,205 additions and 589 deletions.
2 changes: 1 addition & 1 deletion 2.1/404.html
Expand Up @@ -119,7 +119,7 @@ <h1>Page Not Found<a class="headerlink" href="#page-not-found" title="Link to th

<div role="contentinfo">
<p>&#169; Copyright 2016-2024, JFrog.
<span class="lastupdated">Last updated on Mar 05, 2024.
<span class="lastupdated">Last updated on Mar 06, 2024.
</span></p>
</div>

Expand Down
2 changes: 1 addition & 1 deletion 2.1/Page Not Found.html
Expand Up @@ -112,7 +112,7 @@ <h1>Page not found</h1>

<div role="contentinfo">
<p>&#169; Copyright 2016-2024, JFrog.
<span class="lastupdated">Last updated on Mar 05, 2024.
<span class="lastupdated">Last updated on Mar 06, 2024.
</span></p>
</div>

Expand Down
132 changes: 132 additions & 0 deletions 2.1/_sources/examples/tools/meson/build_simple_meson_project.rst.txt
@@ -0,0 +1,132 @@
.. _examples_tools_meson_toolchain_build_simple_meson_project:

Build a simple Meson project using Conan
========================================

In this example, we are going to create a string compressor application
that uses one of the most popular C++ libraries: `Zlib <https://zlib.net/>`__.

.. note::

This example is based on the main :ref:`Build a simple CMake project using Conan<consuming_packages_build_simple_cmake_project>`
tutorial. So we highly recommend reading it before trying out this one.

We'll use Meson as build system and pkg-config as helper tool in this case, so you should get them installed
before going forward with this example.

Please, first clone the sources to recreate this project. You can find them in the
`examples2 repository <https://github.com/conan-io/examples2>`_ in GitHub:

.. code-block:: bash
$ git clone https://github.com/conan-io/examples2.git
$ cd examples2/examples/tools/meson/mesontoolchain/simple_meson_project
We start from a very simple C language project with this structure:

.. code-block:: text
.
├── meson.build
└── src
└── main.c
This project contains a basic *meson.build* including the **zlib** dependency and the
source code for the string compressor program in *main.c*.

Let's have a look at the *main.c* file:

.. code-block:: cpp
:caption: **main.c**
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <zlib.h>
int main(void) {
char buffer_in [256] = {"Conan is a MIT-licensed, Open Source package manager for C and C++ development "
"for C and C++ development, allowing development teams to easily and efficiently "
"manage their packages and dependencies across platforms and build systems."};
char buffer_out [256] = {0};
z_stream defstream;
defstream.zalloc = Z_NULL;
defstream.zfree = Z_NULL;
defstream.opaque = Z_NULL;
defstream.avail_in = (uInt) strlen(buffer_in);
defstream.next_in = (Bytef *) buffer_in;
defstream.avail_out = (uInt) sizeof(buffer_out);
defstream.next_out = (Bytef *) buffer_out;
deflateInit(&defstream, Z_BEST_COMPRESSION);
deflate(&defstream, Z_FINISH);
deflateEnd(&defstream);
printf("Uncompressed size is: %lu\n", strlen(buffer_in));
printf("Compressed size is: %lu\n", strlen(buffer_out));
printf("ZLIB VERSION: %s\n", zlibVersion());
return EXIT_SUCCESS;
}
Also, the contents of *meson.build* are:

.. code-block:: text
:caption: **meson.build**
project('tutorial', 'c')
zlib = dependency('zlib', version : '1.2.11')
executable('compressor', 'src/main.c', dependencies: zlib)
Let's create a *conanfile.txt* with the following content to install **Zlib**:

.. code-block:: ini
:caption: **conanfile.txt**
[requires]
zlib/1.2.11
[generators]
PkgConfigDeps
MesonToolchain
In this case, we will use :ref:`PkgConfigDeps<PkgConfigDeps>` to generate information about where the **Zlib** library
files are installed thanks to the `*.pc` files and :ref:`MesonToolchain<MesonToolchain>` to pass build information
to *Meson* using a `conan_meson_[native|cross].ini` file that describes the native/cross compilation environment, which in
this case is a `conan_meson_native.ini` one.

We will use Conan to install **Zlib** and generate the files that Meson needs to find this library and build our project.
We will generate those files in the folder *build*. To do that, run:

.. code-block:: bash
$ conan install . --output-folder=build --build=missing
Now we are ready to build and run our **compressor** app:

.. code-block:: bash
:caption: Windows
$ cd build
$ meson setup --native-file conan_meson_native.ini .. meson-src
$ meson compile -C meson-src
$ meson-src\compressor.exe
Uncompressed size is: 233
Compressed size is: 147
ZLIB VERSION: 1.2.11
.. code-block:: bash
:caption: Linux, macOS
$ cd build
$ meson setup --native-file conan_meson_native.ini .. meson-src
$ meson compile -C meson-src
$ ./meson-src/compressor
Uncompressed size is: 233
Compressed size is: 147
ZLIB VERSION: 1.2.11
162 changes: 162 additions & 0 deletions 2.1/_sources/examples/tools/meson/create_your_first_package.rst.txt
@@ -0,0 +1,162 @@
.. _examples_tools_meson_create_first_package:

Create your first Conan package with Meson
==========================================

In the :ref:`Create your first Conan package tutorial<creating_packages_create_your_first_conan_package>`
CMake was used as the build system. If you haven't read that section, read it first to familiarize
yourself with the ``conanfile.py`` and ``test_package`` concepts, then come back to read
about the specifics of the ``Meson`` package creation.

Use the :command:`conan new` command to create a "Hello World" C++ library example project:

.. code-block:: bash
$ conan new meson_lib -d name=hello -d version=1.0
This will create a Conan package project with the following structure.

.. code-block:: text
├── conanfile.py
├── meson.build
├── hello.vcxproj
├── src
│   ├── hello.h
│   └── hello.cpp
└── test_package
├── conanfile.py
├── meson.build
└── src
└── example.cpp
The structure and files are very similar to the previous CMake example:

- **conanfile.py**: On the root folder, there is a *conanfile.py* which is the main recipe
file, responsible for defining how the package is built and consumed.
- **meson.build**: A Meson build script. This script doesn't need to contain anything Conan-specific,
it is completely agnostic of Conan, because the integration is transparent.
- **src** folder: the folder that contains the simple C++ "hello" library.
- **test_package** folder: contains an *example* application that will require
and link with the created package. In this case the ``test_package`` also contains a
``meson.build``, but it is possible to have the ``test_package`` using
other build system as CMake if desired. It is not mandatory that the test_package is using
the same build system as the package.

Let's have a look at the package recipe *conanfile.py* (only the relevant new parts):

.. code-block:: python
exports_sources = "meson.build", "src/*"
def layout(self):
basic_layout(self)
def generate(self):
tc = MesonToolchain(self)
tc.generate()
def build(self):
meson = Meson(self)
meson.configure()
meson.build()
def package(self):
meson = Meson(self)
meson.install()
Let's explain the different sections of the recipe briefly:

- The ``layout()`` defines a ``basic_layout()``, this is less flexible than a CMake one, so it
doesn't allow any parametrization.
- The ``generate()`` method calls ``MesonToolchain`` that can generate ``conan_meson_native.ini``
and ``conan_meson_cross.ini`` Meson toolchain files for cross builds. If the project had dependencies
with Conan ``requires``, it should add ``PkgConfigDeps`` too
- The ``build()`` method uses the ``Meson()`` helper to drive the build
- The ``package()`` method uses the ``Meson`` install functionality to define and copy to the package
folder the final artifacts.


The **test_package** folder also contains a ``meson.build`` file that declares a dependency to
the tested package, and links an application, to verify the package was correctly created and contains
that library:

.. code-block::
:caption: test_package/meson.build
project('Testhello', 'cpp')
hello = dependency('hello', version : '>=0.1')
executable('example', 'src/example.cpp', dependencies: hello)
Note the ``test_package/conanfile.py`` contains also a ``generators = "PkgConfigDeps", "MesonToolchain"``,
because the ``test_package`` has the "hello" package as dependency, and ``PkgConfigDeps`` is necessary to
locate it.

.. note::

This example assumes Meson, Ninja and PkgConfig are installed in the system, which might not always be the case.
If they are not, you can create a profile ``myprofile`` with:

.. code-block::
include(default)
[tool_requires]
meson/[*]
pkgconf/[*]
We added `Meson` and `pkg-config` as :ref:`tool requirements to the profile <reference_config_files_profiles_tool_requires>`. By executing ``conan create . -pr=myprofile``, those tools will be installed and made available during the package's build process.


Let's build the package from sources with the current default configuration, and then let
the ``test_package`` folder test the package:

.. code-block:: bash
$ conan create .
...
======== Testing the package: Executing test ========
hello/1.0 (test package): Running test()
hello/1.0 (test package): RUN: .\example
hello/1.0: Hello World Release!
hello/1.0: _M_X64 defined
hello/1.0: MSVC runtime: MultiThreadedDLL
hello/1.0: _MSC_VER1939
hello/1.0: _MSVC_LANG201402
hello/1.0: __cplusplus201402
hello/1.0 test_package
We can now validate that the recipe and the package binary are in the cache:


.. code-block:: bash
$ conan list hello/1.0:*
Local Cache:
hello
hello/1.0
revisions
856c535669f78da11502a119b7d8a6c9 (2024-03-04 17:52:39 UTC)
packages
c13a22a41ecd72caf9e556f68b406569547e0861
info
settings
arch: x86_64
build_type: Release
compiler: msvc
compiler.cppstd: 14
compiler.runtime: dynamic
compiler.runtime_type: Release
compiler.version: 193
os: Windows
.. seealso::

- :ref:`Meson built-in integrations reference<conan_tools_meson>`.
- :ref:`PkgConfigDeps built-in integrations reference<conan_tools_gnu_pkgconfigdeps>`.
3 changes: 2 additions & 1 deletion 2.1/_sources/examples/tools/meson/meson.rst.txt
Expand Up @@ -9,4 +9,5 @@ tools.meson
:maxdepth: 2


mesontoolchain/build_simple_meson_project
build_simple_meson_project
create_your_first_package
Expand Up @@ -346,10 +346,57 @@ Windows or that you want to use the system's CMake installation instead of using
self.tool_requires("cmake/3.22.6")
.. _copy_resources_on_generate:

Use the generate() method to copy resources from packages
---------------------------------------------------------

In some scenarios, Conan packages include files that are useful or even necessary for the
consumption of the libraries they package. These files can range from configuration files,
assets, to specific files required for the project to build or run correctly. Using the
:ref:`generate() method<reference_conanfile_methods_generate>` you can copy these
files from the Conan cache to your project's folder, ensuring that all required resources
are directly available for use.

Here's an example that shows how to copy all resources from a dependency's
``resdirs`` directory to an ``assets`` directory within your project:


.. code-block:: python
import os
from conan import ConanFile
from conan.tools.files import copy
class MyProject(ConanFile):
...
def generate(self):
# Copy all resources from the dependency's resource directory
# to the "assets" folder in the source directory of your project
dep = self.dependencies["dep_name"]
copy(self, "*", dep.cpp_info.resdirs[0], os.path.join(self.source_folder, "assets"))
Then, after the ``conan install`` step, all those resource files will be copied locally,
allowing you to use them in your project's build process. For a complete example of
how to import files from a package in the ``generate()`` method, you can refer to the
`blog post about using the Dear ImGui library
<https://blog.conan.io/2019/06/26/An-introduction-to-the-Dear-ImGui-library.html>`, which
demonstrates how to import bindings for the library depending on the graphics API.

.. note::

It's important to clarify that copying libraries, whether static or shared, is not
necessary. Conan is designed to use the libraries from their locations in the Conan
local cache using :ref:`generators<conan_tools>` and :ref:`environment
tools<conan_tools_env_virtualrunenv>` without the need to copy them to the local
folder.

.. seealso::

- :ref:`Using "cmake_layout" + "CMakeToolchain" + "CMakePresets feature" to build your project<examples-tools-cmake-toolchain-build-project-presets>`.
- :ref:`Understanding the Conan Package layout<tutorial_package_layout>`.
- :ref:`Documentation for all conanfile.py available methods<reference_conanfile_methods>`.
- Importing resource files in the generate() method
- Conditional generators in configure()
Expand Up @@ -338,5 +338,6 @@ An **important** note: the Conan cache is private to the Conan client - modifyin
.. seealso::

- :ref:`Create your first Conan package with Visual Studio/MSBuild<examples_tools_microsoft_create_first_package>`.
- :ref:`Create your first Conan package with Meson<examples_tools_meson_create_first_package>`.
- :ref:`CMake built-in integrations reference<conan_tools_cmake>`.
- :ref:`conan create command reference<reference_commands_create>` and :ref:`Conan list command reference<reference_commands_list>`.
Expand Up @@ -192,6 +192,6 @@ could do in the ``generate()`` method like:

.. seealso::

- Use the ``generate()`` method to import files from dependencies.
- Use the ``generate()`` to :ref:`import files from dependencies<copy_resources_on_generate>`.
- More based on the examples mentioned above ...
- :ref:`generate() method reference<reference_conanfile_methods_generate>`

0 comments on commit fe3e872

Please sign in to comment.