While you can create or use any custom template you like, it is highly recommended that templates follow the BASIS Standards. In addition to the other standards, for BASIS compliance templates must meet the requirements outlined below.
See also
The Using and Customizing Templates How-to explains how to make use of templates.
Benefits
Anyone familar with the standard will be able to quickly navigate the source tree and easily integrate your project into their own because the setup is designed for consistency and interoperability. The idea is to make projects easier for developers to create, share, and use.
BASIS Standardized Templates provide and automate the following steps:
CMakeLists.txt
file setup.Standard project files utilize the following formats:
.txt |
A utf8 plain text file. |
.md |
Markdown |
.rst |
reStructuredText |
CMakeLists.txt |
CMake listfile format. |
.cmake |
CMake listfile format. |
The following files have to be part of any project which follows the Filesystem Layout.
This is the minimal set of project files provided
when instantiating a new software project. Besides these files, a project
will have either a src/
directory or a modules/
directory,
or even both of them. See below for a description of these directories.
Sets basic information about a BASIS Project and calls the basis_project() command.
Note that additional dependencies may optionally be specified using by the CMake code in the config/Depends.cmake file. If the project is a module of another project, this file is read by the top-level project to be able to identify its modules and the dependencies among them.
BasisProject.cmake explains using this file to configure your project.
This is the main CMake script file used to configure the build system, and BASIS. Put CMake code required to configure the build system in this file.
configure_file()
callsset(PROJECT_SUBDIRS random)
will cause BASIS to call basis_add_subdirectory() on <source>/random
at
the appropriate time during the execution of BASIS.This directory contains independent project modules. If the project files are organized into conceptual cohesive groups, similar to the modularization goal of the ITK 4, this directory contains these conceptual modules of the project. The files of each module reside in a subdirectory named after the module. Note that each module itself is a project derived from this project template.
CMake configuration file for performing super-build of external library
components and requirements by utilizing the CMake ExternalProject_Add()
call.
In the latter case, these source packages should be placed in the build/
directory next to this CMake configuration file.
INSTALL_DATA_DIR
directory of the installation tree.INSTALL_EXAMPLE_DIR
directory of the installation tree. It may be modified to configure
and/or build example programs if applicable or required.src/CMakeLists.txt
file using relative paths.src/
directory.CMakeLists.txt
files can be used for each subdirectory.test/input/
, while the baseline
data of the expected test output is stored inside a subdirectory
named test/baseline/
. Generally, however, the Filesystem Layout of
BASIS does not dictate how the test sources, input, and baseline
data have to be organized inside the test/
directory.Tests for internal use only that require data specific to your work organization. These files are expected to be excluded from the public source distribution package are configured using this CMake configuration file.
The customization of the following files is usually not required, and hence, in most cases, most of these files need not to be part of a project.
config/
directory,
is sufficient and thus this file is often not required.An optional convenience file for CMake code which uses the variables set by the standard CMake packageConfig.cmake file. BASIS generates a standard packageConfig.cmake file from config/Config.cmake.in, which is used by other packages to set all the CMake variables they need to utilize your package.
- template_name/
- 1.0/
+ _config.py
+ src/
+ config/
+ data/
+ doc/
+ example/
+ modules/
+ test/
- 1.1/
- 2.0/
- 2.1/
- .../
Note
Only the files which were modified or added have to be present in the new template.
The basisproject
tool will look in older template directories for any missing files.
The template system is designed to help automate updates of existing libraries to new template versions.
Whenever a template file is modified or removed, the previous project template has to be copied to a
new directory with an updated template version! Otherwise, the three-way diff merge used by the
basisproject
tool to update existing projects to this newer template will fail.
The template configuration file named _config.py
and located in the top directory of each project
template defines not only which files constitute a project, but also the available substitution parameters
and defaults used by basisproject
. The template configuration file requires a basic understanding
of Python syntax, but is fairly easy to understand even without much experience. To get an idea of the
syntax, take a look at the example below. A complete example can be found in the BASIS source
package in data/templates/basis/1.0/_config.py
.
# project template configuration script for basisproject tool
# ------------------------------------------------------------------------------
# required project files
required = [
'AUTHORS.txt',
'README.txt',
'INSTALL.txt',
'COPYING.txt',
'CMakeLists.txt',
'BasisProject.cmake'
]
# ------------------------------------------------------------------------------
# optional project files
options = {
'config-settings' : {
'desc' : 'Include/exclude custom Settings.cmake file.',
'path' : [ 'config/Settings.cmake' ]
},
'config' : {
'desc' : 'Include/exclude all custom configuration files.',
'deps' : [
'config-settings'
]
},
'data' : {
'desc' : 'Add/remove directory for auxiliary data files.',
'path' : [ 'data/CMakeLists.txt' ]
}
}
# ------------------------------------------------------------------------------
# preset template options
presets = {
'minimal' : {
'desc' : 'Choose minimal project template.',
'args' : [ 'src' ]
},
'default' : {
'desc' : 'Choose default project template.',
'args' : [ 'doc', 'doc-rst', 'example', 'include', 'src', 'test' ]
},
'toplevel' : {
'desc' : 'Create toplevel project.',
'args' : [ 'doc', 'doc-rst', 'example', 'modules' ]
},
'module' : {
'desc' : 'Create module of toplevel project.',
'args' : [ 'include', 'src', 'test' ]
}
}
# ------------------------------------------------------------------------------
# additional substitutions besides <project>, <template>,...
from datetime import datetime as date
substitutions = {
# fixed computed substitutions
'date' : date.today().strftime('%x'),
'day' : date.today().day,
'month' : date.today().month,
'year' : date.today().year,
# substitutions which can be overridden using a command option
'vendor' : {
'help' : "Package vendor ID (e.g., acronym of provider and/or division).",
'default' : "SBIA"
},
'copyright' : {
'help' : "Copyrigth statement optionally including years.",
'default' : str(date.today().year) + " University of Pennsylvania"
},
'license' : {
'help' : "Software license statement, e.g., \"Simplified BSD\".",
'default' : "See http://www.cbica.upenn.edu/sbia/software/license.html or COPYING file."
},
'contact' : {
'help' : "Package contact information.",
'default' : "<vendor> <<vendor>-software at uphs.upenn.edu>"
}
}
Note
The substitutions are applied recursively up to a depth of 3. Hence, if the value of
a substitution is another substitution tag, it will be replaced by the value of
that respective substitution. See the contact
substitution above for an example.
In general, template files are assumed to be binary and thus no substitution is performed,
unless the template file is known to be a text file. Whether or not a template file is considered
to be a text file for which subsitution takes place depends on its MIME type .
The basisproject
tool uses the Python MIME types module
in order to determine the type of each template file. In addition to the default types known
by this module, the file name extensions .cmake, .md, .mdown, .markdown, .rst, .dox, and .in
are treated as text files.