Version 1 (modified by bakaniko, 14 months ago) (diff)



Here put examples on how to build the docs

Logs of documentation writing:

  • Building the docs:

  • Fixing issues:

  • and locales (1/2):

  • locales (2/2)
  • next time
  • sphinx commands / transifex

Required softwares

  • CMake (>= 2.8)
  • git
  • perl:

1 hour tutorial:

  • sphinx (>=1.1)

Installing dependencies

On <code>ubuntu 16.04</code>

<source lang="bash">sudo apt install cmake git

sudo pip install sphinx</source>

Preparing the repository

cloning the repository


Build commands

Simplest build

This build will only make the English version and will be faster so you can quickly visualize your changes.

<source lang="bash">## making the build folder (where builds will be put) mkdir build

## Getting into the build directory cd build

# Preparing the build cmake -DHTML=ON .. # don't forget the .. at the end !!

# Build html files make html </source> And you're done ! You can go to <code>build/doc/_build/</code> and open <code>index.html</code> in a web browser.

Main workflow

  • make the build directory <code>mkdir build</code>
  • get into build/: <code>cd build/</code>

Prepare the build with CMake

With <code>cmake -D&lt;build option&gt;=ON ..</code> with the option in uppercase:

<code>cmake -DSINGLEHTML=ON ..</code>

Available options

Available options can be see with the command:

<code>cmake -L ..</code>

Building options

There is several option available to the build:

  • HTML (plain HTML)
  • DIRHTML (HTML pages with internal links not working)
  • SINGLEHTML (All the docs in a single html page)
  • JSON
  • LATEX (LaTeX format, used to generate pdfs)
Languages options

As for now the supported languages are:

  • &quot;ca&quot;
  • &quot;de&quot;
  • &quot;es&quot;
  • &quot;fr&quot;
  • &quot;it&quot;
  • &quot;ja&quot;
  • &quot;ko&quot;
  • &quot;pl&quot;
  • &quot;ru&quot;
  • &quot;hu&quot;, &quot;el&quot;, &quot;id&quot; and &quot;zh&quot; are not available yet (bug fixe in progress)

By default, english will be always made. You can add languages easily with the flag <code>-D&lt;Language code&gt;=ON</code>

For example, to get spanish:

<code>cmake -DHTML=ON -DES=ON</code>

To use a specific language, use the cmake flag <code>-D&lt;language code in uppercase&gt;=ON -D&lt;another language code in uppercase&gt;=ON</code>

You can pass no language flag (building only english) or as many flag as there is supported languages (and built all of them).

To build all languages you can use the flag <code>-DALL_LANG=ON</code>

The option (<code>-DES=ON ...</code> or <code>-DALL_LANG=ON</code>) are kept in the <code>OSGeoLiveDoc_BUILD_LANGUAGES</code> variable, which is automatically filled by CMake.

make the build

<code>make &lt;option&gt;</code> with option in lowercase:

<code>make singlehtml</code>

about Sphinx

Sphinx generates the po files used by transifex.

Sphinx needs locales, english is set by default. Other locales are generated from the languages in <code>OSGeoLiveDoc_SUPPORTED_LANGUAGES</code> variable in <code>CMakeLists.txt</code>. For more details, see above.

Projects management

Projects are loaded from the <code>projects_info.csv</code> file. It is the main entry point.

<blockquote>Note: Actually, it is manually build from this file: </blockquote> To add a project or update project version, modify the projects_csv file:<PATH TO FILE>/projects_info.csv

Please indicate if there is a quickstart or not, an overview or not, an openHub account or not, the version, if it is an OSGeo project, or community or none of those.

Overviews will be generated with the data from <code>projects_info.csv</code>, and links to quickstarts will be added automaticly.

More information how CMake use this file are available above.


There is 2 versions: regular and verbose.

The first one can be called with this flag: <code>-DOSGeoLiveDoc_DEBUG=ON</code>

For example: <code>cmake -DHTML=ON -DES=ON -DOSGeoLiveDoc_DEBUG=ON ..</code>

The verbose debug is called with this flag: <code>-DOSGeoLiveDoc_VERBOSE_DEBUG=ON</code>

For example: <code>cmake -DHTML=ON -DES=ON -DOSGeoLiveDoc_VERBOSE_DEBUG=ON ..</code>

Configuring CMake / Setting the build

CMake is use to build the repository instead of simply make because it can be finely tuned. CMake configuration is done by the <code>CMakeLists.txt</code>. CMake says how the build is made from that file.

This file allows to set a few things:

Checking CMake version

<code>cmake_minimum_required(VERSION 2.8 FATAL_ERROR)</code>

Checking build folder

The first thing that CMake does is to check if you are in the folder called <code>build</code>. If it is not the case, CMake will return an error.

<pre class="{bash}">if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} ) message(FATAL_ERROR &quot;In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt.&quot; ) endif()</pre>

Changing the version number

In <code>CMakeLists.txt</code>, you can change the OSGeo-Live version number with the following variables:

<pre class="{bash}">## Major version set(OSGeoLiveDoc_VERSION_MAJOR &quot;12&quot;)

## minor version set(OSGeoLiveDoc_VERSION_MINOR &quot;0&quot;)

## Patch number set(OSGeoLiveDoc_VERSION_PATCH &quot;0&quot;)

## if it is a development version, a Release Candidate or a final release set(OSGeoLiveDoc_VERSION_DEV &quot;-dev&quot;)</pre>

Checking the sphinx version

To build, you sphinx 1.1 and above:

<code>set(SPHINX_MINIMUM_VERSION &quot;1.1&quot;)</code>

If not a warning will be displayed. If you need a more recent version to build the doc, you can test it from here.

Checking Perl

Perl is needed at some point, so

Adding / removing a language

Add the 2 letters code of the new language:

<source lang="bash">set(OSGeoLiveDoc_SUPPORTED_LANGUAGES "ca" "de" "es" "fr" "it" "ja" "ko" "pl" "ru")</source> Then add a new <code>INSERT_INTO_MAP</code> command to add the language to the lang navigation bar (in <code>index.html</code>). For example:

<code>INSERT_INTO_MAP(&quot;fr&quot; &quot;Français&quot;)</code> in the <code>CMakeLists.txt</code>.

The line <code>set(OSGeoLiveDoc_ENGLISH &quot;en&quot;)</code> is not supposed to change, it sets the default build in english.

Projects management

Projects are loaded from the <code>projects_info.csv</code> file. It is the main entry point.

<blockquote>Note: Actually, it is manually build from this file: </blockquote> To add a project or update project version, modify the projects_csv file:<PATH TO FILE>/projects_info.csv

Please indicate there is a quickstart or not, an overview or not, an openHub account or not, the version, if it is an OSGeo project, or community or none of those.

Overviews will be generated with the data from <code>projects_info.csv</code>, and links to quickstarts will be added automaticly.

reading the file

<code>file(STRINGS projects_info.csv OSGeoLiveDoc_PROJECTS_VERSIONS_FILE)</code> opens the csv file

<code>set (OSGeoLiveDoc_PROJECTS_VERSIONS &quot;&quot;)</code> is prepared to stock data from the file

Data are extracted with a regular expression, which detect the column, but has to know the number of columns. Currently the file has 9 columns.

The file is processed line by line.

Slicing the lines with a regex

<code>set (OSGeoLiveDoc_CONFIGURATION_REGEXP &quot;(.*)

So <code>(.*)
|</code> has to be repeated 9 times. If a column is added in projects_info.csv, it is mandatory to add one more <code>(.*)
|</code> in the regex to find the new column.

Each column will extracted by group, for example, column 3 will be extracted as group &quot;\3&quot;; because it's a csv, it's kind of a 1 to 1 relationship between the group and the column.

Quick explanation of the regex:

&lt;--- beginning of line (.) &lt;---- any character = &quot;.&quot; any number of times = &quot;&quot; grouped &quot;(&quot; &quot;)&quot; \| &lt;--- code for vertical line &quot;|&quot;

The for each line in the file, the ones starting with # are treated as comments. Comments will be ignored and the whole line replaced by a <code>#</code>.

This part only use the 5 first column.

Group use

For example, group &quot;\3&quot;, will get the project version, and will be cleaned with <code>STRIP</code>:

<code>string(STRIP ${project_version} project_version)</code> will strip the blanks spaces at the beginning and the end of the string. So &quot; 4.2.1 &quot; will return &quot;4.2.1&quot; and &quot;4.2.2 beta &quot; -&gt; &quot;4.2.2 beta&quot;.


This treatment can be seen with the <code>-DOSGeoLiveDoc_VERBOSE_DEBUG=ON</code> flag. It will show something like that:

-- Y 52nSOS 4.4.0 want_quickstart:Y want_overview:Y -- Y 52nWPS 3.6.1 want_quickstart:Y want_overview:Y -- N 52nWSS retired want_quickstart:N want_overview:N -- 52nWSS is not for documentation -- N atlasstyler retired want_quickstart:N want_overview:N -- atlasstyler is not for documentation -- N cartaro retired want_quickstart:N want_overview:N -- cartaro is not for documentation

Active projects will get want_quickstart and want_overview set to Y; the retired projects will be set to N and won't be used for documentation.

This process is always done, but won't be print unless the <code>-DOSGeoLiveDoc_VERBOSE_DEBUG=ON</code> flag is used.

Project version in

For each line (so active and retired projects), a new python command will be generated for inserting in

<code>.. |version-${project_name}| replace:: ${project_version}\n&quot;</code>

For example, for the 4.4.0 release of the 52nSOS project, the string will be <code>.. |version-52nSOS| replace:: 4.4.0</code>.

Selecting project who needs on overview and a quickstart building

This code add the project name to lists for quickstart and overviews, if a Y is the columns/ groups 4 and 5. Some projects might have an overview but no quickstart, it is mostly libraries.

if (&quot;<math>{want_quickstart}" MATCHES "Y") list(APPEND OSGeoLiveDoc_QUICKSTART "</math>{project_name}&quot;) endif() if (&quot;<math>{want_overview}" MATCHES "Y") list(APPEND OSGeoLiveDoc_OVERVIEW "</math>{project_name}&quot;) endif()


Standards are builded with this set of commandes:

set(OSGeoLiveDoc_STANDARDS &quot;csw&quot; &quot;gml&quot; &quot;sld&quot; &quot;wcs&quot; &quot;wms&quot; &quot;fe&quot; &quot;kml&quot; &quot;sensorml&quot; &quot;sos&quot; &quot;wfs&quot; &quot;wps&quot; ) # Other settings There is several files that is need for the build, they are copied with the command <code>configure_file()</code>

  • licences.csv
  • contributors.csv
  • translators.csv

For example, <code>configure_file(&quot;; &quot;;)</code> will copy and substitute the variables defined in the cmake. Which is very handy.

The csv files are copied but are not modified. They'll be loaded later in the html file with an another process.

Setting building variables

The line <code>add_subdirectory(doc)</code> will add the doc folder to the build and all the files in it will be set with the variables from cmake, by copying the CMakeLists.txt file in each folder and subfolder. Each copy

Comments in CMake

There is no comments in CMake, but there is a way to have code that won't be executed.

if(FALSE) <none executed code> endif()

Included files and folder

CMake will use the files and folders in the main folder (aka <code>OSGeoLive-doc</code>) but only the ones present in the variables <code>OSGeoLiveDoc_FILES</code> and <code>OSGeoLiveDoc_FOLDERS</code>.

In CMakeLists.txt they are set like that:

<pre class="{bash}">#--------------------- # Files #--------------------- set(OSGeoLiveDoc_FILES #&quot;disclaimer.rst&quot; &quot;translators.rst&quot; &quot;osgeo_contact.rst&quot; &quot;contributors.rst&quot; &quot;index.rst&quot; &quot;contact.rst&quot; #&quot;metrics.rst&quot; &quot;sponsors.rst&quot; &quot;welcome_message.txt&quot; &quot;copyright.rst&quot; &quot;download.rst&quot; &quot;mac_installers.rst&quot; &quot;presentation.rst&quot; &quot;sponsors_osgeo.rst&quot; &quot;prior_applications.rst&quot; &quot;win_installers.rst&quot; )

#--------------------- # Directories #--------------------- set(OSGeoLiveDoc_SUBDIRS &quot;WindowsInstallers?&quot; &quot;MacInstallers?&quot; &quot;presentation&quot; &quot;quickstart&quot; &quot;overview&quot; &quot;standards&quot; )</pre> So commented out or deleted lines won't be taken in account, and won't be translated. If you comment &quot;overview&quot;, the overviews won't be built.

Directory processing

This process is managed by the command <code>add_subdirectory()</code> which tell CMake to look for a CMakeLists.txt in the subdirectory and execute it.

For example, the last line of the main CMakeLists.txt is <code>add_subdirectory(doc)</code> so CMake will look into doc/ and execute the CMakeLists.txt in it. Several variables will be initialized like <code>${OSGeoLiveDoc_SUBDIRS}</code> which contains the folders to look into.

Then the following loop will be looking in each named subfolder to execute its CMakeLists.txt

<code>{bash} foreach (dir ${OSGeoLiveDoc_SUBDIRS}) message(STATUS &quot; Adding directory ${dir}&quot;) add_subdirectory(${dir}) endforeach()</code>

For example, the proccessed files for the Overview folder are extract from <code>${OSGeoLiveDoc_OVERVIEW})</code> built in the previous process (from <code>projects_info.csv</code>). Files not listed in <code>${OSGeoLiveDoc_OVERVIEW})</code> won't be processed.

Local list

Some CMakeLists.txt have a local list, for example in quickstart, there is local list for non project quickstart. It is quickstarts non included in the projects_info.csv.

If a new project add its .rst file in the quickstart folder but forget to update projects_info.csv; the quickstart won't show.

For a non project quickstart like virtualization_quickstart, which explain how to use OSGeo-Live in a virtual machine, it has to be set in the LOCAL variable of the quickstarts CMakeLists.txt.

Quickstart and Overview folder

The CMakeLists.txt here to copy all projects listed in <code>projetc_info.csv</code> and transmitted with the variables <code>${OSGeoLiveDoc_QUICKSTART}</code> and <code>${OSGeoLiveDoc_OVERVIEW}</code>.

Local CMakeLists.txt will be initialized with those variables.

Overview folder

in Overview, there is no local files. The Overview webpage (listing all projects) is generated with perl from data extracted of <code>projects_info.csv</code>.


Standards were not part of the documentation any more, they have been removed. The process is still there, in case they come back into the documentation.

Main files

Main files, present at the root of the project and website, are processed if listed in the variable <code>OSGeoLiveDoc_FILES</code> at the beginning of the CMakeLists.txt. They can be added and commented out easily.


The images folder is entirely copied to <code>build/doc/images</code>. All images are copied, even the one that are not used by the documentation any more. That need to be cleaned.


Some files are build with perl scripts like <code>overview.html</code> or <code>metrics</code>. Those scripts will be detailed below.


overview.html is the overview of all projects, and is generated from data in <code>projects_info.csv</code>. So retired project wouldn't appear in it.

The script is there:

First three lines are testing the shell and args.

There is includes (<code>pragmas</code>) from perl library used by the script in line 6 to 8.

Then three specials variables are declared: - name (filename) - dir (get the directory of the perl script) - *prune (get the path to the perl script)

They are shortcuts for functions (<code>*File::Find::name</code> is a function returning the filename).

Those varaibles are loaded with informations from the CMake: * <code>$DEBUG = &quot;@OSGeoLiveDoc_DEBUG@&quot;;</code> * <code>$version = &quot;@OSGeoLiveDoc_VERSION@&quot;;</code> * <code>$projects_info_file = '@CMAKE_SOURCE_DIR@/projects_info.csv';</code> * <code>$output_file = '@CMAKE_BINARY_DIR@/doc/overview/overview.rst';</code>

See if the <code>projects_info.csv</code> file exist, if don't the script stop and throws an error:

<code>die &quot;ERROR: Failed to find: '$projects_info_file'\n&quot; unless -f $projects_info_file;</code>

Get the configuration from projects_info.csv

This line parse the projects_info file and stores it in <code>$configuration</code>. If the flag <code>-DOSGeoLiveDoc_DEBUG=ON</code> is used, then a comment line will be print.

<source lang="perl">my $configuration = read_and_parse_configuration($projects_info_file);</source>

read_and_parse_configuration subroutine

This subroutine takes a file in parameter. It is stored in $file with the keyword <code>shift</code>.

Then an empty Hash called %hash is initialized. It will store hashes extracted during the process.

The script will try to open the file in parameter or die and throws an error.

Then a while loop reads the file line by line and exit when the file is empty (operation becomes <code>TRUE</code>). During the while loop several actions are made: - ignores the commented lines; - clean the line by removing spaces surplus; - ignores project who are not subject to documentation (no overview and / or no quickstart) - get lines in the right bucket (section) <code>$hash{$values[5]}</code>

For example, with the following line:

<code>Y | 52nSOS | 4.4.0 | Y | Y | Web Services | | Sensor Observation Service | SensorObservationService?</code>

The instructions will put the line in the bucket that has the name Web Services.

At the end of the loop, the file is closed and the hash with the collected data is returned.

In the script, the hash will be store in <code>$configuration</code>.

Building sections

Sections are stored in <code>$sections</code>.

For each defined sections, there will be a call for the section in <code>$configuration</code>. It use the subroutine <code>get_section</code>.

The result will be append to <code>$sections</code>.


This subroutine take two parameters: * the name of the section * the variable where the configuration is stored

<blockquote>Note: There is a lot of concatenation in this subroutine. It is short written with <code>.=</code> </blockquote> get_sections() workflow: - prepare the section headers and toc tree - split values around the <code>|</code>and store it in an array (@values) - cleans the excess <code>|</code> and spaces in in each value - Test it overview is set to <code>Y</code> then handle the overview by adding it to the toctree and adding the bullet line - Test it quickstart is set to <code>Y</code> then handle the quickstart by adding it to the toctree and adding the bullet line between brackets - Write the comment / short description if provided.

When all projects have been read, the toctree is added to the contents, then the bullets. The contents is returned.

Writing the file

When all the sections are build and added to <code>$sections</code>, the subroutine <code>write_script()</code> is called.

It takes one parameter, <code>$sections</code> with all the sections, in the right order.

# it tries to create the output file (or die if cannot) # write out the header and the commands to clean up the old extension # paste the content of <code>$sections</code> after the toc (<code>.. contents:\n :local:</code>) and before prior applications # close the file

Script exit

When the script is done, it exit returning <code>0</code>. It is a mandatory for perl.


The variables are loaded by CMake during the build from data in <code>CMakeLists.txt</code>.

<source lang="perl">my $DEBUG = "@OSGeoLiveDoc_DEBUG@"; my $version = "@OSGeoLiveDoc_VERSION@"; my $projects_info_file = '@CMAKE_SOURCE_DIR@/projects_info.csv'; my $output_file = '@CMAKE_CURRENT_BINARY_DIR@/../metrics.rst';</source>

Useful commands

Rename or move files and rename all occurences

Moving the files to the right folder

<source lang="bash">git mv doc/images/projects/gvsigFOOOOOOOOOOOO doc/images/projects/gvsig

# see the change git status</source>

Changing all occurrences

To do that, we will use a one liner perl command to change from projects/gvsigFOOOOOOOOOOOO to projects/gvsig

the <code>/</code> is special in perl so, <code>\</code> is prepended in the command from projects/gvsigFOOOOOOOOOOOO to projects/gvsig

THE command:

<source lang="bash">perl -pi -e "s/projects\/gvsigFOOOOOOOOOOOO/projects\/gvsig/" $(git ls-files)</source>

  • <code>git ls-files</code> : lists the files that git knows about
  • <code>perl</code> &lt;--- use that
  • <code>-pi</code> &lt;--- one liner
  • <code>-e</code> &lt;-- do changes on the file and save them on the file
  • &quot;s/projects/gvsigFOOOOOOOOOOOO/projects/gvsig/&quot; &lt;&lt;&lt; s/<from>/<to>/ substitute from to
  • <code>$(git ls-files)</code> &lt;---- $(<command>)
  • <code>git ls-files</code> &lt;--- generates filenames know to git

Check and remove unused images

When updating the docs, it can happen that some images are not removed. So the script check all the projects (current and retired).

Sphinx need a file with several data. With this project, it is built from where @var@ are modified with data from CMakeLists.txt.

The original should be remove at the end of the project. This is done a the L. 76 of CMakeLists.txt


Themes are stock in the <code>_theme</code> subdirectory, they are loaded by the line L. 79 of CMakeLists.txt

There is a small local CMakeLists.txt for each theme. It is used to configure the language bar with the asked languages.


Locales are stocked in the (locales folder]( This folder is updated by 2 distinct processes:

  • first time, by sphinx, when building the strings to be translated (before pushing it to Transifex)
  • second time, when the translated strings are retrieved from Transifex

Waiting for issue #44 to be fixed.

Sphinx commands

The lines l.115 to l.156 are sphinx commands. Those commands are used to communicate with the Transifex plateform.