|
| 1 | +.. _reference_commands_require: |
| 2 | + |
| 3 | +conan require |
| 4 | +============= |
| 5 | + |
| 6 | +.. include:: ../../common/experimental_warning.inc |
| 7 | + |
| 8 | +.. autocommand:: |
| 9 | + :command: conan require -h |
| 10 | + |
| 11 | + |
| 12 | +The :command:`conan require` command helps to add any requirement as a version range or remove it from your *conanfile.py*. |
| 13 | + |
| 14 | + |
| 15 | +.. important:: |
| 16 | + |
| 17 | + This command is only a UX utility. It's not aimed at replacing editing the conanfile, and it's not expected to cover |
| 18 | + all the use cases, i.e., conditional requirements, requirements with different traits, etc. For all those mentioned |
| 19 | + scenarios, we recommend editing the conanfile.py as usual. |
| 20 | + |
| 21 | + |
| 22 | +conan require add |
| 23 | +----------------- |
| 24 | + |
| 25 | +.. autocommand:: |
| 26 | + :command: conan require add -h |
| 27 | + |
| 28 | +Add a new requirement to your local *conanfile.py* as a version range. |
| 29 | + |
| 30 | +By default, it looks for the recipe name in any of your remotes. When a remote contains any result for the recipe |
| 31 | +required, the latest version is used and written as a version range between the version found and the next major one |
| 32 | +(if possible, as versions based on commits do not have that major version): |
| 33 | + |
| 34 | +.. code-block:: bash |
| 35 | +
|
| 36 | + $ conan require add fmt |
| 37 | + Connecting to remote 'conancenter' anonymously |
| 38 | + Found 21 pkg/version recipes matching fmt/* in conancenter |
| 39 | + Added 'fmt/[>=12.1.0 <13]' as a new requires. |
| 40 | +
|
| 41 | +It admits several arguments as new requirements: |
| 42 | + |
| 43 | +.. code-block:: bash |
| 44 | +
|
| 45 | + $ conan require add fmt zlib |
| 46 | + Connecting to remote 'conancenter' anonymously |
| 47 | + Found 21 pkg/version recipes matching fmt/* in conancenter |
| 48 | + Found 5 pkg/version recipes matching zlib/* in conancenter |
| 49 | + Added 'fmt/[>=12.1.0 <13]' as a new requires. |
| 50 | + Added 'zlib/[>=1.3.1 <2]' as a new requires. |
| 51 | +
|
| 52 | +Or even, you can directly put the requirement version: |
| 53 | + |
| 54 | +.. code-block:: bash |
| 55 | +
|
| 56 | + $ conan require add boost/1.89.0 |
| 57 | + Added 'boost/[>=1.89.0 <2]' as a new requires. |
| 58 | +
|
| 59 | +
|
| 60 | +Tool and test requirements are also supported: |
| 61 | + |
| 62 | +.. code-block:: bash |
| 63 | +
|
| 64 | + $ conan require add --tool cmake --test gtest |
| 65 | + Connecting to remote 'conancenter' anonymously |
| 66 | + Found 54 pkg/version recipes matching cmake/* in conancenter |
| 67 | + Found 10 pkg/version recipes matching gtest/* in conancenter |
| 68 | + Added 'cmake/[>=4.2.2 <5]' as a new tool_requires. |
| 69 | + Added 'gtest/cci.20210126' as a new test_requires. |
| 70 | +
|
| 71 | +Use ``--no-remote`` to resolve versions only from the local cache: |
| 72 | + |
| 73 | +.. code-block:: bash |
| 74 | +
|
| 75 | + $ conan require add boost --no-remote |
| 76 | + Found 2 pkg/version recipes matching boost/* in local cache |
| 77 | + Added 'boost/[>=1.89.0 <2]' as a new requires. |
| 78 | +
|
| 79 | +
|
| 80 | +Use ``--folder`` to point to a different recipe location: |
| 81 | + |
| 82 | +.. code-block:: text |
| 83 | +
|
| 84 | + $ conan require add fmt --folder=path/to/conanfile.py |
| 85 | +
|
| 86 | +
|
| 87 | +conan require remove |
| 88 | +-------------------- |
| 89 | + |
| 90 | +.. autocommand:: |
| 91 | + :command: conan require remove -h |
| 92 | + |
| 93 | +Remove any requirement from your *conanfile.py*: |
| 94 | + |
| 95 | +.. code-block:: bash |
| 96 | +
|
| 97 | + $ conan require remove fmt zlib |
| 98 | + Removed fmt dependency as requires. |
| 99 | + Removed zlib dependency as requires. |
| 100 | +
|
| 101 | +Tool and test requirements are also supported: |
| 102 | + |
| 103 | +.. code-block:: bash |
| 104 | +
|
| 105 | + $ conan require remove --tool cmake --test gtest |
| 106 | + Removed cmake dependency as tool_requires. |
| 107 | + Removed gtest dependency as test_requires. |
| 108 | +
|
| 109 | +Use ``--folder`` to point to a different recipe location: |
| 110 | + |
| 111 | +.. code-block:: text |
| 112 | +
|
| 113 | + $ conan require remove fmt --folder=path/to/conanfile.py |
0 commit comments