Skip to content

Commit c4e66d2

Browse files
committed
Add CMake-based build files (#25)
Support both CMake and the old Make-based approach. Both can be automatically generated using the BUILDCONF.sh scripts to make sure that they stay up to date. Also enable GitHub Actions CI that checks that everything is up to date, the code compiles (with both Make and CMake) and that the test suite passes.
1 parent 88e074d commit c4e66d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+5860
-1219
lines changed

.github/workflows/buildfiles.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Verify build files
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v1
12+
- name: Verify CMake/Make files
13+
run: ./contrib/genbuildall.sh --verify

.github/workflows/buildmake.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Build with Make
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v1
12+
- name: "Install dependencies"
13+
run: sudo apt-get install -y build-essential gfortran liblapack-dev libblas-dev openmpi-bin openmpi-common libopenmpi-dev
14+
- name: Build GRASP
15+
run: |
16+
source make_environment_gfortran
17+
cd src/ && make
18+
- name: Verify binaries
19+
run: ./contrib/checkbin.sh

.github/workflows/test.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v1
12+
- name: "Install dependencies"
13+
run: sudo apt-get install -y build-essential gfortran liblapack-dev libblas-dev openmpi-bin openmpi-common libopenmpi-dev cmake
14+
- name: Build GRASP
15+
run: |
16+
./configure.sh
17+
cd build/
18+
make
19+
make install
20+
- name: Verify binaries
21+
run: ./contrib/checkbin.sh
22+
- name: Run test suite
23+
run: cd build/ && ctest

.gitignore

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
*.out
2-
*.err
1+
# Ignore artifacts from Make builds
32
*.o
43
*.mod
5-
lib/*
6-
bin/*
4+
/bin/*
5+
!/bin/.gitkeep
6+
/lib/*
7+
!/lib/.gitkeep
8+
9+
# Ignore generated CMake files
10+
build/
11+
build-*/
12+
CMakeLists.user
13+
14+
# Ignore output log files
15+
*.out
16+
*.err

CMakeLists.txt

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# To build the CMake-based bits you first need to set up the build directory
2+
# (out of tree builds are preferred). For that run:
3+
#
4+
# mkdir build/ && cd build/ && cmake ..
5+
#
6+
# And then under the build/ directory simply call
7+
#
8+
# make
9+
#
10+
# which will compile and install all the libraries to lib/
11+
#
12+
13+
cmake_minimum_required(VERSION 2.6)
14+
project(grasp)
15+
16+
enable_language(Fortran)
17+
enable_testing()
18+
19+
# "Release" will be the default build type, which gives us optimization flags etc.
20+
# The other relevant option would be "Debug", which disables optimizations and
21+
# enables debugging symbols. The debug build can be enabled when setting up the
22+
# build directory with CMake:
23+
#
24+
# cmake -DCMAKE_BUILD_TYPE=Debug ..
25+
#
26+
if(NOT CMAKE_BUILD_TYPE)
27+
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
28+
"Choose the type of build, options are: Release Debug."
29+
FORCE
30+
)
31+
endif(NOT CMAKE_BUILD_TYPE)
32+
33+
# Find the LAPACK and BLAS libraries
34+
find_package(BLAS REQUIRED)
35+
find_package(LAPACK REQUIRED)
36+
37+
# We need special functions to handle linking Fortran modules between libraries
38+
# etc. The Fortran_MODULE_DIRECTORY_root variable is the directory where all the
39+
# .mod files get written to. It is set be the modules/ subdirectory of the build
40+
# directory.
41+
#
42+
# For every library, the modules get stored in
43+
# ${Fortran_MODULE_DIRECTORY_root}/<library_name>/ so the modules from different
44+
# libraries are separated from each other.
45+
#
46+
#
47+
# Command: setup_fortran_modules(target)
48+
#
49+
# Needs to be called on all libraries that provide modules. It set the
50+
# Fortran_MODULE_DIRECTORY variable for the target, which is then used by
51+
# target_link_libraries_Fortran to set up the appropriate include directories.
52+
#
53+
# Example:
54+
#
55+
# setup_fortran_modules(9290)
56+
#
57+
#
58+
# Command: target_link_libraries_Fortran(target mode libraries...)
59+
#
60+
# Similar to target_link_libraries(), but will also set up paths so that the
61+
# compiler could fine the the Fortran .mod files from of the libraries. Unlike
62+
# for the standard command, mode ( = PUBLIC, PRIVATE) is mandatory.
63+
#
64+
# Modified version of: https://stackoverflow.com/a/43918277/1601695
65+
#
66+
# Example:
67+
#
68+
# target_link_libraries_Fortran(rcsfsplit PRIVATE mod 9290)
69+
#
70+
set(Fortran_MODULE_DIRECTORY_root ${CMAKE_CURRENT_BINARY_DIR}/modules)
71+
function(setup_fortran_modules target)
72+
set_property(TARGET ${target} PROPERTY Fortran_MODULE_DIRECTORY "${Fortran_MODULE_DIRECTORY_root}/${target}")
73+
install(DIRECTORY "${Fortran_MODULE_DIRECTORY_root}/${target}" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/"
74+
FILES_MATCHING PATTERN "*.mod")
75+
endfunction()
76+
function(target_link_libraries_Fortran target mode)
77+
target_link_libraries(${target} ${mode} ${ARGN})
78+
foreach(lib IN LISTS ARGN)
79+
target_include_directories(${target} ${mode} $<TARGET_PROPERTY:${lib},Fortran_MODULE_DIRECTORY>)
80+
endforeach()
81+
endfunction()
82+
83+
84+
# We put the compiled binaries into the bin/ subdirectory of the build directory
85+
# and libraries into the lib/ subdirectory.
86+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin/")
87+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib/")
88+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib/")
89+
# To install the binaries into the standard <repo>/bin/ directory, you need to
90+
# call `make install`.
91+
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
92+
93+
# Additional Fortran compiler flags.
94+
#
95+
# -fno-automatic: this was set in the original make_environment_gfortran_UBC file.
96+
#
97+
# Note: optimization should be enabled on the Release target automatically.
98+
#
99+
# If need be, you can also set up linker flags. E.g.:
100+
#
101+
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgfortran")
102+
#
103+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-automatic")
104+
105+
message("Compiler flags etc. for this GRASP build:")
106+
message("* CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
107+
message("* CMAKE_Fortran_COMPILER: ${CMAKE_Fortran_COMPILER}")
108+
message("* CMAKE_Fortran_COMPILER_VERSION: ${CMAKE_Fortran_COMPILER_VERSION}")
109+
message("* CMAKE_Fortran_FLAGS: ${CMAKE_Fortran_FLAGS}")
110+
message("* CMAKE_Fortran_FLAGS_RELEASE: ${CMAKE_Fortran_FLAGS_RELEASE}")
111+
message("* CMAKE_Fortran_FLAGS_DEBUG: ${CMAKE_Fortran_FLAGS_DEBUG}")
112+
message("* CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
113+
message("* CMAKE_STATIC_LINKER_FLAGS: ${CMAKE_STATIC_LINKER_FLAGS}")
114+
message("* CMAKE_RUNTIME_OUTPUT_DIRECTORY: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
115+
message("* CMAKE_LIBRARY_OUTPUT_DIRECTORY: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
116+
message("* CMAKE_ARCHIVE_OUTPUT_DIRECTORY: ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}")
117+
message("* BLAS_LIBRARIES: ${BLAS_LIBRARIES}")
118+
message("* BLAS_LINKER_FLAGS: ${BLAS_LINKER_FLAGS}")
119+
message("* LAPACK_LIBRARIES: ${LAPACK_LIBRARIES}")
120+
message("* LAPACK_LINKER_FLAGS: ${LAPACK_LINKER_FLAGS}")
121+
122+
# GRASP libraries
123+
add_subdirectory("src/lib/libmod")
124+
add_subdirectory("src/lib/lib9290")
125+
add_subdirectory("src/lib/libdvd90")
126+
add_subdirectory("src/lib/libmcp90")
127+
add_subdirectory("src/lib/librang90")
128+
129+
# GRASP application programs
130+
add_subdirectory("src/appl/HF")
131+
add_subdirectory("src/appl/jj2lsj90")
132+
add_subdirectory("src/appl/jjgen90")
133+
add_subdirectory("src/appl/rangular90")
134+
add_subdirectory("src/appl/rbiotransform90")
135+
add_subdirectory("src/appl/rci90")
136+
add_subdirectory("src/appl/rcsfgenerate90")
137+
add_subdirectory("src/appl/rcsfinteract90")
138+
add_subdirectory("src/appl/rcsfzerofirst90")
139+
add_subdirectory("src/appl/rhfs90")
140+
add_subdirectory("src/appl/rmcdhf90")
141+
add_subdirectory("src/appl/rnucleus90")
142+
add_subdirectory("src/appl/rtransition90")
143+
add_subdirectory("src/appl/rwfnestimate90")
144+
add_subdirectory("src/appl/sms90")
145+
146+
# Additional GRASP tools and programs
147+
add_subdirectory("src/tool")
148+
149+
# We only build MPI programs and libraries if we can actually find MPI on
150+
# the user's system.
151+
find_package(MPI)
152+
if(MPI_Fortran_FOUND)
153+
message("* MPI_Fortran_LIBRARIES: ${MPI_Fortran_LIBRARIES}")
154+
message("* MPI_Fortran_INCLUDE_PATH: ${MPI_Fortran_INCLUDE_PATH}")
155+
message("* MPI_Fortran_COMPILE_FLAGS: ${MPI_Fortran_COMPILE_FLAGS}")
156+
message("* MPI_Fortran_LINK_FLAGS: ${MPI_Fortran_LINK_FLAGS}")
157+
158+
add_subdirectory("src/lib/mpi90")
159+
add_subdirectory("src/appl/rangular90_mpi")
160+
add_subdirectory("src/appl/rbiotransform90_mpi")
161+
add_subdirectory("src/appl/rci90_mpi")
162+
add_subdirectory("src/appl/rmcdhf90_mpi")
163+
add_subdirectory("src/appl/rtransition90_mpi")
164+
else()
165+
message("MPI libraries not found. Not building MPI-dependent programs.")
166+
endif(MPI_Fortran_FOUND)
167+
168+
# Unit and integration tests
169+
add_subdirectory("test")
170+
171+
# We use the CMakeLists.txt so that the user could easily add additional targets
172+
# to the GRASP build, such as additional (external) GRASP programs that need to
173+
# be linked agains the GRASP libraries.
174+
#
175+
# We also set the GRASP variable that the user-defined targets can use to figure
176+
# out where the root of the GRASP source tree is.
177+
set(GRASP ${PROJECT_SOURCE_DIR})
178+
unset(GRASP_CMakeLists_user CACHE)
179+
find_file(GRASP_CMakeLists_user "CMakeLists.user" ${PROJECT_SOURCE_DIR})
180+
if(NOT "${GRASP_CMakeLists_user}" STREQUAL "GRASP_CMakeLists_user-NOTFOUND")
181+
include(${GRASP_CMakeLists_user})
182+
endif()

README.md

+88-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,95 @@
11
# General Relativistic Atomic Structure Package
22

3-
**GRASP2018 - an F95 development version**
4-
53
[![][manual-badge]][manual-pdf]
64

5+
The General Relativistic Atomic Structure Package (GRASP) is a set of Fortran 90
6+
programs for performing fully-relativistic electron structure calculations of
7+
atoms.
8+
9+
## Installation
10+
11+
> **Please note:**
12+
> The installation instructions here are for the _development version_ on the
13+
> `master` branch.
14+
>
15+
> To install the _latest published release_ (2018-12-03), go to the
16+
> ["Releases" page](https://github.com/compas/grasp/releases/tag/2018-12-03),
17+
> download the tarball from there and refer to the instructions in the README in
18+
> the tarball.
19+
20+
To compile and install GRASP, first clone this Git repository:
21+
22+
```sh
23+
git clone https://github.com/compas/grasp.git
24+
```
25+
26+
There are two ways to build GRASP: either via [CMake](https://cmake.org/) or via the
27+
`Makefile`s in the source tree. Either works and you end up with the GRASP binaries in the
28+
`bin/` directory.
29+
30+
CMake is the recommended way to build GRASP. The `Makefile`-based workflow is still there to
31+
make smoother to transition from `Makefile`s to a modern build system.
32+
33+
### CMake-based build
34+
35+
The first step with CMake is to create a separate out-of-source build directory. The
36+
`configure.sh` script can do that for you:
37+
38+
```sh
39+
cd grasp/ && ./configure.sh
40+
```
41+
42+
This will create a `build/` directory with the default _Release_ build
43+
configuration. However, `configure.sh` is just a simple wrapper around a `cmake`
44+
call and if you need more control over the build, you can always invoke `cmake`
45+
yourself (see [CMake documentation](https://cmake.org/documentation/) for more
46+
information).
47+
48+
To then compile GRASP, you need to go into the out-of-source build directory and
49+
simply call `make`:
50+
51+
```sh
52+
cd build/ && make install
53+
```
54+
55+
Remarks:
56+
57+
* Running `make install` instructs CMake to actually _install_ the resulting binaries into
58+
the conventional `bin/` directory at the root of the repository.
59+
60+
When you run just `make`, the resulting binaries will end up under the `build/` directory
61+
(specifically in `build/bin/`). This is useful when developing and debugging, as it allows
62+
you to compile many versions of the binaries from the same source tree with different
63+
compilation options (e.g. build with debug symbols enabled) by using several out of source
64+
build directories.
65+
66+
* With CMake, GRASP also supports parallel builds, which can be enabled by passing the `-j`
67+
option to `make` (e.g. `make -j4 install` to build with four processes).
68+
69+
* The CMake-based build allows running the (non-comprehensive) test suite by calling `ctest`
70+
in the `build/` directory. The configuration and source files for the tests are under
71+
`test/`/
72+
73+
### `Makefile`-based build
74+
75+
The legacy `Makefile`-based build can be performed by first loading the necessary
76+
environment variables (which may have to be modified to suit your system). E.g.:
77+
78+
```sh
79+
source make_environment_gfortran
80+
```
81+
82+
To actually build the binaries, you have to call `make` on the root `Makefile` in `src/`:
83+
84+
```
85+
cd src/ && make
86+
```
87+
88+
**WARNING:** the `Makefile`s do not know about the dependencies between the source files, so
89+
parallel builds (i.e. calling `make` with the `-j` option) does not work.
90+
91+
## About GRASP
92+
793
This version of GRASP is a major revision of the previous GRASP2K package by [P.
894
Jonsson, G. Gaigalas, J. Bieron, C. Froese Fischer, and I.P. Grant Computer
995
Physics Communication, 184, 2197 - 2203 (2013)][grasp2k-2013] written in FORTRAN

0 commit comments

Comments
 (0)