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

2009/09/22

swithching to vim completely...

After some unsuccessful attempts to make Emacs my "editor of choice" I've decided completely go for vim + gnu global.
--
SN

2009/09/01

September, 1

There is important day here in Russia (and I suspect for all other countries).

This day, all children who became 7 or 6 years old goes to school to their first class.

Also it is first day of Autumn, which means that Summer is over :-). 

I’m alive but quite busy…

Well, it not good enough not to updating own blog periodically. Will start it shortly. Sorry for delay.

2009/05/03

boost 1.39.0 is out...

Actually, not big news, since it was planned as per schedule :-)
--
SN

2009/02/22

The Safe C Library

DDJ announced safe C library (as per TR 24731) implementation availability on SourceForge.

--
SN

2009/02/16

mike tyson's fights on espn classic channel

Well it is a pleasure to see Mike's best fights on TV.

Honestly, I wasn't see them all when I was younger.
From the beginning to the knockout.

Thanks to ESPN for that retrospective.

--
SN