CMake, C++ and Jenkins/Continuous integration CMake, C++ and Jenkins/Continuous integration jenkins jenkins

CMake, C++ and Jenkins/Continuous integration


Yes, you can do it in one step.

For example, in my Jenkins environment, when building the Ubuntu jobs I use the CMake plugin for the whole compilation, as it allows multiple build tool invocations.

My screenshot at the bottom of this post is of a CMake step in a job (I use Ninja instead of Unix Makefiles, but the effect is the same).

I use two build invocations:

  • Blank - equivalent to calling ninja or make in a shell,
  • Install - equivalent to calling DESTDIR=. ninja install.

If I wanted to build additional targets from the makefiles, I could just add extra invocations to this step.

Note that in your screenshot you have a blank invocation in the configuration. This will already be calling make, and as confirmed by your log output, you are in fact compiling your project twice, because of your manual call to make all in the following step.

You can remove your shell step and your project will still build.


Regarding your question on best practices and regenerating CMake, I refer you to this article on Jenkins Best Practices where it states:

To ensure a build can be reproducible, the build must be a clean build, which is built fully from Source Code Control. This practice also implies that all code including third-party jars, build scripts, release notes, etc. must be checked into Source Code Control.

Note that I also check "Clean Build" in my CMake step, so that the entire CMake workspace is wiped out and the project is generated from scratch for every build. This ensures there are no issues caused by stale cache variables, etc.

Screenshot of a CMake step in one of my jobs:Jenkins/CMake config


I am not even sure you need this plugin. AFAIR the plugin webpage it is only useful if you want Jenkins to use a specific CMake version, or you want a GUI for which CMake variables you might want to set. I just execute CMake from the command line.

For your second part of the question, If you change CMakeLists.txt, the Makefile will automatically rerun CMake, so strictly speaking it is not necessary to run CMake each time. But on the other side, CMake configuring is quite fast and most likely takes less time than compiling.