Showing posts with label cmake. Show all posts
Showing posts with label cmake. Show all posts

2015/12/22

7 generic steps to build any cmakeable C/C++ project

“If you build it, CR will come…”
from Motorolans folklore


Sometimes digging through SO, I’ve often saw common questions - “How to build < whatever project > using Visual Studio/MinGW/etc... ???”.


It almost always relates to Windows, because a lot of good software naturally born and developed on Linux/Unix platform, where make utility still the primary tool for managing builds. (... and yes, I know about mingw-make... )

But to my personal opinion, all great software should be cross-platform if possible. And here is CMake comes into the scene. 
CMake gains more and more attention and popularity, so major great OSS projects (and commercial) adopting it in their build process. In most cases, but not all, those projects can be built on any platform, where CMake can be run. If it’s not true, you’ve always can submit ticket or patch against any build issues.


So here is common steps for building any project which has CMake support.


Of course I assume that you’re familiar with:
  • Command line/shell usage on your platform
  • VCS tools, like git, svn, hg or even old cvs
so below steps should not be surprise to you.


  1. Clone/checkout/un-pack project to your local storage.
  2. Ensure that project is support cmake build generation.
    • This can be done by searching for CMakeLists.txt file in project sources without cloning (use SCM WebUI). Almost always it can be found in project root folder. If above file is not found - you out of luck, sorry. This post will not help you. But as I’ve already said - you always can submit pull request with basic CMake support. It is really not that hard.
  3. Create build folder inside project root location. For example build and enter it.
  4. Generate build files for project using command
    • cmake < path to CMakeLists.txt >
    • in our example it just cmake ..
  5. Build project with command
    • cmake --build .
  6. Run tests for project
    • ctest -VV
  7. Install artifacts on your platform
    • cmake --build . --target install


Is it simple, huh?


Steps 6 and 7 can be optional. Sometimes it just not implemented in project (cmake install and test are should be explicitly declared in CMakeLists.txt)

Have a nice day and happy building!

-- SN