We are actively working to finalize the Conan 2.0 Release. Some of the information on this page references deprecated features which will not be carried forward with the new release. It’s important to check the Migration Guidelines to ensure you are using the most up to date features.
This section summarizes some possible layouts and workflows when using Conan together with other tools as an end-user for installing and consuming existing packages. To create your own packages, please refer to Creating Packages.
Whether you are working on a single configuration or a multi configuration project, in both cases, the recommended approach is to have a conanfile (either .py or .txt) at the root of your project.
When working with a single configuration, your conanfile will be quite simple as shown in the examples and tutorials we have used so far in this user guide. For example, in Getting started, we showed how you can run the conan install .. command inside the build folder resulting in the conaninfo.txt and conanbuildinfo.cmake files being generated there too. Note that the build folder is temporary, so you should exclude it from version control to exclude these temporary files.
Out-of-source builds are also supported. Let’s look at a simple example:
$ git clone https://github.com/conan-io/examples.git $ cd libraries/poco $ conan install ./md5 --install-folder=md5_build
This will result in the following layout:
md5_build conaninfo.txt conanbuildinfo.txt conanbuildinfo.cmake md5 CMakeLists.txt # If using cmake, but can be Makefile, sln... README.md conanfile.txt md5.cpp
Now you are ready to build:
$ cd md5_build $ cmake ../md5 -G "Visual Studio 15 Win64" # or other generator $ cmake --build . --config Release $ ./bin/md5 > c3fcd3d76192e4007dfb496cca67e13b
We have created a separate build configuration of the project without affecting the original source directory in any way. The benefit is that we can freely experiment with the configuration: We can clear the build folder and build another. For example, changing the build type to Debug:
$ rm -rf * $ conan install ../md5 -s build_type=Debug $ cmake ../md5 -G "Visual Studio 15 Win64" $ cmake --build . --config Debug $ ./bin/md5 > c3fcd3d76192e4007dfb496cca67e13b
You can also manage different configurations, whether in-source or out of source, and switch between them without having to re-issue the conan install command (Note however, that even if you did have to run conan install again, since subsequent runs use the same parameters, they would be very fast since packages would already have been installed in the local cache rather than in the project)
$ git clone firstname.lastname@example.org:conan-io/examples $ cd libraries/poco $ conan install md5 -s build_type=Debug -if md5_build_debug $ conan install md5 -s build_type=Release -if md5_build_release $ cd md5_build_debug && cmake ../md5 -G "Visual Studio 15 Win64" && cd ../.. $ cd md5_build_release && cmake ../md5 -G "Visual Studio 15 Win64" && cd ../..
You can either use the
-if flags to specify where to generate the output files, or
manually create the output directory and navigate to it before executing the conan install command.
So the layout will be:
md5_build_debug conaninfo.txt conanbuildinfo.txt conanbuildinfo.cmake CMakeCache.txt # and other cmake files md5_build_release conaninfo.txt conanbuildinfo.txt conanbuildinfo.cmake CMakeCache.txt # and other cmake files example-poco-timer CMakeLists.txt # If using cmake, but can be Makefile, sln... README.md conanfile.txt md5.cpp
Now you can switch between your build configurations in exactly the same way you do for CMake or other build systems, by moving to the folder in which the build configuration is located, because the Conan configuration files for that build configuration will also be there.
$ cd md5_build_debug && cmake --build . --config Debug && cd ../.. $ cd md5_build_release && cmake --build . --config Release && cd ../..
Note that the CMake
include() of your project must be prefixed with the current cmake binary
directory, otherwise it will not find the necessary file:
There are two generators,
visual_studio_multi that could help to avoid the
context switch and using Debug and Release configurations simultaneously. Read more about them in
cmake_multi and visual_studio_multi