Skip to content

Commit 3f9e410

Browse files
committed
Add module for handling version information of stdlib
1 parent 1e6d04f commit 3f9e410

File tree

11 files changed

+156
-3
lines changed

11 files changed

+156
-3
lines changed

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
cmake_minimum_required(VERSION 3.14.0)
22
project(fortran_stdlib
33
LANGUAGES Fortran
4-
VERSION 0.1.0
54
DESCRIPTION "Community driven and agreed upon de facto standard library for Fortran"
65
)
6+
7+
# Read version from file
8+
file(STRINGS "${PROJECT_SOURCE_DIR}/VERSION" PROJECT_VERSION)
9+
string(REPLACE "." ";" VERSION_LIST ${PROJECT_VERSION})
10+
list(GET VERSION_LIST 0 PROJECT_VERSION_MAJOR)
11+
list(GET VERSION_LIST 1 PROJECT_VERSION_MINOR)
12+
list(GET VERSION_LIST 2 PROJECT_VERSION_PATCH)
13+
unset(VERSION_LIST)
14+
715
enable_testing()
816

917
# Follow GNU conventions for installation directories

Makefile.manual

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ FC ?= gfortran
44
FFLAGS ?= -Wall -Wextra -Wimplicit-interface -fPIC -g -fcheck=all
55
FYPPFLAGS ?=
66

7+
FYPPFLAGS += \
8+
-DPROJECT_VERSION_MAJOR=$(shell cut -d. -f1 VERSION) \
9+
-DPROJECT_VERSION_MINOR=$(shell cut -d. -f2 VERSION) \
10+
-DPROJECT_VERSION_PATCH=$(shell cut -d. -f3 VERSION)
11+
712
export FC
813
export FFLAGS
914
export FYPPFLAGS

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

ci/fpm-deployment.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fi
2222
include=(
2323
"ci/fpm.toml"
2424
"LICENSE"
25+
"VERSION"
2526
)
2627

2728
# Files to remove from collection

ci/fpm.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "stdlib"
2-
version = "0.1.0"
2+
version = "VERSION"
33
license = "MIT"
44
author = "stdlib contributors"
55
maintainer = "@fortran-lang/stdlib"

doc/specs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This is and index/directory of the specifications (specs) for each new module/fe
2828
- [string\_type](./stdlib_string_type.html) - Basic string support
2929
- [strings](./stdlib_strings.html) - String handling and manipulation routines
3030
- [stringlist_type](./stdlib_stringlist_type.html) - 1-Dimensional list of strings
31+
- [version](./stdlib_version.html) - Version information
3132

3233
## Released/Stable Features & Modules
3334

doc/specs/stdlib_version.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Version information
3+
---
4+
5+
# The `stdlib_version` module
6+
7+
[TOC]
8+
9+
## Introduction
10+
11+
The `stdlib_version` module contains the version of the standard library.
12+
The version information an be used as compile time constant or retrieved from a getter function at runtime.
13+
In case the standard library is dynamically linked, the version number retrieved from the getter might mismatch the compile time constants provided from the version built against.
14+
Therefore, it is recommended to retrieve the version information always at runtime.
15+
16+
17+
## Constants provided by `stdlib_version`
18+
19+
### `stdlib_version_string`
20+
21+
String contant representing the version number.
22+
23+
### `stdlib_version_compact`
24+
25+
Compact representation of the version string following the scheme:
26+
major * 10000 + minor * 100 + patch.
27+
28+
29+
### `get_stdlib_version`
30+
31+
#### Status
32+
33+
Experimental
34+
35+
#### Description
36+
37+
Getter function to retrieve version information
38+
39+
#### Syntax
40+
41+
`res = [[stdlib_version(module):get_stdlib_version(function)]] ([major], [minor], [patch], [string])`
42+
43+
#### Class
44+
45+
Pure subroutine.
46+
47+
#### Argument
48+
49+
`major`: shall be an intrinsic integer type. It is an optional, `intent(out)` argument.
50+
`minor`: shall be an intrinsic integer type. It is an optional, `intent(out)` argument.
51+
`patch`: shall be an intrinsic integer type. It is an optional, `intent(out)` argument.
52+
`string`: shall be a deferred length character type. It is an optional, `intent(out)` argument.
53+
54+
#### Example
55+
56+
```fortran
57+
program demo_version
58+
use stdlib_version, only : get_stdlib_version
59+
implicit none
60+
character(len=:), allocatable :: version
61+
call get_stdlib_version(string=version)
62+
print '(a)', version
63+
end program demo_to_lower
64+
```

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set(fppFiles
3939
stdlib_string_type_constructor.fypp
4040
stdlib_strings_to_string.fypp
4141
stdlib_strings.fypp
42+
stdlib_version.fypp
4243
)
4344

4445

@@ -55,6 +56,9 @@ list(
5556
APPEND fyppFlags
5657
"-DWITH_QP=$<BOOL:${WITH_QP}>"
5758
"-DWITH_XDP=$<BOOL:${WITH_XDP}>"
59+
"-DPROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}"
60+
"-DPROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR}"
61+
"-DPROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH}"
5862
)
5963

6064
fypp_f90("${fyppFlags}" "${fppFiles}" outFiles)

src/Makefile.manual

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ SRCFYPP = \
3535
stdlib_string_type.fypp \
3636
stdlib_string_type_constructor.fypp \
3737
stdlib_strings.fypp \
38-
stdlib_strings_to_string.fypp
38+
stdlib_strings_to_string.fypp \
39+
stdlib_version.fypp
3940

4041
SRC = f18estop.f90 \
4142
stdlib_error.f90 \

src/common.fypp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#:mute
22

3+
#! Project version number
4+
#:set PROJECT_VERSION = "{}.{}.{}".format(PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR, PROJECT_VERSION_PATCH)
5+
36
#! Support for quadruple precision floating point numbers
47
#:if not defined("WITH_QP")
58
#:set WITH_QP = False

0 commit comments

Comments
 (0)