Skip to content

Commit 4bb821c

Browse files
committed
use configure_file instead of preprocessing
1 parent b7def64 commit 4bb821c

21 files changed

Lines changed: 119 additions & 151 deletions

.github/workflows/ci.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ jobs:
1919
with:
2020
python-version: '3.x'
2121

22-
- run: pip install meson
23-
- name: Install packages
24-
run: |
25-
sudo apt update -yq
26-
sudo apt install -yq --no-install-recommends ninja-build
22+
- run: pip install meson ninja
2723

2824
- run: meson setup build
2925
env:
@@ -46,10 +42,7 @@ jobs:
4642
env:
4743
FC: gfortran-9
4844

49-
- run: cmake --build build --parallel
50-
51-
- run: ctest -V
52-
working-directory: build
45+
- run: ctest -S setup.cmake -VV
5346
- uses: actions/upload-artifact@v1
5447
if: failure()
5548
with:
@@ -60,10 +53,7 @@ jobs:
6053
env:
6154
FC: gfortran-9
6255

63-
- run: cmake --build build --parallel
64-
65-
- run: ctest -V
66-
working-directory: build
56+
- run: ctest -S setup.cmake -VV
6757
- uses: actions/upload-artifact@v1
6858
if: failure()
6959
with:

CMakeLists.txt

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
11
cmake_minimum_required(VERSION 3.14)
2+
23
if(NOT CMAKE_BUILD_TYPE)
3-
set(CMAKE_BUILD_TYPE Release CACHE STRING "Debug or Release")
4+
set(CMAKE_BUILD_TYPE Release CACHE STRING "default build type")
45
endif()
6+
57
project(MapTran
68
LANGUAGES Fortran
7-
VERSION 1.1.1
9+
VERSION 1.1.2
810
HOMEPAGE_URL https://github.com/geospace-code/maptran3d)
9-
enable_testing()
1011

11-
if(NOT realbits)
12-
set(realbits 64)
13-
endif()
12+
enable_testing()
13+
include(CTest)
14+
include(FeatureSummary)
1415

1516
include(cmake/compilers.cmake)
1617

18+
if(realbits EQUAL 32)
19+
set(wp_real "wp=>real32")
20+
else()
21+
set(wp_real "wp=>real64")
22+
endif()
23+
1724
# OPTIONAL link-time optimization
18-
if(CMAKE_BUILD_TYPE STREQUAL Release)
19-
include(CheckIPOSupported)
20-
check_ipo_supported(RESULT lto_ok OUTPUT _err)
21-
22-
if(lto_ok)
23-
message(STATUS "IPO / LTO enabled")
24-
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
25-
else()
26-
message(STATUS "IPO / LTO disabled: ${_err}")
27-
endif()
25+
if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
26+
if(CMAKE_BUILD_TYPE STREQUAL Release)
27+
include(CheckIPOSupported)
28+
check_ipo_supported(RESULT lto_ok OUTPUT _err)
29+
30+
if(lto_ok)
31+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
32+
endif()
33+
endif()
2834
endif()
2935

30-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
3136
set(CTEST_TEST_TIMEOUT 30)
3237

3338
# --- Maptran library
34-
add_library(maptran)
35-
target_compile_definitions(maptran PRIVATE REALBITS=${realbits})
36-
target_include_directories(maptran INTERFACE
37-
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
38-
$<INSTALL_INTERFACE:include>)
39-
set_target_properties(maptran PROPERTIES
40-
Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
41-
add_library(maptran::maptran ALIAS maptran)
42-
install(TARGETS maptran
43-
ARCHIVE DESTINATION lib
44-
LIBRARY DESTINATION lib)
45-
4639
add_subdirectory(src)
47-
add_subdirectory(src/tests)
40+
41+
if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
42+
add_subdirectory(src/tests)
43+
44+
add_feature_info(ipo lto_ok "Interprocess / Link optimization ${_err}")
45+
feature_summary(WHAT ALL)
46+
endif()

README.md

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,27 @@ and Matlab / GNU Octave
1212
## Install
1313

1414
Requires Fortran 2008 compiler, such as `gfortran`, `ifort`, PGI, `nagfor`, `flang`, Cray, IBM XL, etc.
15-
Use CMake or Meson to build the suite, which creates `libmaptran.so` or similar, a shared library with compile-time polymorphism enabled by configuring Fortran preprocessor with one of:
15+
Use CMake or Meson to build the suite, which creates `libmaptran.a` or similar.
16+
Compile-time polymorphism enabled by configuring with one of:
1617

1718
* `-Drealbits=32`
1819
* `-Drealbits=64`
19-
* `-Drealbits=128`
2020

21-
Note: as with any program or programming language, the accuracy of 32-bit reals can be significantly degraded, by orders of magnitude compared to 64-bit reals that are the default for many years.
2221
The large real values typical of map coordinates can lead to large error with 32-bit reals.
23-
64-bit reals are the default.
24-
25-
### Meson
26-
27-
```sh
28-
meson build
29-
30-
meson test -C build
31-
```
22+
64-bit real is the default.
3223

3324
### CMake
3425

3526
```sh
36-
cmake -B build
37-
38-
cmake --build build --parallel
39-
40-
cd build
41-
42-
ctest -V
27+
ctest -S setup.cmake -VV
4328
```
4429

45-
Optionally, verify Fortran functionality:
30+
### Meson
4631

4732
```sh
48-
ctest -V
33+
meson build
34+
35+
meson test -C build
4936
```
5037

5138
## Usage

cmake/compilers.cmake

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ else()
77
string(APPEND CMAKE_Fortran_FLAGS " -march=native -stand f18 -traceback -warn -heap-arrays")
88
endif()
99
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
10-
string(APPEND CMAKE_Fortran_FLAGS " -Wall -Wextra -fimplicit-none")
10+
string(APPEND CMAKE_Fortran_FLAGS " -fimplicit-none")
1111
string(APPEND CMAKE_Fortran_FLAGS_DEBUG " -fcheck=all -Werror=array-bounds")
1212
# -march=native is not for all CPU arches with GCC.
13-
add_compile_options(-mtune=native)
13+
add_compile_options(-mtune=native -Wall -Wextra)
1414

1515
if(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 8)
1616
string(APPEND CMAKE_Fortran_FLAGS " -std=f2018")
@@ -24,14 +24,7 @@ elseif(CMAKE_Fortran_COMPILER_ID STREQUAL NAG)
2424
endif()
2525

2626
include(CheckFortranSourceCompiles)
27-
check_fortran_source_compiles("implicit none (external); end" f2018impnone SRC_EXT f90)
27+
check_fortran_source_compiles("implicit none (type, external); end" f2018impnone SRC_EXT f90)
2828
if(NOT f2018impnone)
29-
message(FATAL_ERROR "Compiler does not support Fortran 2018 IMPLICIT NONE (EXTERNAL): ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER_VERSION}")
29+
message(FATAL_ERROR "Compiler does not support Fortran 2018 IMPLICIT NONE (type, external): ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER_VERSION}")
3030
endif()
31-
32-
include(CheckFortranSourceRuns)
33-
check_fortran_source_runs("use, intrinsic :: ieee_arithmetic, only: ieee_value, ieee_quiet_nan, ieee_is_nan
34-
real :: r
35-
r = ieee_value(1., ieee_quiet_nan)
36-
if (.not.ieee_is_nan(r)) error stop
37-
end program" f03nan)

meson.build

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
project('MapTran', 'fortran',
2-
version: '1.1.1',
2+
version: '1.1.2',
33
meson_version : '>=0.51.2',
4-
default_options : ['default_library=static', 'buildtype=release', 'warning_level=3'])
5-
6-
realbits = '-DREALBITS=' + get_option('realbits')
4+
default_options : ['default_library=static', 'buildtype=release', 'warning_level=2'])
75

86
fc = meson.get_compiler('fortran')
97
if fc.get_id() == 'intel'
@@ -12,11 +10,15 @@ elif fc.get_id() == 'intel-cl'
1210
add_project_arguments('/fpp', '/heap-arrays', language : 'fortran')
1311
endif
1412

13+
wp_real = get_option('realbits')=='32' ? 'wp=>real32' : 'wp=>real64'
14+
15+
wp_conf = configuration_data()
16+
wp_conf.set('wp_real', wp_real)
17+
1518
subdir('src')
1619
# --- Maptran library
1720
maptran = library('maptran',
18-
sources: srcs,
19-
fortran_args : realbits,
20-
install: true)
21+
sources: srcs,
22+
install: true)
2123

2224
subdir('src/tests')

meson_options.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
option('realbits', type : 'combo', choices : ['64', '32', '128'], description: 'bits of precision for real')
1+
option('realbits', type : 'combo', choices : ['64', '32'], description: 'bits of precision for real')

src/CMakeLists.txt

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
target_sources(maptran PRIVATE maptran.F90 aer.f90 ecef.f90 enu.f90 vallado.F90 utils.f90)
2-
if(f03nan)
3-
target_sources(maptran PRIVATE sphere.f90)
4-
else()
5-
target_sources(maptran PRIVATE no_sphere.f90)
6-
endif()
1+
configure_file(maptran.in.f90 maptran.f90)
2+
configure_file(vallado.in.f90 vallado.f90)
3+
4+
add_library(maptran
5+
${CMAKE_CURRENT_BINARY_DIR}/maptran.f90 ${CMAKE_CURRENT_BINARY_DIR}/vallado.f90
6+
aer.f90 ecef.f90 enu.f90 sphere.f90 utils.f90)
7+
8+
target_include_directories(maptran INTERFACE
9+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
10+
$<INSTALL_INTERFACE:include>)
11+
12+
set_target_properties(maptran PROPERTIES
13+
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}
14+
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}
15+
Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
16+
17+
add_library(maptran::maptran ALIAS maptran)
18+
19+
install(TARGETS maptran
20+
ARCHIVE DESTINATION lib
21+
LIBRARY DESTINATION lib)

src/aer.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
submodule (maptran) aer
22

3-
implicit none (external)
3+
implicit none (type, external)
44

55
contains
66

src/ecef.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
submodule (maptran) ecef
22

3-
implicit none (external)
3+
implicit none (type, external)
44

55
contains
66

src/enu.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
submodule (maptran) enu
22

3-
implicit none (external)
3+
implicit none (type, external)
44

55
contains
66

0 commit comments

Comments
 (0)