-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickstart.html
456 lines (439 loc) · 31.9 KB
/
quickstart.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quick Start — BASIS</title>
<link rel="stylesheet" href="_static/cmake-basis.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: 'v3.3 (fb18c98)',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="shortcut icon" href="_static/favicon.ico"/>
<link rel="author" title="About these documents" href="about.html" />
<link rel="top" title="BASIS" href="index.html" />
<link rel="next" title="How-to Guides" href="howto.html" />
<link rel="prev" title="CMake BASIS" href="index.html" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9">
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="howto.html" title="How-to Guides"
accesskey="N">next</a></li>
<li class="right" >
<a href="index.html" title="CMake BASIS"
accesskey="P">previous</a> |</li>
<li><a href="sidebar.html">BASIS</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="quick-start">
<span id="quickstartguides"></span><h1>Quick Start<a class="headerlink" href="#quick-start" title="Permalink to this headline">¶</a></h1>
<div class="section" id="first-steps">
<span id="firststepsintro"></span><span id="firststeps"></span><h2>First Steps<a class="headerlink" href="#first-steps" title="Permalink to this headline">¶</a></h2>
<p>The following steps will show you how to</p>
<ul class="simple">
<li>download and install BASIS on your system.</li>
<li>use the so-called “basisproject” command line tool to create a new empty project.</li>
<li>add some example source files and edit the build configuration files to build the executable and library files.</li>
<li>build and test the example project.</li>
</ul>
<p>You need to have a Unix-like operating system such as Linux or Mac OS X installed on your
machine in order to follow these steps. At the moment, there is no separate tutorial
available for Windows users, but you can install CygWin as an alternative.
Note, however, that BASIS can also be installed and used on Windows.
Only the tools for <a class="reference internal" href="howto/run-automated-tests.html"><span class="doc">automated software tests</span></a> will not
be available then. These tools are for advanced users who want to set up an automated
software build and test on dedicated test machines. The testing tools are not needed
for what follows.</p>
<div class="section" id="install-basis">
<h3>Install BASIS<a class="headerlink" href="#install-basis" title="Permalink to this headline">¶</a></h3>
<div class="section" id="get-a-copy-of-the-source-code">
<h4>Get a copy of the source code<a class="headerlink" href="#get-a-copy-of-the-source-code" title="Permalink to this headline">¶</a></h4>
<p>Clone the <a class="reference external" href="http://git-scm.com/">Git</a> repository from <a class="reference external" href="https://github.com/cmake-basis/BASIS/">GitHub</a> as follows:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>mkdir -p ~/local/src
<span class="nb">cd</span> ~/local/src
git clone --depth<span class="o">=</span><span class="m">1</span> https://github.com/cmake-basis/BASIS.git basis
<span class="nb">cd</span> basis
</pre></div>
</div>
<p>or <a class="reference internal" href="download.html"><span class="doc">Download</span></a> a pre-packaged <code class="docutils literal"><span class="pre">.tar.gz</span></code> of the latest BASIS release and unpack it using the following command:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>mkdir -p ~/local/src
<span class="nb">cd</span> ~/local/src
tar xzf /path/to/downloaded/cmake-basis-<span class="nv">$version</span>.tar.gz
<span class="nb">cd</span> cmake-basis-<span class="nv">$version</span>
</pre></div>
</div>
</div>
<div class="section" id="configure-the-build">
<h4>Configure the build<a class="headerlink" href="#configure-the-build" title="Permalink to this headline">¶</a></h4>
<p>Configure the build system using CMake 2.8.4 or a more recent version:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>mkdir build <span class="o">&&</span> <span class="nb">cd</span> build
ccmake ..
</pre></div>
</div>
<ul class="simple">
<li>Press <code class="docutils literal"><span class="pre">c</span></code> to configure the project.</li>
<li>Change <code class="docutils literal"><span class="pre">CMAKE_INSTALL_PREFIX</span></code> to <code class="docutils literal"><span class="pre">~/local</span></code>.</li>
<li>Set options <code class="docutils literal"><span class="pre">BUILD_APPLICATIONS</span></code> and <code class="docutils literal"><span class="pre">BUILD_EXAMPLE</span></code> to <code class="docutils literal"><span class="pre">ON</span></code>.</li>
<li>Press <code class="docutils literal"><span class="pre">g</span></code> to generate the Makefiles and exit <code class="docutils literal"><span class="pre">ccmake</span></code>.</li>
</ul>
</div>
<div class="section" id="build-and-install-basis">
<h4>Build and install BASIS<a class="headerlink" href="#build-and-install-basis" title="Permalink to this headline">¶</a></h4>
<p>CMake has generated Makefiles for GNU Make. The build is thus triggered by the make command:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>make
</pre></div>
</div>
<p>To install BASIS after the successful build, run the following command:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>make install
</pre></div>
</div>
<p>As a result, CMake copies the built files into the installation tree as specified by the
<code class="docutils literal"><span class="pre">CMAKE_INSTALL_PREFIX</span></code> variable.</p>
</div>
<div class="section" id="set-up-the-environment">
<span id="gettingstartedenvironment"></span><h4>Set up the environment<a class="headerlink" href="#set-up-the-environment" title="Permalink to this headline">¶</a></h4>
<p>For the following tutorial steps, set up your environment as follows. In general, however,
only the change of the <code class="docutils literal"><span class="pre">PATH</span></code> environment variable is recommended. The other environment
variables are only needed for the tutorial sessions.</p>
<p>Using the C or TC shell (csh/tcsh):</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>setenv PATH <span class="s2">"</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span><span class="s2">/local/bin:</span><span class="si">${</span><span class="nv">PATH</span><span class="si">}</span><span class="s2">"</span>
setenv BASIS_EXAMPLE_DIR <span class="s2">"</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span><span class="s2">/local/share/basis/example"</span>
setenv HELLOBASIS_RSC_DIR <span class="s2">"</span><span class="si">${</span><span class="nv">BASIS_EXAMPLE_DIR</span><span class="si">}</span><span class="s2">/hellobasis"</span>
</pre></div>
</div>
<p>Using the Bourne Again SHell (bash):</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">export</span> <span class="nv">PATH</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span><span class="s2">/local/bin:</span><span class="si">${</span><span class="nv">PATH</span><span class="si">}</span><span class="s2"> "</span>
<span class="nb">export</span> <span class="nv">BASIS_EXAMPLE_DIR</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span><span class="s2">/local/share/basis/example"</span>
<span class="nb">export</span> <span class="nv">HELLOBASIS_RSC_DIR</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">BASIS_EXAMPLE_DIR</span><span class="si">}</span><span class="s2">/hellobasis"</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="create-an-example-project">
<h3>Create an Example Project<a class="headerlink" href="#create-an-example-project" title="Permalink to this headline">¶</a></h3>
<p>Create a new and empty project as follows:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>basisproject create --name HelloBasis --description <span class="s2">"This is a BASIS project."</span> <span class="se">\</span>
--root ~/local/src/hellobasis
</pre></div>
</div>
<p>The next command demonstrates that you can modify a previously created project by using the
project tool again, this time with the <cite>update</cite> command.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>basisproject update --root ~/local/src/hellobasis --noexample --config-settings
</pre></div>
</div>
<p>Here we removed the <code class="docutils literal"><span class="pre">example/</span></code> subdirectory and added some configuration file used by BASIS.
These options could also have been given to the initial command above instead.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">The guide on how to <a class="reference internal" href="howto/create-and-modify-project.html"><span class="doc">Create/Modify a Project</span></a>, <a class="reference internal" href="standard/template.html#basisproject"><span class="std std-ref">BasisProject.cmake</span></a>, and <a class="reference external" href="https://cmake-basis.github.io/apidoc/latest/group__CMakeAPI.html#gad82d479d14499d09c5aeda3af646b9f6">basis_project()</a>.</p>
</div>
</div>
<div class="section" id="install-your-project">
<h3>Install Your Project<a class="headerlink" href="#install-your-project" title="Permalink to this headline">¶</a></h3>
<p>The build and installation of the just created empty example project is identical to the build
and installation of BASIS itself:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>mkdir ~/local/src/hellobasis/build
<span class="nb">cd</span> ~/local/src/hellobasis/build
cmake -D <span class="nv">CMAKE_INSTALL_PREFIX</span><span class="o">=</span>~/local ..
make
</pre></div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">The guide on how to <a class="reference internal" href="howto/install.html"><span class="doc">Install any Software</span></a>.</p>
</div>
</div>
<div class="section" id="add-an-executable">
<h3>Add an Executable<a class="headerlink" href="#add-an-executable" title="Permalink to this headline">¶</a></h3>
<p>Copy the source file from the example to <code class="docutils literal"><span class="pre">src/</span></code>:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">cd</span> ~/local/src/hellobasis
cp <span class="si">${</span><span class="nv">HELLOBASIS_RSC_DIR</span><span class="si">}</span>/helloc++.cxx src/
</pre></div>
</div>
<p>Add the following line to <code class="docutils literal"><span class="pre">src/CMakeLists.txt</span></code> under the section “executable target(s)”:</p>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">basis_add_executable</span><span class="p">(</span><span class="s">helloc++.cxx</span><span class="p">)</span>
</pre></div>
</div>
<p>Alternatively, you can use the implementation of this example executable in
Python, Perl, BASH or MATLAB. In case of MATLAB, add also a dependency to MATLAB:</p>
<div class="highlight-cmake"><div class="highlight"><pre><span></span>basisproject update --root ~/local/src/hellobasis --use MATLAB
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The <code class="docutils literal"><span class="pre">basis_add_executable</span></code> command, if given only a single (existing)
source code file or directory as argument, uses the name of this source
file without extension or the name of the directory containing all
source files of the executable, respectively, as the build target name.</p>
</div>
<div class="section" id="change-target-properties">
<h4>Change target properties<a class="headerlink" href="#change-target-properties" title="Permalink to this headline">¶</a></h4>
<ul class="simple">
<li>The name of the output file is given by the <code class="docutils literal"><span class="pre">OUTPUT_NAME</span></code> property.</li>
<li>To change this property, add the following line to the <code class="docutils literal"><span class="pre">src/CMakeLists.txt</span></code> file
(<strong>after</strong> <code class="docutils literal"><span class="pre">basis_add_executable</span></code>):</li>
</ul>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">basis_set_target_properties</span><span class="p">(</span><span class="s">helloc++</span> <span class="s">PROPERTIES</span> <span class="s">OUTPUT_NAME</span> <span class="s2">"hellobasis"</span><span class="p">)</span>
</pre></div>
</div>
<p>If you used another source file, you need to replace “helloc++” by its name (excl. the extension).</p>
</div>
<div class="section" id="test-the-executable">
<h4>Test the Executable<a class="headerlink" href="#test-the-executable" title="Permalink to this headline">¶</a></h4>
<p>Now build the executable from the previously added source code. As the build system
has been configured before using CMake, only GNU <code class="docutils literal"><span class="pre">make</span></code> has to be invoked.
It will recognize the change of the <code class="docutils literal"><span class="pre">CMakeLists.txt</span></code> file and therefore reconfigure
the build system before re-building the software.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">cd</span> ~/local/src/hellobasis/build
make
bin/hellobasis
How is it going?
</pre></div>
</div>
<p>Install the executable and test it:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>make install
hellobasis
How is it going?
</pre></div>
</div>
<p>Note that the <code class="docutils literal"><span class="pre">hellobasis</span></code> executable was installed into the <code class="docutils literal"><span class="pre">~/local/bin/</span></code> directory
as we set the installation root directory to <code class="docutils literal"><span class="pre">~/local</span></code> using the <code class="docutils literal"><span class="pre">CMAKE_INSTALL_PREFIX</span></code>
CMake variable. This directory should be listed in your <em>PATH</em> environment variable
when you followed the <a class="reference internal" href="#gettingstartedenvironment"><span class="std std-ref">environment set up</span></a> steps at the
begin of this tutorial.</p>
</div>
</div>
<div class="section" id="add-libraries">
<h3>Add Libraries<a class="headerlink" href="#add-libraries" title="Permalink to this headline">¶</a></h3>
<p>Next, you will add three kinds of libraries, i.e., collections of binary or script code, to your example project.
We distinguish here between private, public, and script libraries. A private library is a library without
public interface which is only used by other libraries and in particular executables of the project itself.
A public library provides a public interface for users of your software. Therefore, the declarations of
the interface given by <code class="docutils literal"><span class="pre">.h</span></code> files in case of C/C++ are copied to the installation directory along with
the binary library file upon installation. Another kind of library is one written in a scripting
language such as Python, Perl, or BASH. Such library is more commonly referred to as <em>module</em>.</p>
<div class="section" id="add-a-private-library">
<h4>Add a private library<a class="headerlink" href="#add-a-private-library" title="Permalink to this headline">¶</a></h4>
<p>Copy the files from the example to <code class="docutils literal"><span class="pre">src/</span></code>:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">cd</span> ~/local/src/hellobasis
cp <span class="si">${</span><span class="nv">HELLOBASIS_RSC_DIR</span><span class="si">}</span>/foo.* src/
</pre></div>
</div>
<p>Add the following line to <code class="docutils literal"><span class="pre">src/CMakeLists.txt</span></code> under the section “library target(s)”:</p>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">basis_add_library</span><span class="p">(</span><span class="s">foo</span> <span class="s">foo.cxx</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="add-a-public-library">
<h4>Add a public library<a class="headerlink" href="#add-a-public-library" title="Permalink to this headline">¶</a></h4>
<p>Create the subdirectory tree for the public header files declaring the public interface:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">cd</span> ~/local/src/hellobasis
basisproject update --root . --include
mkdir include/hellobasis
</pre></div>
</div>
<p>Copy the files from the example. The public interface is given by <code class="docutils literal"><span class="pre">bar.h</span></code>.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>cp <span class="si">${</span><span class="nv">HELLOBASIS_RSC_DIR</span><span class="si">}</span>/bar.cxx src/
cp <span class="si">${</span><span class="nv">HELLOBASIS_RSC_DIR</span><span class="si">}</span>/bar.h include/hellobasis/
</pre></div>
</div>
<p>Add the following line to <code class="docutils literal"><span class="pre">src/CMakeLists.txt</span></code> under the section “library target(s)”:</p>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">basis_add_library</span><span class="p">(</span><span class="s">bar</span> <span class="s">bar.cxx</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="add-a-scripted-module">
<h4>Add a scripted module<a class="headerlink" href="#add-a-scripted-module" title="Permalink to this headline">¶</a></h4>
<p>Copy the example Perl module to <code class="docutils literal"><span class="pre">src/</span></code>:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">cd</span> ~/local/src/hellobasis
cp <span class="si">${</span><span class="nv">HELLOBASIS_RSC_DIR</span><span class="si">}</span>/FooBar.pm.in src/
</pre></div>
</div>
<p>Add the following line to <code class="docutils literal"><span class="pre">src/CMakeLists.txt</span></code> under the section “library target(s)”:</p>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">basis_add_library</span><span class="p">(</span><span class="s">FooBar.pm</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Unlike C++ libraries, which are commonly build from multiple source files,
libraries written in a scripting language are separate script module files.
Therefore, <code class="docutils literal"><span class="pre">basis_add_library</span></code> can be called with only a single argument,
the name of the library source file. The name of this source file will be used
as build target name including the file name extension, with <code class="docutils literal"><span class="pre">.</span></code> replaced by <code class="docutils literal"><span class="pre">_</span></code>.
This is to avoid name conflicts between library modules written in different
languages which have the same name such as, for example, the BASIS Utilities
for Python (<code class="docutils literal"><span class="pre">basis.py</span></code>), Perl (<code class="docutils literal"><span class="pre">basis.pm</span></code>), and Bash (<code class="docutils literal"><span class="pre">basis.sh</span></code>).</p>
</div>
</div>
<div class="section" id="the-in-suffix">
<h4>The .in suffix<a class="headerlink" href="#the-in-suffix" title="Permalink to this headline">¶</a></h4>
<ul class="simple">
<li>Note that some of these files have a <code class="docutils literal"><span class="pre">.in</span></code> file name suffix.</li>
<li>This suffix can be omitted in the <code class="docutils literal"><span class="pre">basis_add_library</span></code> statement. It has however an impact on how this function treats this file.</li>
<li>The .in suffix indicates that the file is not usable as is, but contains patterns such as <code class="docutils literal"><span class="pre">@PROJECT_NAME@</span></code> which BASIS should replace during the build of the module.</li>
<li>The substitution of these <code class="docutils literal"><span class="pre">@*@</span></code> patterns is what we refer to as “building” script files.</li>
</ul>
</div>
<div class="section" id="install-the-libraries">
<h4>Install the libraries<a class="headerlink" href="#install-the-libraries" title="Permalink to this headline">¶</a></h4>
<p>Now build the libraries and install them:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">cd</span> ~/local/src/hellobasis/build
make <span class="o">&&</span> make install
</pre></div>
</div>
</div>
</div>
<div class="section" id="create-a-modularized-repository">
<h3>Create a Modularized Repository<a class="headerlink" href="#create-a-modularized-repository" title="Permalink to this headline">¶</a></h3>
<p>BASIS is designed to integrate multiple BASIS libraries as
part of a modular build system where components can be added
and removed with ease. A top-level repository contains one or
more modules or sub-projects, then builds those modules based
on their dependencies.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">See <a class="reference internal" href="howto/create-and-modify-project.html#howtomodularizeaproject"><span class="std std-ref">Modularize a Project</span></a> for usage instructions,
<a class="reference internal" href="standard/template.html"><span class="doc">Project Template</span></a> for a reference implementation,
and <a class="reference internal" href="standard/modules.html"><span class="doc">Project Modularization</span></a> for the design.</p>
</div>
<div class="section" id="create-a-top-level-project">
<h4>Create a Top Level Project<a class="headerlink" href="#create-a-top-level-project" title="Permalink to this headline">¶</a></h4>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">export</span> <span class="nv">TOPLEVEL_DIR</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span><span class="s2">/local/src/collection"</span>
basisproject create --name Collection --description <span class="s2">"This is a BASIS TopLevel project. It demonstrates a modular project organization."</span> --root <span class="si">${</span><span class="nv">TOPLEVEL_DIR</span><span class="si">}</span> --toplevel
</pre></div>
</div>
</div>
<div class="section" id="create-a-sub-project-containing-a-library">
<h4>Create a Sub-project Containing a Library<a class="headerlink" href="#create-a-sub-project-containing-a-library" title="Permalink to this headline">¶</a></h4>
<p>Create a sub-project module similarly to how helloBasis was created earlier.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">export</span> <span class="nv">MODA_DIR</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span><span class="s2">/local/src/collection/modules/moda"</span>
basisproject create --name moda --description <span class="s2">"Subproject library to be used elsewhere"</span> --root <span class="si">${</span><span class="nv">MODA_DIR</span><span class="si">}</span> --module --include
cp <span class="si">${</span><span class="nv">HELLOBASIS_RSC_DIR</span><span class="si">}</span>/moda.cxx <span class="si">${</span><span class="nv">MODA_DIR</span><span class="si">}</span>/src/
mkdir <span class="si">${</span><span class="nv">MODA_DIR</span><span class="si">}</span>/include/moda
cp <span class="si">${</span><span class="nv">HELLOBASIS_RSC_DIR</span><span class="si">}</span>/moda.h <span class="si">${</span><span class="nv">MODA_DIR</span><span class="si">}</span>/include/moda/
</pre></div>
</div>
<p>Add the following line to <code class="docutils literal"><span class="pre">${MODA_DIR}/src/CMakeLists.txt</span></code> under the section “library target(s)”:</p>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">basis_add_library</span><span class="p">(</span><span class="s">moda</span> <span class="s">SHARED</span> <span class="s">moda.cxx</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="create-a-sub-project-that-uses-the-library">
<h4>Create a Sub-project that uses the Library<a class="headerlink" href="#create-a-sub-project-that-uses-the-library" title="Permalink to this headline">¶</a></h4>
<p>Create a sub-project module similarly to how helloBasis was created earlier.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">export</span> <span class="nv">MODB_DIR</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">TOPLEVEL_DIR</span><span class="si">}</span><span class="s2">/modules/modb"</span>
basisproject create --name modb --description <span class="s2">"User example subproject executable utility repository that uses the library"</span> --root <span class="si">${</span><span class="nv">MODB_DIR</span><span class="si">}</span> --module --src --use moda
cp <span class="si">${</span><span class="nv">HELLOBASIS_RSC_DIR</span><span class="si">}</span>/userprog.cxx <span class="si">${</span><span class="nv">MODB_DIR</span><span class="si">}</span>/src/
</pre></div>
</div>
<p>Add the following line to <code class="docutils literal"><span class="pre">${MODB_DIR}/src/CMakeLists.txt</span></code> under the section “executable target(s)”:</p>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">basis_add_executable</span><span class="p">(</span><span class="s">userprog.cxx</span><span class="p">)</span>
<span class="nb">basis_target_link_libraries</span><span class="p">(</span><span class="s">userprog</span> <span class="s">moda</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="install-the-projects">
<h4>Install the Projects<a class="headerlink" href="#install-the-projects" title="Permalink to this headline">¶</a></h4>
<div class="highlight-bash"><div class="highlight"><pre><span></span>mkdir <span class="si">${</span><span class="nv">TOPLEVEL_DIR</span><span class="si">}</span>/build
<span class="nb">cd</span> <span class="si">${</span><span class="nv">TOPLEVEL_DIR</span><span class="si">}</span>/build
cmake -D <span class="nv">CMAKE_INSTALL_PREFIX</span><span class="o">=</span>~/local -D <span class="nv">MODULE_moda</span><span class="o">=</span>ON -D <span class="nv">MODULE_modb</span><span class="o">=</span>ON ..
make install
</pre></div>
</div>
</div>
</div>
<div class="section" id="next-steps">
<h3>Next Steps<a class="headerlink" href="#next-steps" title="Permalink to this headline">¶</a></h3>
<p>Congratulations! You just finished your first BASIS tutorial.</p>
<p>So far you have already learned how to install BASIS on your system and set up
your own software project. You have also seen how you can add your own source
files to your newly created project and build the respective executables
and libraries. The essentials of any software package! Thanks to BASIS, only
few lines of CMake code are needed to accomplish this.</p>
<p>Now check out the various <a class="reference internal" href="howto.html"><span class="doc">How-to Guides</span></a> which will introduce
you to even more BASIS concepts and best practices.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="index.html">
<img class="logo" src="_static/logo_title.svg" alt="Logo"/>
</a></p>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
<h3><a href="contents.html">Table Of Contents</a></h3>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="index.html">Overview</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Quick Start</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#first-steps">First Steps</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#install-basis">Install BASIS</a></li>
<li class="toctree-l3"><a class="reference internal" href="#create-an-example-project">Create an Example Project</a></li>
<li class="toctree-l3"><a class="reference internal" href="#install-your-project">Install Your Project</a></li>
<li class="toctree-l3"><a class="reference internal" href="#add-an-executable">Add an Executable</a></li>
<li class="toctree-l3"><a class="reference internal" href="#add-libraries">Add Libraries</a></li>
<li class="toctree-l3"><a class="reference internal" href="#create-a-modularized-repository">Create a Modularized Repository</a></li>
<li class="toctree-l3"><a class="reference internal" href="#next-steps">Next Steps</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="howto.html">How-to Guides</a></li>
<li class="toctree-l1"><a class="reference internal" href="standard.html">Standards</a></li>
<li class="toctree-l1"><a class="reference internal" href="guideline.html">Guidelines</a></li>
<li class="toctree-l1"><a class="reference internal" href="reference.html">Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="apidoc.html">API</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="changelog.html">News</a></li>
<li class="toctree-l1"><a class="reference internal" href="download.html">Download</a></li>
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="help.html">Support</a></li>
<li class="toctree-l1"><a class="reference internal" href="about.html">About</a></li>
</ul>
<h3>External Links</h3>
<ul>
<li><a href="https://github.com/cmake-basis/BASIS">Repository</a></ li>
<li><a href="https://github.com/cmake-basis/BASIS/issues">Issues</a></ li>
</ul>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
© Copyright 2011-12 University of Pennsylvania, 2013-14 Carnegie Mellon University, 2013-16 Andreas Schuh.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.1.
</div>
</body>
</html>