Skip to content

kenrickschulze/seqan-cmake-tutorials

 
 

Repository files navigation

PREFACE

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


seqan cmake tutorial

preliminaries

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).

setup tutorial

mkdir ~/tutorials
cd ~/tutorials

01 Hello world with cmake

mkdir ~/tutorials/test_hello_world
cd ~/tutorials/test_hello_world

create hello.cpp

// ~/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

How to automate the build process?

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)

Using cmake as an abstraction layer

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

next

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • CMake 56.6%
  • C++ 31.5%
  • C 10.7%
  • Makefile 1.2%