c-ares/1.18.1¶
Using the c-ares Conan Package¶
Conan integrates with different build systems. You can declare which build system you want your project to use setting in the [generators] section of the conanfile.txt or using the generators attribute in the conanfile.py. Here, there is some basic information you can use to integrate c-ares in your own project. For more detailed information, please check the Conan documentation.
Using c-ares with CMake¶
Conan CMake generators¶
-
CMakeDeps: generates information about where the c-ares library and its dependencies are installed together with other information like version, flags, and directory data or configuration. CMake will use this files when you invoke
find_package()in your CMakeLists.txt. -
CMakeToolchain: generates a CMake toolchain file that you can later invoke with CMake in the command line using
-DCMAKE_TOOLCHAIN_FILE=conantoolchain.cmake.
Declare these generators in your conanfile.txt along with your c-ares dependency like:
[requires]
c-ares/1.18.1
[generators]
CMakeDeps
CMakeToolchain
To use c-ares in a simple CMake project with this structure:
.
|-- CMakeLists.txt
|-- conanfile.txt
`-- src
`-- main..c
Your CMakeLists.txt could look similar to this, using the global c-ares::cares CMake's target:
cmake_minimum_required(VERSION 3.15)
project(c-ares_project C)
find_package(c-ares)
add_executable(${PROJECT_NAME} src/main.c)
# Use the global target
target_link_libraries(${PROJECT_NAME} c-ares::cares)
To install c-ares/1.18.1, its dependencies and build your project, you just have to do:
# for Linux/macOS
$ conan install . --install-folder cmake-build-release --build=missing
$ cmake . -DCMAKE_TOOLCHAIN_FILE=cmake-build-release/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
$ cmake --build .
# for Windows and Visual Studio 2017
$ conan install . --output-folder cmake-build --build=missing
$ cmake . -G "Visual Studio 15 2017" -DCMAKE_TOOLCHAIN_FILE=cmake-build/conan_toolchain.cmake
$ cmake --build . --config Release
As the c-ares Conan package defines components, you can link only the desired parts of the library in your project. For example, linking only with the c-ares cares component, through the c-ares::cares target.
...
# Link just to c-ares cares component
target_link_libraries(${PROJECT_NAME} c-ares::cares)
To check all the available components for c-ares Conan package, please check the dedicated section at the end of this document.
Using c-ares with Visual Studio¶
Visual Studio Conan generators¶
-
MSBuildDeps: generates the conandeps.props properties file with information about where the c-ares library and its dependencies are installed together with other information like version, flags, and directory data or configuration.
-
MSBuildToolchain: Generates the conantoolchain.props properties file with the current package configuration, settings, and options.
Declare these generators in your conanfile.txt along with your c-ares dependency like:
[requires]
c-ares/1.18.1
[generators]
MSBuildDeps
MSBuildToolchain
Please, check the Conan documentation for more detailed information on how to add these properties files to your Visual Studio projects.
Using c-ares with Autotools and pkg-config¶
Autotools Conan generators¶
-
AutotoolsToolchain: generates the conanautotoolstoolchain.sh/bat script translating information from the current package configuration, settings, and options setting some enviroment variables for Autotools like:
CPPFLAGS,CXXFLAGS,CFLAGSandLDFLAGS. It will also generate adeactivate_conanautotoolstoolchain.sh/batso you can restore your environment. -
AutotoolsDeps: generates the conanautotoolsdeps.sh/bat script with information about where the c-ares library and its dependencies are installed together with other information like version, flags, and directory data or configuration. This is done setting some enviroment variables for Autotools like:
LIBS,CPPFLAGS,CXXFLAGS,CFLAGSandLDFLAGS. It will also generate adeactivate_conanautotoolsdeps.sh/batso you can restore your environment.
Declare these generators in your conanfile.txt along with your c-ares dependency like:
[requires]
c-ares/1.18.1
[generators]
AutotoolsToolchain
AutotoolsDeps
Then, building your project is as easy as:
$ conan install .
# set the environment variables for Autotools
$ source conanautotoolstoolchain.sh
$ source conanautotoolsdeps.sh
$ ./configure
$ make
# restore the environment after the build is completed
$ source deactivate_conanautotoolstoolchain.sh
$ source deactivate_conanautotoolsdeps.sh
pkg-config Conan generator¶
- PkgConfigDeps: generates the libcares.pc file (and the ones corresponding to c-ares dependencies) with information about the dependencies that can be later used by the pkg-config tool pkg-config to collect data about the libraries Conan installed.
You can use this generator instead of the AutotoolsDeps one:
[requires]
c-ares/1.18.1
[generators]
AutotoolsToolchain
PkgConfigDeps
And then using pkg-config to set the environment variables you want, like:
$ conan install .
# set the environment variables for Autotools
$ source conanautotoolstoolchain.sh
$ export CPPFLAGS="$CPPFLAGS $(pkg-config --cflags c-ares)"
$ export LIBS="$LIBS $(pkg-config --libs-only-l c-ares)"
$ export LDFLAGS="$LDFLAGS $(pkg-config --libs-only-L --libs-only-other c-ares)"
$ ./configure
$ make
# restore the environment after the build is completed
$ source deactivate_conanautotoolstoolchain.sh
As the c-ares Conan package defines components you can use them to link only that desired part of the library in your project. To check all the available components for c-ares Conan package, and the corresponding .pc files names, please check the dedicated section at the end of this document.
Other build systems¶
Please, check the Conan documentation for other integrations besides the ones listed in this document.
Declared components for c-ares¶
These are all the declared components for the c-ares Conan package:
* Component cares:
* CMake target name: c-ares::cares
* pkg-config .pc file: libcares.pc
* Links to libraries: cares
* Systems libs: rt
* Preprocessor definitions: CARES_STATICLIB
Exposed header files for c-ares¶
#include <ares_nameser.h>
#include <ares_build.h>
#include <ares_dns.h>
#include <ares.h>
#include <ares_version.h>
#include <ares_rules.h>
---¶
Conan 1.58.0. JFrog LTD. https://conan.io. Autogenerated 2023-02-05 17:37:10.