Eyes, JAPAN Blog > Building projects in more convinient way

Building projects in more convinient way

denvazh

この記事は1年以上前に書かれたもので、内容が古い可能性がありますのでご注意ください。

When does it happen?

Recently, I found found myself writing and building similar project for various platforms (actually there are three major ones): os x, linux and windows. As soon as my “sane” life as software developer was about writing and building code for mac or linux, I found it very painful to bring code to the windows platform. *Forgetting about library differences and assuming that we writing something simple, that do not depends much on anything.*

Usually, if I needed to write some code using C/C++ I was writing Makefile and used to for builds, however in case of windows I found it a bit difficult to port. On the other hand, I found and start using another great tool – CMake.

Convenience is a bliss…

To make long story short, CMake is a cross-platform, open-source build system. CMake is a family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files. CMake generates native makefiles and workspaces that can be used in the compiler environment of your choice. (description is taken from the CMake web-site)

This is very convenient. What is required is a nice cmake script, that is put in a CMakeLists.txt.
Assume you have code following files in the folder:

CMakeLists.txt
example.cxx

then for initial build its only needed to create build folder for Makefile and its settings file

$: mkdir build
$: cd build

then you can create build file like this (it can be any path to the CMakeLists.txt file):

$: cmake ../

or, it can be forcefully platform and IDE specific:

$: cmake ../ -G Xcode

as a result you will end up with following files in build:

CMakeCache.txt
CMakeFiles
Makefile
Example.app
cmake_install.cmake

Now let’s actually build. As you can see, what you need to do then, is only to run make:

$: make
[100%] Building CXX object CMakeFiles/Example.dir/Example.cxx.o
Linking CXX executable Example.app/Contents/MacOS/Example

Done!

Conclusion

I’m very glad, that I found CMake. Really. Now I write CMake file to build project, because it also provides nice ways to search the system for libraries and necessary dependencies. How to actually write CMakeLists.txt file for the project I will explain next time.

  • このエントリーをはてなブックマークに追加

Comments are closed.