CMake
CMake is similar to make. It uses a project description to automate the compilation of a project. The difference is that CMake uses a platform independent description of the project, called a cmake list.
Example cmake list (named CMakeLists.txt by default):
PROJECT(Example)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
# header and module list
SET(LIB_HDRS
module.h
# insert additional module headers here
)
SET(LIB_SRCS
module.c
# insert additional module files here
)
# library
SET(LIB_NAME ${PROJECT_NAME})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
ADD_LIBRARY(${LIB_NAME} ${LIB_SRCS} ${LIB_HDRS})
# executable
ADD_EXECUTABLE(main main.c)
TARGET_LINK_LIBRARIES(main
${LIB_NAME}
)
Use the above cmake list file as a template for your own projects. Substitute the first two set commands with the names of your own projects’ headers and modules.
- On Unix, type “cmake .” on the console and the cmake program will create a Makefile. Then type “make” on the console and the make program will create the corresponding executable.
- To install cmake, type
sudo apt-get install cmake
on the terminal.
- To install cmake, type
- On a Mac, cmake behaves identical to Unix as decribed above, except that it is recommended to install cmake from source:
- get the source tarball from cmake.org
- in the following, let the source tarball be cmake-3.2.1.tar.gz
tar zxf cmake-3.2.1.tar.gz
cd cmake-3.2.1
./configure && make && sudo make install
- On Windows, open the CMake GUI and specify the location of the cmake list file. Then press the configure and generate button twice and the cmake program will create a Microsoft Visual Studio project and solution file. Open the solution file and compile the project in the Visual Studio GUI.
- To install cmake, download the most recent installer exe from cmake.org.
In summary, CMake is a meta make tool. It creates make instructions for the make tools of a particular platform utilizing the same project description for all supported platforms. As a result, project maintenance is limited to a single cmake file and does not have to be performed for a multitude of different project files used by different build tools on different platforms.
For those reasons, CMake is the open-source standard for multi-platform development.
CMake is also compatible with IDEs like KDevelop or QtCreator.