docs: conanfile.py examples added to the installation chapter

This commit is contained in:
Mateusz Pusz
2024-11-19 23:53:21 +01:00
parent 86cbe972d3
commit 8c39e02f88

View File

@ -239,12 +239,14 @@ The following steps may be performed to obtain an official library release:
project's top-level directory and add **mp-units** as a dependency of your project.
For example, the simplest file may look as follows:
```ini title="conanfile.txt"
=== "_conanfile.txt_"
```ini
[requires]
mp-units/2.4.0
[options]
# The below mp-units options are automatically deduced based on the current system's settings.
# The below mp-units options are automatically deduced based on the current settings.
# Uncomment and set to an explicit value to override the auto-deduction.
#
# mp-units*:cxx_modules=True
@ -262,6 +264,44 @@ The following steps may be performed to obtain an official library release:
CMakeDeps
```
=== "_conanfile.py_"
```python
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
class MPUnitsTestConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain"
def requirements(self):
self.requires(
"mp-units/2.4.0",
options={
# The below mp-units options are automatically deduced based on the current settings.
# Uncomment and set to an explicit value to override the auto-deduction.
#
# "cxx_modules": False,
# "import_std": False,
# "std_format": True,
# "no_crtp": True,
# "contracts": "gsl-lite",
# "freestanding": False,
},
)
def layout(self):
cmake_layout(self)
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
if can_run(self):
cmake.ctest(cli_args=["--output-on-failure"])
```
2. Import **mp-units** and its dependencies definitions with `find_package`:
```cmake
@ -276,10 +316,19 @@ The following steps may be performed to obtain an official library release:
4. Download, build, and install Conan dependencies before running the CMake configuration step:
=== "_conanfile.txt_ or _conanfile.py_"
```shell
conan install . -pr <your_conan_profile> -s compiler.cppstd=20 -b=missing
cmake --preset conan-default
cmake --build --preset conan-release
cmake --build --preset conan-release --target test
```
=== "_conanfile.py_ only"
```shell
conan build . -pr <your_conan_profile> -s compiler.cppstd=20 -b=missing
```
### Conan + CMake (Live At Head)
@ -306,12 +355,14 @@ with the following differences:
2. In your Conan configuration file, provide the package identifier of the `mpusz/testing` stream:
```ini title="conanfile.txt" hl_lines="2"
=== "_conanfile.txt_"
```ini hl_lines="2"
[requires]
mp-units/2.5.0@mpusz/testing
[options]
# The below mp-units options are automatically deduced based on the current system's settings.
# The below mp-units options are automatically deduced based on the current settings.
# Uncomment and set to an explicit value to override the auto-deduction.
#
# mp-units*:cxx_modules=True
@ -329,6 +380,44 @@ with the following differences:
CMakeDeps
```
=== "_conanfile.py_"
```python hl_lines="11"
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
class MPUnitsTestConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain"
def requirements(self):
self.requires(
"mp-units/2.5.0@mpusz/testing",
options={
# The below mp-units options are automatically deduced based on the current settings.
# Uncomment and set to an explicit value to override the auto-deduction.
#
# "cxx_modules": False,
# "import_std": False,
# "std_format": True,
# "no_crtp": True,
# "contracts": "gsl-lite",
# "freestanding": False,
},
)
def layout(self):
cmake_layout(self)
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
if can_run(self):
cmake.ctest(cli_args=["--output-on-failure"])
```
!!! tip
The identifiers of the latest packages can always be found in