--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html lang="et" xmlns="http://www.w3.org/1999/xhtml" xml:lang="et">
+
+ <head>
+ <meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" />
+ <title>eVaf Tutorial - 05 - Building Generator Module</title>
+ <meta name="Author" content="Enar Väikene" />
+ <meta name="description" content="eVaf Tutorial" />
+ <meta name="keywords" content="evaf c++ application development framework tutorial password generator" />
+ <link rel="StyleSheet" href="evaf.css" type="text/css" media="all" />
+ <link rel="StyleSheet" href="highlight.css" type="text/css" media="all" />
+ </head>
+
+ <body>
+
+ <h1>eVaf Tutorial</h1>
+
+ <h2>05 - Building Generator Module</h2>
+
+ <h3>CMakeLists.txt</h3>
+
+ <p>eVaf uses <a href="http://www.cmake.org">CMake</a> as its build system and needs a file called <tt>CMakeLists.txt</tt>
+ in the <tt>src/apps/PswGen/Generator</tt> directory. Create the file and start editing it.</p>
+
+ <p>We use the <tt>TARGET</tt> variable to set the name of the module. This makes it easier to re-use the <tt>CMakeLists.txt</tt>
+ file in other modules and applications.</p>
+
+<pre class="hl"><span class="hl kwa">set</span><span class="hl opt">(</span>TARGET PswGen<span class="hl opt">)</span></pre>
+
+ <p>Then we include Qt include files and libraries. We also specify, that we do not want to include the QtGui module as this
+ module does not any classes from the QtGui module. By removing the QtGui module, we remove any graphical libraries as
+ dependencies for this module and it can be used in headless systems.</p>
+
+<pre class="hl"><span class="hl kwa">set</span><span class="hl opt">(</span>QT_DONT_USE_QTGUI TRUE<span class="hl opt">)</span>
+<span class="hl kwa">include</span><span class="hl opt">(</span><span class="hl kwd">${QT_USE_FILE}</span><span class="hl opt">)</span></pre>
+
+ <p>The next line adds the <tt>PSWGEN_GENERATOR_LIBRARY</tt> definition to the compiler (remember the <tt>lib.h</tt> file and
+ the <tt>PSWGEN_GENERATOR_EXPORT</tt> macro in the <tt>igeneraror.h</tt> file?):
+
+<pre class="hl"><span class="hl kwa">add_definitions</span><span class="hl opt">(</span>-DPSWGEN_GENERATOR_LIBRARY<span class="hl opt">)</span></pre>
+
+ <p>Add all the eVaf include directories to the compiler. The variable <tt>eVaf_INCLUDE</tt> contains all the eVaf include
+ directories and is already initialized with proper values when this <tt>CMakeLists.txt</tt> file is processed.</p>
+
+<pre class="hl"><span class="hl kwa">include_directories</span><span class="hl opt">(</span><span class="hl kwd">${eVaf_INCLUDE}<span class="hl opt">)</span></pre>
+
+ <p>Then we initialize a variable with the names of all the eVaf modules that this module needs to be linked with. We only
+ need to specify the names of libraries without prefixes or suffixes like ".dll" or ".so". These libraries also become dependencies
+ of this module and will be built whenever we build this module.</p>
+
+<pre class="hl"><span class="hl kwa">set</span><span class="hl opt">(</span>eVaf_LIBRARIES CommonLib PluginsLib<span class="hl opt">)</span></pre>
+
+ <p>Collect all the source files that needs to be compiled:</p>
+
+<pre class="hl"><span class="hl kwa">set</span><span class="hl opt">(</span>SRCS
+ module.cpp
+<span class="hl opt">)</span></pre>
+
+ <p>Collect header files that need to be processed with the Qt meta-object compiler. Any header file that contains
+ class declarations with the Q_OBJECT keyword and/or signals and slots, needs to be included here. To avoid warnings
+ during the build, do not include here any other header files.</p>
+
+<pre class="hl"><span class="hl kwa">set</span><span class="hl opt">(</span>MOC_HDRS
+ igenerator.h
+ module.h
+<span class="hl opt">)</span></pre>
+
+ <p>The following line adds the Windows version info resource file to the list of source files:</p>
+<pre class="hl"><span class="hl kwa">if</span><span class="hl opt">(</span><span class="hl kwb">WIN32</span><span class="hl opt">)</span>
+ <span class="hl kwa">set</span><span class="hl opt">(</span>SRCS <span class="hl kwd">${SRCS}</span> version.rc<span class="hl opt">)</span>
+<span class="hl kwa">endif</span><span class="hl opt">(</span><span class="hl kwb">WIN32</span><span class="hl opt">)</span></pre>
+
+ <p>Process specified header files with the Qt meta-object compiler:</p>
+
+<pre class="hl"><span class="hl kwd">qt4_wrap_cpp</span><span class="hl opt">(</span>MOC_SRCS <span class="hl kwd">${MOC_HDRS}</span><span class="hl opt">)</span></pre>
+
+ <p>Put it all together and compile the module:</p>
+
+<pre class="hl"><span class="hl kwa">add_library</span><span class="hl opt">(</span><span class="hl kwd">${TARGET}</span> <span class="hl kwb">SHARED</span> <span class="hl kwd">${SRCS} ${MOC_SRCS}</span><span class="hl opt">)</span></pre>
+
+ <p>Finally, link the module:</p>
+
+<pre class="hl"><span class="hl kwa">target_link_libraries</span><span class="hl opt">(</span><span class="hl kwd">${TARGET} ${QT_LIBRARIES} ${eVaf_LIBRARIES}</span><span class="hl opt">)</span></pre>
+
+ <p>And the final <tt>CMakeLists.txt</tt> file looks the following:</p>
+
+<pre class="hl"><span class="hl com"># src/apps/PswGen/Generator/CMakeLists.txt</span>
+
+<span class="hl com"># Name of the target</span>
+<span class="hl kwa">set</span><span class="hl opt">(</span>TARGET PswGen<span class="hl opt">)</span>
+
+<span class="hl com"># Qt modules</span>
+<span class="hl kwa">set</span><span class="hl opt">(</span>QT_DONT_USE_QTGUI TRUE<span class="hl opt">)</span>
+<span class="hl kwa">include</span><span class="hl opt">(</span><span class="hl kwd">${QT_USE_FILE}</span><span class="hl opt">)</span>
+
+<span class="hl com"># Needed for exporting symbols from this library</span>
+<span class="hl kwa">add_definitions</span><span class="hl opt">(</span>-DPSWGEN_GENERATOR_LIBRARY<span class="hl opt">)</span>
+
+<span class="hl com"># Include directories</span>
+<span class="hl kwa">include_directories</span><span class="hl opt">(</span><span class="hl kwd">${eVaf_INCLUDE}<span class="hl opt">)</span>
+
+<span class="hl com"># Required eVaf libraries</span>
+<span class="hl kwa">set</span><span class="hl opt">(</span>eVaf_LIBRARIES CommonLib PluginsLib<span class="hl opt">)</span>
+
+<span class="hl com"># Source files</span>
+<span class="hl kwa">set</span><span class="hl opt">(</span>MOC_HDRS
+ igenerator.h
+ module.h
+<span class="hl opt">)</span>
+
+<span class="hl com"># Header files for the Qt meta-object compiler</span>
+<span class="hl kwa">set</span><span class="hl opt">(</span>MOC_HDRS
+ igenerator.h
+ module.h
+<span class="hl opt">)</span>
+
+<span class="hl com"># Version info resource file for Windows builds</span>
+<span class="hl kwa">if</span><span class="hl opt">(</span><span class="hl kwb">WIN32</span><span class="hl opt">)</span>
+ <span class="hl kwa">set</span><span class="hl opt">(</span>SRCS <span class="hl kwd">${SRCS}</span> version.rc<span class="hl opt">)</span>
+<span class="hl kwa">endif</span><span class="hl opt">(</span><span class="hl kwb">WIN32</span><span class="hl opt">)</span>
+
+<span class="hl com"># Run the Qt meta-object compiler</span>
+<span class="hl kwd">qt4_wrap_cpp</span><span class="hl opt">(</span>MOC_SRCS <span class="hl kwd">${MOC_HDRS}</span><span class="hl opt">)</span>
+
+<span class="hl com"># Compile the module</span>
+<span class="hl kwa">add_library</span><span class="hl opt">(</span><span class="hl kwd">${TARGET}</span> <span class="hl kwb">SHARED</span> <span class="hl kwd">${SRCS} ${MOC_SRCS}</span><span class="hl opt">)</span>
+
+<span class="hl com"># Link the module</span>
+<span class="hl kwa">target_link_libraries</span><span class="hl opt">(</span><span class="hl kwd">${TARGET} ${QT_LIBRARIES} ${eVaf_LIBRARIES}</span><span class="hl opt">)</span></pre>
+
+ <p>We also need <tt>CMakeLists.txt</tt> files in parent directory <tt>src/apps/PswGen</tt>.
+ In this file we add the <tt>PswGen</tt> directory to the list of include directories, which makes it possible to use
+
+<pre class="hl"><span class="hl com"># src/apps/PswGen/CMakeLists.txt</span>
+<span class="hl kwa">set</span><span class="hl opt">(</span>eVaf_INCLUDE <span class="hl kwd">${eVaf_INCLUDE} ${SMAKE_SOURCE_DIR}</span>/src/apps/PswGen<span class="hl opt">)</span>
+<span class="hl kwa">add_subdirectory</span><span class="hl opt">(</span>Generator<span class="hl opt">)</span></pre>
+
+ <p>Modify the <tt>CMakeLists.txt</tt> file in the <tt>src/apps</tt> directory and include the <tt>PswGen</tt> application:</p>
+
+<pre class="hl"><span class="hl com"># src/apps/CMakeLists.txt</span>
+<span class="hl com"># ...</span>
+<span class="hl kwa">add_subdirectory</span><span class="hl opt">(</span>PswGen<span class="hl opt">)</span></pre>
+
+ <h3>Building the module</h3>
+
+ <p>Now our module is included in the build system and we can try to compile it. Go to the eVaf root directory and create
+ a build directory:</p>
+
+<pre>evaf $ <code>mkdir build</code>
+evaf $ <code>cd build</code></pre>
+
+ <p>In the build directory, run <tt>cmake</tt>:</p>
+
+<pre>evaf/build $ <code>cmake ..</code></pre>
+
+ <p>If <tt>cmake</tt> finishes without errors, build the module with the <tt>make</tt> command:</p>
+
+<pre>evaf/build $ <code>make PswGen</code></pre>
+
+ <p>If you get compiler errors during the build, fix them. If the build finishes without errors, check the content of the
+ <tt>bin</tt> directory:</p>
+
+<pre>evaf/build $ <code>ls bin</code>
+libCommonLib.so* libPluginsLib.so* libPswGen.so*
+evaf/build $</pre>
+
+ <p>As you can see, there are three libraries now. The <tt>libPswGen.so</tt> is our module and others are eVaf libraries
+ that our module needs in order to be run.</p>
+
+ <p>In the next section <a href="pswgen06.html">06 - Storage Module</a> we write the Storage module.
+
+ </body>
+</html>