HOWTO_cmake.html 4.63 KB
Newer Older
1 2 3
<html>
<head>
<title> Using AMDiS with cmake </title>
4 5 6
<style type="text/css" >
.desc { background-color:#E0E0E0; margin-left:100px }
</style >
7 8 9 10
</head>
<body>
<h1> Using AMDiS with cmake </h1>
With this short page, I will show you, how to use the cmake buildsystem with AMDiS. The introduction consists of two main parts:
11
<ol>
12 13 14 15
<li> <a href="#compiling" > compiling and installing AMDiS with CMake </a ></li>
<li> <a href="#using" > using the cmake installed AMDiS in your project </a ></li>
<li> <a href="#faq" > some frequently asked questions </a ></li>
</ol>
16

17
<h2> <a name="compiling" > Compiling and installing AMDiS with CMake </a > </h2>
18 19 20 21 22 23
<h3> configure </h3>
There are 3 different configure tools for CMake:
<ul> <li> cmake (non interactive) </li>
<li> ccmake (interactive on command line) </li>
<li> cmake-gui (qt-based gui) </li></ul>

24
<p>I will use the cmake and ccmake. The autoconf/automake implementation was used directly inside the AMDiS source directory (i.e. the directory you get through svn). To use the CMake buildsystem, I recommend a different directory structure for building and compiling AMDiS. The script <a href="https://fusionforge.zih.tu-dresden.de/frs/download.php/34/getamdis_cmake.sh" >getamdis_cmake.sh</a>, which can be found on <a href="https://fusionforge.zih.tu-dresden.de" >https://fusionforge.zih.tu-dresden.de</a>, creates such a directory structure.</p>
25
Assume, you have AMDiS downloaded in the directory
26 27
<pre class="desc" >
${HOME}/work/ </pre>
28
, the AMDiS source directory is
29 30 31 32 33 34 35 36 37 38 39
<pre class="desc">
${HOME}/work/amdis/AMDiS </pre>
. To configure and compile AMDiS I recommend using out of source builds. This means, you should create a directory amdis_build
<pre class="desc">
mkdir ${HOME}/work/amdis_build </pre>
and do the remaining work from there.
<pre class="desc">
cd ${HOME}/work/amdis_build </pre>
 The simplest configuration of AMDiS, i.e. without umfpack and parallelization, only sets the install destination to the directory "${HOME}/programs/". To do this, you have to call cmake with your install destination and the AMDiS source directory as commandline arguments
 <pre class="desc" >
cmake -DCMAKE_INSTALL_PREFIX=${HOME}/programs/ ../amdis/AMDiS</pre>
40

41
Compilation and installation is the same as with automake/autoconf:
42 43 44
<pre class="desc">
make && make install </pre >
The last command will install AMDiS to ${HOME}/programs
45

46
<h2> <a name="using" > Using the cmake installed AMDiS in your project </a > </h2>
47
A cmake-project consists of the source files and a file CMakeLists.txt, which contains a description of needed libraries, headers and programs. If you have a simple project with one program "fooProg", which have to compile only one source file "src/foo.cc", your CMakeLists.txt consist of the following lines:
48
<pre class="desc" >
49 50 51
project(projectName) <br>
cmake_minimum_required(VERSION 2.8)<br><br>

52 53 54
find_package(AMDIS REQUIRED)<br>
if(AMDIS_FOUND)<br>
	include(${AMDIS_USE_FILE})<br>
55
	add_executable(fooProg src/foo.cc)<br>
Naumann, Andreas's avatar
Naumann, Andreas committed
56
	target_link_libraries(fooProg ${AMDIS_LIBRARIES})<br>
57 58
endif(AMDIS_FOUND)<br>
</pre >
59 60

The first two lines
61
<pre class="desc" >
62 63
project(projectName) <br>
cmake_minimum_required(VERSION 2.8)
64
</pre >
65 66
tell cmake the name of your project and that you whish to use only cmake versions newer than 2.8.<br>
The line
67 68 69
<pre class="desc" >
find_package(AMDIS REQUIRED)
</pre >
70
tells cmake, that you want to use AMDiS and it should complain if AMDiS was not found. CMake will print an error message, bu will not stop the execution! With the command
71 72 73
<pre class="desc" >
	include(${AMDIS_USE_FILE})
</pre >
74
we read an AMDiS specific configuration file, which sets some compilerflags and adds the include directorys. The program is added with
75
<pre class="desc" >
76
	add_executable(fooProg src/foo.cc)
77
</pre >
78
and we have to tell cmake, that we need the library amdis and each library amdis depends on. This is done with the command
79
<pre class="desc" >
Naumann, Andreas's avatar
Naumann, Andreas committed
80
	target_link_libraries(fooProg ${AMDIS_LIBRARIES})
81
</pre >
82

83
If cmake does not find AMDiS, you have to set the variable AMDIS_DIR to the directory containing the file AMDiSConfig.cmake. This file resides in
84 85 86 87
<pre class="desc" >
  ${CMAKE_INSTALL_PREFIX}/share/amdis/
</pre >
 where CMAKE_INSTALL_PREFIX is the directory you choose during installation of amdis.
88 89 90 91 92 93 94

<h2 > <a name="faq" > Frequently asked questions </a ></h2 >
<h3 > Boost </h3>
If you have different boost versions on your system and you do not want to use the standard version in /usr/lib and /usr/include, you should set the environment variable BOOST_ROOT to your boost-installation.

<h3 > I will not set the AMDIS_DIR in every project. </h3 >
If you always use the same AMDiS directory, you can add the directory to your PATH variable.
95 96
</body>
</html>