1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html lang=
"et" xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"et">
5 <meta http-equiv=
"CONTENT-TYPE" content=
"text/html; charset=utf-8" />
6 <title>eVaf Tutorial -
11 - Building PswGen application
</title>
7 <meta name=
"Author" content=
"Enar Väikene" />
8 <meta name=
"description" content=
"eVaf Tutorial" />
9 <meta name=
"keywords" content=
"evaf c++ application development framework tutorial password generator" />
10 <link rel=
"StyleSheet" href=
"evaf.css" type=
"text/css" media=
"all" />
11 <link rel=
"StyleSheet" href=
"highlight.css" type=
"text/css" media=
"all" />
16 <p>Previous:
<a href=
"pswgen10.html">10 - GUI Module
</a></p>
18 <h1>eVaf Tutorial
</h1>
20 <h2>11 - Buiding PswGen application
</h2>
22 <h3>CMakeLists.txt
</h3>
24 <p>Copy an existing
<tt>CMakeLists.txt
</tt> file from the
<tt>Storage
</tt> module:
</p>
26 <pre>evaf/src/apps/PswGen/GUI $
<code>cp ../Storage/CMakeLists.txt .
</code></pre>
28 <p>We need to modify the
<tt>TARGET
</tt> variable and remove
<tt>QT_USE_QTSQL
</tt> and
<tt>QT_DONT_USE_QTGUI
</tt> variables.
29 This module needs
<tt>QtGui
</tt> and does not need
<tt>QtSql
</tt>. Als add
<tt>SdiWindow
</tt> to the list of eVaf libraries
30 as the module that implements the main window.
</p>
32 <pre class=
"hl"><span class=
"hl com"># Name of the target
</span>
33 <span class=
"hl kwa">set
</span><span class=
"hl opt">(
</span>TARGET PswGui
<span class=
"hl opt">)
</span>
35 <span class=
"hl com"># Qt modules
</span>
36 <span class=
"hl kwa">include
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">${QT_USE_FILE}
</span><span class=
"hl opt">)
</span>
38 <span class=
"hl com"># Required eVaf libraries
</span>
39 <span class=
"hl kwa">set
</span><span class=
"hl opt">(
</span>eVaf_LIBRARIES CommonLib PluginsLib SdiWindow
<span class=
"hl opt">)
</span></pre>
41 <p>Here is the final
<tt>CMakeLists.txt
</tt> file:
</p>
43 <pre class=
"hl"><span class=
"hl com"># src/apps/PswGen/GUI/CMakeLists.txt
</span>
45 <span class=
"hl com"># Name of the target
</span>
46 <span class=
"hl kwa">set
</span><span class=
"hl opt">(
</span>TARGET PswGui
<span class=
"hl opt">)
</span>
48 <span class=
"hl com"># Qt modules
</span>
49 <span class=
"hl kwa">include
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">${QT_USE_FILE}
</span><span class=
"hl opt">)
</span>
51 <span class=
"hl com"># Include directories
</span>
52 <span class=
"hl kwa">include_directories
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">${eVaf_INCLUDE}
<span class=
"hl opt">)
</span>
54 <span class=
"hl com"># Required eVaf libraries
</span>
55 <span class=
"hl kwa">set
</span><span class=
"hl opt">(
</span>eVaf_LIBRARIES CommonLib PluginsLib SdiWindow
<span class=
"hl opt">)
</span>
57 <span class=
"hl com"># Source files
</span>
58 <span class=
"hl kwa">set
</span><span class=
"hl opt">(
</span>SRCS
60 <span class=
"hl opt">)
</span>
62 <span class=
"hl com"># Header files for the Qt meta-object compiler
</span>
63 <span class=
"hl kwa">set
</span><span class=
"hl opt">(
</span>MOC_HDRS
65 <span class=
"hl opt">)
</span>
67 <span class=
"hl com"># Version info resource file for Windows builds
</span>
68 <span class=
"hl kwa">if
</span><span class=
"hl opt">(
</span><span class=
"hl kwb">WIN32
</span><span class=
"hl opt">)
</span>
69 <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>
70 <span class=
"hl kwa">endif
</span><span class=
"hl opt">(
</span><span class=
"hl kwb">WIN32
</span><span class=
"hl opt">)
</span>
72 <span class=
"hl com"># Run the Qt meta-object compiler
</span>
73 <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>
75 <span class=
"hl com"># Compile the module
</span>
76 <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>
78 <span class=
"hl com"># Link the module
</span>
79 <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>
81 <p>Open the
<tt>CMakeLists.txt
</tt> file in the parent directory and add the command to include the
<tt>GUI
</tt>
84 <pre class=
"hl"><span class=
"hl com"># src/apps/PswGen/CMakeLists.txt
</span>
85 <span class=
"hl com"># ...
</span>
86 <span class=
"hl kwa">add_subdirectory
</span><span class=
"hl opt">(
</span>GUI
<span class=
"hl opt">)
</span></pre>
88 <h3>Building the module
</h3>
90 <p>Go to the previously made
<tt>build
</tt> directory and build the module:
</p>
92 <pre>evaf $
<code>cd build
</code>
93 evaf/build $
<code>make PswGui
</code></pre>
95 <p>Check the
<tt>bin
</tt> directory, which should now contain two new libraries:
</p>
97 <pre>evaf/build $
<code>ls bin
</code>
98 libCommonLib.so* libPluginsLib.so* libPswGen.so*
<b>libPswGui.so*
</b> libPswStorage.so*
<b>libSdiWindow.so*
</b>
101 <p>The
<tt>libSdiWindow.so
</tt> library was built because it is a dependency of the
<tt>GUI
</tt> module.
</p>
103 <h3>Running the PswGen application
</h3>
105 <p>In the same
<tt>build
</tt> directory, create few more sub-directories needed by any
<tt>eVaf
</tt> applications:
</p>
107 <pre> evaf/build $
<code>mkdir {etc,log}
</code></pre>
109 <p>Create the
<tt>PswGen.xml
</tt> file in the
<tt>build/etc
</tt> directory. The
<tt>PswGen.xml
</tt> file defines the
110 application by specifying all the modules that the application needs to load.
</p>
112 <pre class=
"hl"><span class=
"hl kwa"><?xml
</span> <span class=
"hl kwb">version
</span>=
<span class=
"hl str">"1.0"</span> <span class=
"hl kwb">encoding
</span>=
<span class=
"hl str">"UTF-
8"</span><span class=
"hl kwa">?
></span>
113 <span class=
"hl kwa"><!DOCTYPE
</span> eVaf
<span class=
"hl kwa">></span>
114 <span class=
"hl kwa"><eVaf
</span> <span class=
"hl kwb">version
</span>=
<span class=
"hl str">"1.0"</span><span class=
"hl kwa">></span>
115 <span class=
"hl kwa"><plugins
></span>
116 <span class=
"hl kwa"><plugin
</span> <span class=
"hl kwb">name
</span>=
<span class=
"hl str">"SdiWindow
"</span> <span class=
"hl kwb">filename
</span>=
<span class=
"hl str">"SdiWindow
"</span> <span class=
"hl kwa">/
></span>
117 <span class=
"hl kwa"><plugin
</span> <span class=
"hl kwb">name
</span>=
<span class=
"hl str">"Generator
"</span> <span class=
"hl kwb">filename
</span>=
<span class=
"hl str">"PswGen
"</span> <span class=
"hl kwa">/
></span>
118 <span class=
"hl kwa"><plugin
</span> <span class=
"hl kwb">name
</span>=
<span class=
"hl str">"Storage
"</span> <span class=
"hl kwb">filename
</span>=
<span class=
"hl str">"PswStorage
"</span> <span class=
"hl kwa">/
></span>
119 <span class=
"hl kwa"><plugin
</span> <span class=
"hl kwb">name
</span>=
<span class=
"hl str">"GUI
"</span> <span class=
"hl kwb">filename
</span>=
<span class=
"hl str">"PswGui
"</span> <span class=
"hl kwa">/
></span>
120 <span class=
"hl kwa"></plugins
></span>
121 <span class=
"hl kwa"></eVaf
></span></pre>
123 <p>Modules are loaded and initialized in the order how they are specified in the xml file. We have to make sure that
124 <tt>SdiWindow
</tt>,
<tt>Generator
</tt> and
<tt>Storage
</tt> modules are loaded before the
<tt>GUI
</tt> module. Otherwise
125 their interfaces wouldn't be available when the
<tt>GUI
</tt> module is initialized.
</p>
127 <p>The
<tt>name
</tt> attribute here is optional and will be replaced with the name reported by the actual module.
</p>
129 <p>The
<tt>filename
</tt> attribute specifies the name of the library file without prefixes and suffixes meaning that
130 <tt>lib
<b>PswGen
</b>.so
</tt> shall be specified as
<tt>PswGen
</tt>. This makes sure that the same xml file can be also used
131 on Windows, where the library would be called
<tt><b>PswGen
</b>.dll
</tt>.
</p>
133 <p>There is no executable file yet that we can run. Build it with the following command:
</p>
135 <pre>evaf/build $
<code>make eVafGUI
</code></pre>
137 <p>This command builds the GUI executable and stores it in the
<tt>evaf/build/bin
</tt> directory. The
<tt>bin
</tt> directory should look now the following:
</p>
139 <pre>evaf/build $
<code>ls bin
</code>
140 eVafGUI* libCommonLib.so* libPluginsLib.so* libPswGen.so* libPswGui.so* libPswStorage.so* libSdiWindow.so*
143 <p>Now we can run the PswGen application. Change
<tt>--dataroot=${HOME}/evaf/build
</tt> to your actual build directory name:
</p>
145 <pre>evaf/build $
<code>bin/eVafGUI --application=PswGen --dataroot=${HOME}/evaf/build --verbose=INFO
</code></pre>
147 <p>The
<tt>--application=PswGen
</tt> command line option specifies the name of the application and also means that the xml file
148 should be called
<tt>PswGen.xml
</tt>. Different applications can be run in the same build directories by changing the name
149 of the application. The default application is called
<tt>eVaf
</tt> and if no name is given, then the xml file should be called
150 <tt>eVaf.xml
</tt>.
</p>
152 <p>The
<tt>--dataroot=${HOME}/evaf/build
</tt> command line option specifies the location of data files for the application. The
153 application assumes that
<tt>etc
</tt> and
<tt>spool
</tt> directories are sub-directories in the data root directory. The default
154 data root directory is
<tt>${HOME}/.local/share/data
</tt> on
157 <p>Finally, the
<tt>--verbose=INFO
</tt> command line option makes the application to be verbose and output all the info
158 messages to the console.
</p>
160 <h3>Releasing the PswGen application
</h3>
162 <p>Now the application is written and tested. We are ready to make a release build and ship it.
</p>
164 <p>Clean the build directory:
</p>
166 <pre>evaf/build $
<code>make clean
&& rm CMakeCache.txt
</code></pre>
168 <p>Prepare for a release build and build the application:
</p>
170 <pre>evaf/build $
<code>cmake -DCMAKE_BUILD_TYPE=Release ..
</code>
171 evaf/build $
<code>make eVafGUI SdiWindow PswGen PswStorage PswGui
</code></pre>
173 <p>Packaging and shipping the application is out of the scope of this tutorial and involves more than just copying files that
174 we built. As a minimum, we have to make sure that the target system has Qt libraries installed. In this tutorial, we simply copy the
175 released application into the
<tt>{$HOME}/bin/evaf
</tt> directory. Qt libraries are already installed and we do not need to
176 worry about them.
</p>
178 <p>Create the
<tt>${HOME}/bin/evaf
</tt> directory:
</p>
180 <pre>evaf/build $
<code>mkdir -p ${HOME}/bin/evaf
</code></pre>
182 <p>Copy the content of
<tt>bin
</tt> and
</tt>etc
</tt> directories
</p>
184 <pre>evaf/build $
<code>cp -R bin etc ${HOME}/bin/evaf/
</code></pre>
186 <p>Create the bash script
<tt>PswGen
</tt> in the
<tt>${HOME}/bin
</tt> directory:
</p>
188 <pre class=
"hl"><span class=
"hl slc">#!/bin/bash
</span>
189 EVAF_DIR
<span class=
"hl opt">=
</span><span class=
"hl kwd">${HOME}
</span><span class=
"hl opt">/
</span>bin
<span class=
"hl opt">/
</span>evaf
190 <span class=
"hl kwd">${EVAF_DIR}
</span><span class=
"hl opt">/
</span>bin
<span class=
"hl opt">/
</span>eVafGUI
<span class=
"hl opt">--
</span>rootdir
<span class=
"hl opt">=
</span><span class=
"hl kwd">${EVAF_DIR}
</span> <span class=
"hl opt">--
</span>dataroot
<span class=
"hl opt">=
</span><span class=
"hl kwd">${EVAF_DIR}
</span> <span class=
"hl opt">--
</span>application
<span class=
"hl opt">=
</span>PswGen
193 <p>Don't forget to make it runnable:
</p>
195 <pre> bin $
<code>chmod a+x PswGen
</code></pre>
197 <p>Now we can run the application by simply running the bash script
<tt>PswGen
</tt> in the
<tt>${HOME}/bin
</tt> directory.