diff --git a/INSTALL.md b/INSTALL.md index c983e11a..b0fc54c6 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -13,7 +13,7 @@ Installation - python should be installed - gnuplot should be installed -**Note: The `build_things.sh` script assumes that TDEP was cloned and lives in a git repository. If you wish obtain TDEP in another you have to adjust the script.** +**Note: The `build_things.sh` script assumes that TDEP was cloned and lives in a git repository. If you wish obtain TDEP in another way you have to adjust the script.** **If you have a package manager, `homebrew`, `apt-get`, `yay`, `pacman`, you name it, getting these dependencies should be straightforward.** @@ -78,29 +78,6 @@ i.e., add the respective lines to your `.bashrc` and you are all set up! **If problems occur, please look at the [Troubleshooting section below](#Troubleshooting). If you cannot fix the error, please reach out, e.g., via the [issue tracker](https://github.com/tdep-developers/tdep/issues).** -## Meson build system - -Alternativaly to the `build_things.sh` script, there is also the possibility to use [Meson](https://mesonbuild.com/). It is a build automation tool, and it supports incremental builds. The dependencies should be installed in standard locations (e.g. `/usr/local/`) or specified in the `PKG_CONFIG_PATH`. - -First setup the git version for the code: -```setup_git_version.sh``` -Then you can run the configuration step: -```meson setup build``` -And finally compile the code: -``` -cd build -meson compile -meson install -``` - -If some dependencies are not found, please make sure that they are in your PKG_CONFIG_PATH. For example, put something of the form in your `.bashrc` / `.bash_profile` : -```export PKG_CONFIG_PATH="/path/to/your/netcdf/:${PKG_CONFIG_PATH}"``` -Depending on the method used to install the required libraries, they may not be automatically put inside the search path (Homebrew is known to not always do it). -You can make sure that `pkg-config` is able to find the dependencies by running: `pkg-config --libs hdf5` -Meson will first try to find dependencies via `pkg-config`. If it does not find them, it will try to use CMake (if installed/loaded). - -Once the configuration step is done, everything should go smoothly. The binaries will be in build/bin/executable_name. - ## Check your installation We advise to run the tests in [`./tests`](./tests) to check your installation. @@ -122,6 +99,7 @@ where `FC` and `CC` should point to the same Fortran/C compilers you are using t - [macOS](#macOS) - [Supercomputers](#Supercomputers) - [Platform-agnostic installation using Anaconda](#Anaconda) +- [Platform-agnostic installation using the Meson build system](#Meson-build-system) ## macOS @@ -146,6 +124,10 @@ There are two template settings files you can look into: One convenient, (mostly) platform-agnostic way to install TDEP is to use [Anaconda](https://anaconda.org/). +## Meson build system + +To use the Meson build system instead of the `build_things.sh` script, see [INSTALL_Meson.md](INSTALL_Meson.md). + ### Prepare environment diff --git a/INSTALL_Meson.md b/INSTALL_Meson.md new file mode 100644 index 00000000..03e59725 --- /dev/null +++ b/INSTALL_Meson.md @@ -0,0 +1,31 @@ +Installation with the Meson build system +=== + +Alternativaly to the `build_things.sh` script, there is also the possibility to use [Meson](https://mesonbuild.com/). It is a build automation tool, and it supports incremental builds (similarly to autotools and CMake). The dependencies should be installed in standard locations (e.g. `/usr/local/`) or specified in the `PKG_CONFIG_PATH`. + +First setup the git version for the code: +```setup_git_version.sh``` +Then you can run the configuration step: +```meson setup build``` +And finally compile the code: +``` +cd build +meson compile +meson install +``` + +If some dependencies are not found, please make sure that they are in your PKG_CONFIG_PATH. For example, put a line of the form in your `.bashrc` / `.bash_profile` : +```export PKG_CONFIG_PATH="/path/to/your/hdf5/:${PKG_CONFIG_PATH}"``` +Depending on the method used to install the required libraries, they may not be automatically put inside the search path (Homebrew is known to not always do it). You may also have to set the environment variables `PKG_CONFIG_ALLOW_SYSTEM_LIBS` and `PKG_CONFIG_ALLOW_SYSTEM_CFLAGS` to 1: +``` +export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 +export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 +``` +You can make sure that `pkg-config` is able to find the dependencies and proper compilation/linking flags by running: +``` +pkg-config --libs hdf5 +pkg-config --cflags hdf5 +``` +Meson will first try to find dependencies via `pkg-config`. If it does not find them, it will try to use CMake (if installed/loaded). + +Once the configuration step is done, everything should go smoothly. The binaries will be in bin/executable_name. diff --git a/meson.build b/meson.build index 2b225ff3..1a194ea9 100644 --- a/meson.build +++ b/meson.build @@ -1,17 +1,50 @@ -project('tdep', 'fortran', 'c', 'cpp') +project('tdep', + 'fortran', 'c', 'cpp', + meson_version: '>=1.1', + default_options: ['buildtype=custom', 'debug=true', 'optimization=3']) add_project_arguments('-cpp', language: 'fortran') add_project_arguments('-ffree-line-length-none', language: 'fortran') # add_project_arguments('-std=f2008', language: 'fortran') add_project_arguments('-fallow-argument-mismatch', language: 'fortran') # global dependencies: + +# mpi dep_mpi = dependency('mpi', language: 'fortran') -dep_blas = dependency('blas') -dep_lapack = dependency('lapack') + +# linear algebra +dep_linalg_found = false +# 1) try accelerate framework for macos (if wanted) +# enabled via -Daccfrmwrk=true +if build_machine.system() == 'darwin' and get_option('accfrmwrk') == true + dep_linalg = dependency('appleframeworks', modules : 'accelerate', required: false) + dep_linalg_found = dep_linalg.found() +endif + +# 2) try blas/openblas + lapack otherwise +if not dep_linalg_found + dep_blas = dependency('blas', required: false) + if not dep_blas.found() + message('Did not find the blas library. Trying with openblas') + dep_blas = dependency('openblas', required: true) # required as it is the last try + endif + dep_lapack = dependency('lapack', required: true) + dep_linalg = [dep_blas, dep_lapack] +endif +# # add some common path to pkg-config search path +# env = environ() +# env.prepend('PKG_CONFIG_PATH', '/usr/lib/x86_64-linux-gnu') + +# message(get_option('linalg_flavor')) + +# fft dep_fftw = dependency('fftw3') + +# hdf5 dep_hdf5 = dependency('hdf5', language: 'fortran', version: '>1.10.7') -dep_netcdf = dependency('netcdf', language: 'fortran') -dep_all = [dep_mpi, dep_blas, dep_lapack, dep_fftw, dep_hdf5, dep_netcdf] + +# dep_all = [dep_mpi, dep_blas, dep_lapack, dep_fftw, dep_hdf5] +dep_all = [dep_mpi, dep_linalg, dep_fftw, dep_hdf5] subdir('src/libolle') subdir('src/libflap') diff --git a/meson.options b/meson.options new file mode 100644 index 00000000..decf5240 --- /dev/null +++ b/meson.options @@ -0,0 +1,4 @@ +# wether to use the apple accelerate framework on macos +option('accfrmwrk', type : 'boolean', value : false, description : 'Enables the use of Apple\'s accelerate framework for linear algebra, replacing blas/lapack.') +# option('linalg_flavor', type : 'combo', choices : ['auto', 'lapack', 'mkl']) +# option('fft_flavor', type : 'combo', choices : ['auto', 'fftw', 'mkl_dfti']) diff --git a/src/anharmonic_free_energy/meson.build b/src/anharmonic_free_energy/meson.build index 7916c366..6fadcea5 100644 --- a/src/anharmonic_free_energy/meson.build +++ b/src/anharmonic_free_energy/meson.build @@ -1,12 +1,11 @@ -executable('anharmonic_free_energy', +exec_name='anharmonic_free_energy' +executable(exec_name, 'energy.f90', 'epot.f90', 'main.f90', 'options.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('anharmonic_free_energy', pointing_to: meson.project_build_root() / 'bin/anharmonic_free_energy', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/atomic_distribution/meson.build b/src/atomic_distribution/meson.build index 21839da2..86bb9ac3 100644 --- a/src/atomic_distribution/meson.build +++ b/src/atomic_distribution/meson.build @@ -1,4 +1,5 @@ -executable('atomic_distribution', +exec_name='atomic_distribution' +executable(exec_name, 'correlationfunction.f90', 'diffraction.f90', 'main.f90', @@ -9,8 +10,6 @@ executable('atomic_distribution', 'vectordist.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('atomic_distribution', pointing_to: meson.project_build_root() / 'bin/atomic_distribution', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/canonical_configuration/meson.build b/src/canonical_configuration/meson.build index 57226928..0ea1f654 100644 --- a/src/canonical_configuration/meson.build +++ b/src/canonical_configuration/meson.build @@ -1,11 +1,10 @@ -executable('canonical_configuration', +exec_name='canonical_configuration' +executable(exec_name, 'main.f90', 'options.f90', 'semirandom.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('canonical_configuration', pointing_to: meson.project_build_root() / 'bin/canonical_configuration', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/crystal_structure_info/meson.build b/src/crystal_structure_info/meson.build index 1ce986b0..e624d95b 100644 --- a/src/crystal_structure_info/meson.build +++ b/src/crystal_structure_info/meson.build @@ -1,10 +1,9 @@ -executable('crystal_structure_info', +exec_name='crystal_structure_info' +executable(exec_name, 'main.f90', 'options.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('crystal_structure_info', pointing_to: meson.project_build_root() / 'bin/crystal_structure_info', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/dump_dynamical_matrices/meson.build b/src/dump_dynamical_matrices/meson.build index 9466d935..0985bcd4 100644 --- a/src/dump_dynamical_matrices/meson.build +++ b/src/dump_dynamical_matrices/meson.build @@ -1,10 +1,9 @@ -executable('dump_dynamical_matrices', +exec_name='dump_dynamical_matrices' +executable(exec_name, 'main.f90', 'options.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('dump_dynamical_matrices', pointing_to: meson.project_build_root() / 'bin/dump_dynamical_matrices', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/extract_forceconstants/meson.build b/src/extract_forceconstants/meson.build index 654d19ea..d6c22876 100644 --- a/src/extract_forceconstants/meson.build +++ b/src/extract_forceconstants/meson.build @@ -1,10 +1,9 @@ -executable('extract_forceconstants', +exec_name='extract_forceconstants' +executable(exec_name, 'main.f90', 'options.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('extract_forceconstants', pointing_to: meson.project_build_root() / 'bin/extract_forceconstants', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/generate_structure/meson.build b/src/generate_structure/meson.build index 60127f53..2d92a592 100644 --- a/src/generate_structure/meson.build +++ b/src/generate_structure/meson.build @@ -1,11 +1,10 @@ -executable('generate_structure', +exec_name='generate_structure' +executable(exec_name, 'autocell.f90', 'main.f90', 'options.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('generate_structure', pointing_to: meson.project_build_root() / 'bin/generate_structure', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/lineshape/meson.build b/src/lineshape/meson.build index fb5f6e6b..9d456570 100644 --- a/src/lineshape/meson.build +++ b/src/lineshape/meson.build @@ -1,4 +1,5 @@ -executable('lineshape', +exec_name='lineshape' +executable(exec_name, 'dielscatter.f90', 'dielscatter_helper.f90', # 'dielscatter_matrixelement.f90', @@ -16,8 +17,6 @@ executable('lineshape', 'scatteringrates.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('lineshape', pointing_to: meson.project_build_root() / 'bin/lineshape', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/pack_simulation/meson.build b/src/pack_simulation/meson.build index f29c96e2..88d05a4c 100644 --- a/src/pack_simulation/meson.build +++ b/src/pack_simulation/meson.build @@ -1,10 +1,9 @@ -executable('pack_simulation', +exec_name='pack_simulation' +executable(exec_name, 'main.f90', 'options.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('pack_simulation', pointing_to: meson.project_build_root() / 'bin/pack_simulation', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/phasespace_surface/meson.build b/src/phasespace_surface/meson.build index 3a867b1b..4059e2db 100644 --- a/src/phasespace_surface/meson.build +++ b/src/phasespace_surface/meson.build @@ -1,11 +1,10 @@ -executable('phasespace_surface', +exec_name='phasespace_surface' +executable(exec_name, 'main.f90', 'options.f90', 'type_phasespacesurface.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('phasespace_surface', pointing_to: meson.project_build_root() / 'bin/phasespace_surface', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/phonon_dispersion_relations/meson.build b/src/phonon_dispersion_relations/meson.build index c7de5506..23a377e1 100644 --- a/src/phonon_dispersion_relations/meson.build +++ b/src/phonon_dispersion_relations/meson.build @@ -1,4 +1,5 @@ -executable('phonon_dispersion_relations', +exec_name='phonon_dispersion_relations' +executable(exec_name, 'activity.f90', 'densityplots.f90', 'densityplots_stuntscattering.f90', @@ -9,8 +10,6 @@ executable('phonon_dispersion_relations', 'velocitydos.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('phonon_dispersion_relations', pointing_to: meson.project_build_root() / 'bin/phonon_dispersion_relations', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/refine_structure/meson.build b/src/refine_structure/meson.build index 1cf29c17..5eabdf75 100644 --- a/src/refine_structure/meson.build +++ b/src/refine_structure/meson.build @@ -1,4 +1,5 @@ -executable('refine_structure', +exec_name='refine_structure' +executable(exec_name, 'lo_spacegroup_applyoperation.f90', 'lo_spacegroup_charactertable.f90', 'lo_spacegroup.f90', @@ -9,8 +10,6 @@ executable('refine_structure', 'refine.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('refine_structure', pointing_to: meson.project_build_root() / 'bin/refine_structure', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name/ exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/samples_from_md/meson.build b/src/samples_from_md/meson.build index 7f9d82b5..cbd796d2 100644 --- a/src/samples_from_md/meson.build +++ b/src/samples_from_md/meson.build @@ -1,10 +1,9 @@ -executable('samples_from_md', +exec_name='samples_from_md' +executable(exec_name, 'main.f90', 'options.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('samples_from_md', pointing_to: meson.project_build_root() / 'bin/samples_from_md', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/thermal_conductivity/meson.build b/src/thermal_conductivity/meson.build index ef3c74ec..90c616ea 100644 --- a/src/thermal_conductivity/meson.build +++ b/src/thermal_conductivity/meson.build @@ -1,4 +1,5 @@ -executable('thermal_conductivity', +exec_name='thermal_conductivity' +executable(exec_name, 'cumulative_kappa.f90', 'kappa.f90', 'main.f90', @@ -6,8 +7,6 @@ executable('thermal_conductivity', 'scattering.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('thermal_conductivity', pointing_to: meson.project_build_root() / 'bin/thermal_conductivity', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin') diff --git a/src/thermal_conductivity_2023/meson.build b/src/thermal_conductivity_2023/meson.build index 39f7bcd8..97799f91 100644 --- a/src/thermal_conductivity_2023/meson.build +++ b/src/thermal_conductivity_2023/meson.build @@ -1,4 +1,5 @@ -executable('thermal_conductivity_2023', +exec_name='thermal_conductivity_2023' +executable(exec_name, 'main.f90', 'mfp.f90', 'options.f90', @@ -7,8 +8,6 @@ executable('thermal_conductivity_2023', 'scatteringstrengths.f90', link_with: [libolle, libflap], include_directories: ['../libolle', '../libflap'], - dependencies: dep_all, - install: true, - install_dir: meson.project_build_root() / 'bin') + dependencies: dep_all) -install_symlink('thermal_conductivity_2023', pointing_to: meson.project_build_root() / 'bin/thermal_conductivity_2023', install_dir: meson.project_source_root() / 'bin') +install_symlink(exec_name, pointing_to: meson.project_build_root() / 'src' / exec_name / exec_name, install_dir: meson.project_source_root() / 'bin')