This tutorial was written for a course named PMBS (summer 2016) for bachelor students at the Free University Berlin. In this tutorial session (2h) we looked at, what cmake is, what it does and how you use it to incoperate our library SeqAn into your own project.
Since this information is already two years old, it might be at some points out-dated, but should be in general usable as a reference.
For an up-to-date user-guide for cmake, see our docs: http://seqan.readthedocs.io/en/master/Infrastructure/Use/FindSeqAnCMake.html
check if you have cmake installed by
cmake --version
will deliver
cmake version 3.0.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
mkdir ~/tutorials
cd ~/tutorials
mkdir ~/tutorials/test_hello_world
cd ~/tutorials/test_hello_world
// ~/tutorials/test_hello_world/hello.cpp
#include <iostream>
int main()
{
std::cout << "Hello World" << std::endl;
return 0;
}
try to compile and run it
g++ ~/tutorials/test_hello_world/hello.cpp
./a.out
Hello World
We could use Makefiles.
#~/tutorials/test_hello_world/Makefile
all:
mkdir build
g++ hello.cpp -o build/hello
clean:
rm -r build
(notice that the indention must be tabs) and use it
make
mkdir build
g++ hello.cpp -o build/hello
but Makefiles are kinda hard to maintain and to program. (also platform specific)
Creating a minimal cmake file.
# ~/tutorials/test_hello_world/CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(hello CXX)
# add the executable
add_executable(hello hello.cpp)
Now, we need a build folder to build the library.
mkdir ~/tutorials/build
cd ~/tutorials/build
And now let us build the hello world program.
cmake ../test_hello_world
-- The CXX compiler identification is GNU 4.8.5
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/marehr/tutorials/build
This only generated the Makefile, we will build it right now.
make
Scanning dependencies of target hello
[100%] Building CXX object CMakeFiles/hello.dir/hello.cpp.o
Linking CXX executable hello
[100%] Built target hello
Where to find the executable?
ls ~/tutorials/build
[...] hello [...]
executing the file
./hello
Hello World