|
| 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() |
0 commit comments