In my last posts on conan, I explained how to start migrating your project to use a few simple conan libraries and then how to integrate a somewhat more complicated library with custom build steps.
Of course, you still want your library in CI. We previously advocated simply adding some dependencies to your source tree, but in other cases, we provisioned our build-systems with the right libraries on a system-level (alternatively, using docker). Now using conan, this is all totally different – we want to avoid setting up too many dependencies on our build-system. The fewer dependencies they have, the less likely they will accidentally be used during compilation. This is crucial to implement portability of your artifacts.
Setting up the build-systems
The build systems still have to be provisioned. You will at least need conan and your compiler-suite installed. Whether to install CMake is a point of contention – since the CMake-Plugin for Jenkins can do that.
Setting up the build job
The first thing you usually need is to configure your remotes properly. One way to do this is to use conan config install
command, which can synchronize remotes (or the whole of the conan config) from either a folder, a zip file or a git repository. Since I like to have stuff readable in plain text in my repository, I opt to store my remotes in a specific folder. Create a new folder in your repository. I use ci/conan_config
in this example. In it, place a remotes.txt
like this:
bincrafters https://api.bintray.com/conan/bincrafters/public-conan True conan-center https://conan.bintray.com True
Note that conan needs a whole folder, you cannot read just this file. Your first command should then be to install these remotes:
conan config install ci/conan_config
Jenkins’ CMake for conan
The next step prepares for installing our dependencies. Depending on whether you’re building some of those dependencies (the --build
option), you might want to have CMake available for conan to call. This is a problem when using the Jenkins CMake Plugin, because that only gives you cmake for its specific build steps, while conan simply uses the cmake
executable by default. If you’re provisioning your build-systems with conan or not building any dependencies, you can skip this step.
One way to give conan access to the Jenkins CMake installation is to run a small CMake script via a “CMake/CPack/CTest execution” step and have it configure conan appropriatly. Create a file ci/configure_for_conan.cmake
:
execute_process(COMMAND conan config set general.conan_cmake_program=\"${CMAKE_COMMAND}\")
Create a new “CMake/CPack/CTest execution” step with tool “CMake” and arguments “-P ci/configure_for_conan.cmake”. This will setup conan with the given cmake installation.
Install dependencies and build
Next run the conan install command:
mkdir build && cd build conan install .. --build missing
After that, you’re ready to invoke cmake and the build tool with an additional “CMake Build” step. The build should now be up and running. But who am I kidding, the build is always red on first try 😉