From 3d27e5c0abb90d059d1a5c0a91c48c4f4bb63d45 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Thu, 26 Jan 2023 17:10:44 +0100 Subject: [PATCH 01/16] Add pre-commit Signed-off-by: Cristian Le --- .gitignore | 4 ++++ .pre-commit-config.yaml | 31 +++++++++++++++++++++++++++++++ pyproject.toml | 17 +++++++++++++++++ requirements-dev.txt | 1 + 4 files changed, 53 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml create mode 100644 requirements-dev.txt diff --git a/.gitignore b/.gitignore index 188e2add8d..50d75f5d04 100644 --- a/.gitignore +++ b/.gitignore @@ -223,3 +223,7 @@ src/.fortran_dependencies/ # /testsuite/photo_electron/ /testsuite/photo_electron/.log + +### Custom development +/venv +/_build-pre-commit diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..fd1a3c96c3 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,31 @@ +default_stages: [push, manual] +exclude: | + (?x)^( + external_libs/| + liboct_parser/| + share/ + ) +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-yaml + - id: check-toml + - id: trailing-whitespace + stages: [commit, push, manual] + - id: no-commit-to-branch + args: [ --branch=main ] + stages: [commit, push, manual] + - id: mixed-line-ending + args: [ --fix=lf ] + - id: end-of-file-fixer + stages: [commit, push, manual] + - id: check-case-conflict + - id: check-added-large-files + # TODO: Disabled because it is too aggressive + # https://github.com/cphyc/fortran-linter/issues/19 +# - repo: https://github.com/cphyc/fortran-linter +# rev: v1.1.2 +# hooks: +# - id: fortran-linter +# args: [--syntax-only] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..c0c717af62 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[project] +name = "octopus-devtools" +version = "0.0.0" +requires-python = ">=3.7" +description = "This is currently a dummy octopus project to install the necessary environment requirements. Python bindings: TBD" +readme = "README" +license = { text = "GPL-v2" } +authors = [ ] +maintainers = [ + {name="Cristian Le", email="cristian.le@mpsd.mpg.de"}, +] + +[project.optional-dependencies] +testing = [ ] +doc = [ ] +benchmark = [ ] +dev = [ "pre-commit" ] diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000000..416634f528 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1 @@ +pre-commit -- GitLab From 4576867ee51c8f71f1e3ecab0a271e661283b902 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Wed, 15 Feb 2023 11:17:44 +0100 Subject: [PATCH 02/16] Missing include in share_directory.hpp Signed-off-by: Cristian Le --- src/species/share_directory.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/species/share_directory.hpp b/src/species/share_directory.hpp index bfe94ffaee..e3bbbceb9e 100644 --- a/src/species/share_directory.hpp +++ b/src/species/share_directory.hpp @@ -20,6 +20,7 @@ */ #include +#include "config.h" namespace pseudopotential { -- GitLab From 6396f30d77c317db1cb4a562f40624f443c26416 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Wed, 15 Feb 2023 11:18:48 +0100 Subject: [PATCH 03/16] Use NDEBUG instead of pearl substitution Signed-off-by: Cristian Le --- src/basic/messages.F90 | 2 ++ src/include/global.h | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/basic/messages.F90 b/src/basic/messages.F90 index f504894fad..c351fa7002 100644 --- a/src/basic/messages.F90 +++ b/src/basic/messages.F90 @@ -49,8 +49,10 @@ module messages_oct_m alloc_error, & dealloc_error, & messages_input_error, & +#ifndef NDEBUG push_sub, & pop_sub, & +#endif messages_print_stress, & messages_print_var_info, & messages_print_var_option, & diff --git a/src/include/global.h b/src/include/global.h index fdbadb0700..60586e9264 100644 --- a/src/include/global.h +++ b/src/include/global.h @@ -246,6 +246,7 @@ ! and finish it with the PUSH_SUB and POP_SUB macros, which are these ! pieces of code that call the push_sub and pop_sub routines defined ! in the messages_m module. +#ifndef NDEBUG #define PUSH_SUB(routine) \ if(debug%trace) then; if(not_in_openmp()) then; CARDINAL \ call push_sub(__FILE__+"." ACARDINAL +TOSTRING(routine)); CARDINAL \ @@ -256,6 +257,10 @@ call pop_sub(__FILE__+"." ACARDINAL +TOSTRING(routine)); CARDINAL \ endif; endif; \ CARDINAL +#else +#define PUSH_SUB(routine) +#define POP_SUB(routine) +#endif !! Local Variables: !! mode: f90 -- GitLab From e1e8248a8c7f583de20744db457d18e7c5ad0784 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Mon, 14 Nov 2022 18:38:57 +0100 Subject: [PATCH 04/16] Initial cmake buildtool migration Signed-off-by: Cristian Le --- .gitignore | 90 +++++++- CMakeLists.txt | 31 +++ cmake/FindFFTW.cmake | 419 +++++++++++++++++++++++++++++++++++++ cmake/mock_autotools.cmake | 12 ++ doc/CMakeLists.txt | 0 src/CMakeLists.txt | 50 +++++ src/include/config.h.in | 209 ++++++++++++++++++ 7 files changed, 810 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt create mode 100644 cmake/FindFFTW.cmake create mode 100644 cmake/mock_autotools.cmake create mode 100644 doc/CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 src/include/config.h.in diff --git a/.gitignore b/.gitignore index 50d75f5d04..612ad7b5b3 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,7 @@ autom4te.cache autogen* INSTALL configure -config.h.in +/config.h.in build-aux build-stamp semantic.cache @@ -224,6 +224,94 @@ src/.fortran_dependencies/ # /testsuite/photo_electron/ /testsuite/photo_electron/.log +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### CMake template +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + + ### Custom development /venv /_build-pre-commit +/.idea/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..884556bb9f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.23) +project(Octopus VERSION 12.1 + LANGUAGES C Fortran) + +set(CMAKE_CXX_STANDARD 20) + +# Add custom/third-party cmake modules +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") + +# Build tools +find_package(PkgConfig REQUIRED) + +# Compute libraries +find_package(MPI) +find_package(BLAS REQUIRED) +find_package(LAPACK REQUIRED) +find_package(FFTW REQUIRED) +find_package(GSL REQUIRED) +find_package(Libxc 4.0 QUIET) +IF (NOT ${Libxc_FOUND}) + pkg_check_modules(REQUIRED libxc>=4.0) +ENDIF () + +# Mimic autotools +include(cmake/mock_autotools.cmake) + +# Main project +add_subdirectory(src) + +# Generate documentation +add_subdirectory(doc) \ No newline at end of file diff --git a/cmake/FindFFTW.cmake b/cmake/FindFFTW.cmake new file mode 100644 index 0000000000..f47f390d6d --- /dev/null +++ b/cmake/FindFFTW.cmake @@ -0,0 +1,419 @@ +# - Find the FFTW library +# +# Original version of this file: +# Copyright (c) 2015, Wenzel Jakob +# https://github.com/wjakob/layerlab/blob/master/cmake/FindFFTW.cmake, commit 4d58bfdc28891b4f9373dfe46239dda5a0b561c6 +# Modifications: +# Copyright (c) 2017, Patrick Bos +# +# Usage: +# find_package(FFTW [REQUIRED] [QUIET] [COMPONENTS component1 ... componentX] ) +# +# It sets the following variables: +# FFTW_FOUND ... true if fftw is found on the system +# FFTW_[component]_LIB_FOUND ... true if the component is found on the system (see components below) +# FFTW_LIBRARIES ... full paths to all found fftw libraries +# FFTW_[component]_LIB ... full path to one of the components (see below) +# FFTW_INCLUDE_DIRS ... fftw include directory paths +# +# The following variables will be checked by the function +# FFTW_USE_STATIC_LIBS ... if true, only static libraries are found, otherwise both static and shared. +# FFTW_ROOT ... if set, the libraries are exclusively searched +# under this path +# +# This package supports the following components: +# FLOAT_LIB +# DOUBLE_LIB +# LONGDOUBLE_LIB +# FLOAT_THREADS_LIB +# DOUBLE_THREADS_LIB +# LONGDOUBLE_THREADS_LIB +# FLOAT_OPENMP_LIB +# DOUBLE_OPENMP_LIB +# LONGDOUBLE_OPENMP_LIB +# + +# TODO (maybe): extend with ExternalProject download + build option +# TODO: put on conda-forge + + +if( NOT FFTW_ROOT AND DEFINED ENV{FFTWDIR} ) + set( FFTW_ROOT $ENV{FFTWDIR} ) +endif() + +# Check if we can use PkgConfig +find_package(PkgConfig) + +#Determine from PKG +if( PKG_CONFIG_FOUND AND NOT FFTW_ROOT ) + pkg_check_modules( PKG_FFTW QUIET "fftw3" ) +endif() + +#Check whether to search static or dynamic libs +set( CMAKE_FIND_LIBRARY_SUFFIXES_SAV ${CMAKE_FIND_LIBRARY_SUFFIXES} ) + +if( ${FFTW_USE_STATIC_LIBS} ) + set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX} ) +else() + set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SAV} ) +endif() + +if( FFTW_ROOT ) + # find libs + + find_library( + FFTW_DOUBLE_LIB + NAMES "fftw3" libfftw3-3 + PATHS ${FFTW_ROOT} + PATH_SUFFIXES "lib" "lib64" + NO_DEFAULT_PATH + ) + + find_library( + FFTW_DOUBLE_THREADS_LIB + NAMES "fftw3_threads" + PATHS ${FFTW_ROOT} + PATH_SUFFIXES "lib" "lib64" + NO_DEFAULT_PATH + ) + + find_library( + FFTW_DOUBLE_OPENMP_LIB + NAMES "fftw3_omp" + PATHS ${FFTW_ROOT} + PATH_SUFFIXES "lib" "lib64" + NO_DEFAULT_PATH + ) + + find_library( + FFTW_DOUBLE_MPI_LIB + NAMES "fftw3_mpi" + PATHS ${FFTW_ROOT} + PATH_SUFFIXES "lib" "lib64" + NO_DEFAULT_PATH + ) + + find_library( + FFTW_FLOAT_LIB + NAMES "fftw3f" libfftw3f-3 + PATHS ${FFTW_ROOT} + PATH_SUFFIXES "lib" "lib64" + NO_DEFAULT_PATH + ) + + find_library( + FFTW_FLOAT_THREADS_LIB + NAMES "fftw3f_threads" + PATHS ${FFTW_ROOT} + PATH_SUFFIXES "lib" "lib64" + NO_DEFAULT_PATH + ) + + find_library( + FFTW_FLOAT_OPENMP_LIB + NAMES "fftw3f_omp" + PATHS ${FFTW_ROOT} + PATH_SUFFIXES "lib" "lib64" + NO_DEFAULT_PATH + ) + + find_library( + FFTW_FLOAT_MPI_LIB + NAMES "fftw3f_mpi" + PATHS ${FFTW_ROOT} + PATH_SUFFIXES "lib" "lib64" + NO_DEFAULT_PATH + ) + + find_library( + FFTW_LONGDOUBLE_LIB + NAMES "fftw3l" libfftw3l-3 + PATHS ${FFTW_ROOT} + PATH_SUFFIXES "lib" "lib64" + NO_DEFAULT_PATH + ) + + find_library( + FFTW_LONGDOUBLE_THREADS_LIB + NAMES "fftw3l_threads" + PATHS ${FFTW_ROOT} + PATH_SUFFIXES "lib" "lib64" + NO_DEFAULT_PATH + ) + + find_library( + FFTW_LONGDOUBLE_OPENMP_LIB + NAMES "fftw3l_omp" + PATHS ${FFTW_ROOT} + PATH_SUFFIXES "lib" "lib64" + NO_DEFAULT_PATH + ) + + find_library( + FFTW_LONGDOUBLE_MPI_LIB + NAMES "fftw3l_mpi" + PATHS ${FFTW_ROOT} + PATH_SUFFIXES "lib" "lib64" + NO_DEFAULT_PATH + ) + + #find includes + find_path(FFTW_INCLUDE_DIRS + NAMES "fftw3.h" + PATHS ${FFTW_ROOT} + PATH_SUFFIXES "include" + NO_DEFAULT_PATH + ) + +else() + + find_library( + FFTW_DOUBLE_LIB + NAMES "fftw3" + PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} + ) + + find_library( + FFTW_DOUBLE_THREADS_LIB + NAMES "fftw3_threads" + PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} + ) + + find_library( + FFTW_DOUBLE_OPENMP_LIB + NAMES "fftw3_omp" + PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} + ) + + find_library( + FFTW_DOUBLE_MPI_LIB + NAMES "fftw3_mpi" + PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} + ) + + find_library( + FFTW_FLOAT_LIB + NAMES "fftw3f" + PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} + ) + + find_library( + FFTW_FLOAT_THREADS_LIB + NAMES "fftw3f_threads" + PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} + ) + + find_library( + FFTW_FLOAT_OPENMP_LIB + NAMES "fftw3f_omp" + PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} + ) + + find_library( + FFTW_FLOAT_MPI_LIB + NAMES "fftw3f_mpi" + PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} + ) + + find_library( + FFTW_LONGDOUBLE_LIB + NAMES "fftw3l" + PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} + ) + + find_library( + FFTW_LONGDOUBLE_THREADS_LIB + NAMES "fftw3l_threads" + PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} + ) + + find_library(FFTW_LONGDOUBLE_OPENMP_LIB + NAMES "fftw3l_omp" + PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} + ) + + find_library(FFTW_LONGDOUBLE_MPI_LIB + NAMES "fftw3l_mpi" + PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} + ) + + find_path(FFTW_INCLUDE_DIRS + NAMES "fftw3.h" + PATHS ${PKG_FFTW_INCLUDE_DIRS} ${INCLUDE_INSTALL_DIR} + ) + +endif( FFTW_ROOT ) + +#--------------------------------------- components + +if (FFTW_DOUBLE_LIB) + set(FFTW_DOUBLE_LIB_FOUND TRUE) + set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_DOUBLE_LIB}) + add_library(FFTW::Double INTERFACE IMPORTED) + set_target_properties(FFTW::Double + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFTW_DOUBLE_LIB}" + ) +else() + set(FFTW_DOUBLE_LIB_FOUND FALSE) +endif() + +if (FFTW_FLOAT_LIB) + set(FFTW_FLOAT_LIB_FOUND TRUE) + set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_FLOAT_LIB}) + add_library(FFTW::Float INTERFACE IMPORTED) + set_target_properties(FFTW::Float + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFTW_FLOAT_LIB}" + ) +else() + set(FFTW_FLOAT_LIB_FOUND FALSE) +endif() + +if (FFTW_LONGDOUBLE_LIB) + set(FFTW_LONGDOUBLE_LIB_FOUND TRUE) + set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_LONGDOUBLE_LIB}) + add_library(FFTW::LongDouble INTERFACE IMPORTED) + set_target_properties(FFTW::LongDouble + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFTW_LONGDOUBLE_LIB}" + ) +else() + set(FFTW_LONGDOUBLE_LIB_FOUND FALSE) +endif() + +if (FFTW_DOUBLE_THREADS_LIB) + set(FFTW_DOUBLE_THREADS_LIB_FOUND TRUE) + set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_DOUBLE_THREADS_LIB}) + add_library(FFTW::DoubleThreads INTERFACE IMPORTED) + set_target_properties(FFTW::DoubleThreads + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFTW_DOUBLE_THREADS_LIB}" + ) +else() + set(FFTW_DOUBLE_THREADS_LIB_FOUND FALSE) +endif() + +if (FFTW_FLOAT_THREADS_LIB) + set(FFTW_FLOAT_THREADS_LIB_FOUND TRUE) + set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_FLOAT_THREADS_LIB}) + add_library(FFTW::FloatThreads INTERFACE IMPORTED) + set_target_properties(FFTW::FloatThreads + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFTW_FLOAT_THREADS_LIB}" + ) +else() + set(FFTW_FLOAT_THREADS_LIB_FOUND FALSE) +endif() + +if (FFTW_LONGDOUBLE_THREADS_LIB) + set(FFTW_LONGDOUBLE_THREADS_LIB_FOUND TRUE) + set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_LONGDOUBLE_THREADS_LIB}) + add_library(FFTW::LongDoubleThreads INTERFACE IMPORTED) + set_target_properties(FFTW::LongDoubleThreads + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFTW_LONGDOUBLE_THREADS_LIB}" + ) +else() + set(FFTW_LONGDOUBLE_THREADS_LIB_FOUND FALSE) +endif() + +if (FFTW_DOUBLE_OPENMP_LIB) + set(FFTW_DOUBLE_OPENMP_LIB_FOUND TRUE) + set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_DOUBLE_OPENMP_LIB}) + add_library(FFTW::DoubleOpenMP INTERFACE IMPORTED) + set_target_properties(FFTW::DoubleOpenMP + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFTW_DOUBLE_OPENMP_LIB}" + ) +else() + set(FFTW_DOUBLE_OPENMP_LIB_FOUND FALSE) +endif() + +if (FFTW_FLOAT_OPENMP_LIB) + set(FFTW_FLOAT_OPENMP_LIB_FOUND TRUE) + set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_FLOAT_OPENMP_LIB}) + add_library(FFTW::FloatOpenMP INTERFACE IMPORTED) + set_target_properties(FFTW::FloatOpenMP + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFTW_FLOAT_OPENMP_LIB}" + ) +else() + set(FFTW_FLOAT_OPENMP_LIB_FOUND FALSE) +endif() + +if (FFTW_LONGDOUBLE_OPENMP_LIB) + set(FFTW_LONGDOUBLE_OPENMP_LIB_FOUND TRUE) + set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_LONGDOUBLE_OPENMP_LIB}) + add_library(FFTW::LongDoubleOpenMP INTERFACE IMPORTED) + set_target_properties(FFTW::LongDoubleOpenMP + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFTW_LONGDOUBLE_OPENMP_LIB}" + ) +else() + set(FFTW_LONGDOUBLE_OPENMP_LIB_FOUND FALSE) +endif() + +if (FFTW_DOUBLE_MPI_LIB) + set(FFTW_DOUBLE_MPI_LIB_FOUND TRUE) + set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_DOUBLE_MPI_LIB}) + add_library(FFTW::DoubleMPI INTERFACE IMPORTED) + set_target_properties(FFTW::DoubleMPI + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFTW_DOUBLE_MPI_LIB}" + ) +else() + set(FFTW_DOUBLE_MPI_LIB_FOUND FALSE) +endif() + +if (FFTW_FLOAT_MPI_LIB) + set(FFTW_FLOAT_MPI_LIB_FOUND TRUE) + set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_FLOAT_MPI_LIB}) + add_library(FFTW::FloatMPI INTERFACE IMPORTED) + set_target_properties(FFTW::FloatMPI + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFTW_FLOAT_MPI_LIB}" + ) +else() + set(FFTW_FLOAT_MPI_LIB_FOUND FALSE) +endif() + +if (FFTW_LONGDOUBLE_MPI_LIB) + set(FFTW_LONGDOUBLE_MPI_LIB_FOUND TRUE) + set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_LONGDOUBLE_MPI_LIB}) + add_library(FFTW::LongDoubleMPI INTERFACE IMPORTED) + set_target_properties(FFTW::LongDoubleMPI + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFTW_LONGDOUBLE_MPI_LIB}" + ) +else() + set(FFTW_LONGDOUBLE_MPI_LIB_FOUND FALSE) +endif() + +#--------------------------------------- end components + +set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SAV} ) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(FFTW + REQUIRED_VARS FFTW_INCLUDE_DIRS + HANDLE_COMPONENTS + ) + +mark_as_advanced( + FFTW_INCLUDE_DIRS + FFTW_LIBRARIES + FFTW_FLOAT_LIB + FFTW_DOUBLE_LIB + FFTW_LONGDOUBLE_LIB + FFTW_FLOAT_THREADS_LIB + FFTW_DOUBLE_THREADS_LIB + FFTW_LONGDOUBLE_THREADS_LIB + FFTW_FLOAT_OPENMP_LIB + FFTW_DOUBLE_OPENMP_LIB + FFTW_LONGDOUBLE_OPENMP_LIB + FFTW_FLOAT_MPI_LIB + FFTW_DOUBLE_MPI_LIB + FFTW_LONGDOUBLE_MPI_LIB +) diff --git a/cmake/mock_autotools.cmake b/cmake/mock_autotools.cmake new file mode 100644 index 0000000000..2a3faf69a3 --- /dev/null +++ b/cmake/mock_autotools.cmake @@ -0,0 +1,12 @@ +string(TIMESTAMP BUILD_TIME) +execute_process( + COMMAND git log -1 --format=%h + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +if (MPI_FORTRAN_FOUND) + set(MPI_MOD 1) + set(HAVE_MPI 1) +endif () \ No newline at end of file diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000000..dfb5201388 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,50 @@ +#SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -save-temps=obj") +#SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}") +#SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffixed-line-length-none") + + + +add_library(oct STATIC + basic/command_line.F90 + basic/varinfo.F90 + basic/global.F90 + basic/kind.F90 + basic/string.F90 + basic/loct.F90 + basic/mpi.F90 + basic/blacs.F90 + basic/mpi_debug.F90 + basic/hardware.F90 + basic/getopt_f.c + basic/varinfo_low.c + basic/oct_f.c + basic/varia.c) +if (MPI_FORTRAN_FOUND) + target_link_libraries(oct PUBLIC + MPI::MPI_Fortran) +else () +# target_sources(oct PUBLIC) +endif () + +target_include_directories(oct PUBLIC + include ${CMAKE_CURRENT_BINARY_DIR}/include) +configure_file(include/config.h.in include/config_F90.h) +configure_file(include/config.h.in include/config.h) + +# TODO: Switch to CMake native method or equivalent so that it can be indexed +#configure_file(include/options.h.in include/options.h) +#configure_file(include/defaults.h.in include/defaults.h) +add_custom_target(VarInfo + COMMAND ${PROJECT_SOURCE_DIR}/scripts/mk_varinfo.pl + -s ${PROJECT_SOURCE_DIR} + -b ${PROJECT_BINARY_DIR} + COMMENT "Generating variable information:" + ) +add_dependencies(oct VarInfo) + +target_include_directories(oct PUBLIC + ../liboct_parser) + +add_executable(oct-help + utils/help.F90) +target_link_libraries(oct-help PRIVATE oct) \ No newline at end of file diff --git a/src/include/config.h.in b/src/include/config.h.in new file mode 100644 index 0000000000..287cad95ca --- /dev/null +++ b/src/include/config.h.in @@ -0,0 +1,209 @@ +#define BUILD_TIME "@BUILD_TIME@" +#define PACKAGE_VERSION "@CMAKE_PROJECT_VERSION@" +#define SHARE_DIR "" + +#define CC "@CMAKE_C_COMPILER@" +/* #undef CC_FORTRAN_INT */ +#define CFLAGS "@CMAKE_C_FLAGS" +#define CFLAGS_EXTRA "" +#define CXX "@CMAKE_CXX_COMPILER@" +#define CXXFLAGS "@CMAKE_CXX_FLAGS" +#define CXXFLAGS_EXTRA "" + +/* #undef C_ALLOCA */ +/* #undef F90_ACCEPTS_LINE_NUMBERS */ +#define FC "@CMAKE_Fortran_COMPILER@" +#define FCFLAGS "@CMAKE_Fortran_FLAGS" +#define FCFLAGS_EXTRA "" + +#define FC_COMMAND_LINE_ARGUMENTS 2003 +/* #undef FC_COMMAND_LINE_IMPLICIT */ +/* #undef FC_COMMAND_LINE_INCLUDE */ +/* #undef FC_COMMAND_LINE_INTRINSIC */ +/* #undef FC_COMMAND_LINE_MODULE */ +/* #undef FC_DUMMY_MAIN */ +/* #undef FC_DUMMY_MAIN_EQ_F77 */ +/* #define FC_INTEGER_SIZE 4 */ + +#ifdef __GFORTRAN__ +#define FC_FUNC(name,NAME) name/**/_ +#define FC_FUNC_(name,NAME) name/**/_ +#else +#define FC_FUNC(name,NAME) name ## _ +#define FC_FUNC_(name,NAME) name ## _ +#endif +#define GIT_COMMIT "@GIT_HASH@" + + +#define HAVE_STDINT_H 1 + +#define SIZEOF_VOIDP @CMAKE_SIZEOF_VOID_P@ + +#define LONG_LINES + + + +#cmakedefine MPI_MOD + +#cmakedefine HAVE_MPI + +/* From autotools: */ + +/* The size of a Fortran integer */ + + +/* #define HAVE_ALLOCA 1 */ +/* #define HAVE_ALLOCA_H 1 */ +/* #define HAVE_ALPHASORT 1 */ +/* #undef HAVE_BERKELEYGW */ +/* #undef HAVE_BLACS */ +/* #define HAVE_BLAS 1 */ +/* #undef HAVE_BLUE_GENE */ +/* #undef HAVE_BLUE_GENE_Q */ +/* #undef HAVE_BOOST */ +/* #define HAVE_BUILTIN_PREFETCH 1 */ +/* #undef HAVE_CGAL */ +/* #undef HAVE_CLBLAS */ +/* #undef HAVE_CLFFT */ +/* #define HAVE_CLOSEDIR 1 */ +/* #undef HAVE_CL_CL_H */ +/* #define HAVE_COMP_ISF 1 */ +/* #undef HAVE_COMP_METIS */ +/* #undef HAVE_CUDA */ +/* #undef HAVE_CUDA_MPI */ +/* #undef HAVE_DFTBPLUS */ +/* #undef HAVE_DFTBPLUS_DEVEL */ +/* #define HAVE_DIRENT_H 1 */ +/* #undef HAVE_DLFCN_H */ +/* #undef HAVE_ELPA */ +/* #define HAVE_ERRNO_H 1 */ +/* #undef HAVE_ETSF_IO */ +/* #define HAVE_FC_COMPILER_VERSION 1 */ +/* #define HAVE_FC_SIZEOF 1 */ +/* #define HAVE_FFTW3 1 */ +/* #undef HAVE_FFTW3_MPI */ +/* #define HAVE_FFTW3_THREADS 1 */ +/* #define HAVE_FLUSH 1 */ +/* #undef HAVE_FMA3 */ +/* #undef HAVE_FMA4 */ +/* #define HAVE_FORTRAN_LOC 1 */ +/* #undef HAVE_FUTILE */ +/* #undef HAVE_GDLIB */ +/* #undef HAVE_GD_FONTCONFIG */ +/* #undef HAVE_GD_FREETYPE */ +/* #undef HAVE_GD_GIF */ +/* #undef HAVE_GD_JPEG */ +/* #undef HAVE_GD_PNG */ +/* #undef HAVE_GD_XPM */ +/* #define HAVE_GETOPT_LONG 1 */ +/* #define HAVE_GETPID 1 */ +/* #define HAVE_GETTIMEOFDAY 1 */ +/* #define HAVE_INTTYPES_H 1 */ +/* #define HAVE_IOCTL 1 */ +/* #define HAVE_LAPACK 1 */ +/* #undef HAVE_LIBCUBLAS */ +/* #undef HAVE_LIBCUDA */ +/* #undef HAVE_LIBCUFFT */ +/* #undef HAVE_LIBFM */ +/* #undef HAVE_LIBISF */ +/* #undef HAVE_LIBNVRTC */ +/* #undef HAVE_LIBVDWXC */ +/* #undef HAVE_LIBVDWXC_MPI */ +/* #define HAVE_LIBXC5 1 */ +/* #define HAVE_LIBXC_FXC 1 */ +/* #define HAVE_LIBXC_KXC 1 */ +/* #undef HAVE_LIKWID */ +/* #define HAVE_M128D 1 */ +/* #undef HAVE_M256D */ +/* #undef HAVE_M512D */ +/* #undef HAVE_METIS */ +/* #undef HAVE_MPI */ +/* #define HAVE_NANOSLEEP 1 */ +/* #undef HAVE_NDIR_H */ +/* #undef HAVE_NETCDF */ +/* #undef HAVE_NFFT */ +/* #undef HAVE_NLOPT */ +/* #undef HAVE_NVTX */ +/* #undef HAVE_OPENCL */ +/* #undef HAVE_OPENCL_CL_H */ +/* #undef HAVE_OPENMP */ +/* #undef HAVE_PARMETIS */ +/* #define HAVE_PERROR 1 */ +/* #undef HAVE_PFFT */ +/* #undef HAVE_PNFFT */ +/* #undef HAVE_POKE */ +/* #undef HAVE_PSOLVER */ +/* #undef HAVE_PSPIO */ +/* #define HAVE_READDIR 1 */ +/* #define HAVE_SBRK 1 */ +/* #undef HAVE_SCALAPACK */ +/* #define HAVE_SCANDIR 1 */ +/* #define HAVE_SIGACTION 1 */ +/* #define HAVE_SIGNAL_H 1 */ +/* #undef HAVE_SPARSKIT */ +/* #undef HAVE_STAT_EMPTY_STRING_BUG */ +/* #define HAVE_STDINT_H 1 */ +/* #define HAVE_STDIO_H 1 */ +/* #define HAVE_STDLIB_H 1 */ +/* #define HAVE_STRCASESTR 1 */ +/* #define HAVE_STRCHR 1 */ +/* #define HAVE_STRINGS_H 1 */ +/* #define HAVE_STRING_H 1 */ +/* #define HAVE_STRNDUP 1 */ +/* #define HAVE_STRSIGNAL 1 */ +/* #define HAVE_STRTOD 1 */ +/* #define HAVE_SYSCONF 1 */ +/* #undef HAVE_SYS_DIR_H */ +/* #undef HAVE_SYS_NDIR_H */ +/* #define HAVE_SYS_STAT_H 1 */ +/* #define HAVE_SYS_TIME_H 1 */ +/* #define HAVE_SYS_TYPES_H 1 */ +/* #define HAVE_TCGETPGRP 1 */ +/* #define HAVE_UINT32_T 1 */ +/* #define HAVE_UINT64_T 1 */ +/* #define HAVE_UNAME 1 */ +/* #define HAVE_UNISTD_H 1 */ +/* #define HAVE_VEC 1 */ +/* #undef HAVE_WINDOWS_H */ +/* #undef HAVE_YAML */ +/* #define ISO_C_BINDING 1 */ +/* #define LONG_LINES 1 */ +/* #define LSTAT_FOLLOWS_SLASHED_SYMLINK 1 */ +/* #define LT_OBJDIR ".libs/" */ +/* #define MAX_DIM 3 */ +/* #define METIS_IDXTYPEWIDTH 32 */ +/* #undef MPI_H */ +/* #undef MPI_MOD */ +/* #undef NDEBUG */ +/* #define OCT_ARCH x86_64 */ +/* #define PACKAGE "octopus" */ +/* #define PACKAGE_BUGREPORT "octopus-devel@tddft.org" */ +/* #define PACKAGE_NAME "Octopus" */ +/* #define PACKAGE_STRING "Octopus bimaculatus" */ +/* #define PACKAGE_TARNAME "octopus" */ +/* #define PACKAGE_URL "" */ +/* #define PACKAGE_VERSION "bimaculatus" */ +/* #define SIZEOF_SIZE_T 8 */ +/* #define SIZEOF_UNSIGNED_INT 4 */ +/* #define SIZEOF_UNSIGNED_LONG 8 */ +/* #define SIZEOF_UNSIGNED_LONG_LONG 8 */ +/* #define SIZEOF_VOIDP 8 */ +/* #undef STACK_DIRECTION */ +/* #define STDC_HEADERS 1 */ +/* #define TIME_WITH_SYS_TIME 1 */ +/* #define TLS_SPECIFIER __thread */ +/* #define VERSION "bimaculatus" */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +/* #ifndef __cplusplus */ +/* #undef inline */ +/* #endif */ +/* #undef pid_t */ +/* #define restrict __restrict__ */ +/* #if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__ */ +/* # define _Restrict */ +/* # define __restrict__ */ +/* #endif */ +/* #undef size_t */ \ No newline at end of file -- GitLab From 6cf1ca02bcef4540090409eeeabd7c33b135f594 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Tue, 31 Jan 2023 12:14:50 +0100 Subject: [PATCH 05/16] Add cmake pre-commit Signed-off-by: Cristian Le --- .gitignore | 3 ++- .pre-commit-config.yaml | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 612ad7b5b3..115ea6718a 100644 --- a/.gitignore +++ b/.gitignore @@ -141,7 +141,7 @@ src/.fortran_dependencies/ /share/recipes/da/varinfo /share/recipes/da/varinfo_orig /share/recipes/da/variables -/share/recipes/da/variables.xml +/share/recipes/da/variables.xml # /share/recipes/en/ /share/recipes/en/varinfo @@ -315,3 +315,4 @@ _deps /venv /_build-pre-commit /.idea/ +/compile_commands.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fd1a3c96c3..204113b034 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,6 +22,47 @@ repos: stages: [commit, push, manual] - id: check-case-conflict - id: check-added-large-files + - repo: https://github.com/Takishima/cmake-pre-commit-hooks + rev: v1.7.0 + hooks: + - id: clang-format + exclude: | + (?x)( + ^external_libs/| + ^liboct_parser/| + ^share/| + ^.idea/| + global\.h$ + ) + args: + - '-B_build-pre-commit' + - '-DUSE_BUNDLED=ON' + - '-i' + stages: [push, manual] + - id: clang-tidy + exclude: | + (?x)( + ^external_libs/| + ^liboct_parser/| + ^share/| + ^.idea/| + global\.h$ + ) + args: + - '-B_build-pre-commit' + - '-DUSE_BUNDLED=ON' + # TODO: This should be enforced at push. Please fix the issues + stages: [manual] + - id: lizard + exclude: | + (?x)( + ^external_libs/| + ^liboct_parser/| + ^share/| + ^.idea/| + global\.h$ + ) + stages: [manual] # TODO: Disabled because it is too aggressive # https://github.com/cphyc/fortran-linter/issues/19 # - repo: https://github.com/cphyc/fortran-linter -- GitLab From c166d3709db6f926d263465729a49a30830dd2bd Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Mon, 21 Nov 2022 18:54:08 +0100 Subject: [PATCH 06/16] Configure SHARE_DIR in cmake Signed-off-by: Cristian Le --- scripts/mk_varinfo.pl | 13 +++++++++++-- src/include/config.h.in | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/mk_varinfo.pl b/scripts/mk_varinfo.pl index 53669bb444..2ff4df92b7 100755 --- a/scripts/mk_varinfo.pl +++ b/scripts/mk_varinfo.pl @@ -21,6 +21,7 @@ use Getopt::Std; use File::Find; +use File::Path qw(make_path); getopts "hs:b:"; if($opt_h) { @@ -44,10 +45,10 @@ $src = "$top_srcdir/src"; $share = "$top_builddir/share"; $include = "$top_builddir/src/include"; -if(!-d $src && !-d $share) { +if(!-d $src || !-d $top_builddir) { print stderr <<"EndOfErrorMsg"; -The src and share directory could not be found. Please run +The src or build directory could not be found. Please run this script from the octopus toplevel directory or set -s and -b options appropriately. @@ -56,6 +57,14 @@ EndOfErrorMsg exit 1; } +# Make missing build directories if missing +if(!-d $share) { + make_path($share) +} +if(!-d $include) { + make_path($include) +} + # get all files named *.F90 recursively @F90 = (); finddepth (sub{ push @F90, $File::Find::name if /\.F90$/ }, "$src"); diff --git a/src/include/config.h.in b/src/include/config.h.in index 287cad95ca..f4363f70bb 100644 --- a/src/include/config.h.in +++ b/src/include/config.h.in @@ -1,6 +1,7 @@ #define BUILD_TIME "@BUILD_TIME@" #define PACKAGE_VERSION "@CMAKE_PROJECT_VERSION@" -#define SHARE_DIR "" +/* TODO: Implement a search function via $OCTOPUS_DIR/share:$(pwd)/share:/usr/share/octopus */ +#define SHARE_DIR "@PROJECT_BINARY_DIR@/share" #define CC "@CMAKE_C_COMPILER@" /* #undef CC_FORTRAN_INT */ -- GitLab From 1ab0571025995f75d82fec369eb4db25ec5c4bc0 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Mon, 20 Feb 2023 19:11:01 +0100 Subject: [PATCH 07/16] Configure basic targets Signed-off-by: Cristian Le --- CMakeLists.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 884556bb9f..9a01615867 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,34 @@ IF (NOT ${Libxc_FOUND}) pkg_check_modules(REQUIRED libxc>=4.0) ENDIF () +# Define the main targets (binaries, libraries, virtual targets/interfaces) +# Note: other targets (e.g. oct-help) are defined in src/MakeLists.txt +# Common octopus base included in all targets +add_library(base_octopus STATIC) +# TODO: Switch to CMake native method or equivalent so that it can be indexed +#configure_file(include/options.h.in include/options.h) +#configure_file(include/defaults.h.in include/defaults.h) +add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/share/varinfo ${PROJECT_BINARY_DIR}/share/variables + COMMAND ${PROJECT_SOURCE_DIR}/scripts/mk_varinfo.pl + -s ${PROJECT_SOURCE_DIR} + -b ${PROJECT_BINARY_DIR} + COMMENT "Generating variable information:" + ) +add_custom_target(VarInfo DEPENDS ${PROJECT_BINARY_DIR}/share/varinfo ${PROJECT_BINARY_DIR}/share/variables) +# Auxiliary files +file(COPY share DESTINATION ${PROJECT_BINARY_DIR} + PATTERN *.am EXCLUDE) + +add_dependencies(base_octopus VarInfo) + +# Helper target for all fortran CLI executables +add_library(fortran_cli STATIC) +# Octopus library that we wish to expose +# TODO: Figure out the libraries we want to export +#add_library(liboctopus) +# Main octopus executable +add_executable(octopus) + # Mimic autotools include(cmake/mock_autotools.cmake) -- GitLab From db44ebaf8eee6e9a83ed06c53d7bca691799c0a0 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Sun, 20 Nov 2022 17:35:05 +0100 Subject: [PATCH 08/16] Configure cmake target Signed-off-by: Cristian Le --- CMakeLists.txt | 67 ++++++++- cmake/CheckFortranTypeSizes.cmake | 55 +++++++ cmake/mock_autotools.cmake | 86 ++++++++++- cmake/test_compiler.F90 | 4 + external_libs/CMakeLists.txt | 30 ++++ src/CMakeLists.txt | 68 +++------ src/basic/CMakeLists.txt | 89 ++++++++++++ src/basis_set/CMakeLists.txt | 16 +++ src/boxes/CMakeLists.txt | 29 ++++ src/classical/CMakeLists.txt | 12 ++ src/electrons/CMakeLists.txt | 64 +++++++++ src/grid/CMakeLists.txt | 95 ++++++++++++ src/hamiltonian/CMakeLists.txt | 71 +++++++++ src/include/CMakeLists.txt | 5 + src/include/config.h.in | 231 ++++++++++++------------------ src/interactions/CMakeLists.txt | 15 ++ src/ions/CMakeLists.txt | 28 ++++ src/main/CMakeLists.txt | 29 ++++ src/math/CMakeLists.txt | 44 ++++++ src/maxwell/CMakeLists.txt | 18 +++ src/multisystem/CMakeLists.txt | 35 +++++ src/opt_control/CMakeLists.txt | 13 ++ src/output/CMakeLists.txt | 17 +++ src/poisson/CMakeLists.txt | 25 ++++ src/scf/CMakeLists.txt | 30 ++++ src/species/CMakeLists.txt | 32 +++++ src/states/CMakeLists.txt | 37 +++++ src/sternheimer/CMakeLists.txt | 5 + src/td/CMakeLists.txt | 42 ++++++ src/utils/CMakeLists.txt | 83 +++++++++++ 30 files changed, 1179 insertions(+), 196 deletions(-) create mode 100644 cmake/CheckFortranTypeSizes.cmake create mode 100644 cmake/test_compiler.F90 create mode 100644 external_libs/CMakeLists.txt create mode 100644 src/basic/CMakeLists.txt create mode 100644 src/basis_set/CMakeLists.txt create mode 100644 src/boxes/CMakeLists.txt create mode 100644 src/classical/CMakeLists.txt create mode 100644 src/electrons/CMakeLists.txt create mode 100644 src/grid/CMakeLists.txt create mode 100644 src/hamiltonian/CMakeLists.txt create mode 100644 src/include/CMakeLists.txt create mode 100644 src/interactions/CMakeLists.txt create mode 100644 src/ions/CMakeLists.txt create mode 100644 src/main/CMakeLists.txt create mode 100644 src/math/CMakeLists.txt create mode 100644 src/maxwell/CMakeLists.txt create mode 100644 src/multisystem/CMakeLists.txt create mode 100644 src/opt_control/CMakeLists.txt create mode 100644 src/output/CMakeLists.txt create mode 100644 src/poisson/CMakeLists.txt create mode 100644 src/scf/CMakeLists.txt create mode 100644 src/species/CMakeLists.txt create mode 100644 src/states/CMakeLists.txt create mode 100644 src/sternheimer/CMakeLists.txt create mode 100644 src/td/CMakeLists.txt create mode 100644 src/utils/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a01615867..0331f0acf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,25 +1,75 @@ -cmake_minimum_required(VERSION 3.23) +cmake_minimum_required(VERSION 3.13) project(Octopus VERSION 12.1 - LANGUAGES C Fortran) + HOMEPAGE_URL https://www.octopus-code.org + DESCRIPTION "real-space, real-time, TDDFT code" + LANGUAGES C Fortran CXX) -set(CMAKE_CXX_STANDARD 20) +# TODO: Add the other language standards used +set(CMAKE_CXX_STANDARD 14) +# Basic setup # Add custom/third-party cmake modules set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") +# Build all fortran modules in a common module file for simpler loading +if (NOT CMAKE_Fortran_MODULE_DIRECTORY) + set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fortran_mods) +endif() +include_directories(${CMAKE_Fortran_MODULE_DIRECTORY}) + +# Add options +# TODO: Clarify max_dim of what +set(max-dim 3 + CACHE STRING "maximum number of dimensions Octopus can use; [default=3;must be>=3]") +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() # Build tools find_package(PkgConfig REQUIRED) # Compute libraries +## TODO: remove separation headers when all libraries included +## TODO: Specify the supported versions +## Natively available libraries to cmake find_package(MPI) +find_package(OpenMP) find_package(BLAS REQUIRED) find_package(LAPACK REQUIRED) +## Included in the cmake directory. Should deffer to packaged version or module find_package(FFTW REQUIRED) +## Other installed packages +## TODO: Require cmake targets over pkg-config once these are included find_package(GSL REQUIRED) -find_package(Libxc 4.0 QUIET) -IF (NOT ${Libxc_FOUND}) - pkg_check_modules(REQUIRED libxc>=4.0) -ENDIF () +find_package(Libxc 5.0 QUIET) +if(NOT Libxc_FOUND) + pkg_check_modules(Libxc_f03 REQUIRED libxcf03>=5.0 IMPORTED_TARGET) + set(Libxc_VERSION ${Libxc_f03_VERSION}) + set(Libxc_Target "PkgConfig::Libxc_f03") + # TODO: libxc is packaged wrong on fedora with respect to pkg-config files + include_directories(/usr/lib64/gfortran/modules) +# message(FATAL_ERROR +# "Libxc_f03_LINK_LIBRARIES = ${Libxc_f03_LINK_LIBRARIES} +# Libxc_f03_CFLAGS = ${Libxc_f03_CFLAGS} +# Libxc_f03_LIBRARIES = ${Libxc_f03_LIRARIES}") +else() + set(Libxc_Target "Libxc::xcf03") +endif () +find_package(spglib QUIET) +if(NOT spglib_FOUND) + pkg_check_modules(spglib_f08 REQUIRED spglib_f08) + set(spglib_Target "PkgConfig::spglib_f08") +else() + set(spglib_Target "spglib::spglib_f08") +endif () + + +if(Libxc_VERSION VERSION_GREATER_EQUAL 5) + set(HAVE_LIBXC5 1) +endif() +if(Libxc_VERSION VERSION_GREATER 6) + message(WARNING "Libxc version ${Libxc_VERSION} is not officially supported. Use it at your own risk.\n + Please report any issues in the build and execution to the official repository so we can support it as quickly as possible.") +endif() # Define the main targets (binaries, libraries, virtual targets/interfaces) # Note: other targets (e.g. oct-help) are defined in src/MakeLists.txt @@ -52,6 +102,9 @@ add_executable(octopus) # Mimic autotools include(cmake/mock_autotools.cmake) +# Include necessary third-party libs +add_subdirectory(external_libs) + # Main project add_subdirectory(src) diff --git a/cmake/CheckFortranTypeSizes.cmake b/cmake/CheckFortranTypeSizes.cmake new file mode 100644 index 0000000000..6257aa2b61 --- /dev/null +++ b/cmake/CheckFortranTypeSizes.cmake @@ -0,0 +1,55 @@ +# This module perdorms several try-compiles to determine the default integer +# size being used by the fortran compiler +# +# After execution, the following variables are set. If they are un set then +# size detection was not possible +# +# SIZEOF_INTEGER - Number of bytes used to store the default INTEGER type +# SIZEOF_REAL - Number of bytes used to store the default REAL type +# SIZEOF_LOGICAL - Number of bytes used to store the default LOGICAL type +# SIZEOF_CHARACTER - Number of bytes used to store the default CHARACTER type +# +#============================================================================= +# Author: Chuck Atkins +# Copyright 2011 +# Original code: https://github.com/Reference-LAPACK/lapack/blob/f8fb0842d55c34ad2c26da58e9f55a3f10e52d0b/CMAKE/CheckFortranTypeSizes.cmake +#============================================================================= + +# Check the size of a single fortran type +macro( _CHECK_FORTRAN_TYPE_SIZE _TYPE_NAME _TEST_SIZES ) + + foreach( __TEST_SIZE ${_TEST_SIZES} ) + set( __TEST_FILE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortran${_TYPE_NAME}Size${__TEST_SIZE}.f90 ) + file( WRITE ${__TEST_FILE} + " + PROGRAM check_size + ${_TYPE_NAME}*${__TEST_SIZE}, TARGET :: a + ${_TYPE_NAME}, POINTER :: pa + pa => a + END PROGRAM +") + try_compile( SIZEOF_${_TYPE_NAME} ${CMAKE_BINARY_DIR} ${__TEST_FILE} ) + if( SIZEOF_${_TYPE_NAME} ) + message( STATUS "Testing default ${_TYPE_NAME}*${__TEST_SIZE} - found" ) +# set( SIZEOF_${_TYPE_NAME} ${__TEST_SIZE} CACHE INTERNAL "Size of the default ${_TYPE_NAME} type" FORCE ) + set( SIZEOF_Fortran_${_TYPE_NAME} ${__TEST_SIZE} CACHE INTERNAL "Size of the default ${_TYPE_NAME} type" FORCE ) + break() + else() + message( STATUS "Testing default ${_TYPE_NAME}*${__TEST_SIZE} -" ) + endif() + endforeach() + +endmacro() + + +macro( CHECK_FORTRAN_TYPE_SIZES ) + if( NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90 ) + message( FATAL_ERROR "Type size tests require Fortran 90 support" ) + endif() + + _CHECK_FORTRAN_TYPE_SIZE( "INTEGER" "2;4;8;16" ) + _CHECK_FORTRAN_TYPE_SIZE( "REAL" "4;8;12;16" ) + _CHECK_FORTRAN_TYPE_SIZE( "LOGICAL" "1;2;4;8;16" ) + _CHECK_FORTRAN_TYPE_SIZE( "CHARACTER" "1;2;4;8;16" ) +endmacro() + diff --git a/cmake/mock_autotools.cmake b/cmake/mock_autotools.cmake index 2a3faf69a3..76a179023a 100644 --- a/cmake/mock_autotools.cmake +++ b/cmake/mock_autotools.cmake @@ -1,3 +1,5 @@ +# TODO: When removing autotools, replace flags with target_compile_define + string(TIMESTAMP BUILD_TIME) execute_process( COMMAND git log -1 --format=%h @@ -6,7 +8,89 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ) -if (MPI_FORTRAN_FOUND) +if(CMAKE_BUILD_TYPE MATCHES Debug.*) + set(SHARE_DIR ${CMAKE_CURRENT_BINARY_DIR}/share) +else() + set(SHARE_DIR ${CMAKE_INSTALL_DATADIR}) +endif() + +include(CheckTypeSize) +check_type_size(size_t SIZEOF_SIZE_T LANGUAGE C) +check_type_size("unsigned int" SIZEOF_UNSIGNED_INT LANGUAGE C) +check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG LANGUAGE C) +check_type_size("unsigned long long" SIZEOF_UNSIGNED_LONG_LONG LANGUAGE C) +check_type_size(uint32_t UINT32_T LANGUAGE C) +check_type_size(uint64_t UINT64_T LANGUAGE C) +include(cmake/CheckFortranTypeSizes.cmake) +check_fortran_type_sizes() +include(CheckIncludeFile) +include(CheckFunctionExists) +check_include_file(dirent.h HAVE_DIRENT_H) +check_include_file(errno.h HAVE_ERRNO_H) +check_include_file(signal.h HAVE_SIGNAL_H) +check_include_file(stdint.h HAVE_STDINT_H) +check_include_file(string.h HAVE_STRING_H) +check_include_file(windows.h HAVE_WINDOWS_H) +#check_include_file(iotcl.h HAVE_IOCTL) +# TODO: Eliminate unnecessary function checks in code +# NOTE: Some files do not have checks +check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) +check_function_exists(nanosleep HAVE_NANOSLEEP) +check_function_exists(closedir HAVE_CLOSEDIR) +check_function_exists(readdir HAVE_READDIR) +check_function_exists(strchr HAVE_STRCHR) +check_function_exists(strtod HAVE_STRTOD) +check_function_exists(alphasort HAVE_ALPHASORT) +check_function_exists(scandir HAVE_SCANDIR) +check_function_exists(getopt_long HAVE_GETOPT_LONG) +check_function_exists(getpid HAVE_GETPID) +check_function_exists(perror HAVE_PERROR) +check_function_exists(sbrk HAVE_SBRK) +check_function_exists(sigaction HAVE_SIGACTION) +check_function_exists(strcasestr HAVE_STRCASESTR) +check_function_exists(strndup HAVE_STRNDUP) +check_function_exists(strsignal HAVE_STRSIGNAL) +check_function_exists(sysconf HAVE_SYSCONF) +check_function_exists(tcgetpgrp HAVE_TCGETPGRP) +check_function_exists(uname HAVE_UNAME) + + +if (MPI_Fortran_FOUND) set(MPI_MOD 1) set(HAVE_MPI 1) +endif () +if (OpenMP_Fortran_FOUND) + set(HAVE_OPENMP 1) +endif () +#message(FATAL_ERROR +# "PKG_FFTW_LIBRARY_DIRS = ${PKG_FFTW_LIBRARY_DIRS} +# LIB_INSTALL_DIR = ${LIB_INSTALL_DIR} +# FFTW_DOUBLE_LIB_FOUND = ${FFTW_DOUBLE_LIB_FOUND} +# FFTW_DOUBLE_THREADS_LIB_FOUND = ${FFTW_DOUBLE_THREADS_LIB_FOUND} +# FFTW_DOUBLE_MPI_LIB_FOUND = ${FFTW_DOUBLE_MPI_LIB_FOUND}") +if (FFTW_DOUBLE_LIB_FOUND_FOUND) + set(HAVE_FFTW3 1) + if (FFTW_DOUBLE_THREADS_LIB_FOUND) + set(HAVE_FFTW3_THREADS 1) + endif () + if (FFTW_DOUBLE_MPI_LIB_FOUND) + set(HAVE_FFTW3_MPI 1) + endif () +endif () + +# Currently long lines have to be supported to avoid preprocess.pl +if (CMAKE_Fortran_COMPILER_ID MATCHES GNU) + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-none") +endif () +set(LONG_LINES 1) + +try_compile(FC_Test_SUCCESS ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/test_compiler.F90 + OUTPUT_VARIABLE FC_Test_OUTPUT) +if (FC_Test_SUCCESS) +else () + message(SEND_ERROR "Failed to build test fortran file cmake/test_compiler.F90 with: + CMAKE_Fortran_COMPILER: ${CMAKE_Fortran_COMPILER} + CMAKE_Fortran_FLAGS: ${CMAKE_Fortran_FLAGS}") + message(FATAL_ERROR ${FC_Test_OUTPUT}) endif () \ No newline at end of file diff --git a/cmake/test_compiler.F90 b/cmake/test_compiler.F90 new file mode 100644 index 0000000000..00aa94c132 --- /dev/null +++ b/cmake/test_compiler.F90 @@ -0,0 +1,4 @@ +program test_compiler + ! Test long lines are supported (beyond 132) + print *, "Testing if the fortran file compiles with long lines. Here we are just filling up the space until it surpasses the standard limit of 132 characters. We are just continuing to add to this file way beyond the 132 character, approaching 400 characters, to make sure there is not another higher limit that we are not taking into account. Realistically we don't need this high of a limit, but we just want to be sure." +end program test_compiler \ No newline at end of file diff --git a/external_libs/CMakeLists.txt b/external_libs/CMakeLists.txt new file mode 100644 index 0000000000..30eb924e2c --- /dev/null +++ b/external_libs/CMakeLists.txt @@ -0,0 +1,30 @@ +add_library(bpdn STATIC + bpdn/expmm.c + bpdn/heap.c + bpdn/oneProjectorCore.c + bpdn/spgl1_projector.c + bpdn/bpdn.f90) +target_include_directories(bpdn PRIVATE + ${CMAKE_CURRENT_BINARY_DIR}/../src/include) +target_include_directories(bpdn INTERFACE + ${CMAKE_CURRENT_BINARY_DIR}) +add_library(dftd3 STATIC + dftd3/api.f90 + dftd3/common.f90 + dftd3/core.f90 + dftd3/pars.f90 + dftd3/sizes.f90) +target_include_directories(dftd3 PRIVATE + ${CMAKE_CURRENT_BINARY_DIR}/../src/include) +target_include_directories(dftd3 INTERFACE + ${CMAKE_CURRENT_BINARY_DIR}) +add_library(qshep STATIC + qshep/qshep2d.f90 + qshep/qshep3d.f90) +target_include_directories(qshep PRIVATE + ${CMAKE_CURRENT_BINARY_DIR}/../src/include) +target_include_directories(qshep INTERFACE + ${CMAKE_CURRENT_BINARY_DIR}) + +add_library(rapidxml INTERFACE) +target_include_directories(rapidxml INTERFACE rapidxml) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dfb5201388..79ed8804e4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,50 +1,26 @@ -#SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -save-temps=obj") -#SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}") -#SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffixed-line-length-none") +# Further configure the main targets +#set_target_properties(liboctopus PROPERTIES +# LIBRARY_OUTPUT_NAME liboct) +# Define additional helper interface targets +foreach (int_lib IN ITEMS + atomic_orbital basic_accel batch box box_factory classical_particles cube derivatives ext_partner_list grid + hamiltonian_elec interaction interactions_factory ion_dynamics ions kick kpoints math math_adv math_fft maxwell + mesh multibox multigrid multisystem multisystem_debug orbitalset output poisson projector scf species + species_pot states_elec symmetries system wfs_elec xc_oct v_ks density photon_mode eigensolver linear_solver + exponential sternheimer scf_tol mix perturbation elf fourier_shell maxwell_boundary states_elec_io orbitalset_utils + td td_write electrons forces born_charges excited_states classical_particle electrons_ground_state lcao pes + opt_control spectrum) + add_library(${int_lib} STATIC) +endforeach () -add_library(oct STATIC - basic/command_line.F90 - basic/varinfo.F90 - basic/global.F90 - basic/kind.F90 - basic/string.F90 - basic/loct.F90 - basic/mpi.F90 - basic/blacs.F90 - basic/mpi_debug.F90 - basic/hardware.F90 - basic/getopt_f.c - basic/varinfo_low.c - basic/oct_f.c - basic/varia.c) -if (MPI_FORTRAN_FOUND) - target_link_libraries(oct PUBLIC - MPI::MPI_Fortran) -else () -# target_sources(oct PUBLIC) -endif () +# Include specific definitions of these targets +foreach (subdir IN ITEMS classical ions math multisystem species interactions basic scf grid boxes states electrons + poisson hamiltonian basis_set maxwell output sternheimer td opt_control main utils include) + add_subdirectory(${subdir}) +endforeach () -target_include_directories(oct PUBLIC - include ${CMAKE_CURRENT_BINARY_DIR}/include) -configure_file(include/config.h.in include/config_F90.h) -configure_file(include/config.h.in include/config.h) - -# TODO: Switch to CMake native method or equivalent so that it can be indexed -#configure_file(include/options.h.in include/options.h) -#configure_file(include/defaults.h.in include/defaults.h) -add_custom_target(VarInfo - COMMAND ${PROJECT_SOURCE_DIR}/scripts/mk_varinfo.pl - -s ${PROJECT_SOURCE_DIR} - -b ${PROJECT_BINARY_DIR} - COMMENT "Generating variable information:" - ) -add_dependencies(oct VarInfo) - -target_include_directories(oct PUBLIC - ../liboct_parser) - -add_executable(oct-help - utils/help.F90) -target_link_libraries(oct-help PRIVATE oct) \ No newline at end of file +## Unused sources +# boxes/box_intersection.F90 +# scf/mixing_metric.F90 diff --git a/src/basic/CMakeLists.txt b/src/basic/CMakeLists.txt new file mode 100644 index 0000000000..3287cc7920 --- /dev/null +++ b/src/basic/CMakeLists.txt @@ -0,0 +1,89 @@ +target_sources(base_octopus PRIVATE + ../../liboct_parser/gsl_userdef.c + ../../liboct_parser/parse.c + ../../liboct_parser/parse_exp.c + ../../liboct_parser/parser_f.c + ../../liboct_parser/symbols.c + blacs.F90 + calc_mode_par.F90 + clock.F90 + comm.F90 + debug.F90 + distributed.F90 + getopt_f.c + global.F90 + hardware.F90 + iihash.F90 + iihash_low.cc + io.F90 + io_binary.c + io_binary_f.F90 + io_csv.c + io_csv_f.F90 + kind.F90 + linked_list.F90 + list_node.F90 + loct.F90 + messages.F90 + mpi.F90 + mpi_debug.F90 + mpi_lib.F90 + multicomm.F90 + namespace.F90 + nvtx.F90 + nvtx_low.cc + oct_f.c + parser.F90 + profiling.F90 + recipes.c + signals.c + sihash.F90 + sihash_low.cc + sort.F90 + sort_low.cc + sphash.F90 + sphash_low.cc + string.F90 + types.F90 + unit.F90 + unit_system.F90 + utils.F90 + varia.c + varinfo.F90 + varinfo_low.c + walltimer.F90 + write_iter.F90 + write_iter_low.cc + ) +target_sources(basic_accel PRIVATE + accel.F90 + alloc_cache.F90 + alloc_cache_low.cc + cuda.F90 + cuda_low.cc + ) +target_sources(fortran_cli PRIVATE + command_line.F90) + +# These should be on object target. See previous comment on object and interface separation +target_link_libraries(basic_accel PUBLIC base_octopus) +target_link_libraries(fortran_cli PUBLIC base_octopus) + +target_include_directories(base_octopus PUBLIC + $ + ../include) +# TODO: Not sure why this is not in /src +target_include_directories(base_octopus PUBLIC + ../../liboct_parser) +target_link_libraries(base_octopus PUBLIC + PRIVATE GSL::gsl) + +if (OpenMP_Fortran_FOUND) + target_link_libraries(base_octopus PRIVATE OpenMP::OpenMP_Fortran) +endif () + + +if (MPI_FORTRAN_FOUND) +# target_link_libraries(base_octopus_obj PUBLIC +# MPI::MPI_Fortran) +endif () \ No newline at end of file diff --git a/src/basis_set/CMakeLists.txt b/src/basis_set/CMakeLists.txt new file mode 100644 index 0000000000..6edb559515 --- /dev/null +++ b/src/basis_set/CMakeLists.txt @@ -0,0 +1,16 @@ +target_sources(atomic_orbital PRIVATE + atomic_orbital.F90 + ) +target_sources(orbitalset PRIVATE + orbitalset.F90 + ) +target_sources(orbitalset_utils PRIVATE + orbitalset_utils.F90) + +target_link_libraries(atomic_orbital PUBLIC + ions orbitalset box_factory) +target_link_libraries(orbitalset PUBLIC + poisson) +target_link_libraries(orbitalset_utils PUBLIC + atomic_orbital) + diff --git a/src/boxes/CMakeLists.txt b/src/boxes/CMakeLists.txt new file mode 100644 index 0000000000..a1a8b317a7 --- /dev/null +++ b/src/boxes/CMakeLists.txt @@ -0,0 +1,29 @@ +target_sources(box PRIVATE + box.F90 + box_minimum.F90 + box_shape.F90 + ../basic/lookup.F90 # used by box_minimum only + ) +target_sources(multibox PRIVATE + multibox.F90 + ) +target_sources(box_factory PRIVATE + box_factory.F90 + box_cgal.F90 + ../basic/cgal_polyhedra.F90 # used by box_cgal and a few other + ../basic/cgal_polyhedra_low.cc + ../basic/gdlib.F90 # used by box_image only + ../basic/gdlib_f.c + box_cylinder.F90 + box_image.F90 + box_parallelepiped.F90 + box_sphere.F90 + box_user_defined.F90 + ) + +target_link_libraries(box PUBLIC + math_adv) +target_link_libraries(multibox PUBLIC + box) +target_link_libraries(box_factory PUBLIC + box) diff --git a/src/classical/CMakeLists.txt b/src/classical/CMakeLists.txt new file mode 100644 index 0000000000..20295f4c55 --- /dev/null +++ b/src/classical/CMakeLists.txt @@ -0,0 +1,12 @@ +target_sources(classical_particles PRIVATE + classical_particles.F90 + propagator_data_classical_particles.F90 + ) +target_sources(classical_particle PRIVATE + classical_particle.F90 + ) + +target_link_libraries(classical_particles PUBLIC + system math_adv) +target_link_libraries(classical_particle PUBLIC + interactions_factory) diff --git a/src/electrons/CMakeLists.txt b/src/electrons/CMakeLists.txt new file mode 100644 index 0000000000..1d99acbbbc --- /dev/null +++ b/src/electrons/CMakeLists.txt @@ -0,0 +1,64 @@ +add_library(preconditioners STATIC + preconditioners.F90) + +target_sources(kpoints PRIVATE + kpoints.F90) +target_sources(v_ks PRIVATE + ../hamiltonian/pcm_potential.F90 # Only used by v_ks + ../hamiltonian/vdw_ts.F90 # Used together with v_ks + ../hamiltonian/vdw_ts_low.c + ../hamiltonian/hirshfeld.F90 # Used by vdw_ts and partial_charges, which is only called with v_ks + ../poisson/photon_mode_mf.F90 # Only used by v_ks and td + current.F90 + v_ks.F90 + xc_ks_inversion.F90 + xc_sic.F90 + xc_oep.F90 + partial_charges.F90 + ) +target_sources(eigensolver PRIVATE + eigensolver.F90 + eigen_cg.F90 + eigen_rmmdiis.F90 + subspace.F90 + ) +target_sources(linear_solver PRIVATE + linear_solver.F90) +target_sources(exponential PRIVATE + exponential.F90) +target_sources(perturbation PRIVATE + ../ions/vibrations.F90 # can be consolidated + perturbation.F90 + perturbation_electric.F90 + perturbation_ionic.F90 + perturbation_kdotp.F90 + perturbation_magnetic.F90 + perturbation_none.F90) +target_sources(elf PRIVATE + elf.F90) +target_sources(electrons PRIVATE + electrons.F90) +target_sources(forces PRIVATE + forces.F90) + +target_link_libraries(kpoints PUBLIC + math symmetries) +target_link_libraries(v_ks PUBLIC + density linear_solver photon_mode scf_tol eigensolver + PRIVATE dftd3) +target_link_libraries(eigensolver PUBLIC + xc_oct preconditioners exponential) +target_link_libraries(linear_solver PUBLIC + preconditioners) +target_link_libraries(preconditioners PUBLIC + hamiltonian_elec) +target_link_libraries(exponential PUBLIC + hamiltonian_elec) +target_link_libraries(perturbation PUBLIC + hamiltonian_elec) +target_link_libraries(elf PUBLIC + density states_elec) +target_link_libraries(electrons PUBLIC + td) +target_link_libraries(forces PUBLIC + v_ks born_charges) diff --git a/src/grid/CMakeLists.txt b/src/grid/CMakeLists.txt new file mode 100644 index 0000000000..a1e7bf5463 --- /dev/null +++ b/src/grid/CMakeLists.txt @@ -0,0 +1,95 @@ +add_library(coordinate_system STATIC + coordinate_system.F90 + affine_coordinates.F90) +add_library(mesh_init STATIC + ../basic/heap.F90 # Used by mesh_init only + ../basic/merge_sorted.F90 # Used by mesh_init only + ../math/accel_blas.F90 # Used by mesh_batch (other dependencies depend on it as well) + ../math/checksum.c + ../math/checksum_interface.F90 # Used by mesh_init only + ../math/metis.F90 + ../math/metis_f.c + ../math/root_solver.F90 # Used by grid and species_pot (depends on mesh_function, etc.) + io_function.F90 + mesh_batch.F90 + mesh_init.F90 + mesh_partition.F90 + nl_operator.F90 + operate.c + operate_f.F90 + restart.F90 + stencil_star.F90 + vtk.F90 + ) + +target_sources(batch PRIVATE + allocate_hardware_aware.cc + allocate_hardware_aware_f.F90 + batch.F90 + batch_ops.F90 + ) +target_sources(grid PRIVATE + curv_briggs.F90 + curv_gygi.F90 + curv_modine.F90 + grid.F90 + ../hamiltonian/absorbing_boundaries.F90 + ) +target_sources(derivatives PRIVATE + derivatives.F90 + cartesian.F90 + stencil_cube.F90 + stencil_starplus.F90 + stencil_stargeneral.F90 + stencil_variational.F90 + transfer_table.F90 + ) +target_sources(mesh PRIVATE + ../math/qshep.F90 # Used by mesh_function only + ../math/quickrnd.F90 + basis_set_abst.F90 + index.F90 + hilbert.c + mesh.F90 + mesh_function.F90 + par_vec.F90 + partition.F90 + stencil.F90 + symmetrizer.F90 + mesh_interpolation.F90 + ) +target_sources(multigrid PRIVATE + multigrid.F90) +target_sources(cube PRIVATE + cube.F90 + mesh_cube_map.F90 + cube_function.F90 + mesh_cube_parallel_map.F90 + partition_transfer.F90 + submesh.F90 + boundaries.F90 + fourier_space.F90 + ) +target_sources(fourier_shell PRIVATE + fourier_shell.F90) + +target_link_libraries(batch PUBLIC + basic_accel math) +target_link_libraries(grid PUBLIC + derivatives) +target_link_libraries(multigrid PUBLIC + derivatives) +target_link_libraries(derivatives PUBLIC + mesh_init) +target_link_libraries(mesh_init PUBLIC + cube box_factory ions kpoints) +target_link_libraries(cube PUBLIC + mesh math_fft batch wfs_elec) +target_link_libraries(mesh PUBLIC + species box coordinate_system basic_accel symmetries + qshep) +target_link_libraries(coordinate_system PUBLIC + math_adv) +target_link_libraries(fourier_shell PUBLIC + cube) + diff --git a/src/hamiltonian/CMakeLists.txt b/src/hamiltonian/CMakeLists.txt new file mode 100644 index 0000000000..c223653c63 --- /dev/null +++ b/src/hamiltonian/CMakeLists.txt @@ -0,0 +1,71 @@ +target_sources(xc_oct PRIVATE + ../interactions/xc_interaction.F90 + exchange_operator.F90 + libvdwxc.F90 + xc.F90 + xc_functional.F90 + ) +target_sources(hamiltonian_elec PRIVATE + hamiltonian_elec.F90 + hamiltonian_elec_base.F90 + hamiltonian_abst.F90 + epot.F90 + projector_matrix.F90 + energy.F90 + ../interactions/ion_electron_local_potential.F90 + ../interactions/external_potential.F90 + lda_u.F90 + lda_u_io.F90 + ../basis_set/loewdin.F90 # Only used by lda_u + ../basis_set/orbitalbasis.F90 # Only used by lda_u + magnetic_constrain.F90 + ../electrons/magnetic.F90 + ../interactions/nlcc.F90 # Only used by hamiltonian_elec + ../electrons/energy_calc.F90 # Only used together with hamiltonian_elec + oct_exchange.F90 + scissor.F90 + ) +target_sources(projector PRIVATE + projector.F90 + hgh_projector.F90 + kb_projector.F90 + rkb_projector.F90 + ) +target_sources(species_pot PRIVATE + species_pot.F90 + ../grid/volume.F90 # Used only by species_pot + ) +target_sources(ext_partner_list PRIVATE + ext_partner_list.F90 + gauge_field.F90 + lasers.F90 + ) +target_sources(kick PRIVATE + kick.F90 + pcm.F90 + pcm_eom.F90 + ) +target_sources(scf_tol PRIVATE + scf_tol.F90) + +target_link_libraries(xc_oct + PUBLIC states_elec poisson + PRIVATE ${Libxc_Target}) +target_link_libraries(hamiltonian_elec + PUBLIC xc_oct projector species_pot ext_partner_list kick orbitalset_utils) +target_link_libraries(projector + PUBLIC ions states_elec) +target_link_libraries(species_pot + PUBLIC species atomic_orbital) +target_link_libraries(ext_partner_list + PUBLIC interactions_factory) +target_link_libraries(kick + PUBLIC ion_dynamics poisson states_elec) +target_link_libraries(scf_tol + PUBLIC base_octopus) + + + + + + diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt new file mode 100644 index 0000000000..b1ad36516c --- /dev/null +++ b/src/include/CMakeLists.txt @@ -0,0 +1,5 @@ +configure_file(config.h.in config_F90.h) +configure_file(config.h.in config.h) +target_include_directories(base_octopus PUBLIC + $ + ${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/src/include/config.h.in b/src/include/config.h.in index f4363f70bb..2f05c86986 100644 --- a/src/include/config.h.in +++ b/src/include/config.h.in @@ -1,31 +1,28 @@ #define BUILD_TIME "@BUILD_TIME@" #define PACKAGE_VERSION "@CMAKE_PROJECT_VERSION@" /* TODO: Implement a search function via $OCTOPUS_DIR/share:$(pwd)/share:/usr/share/octopus */ -#define SHARE_DIR "@PROJECT_BINARY_DIR@/share" +#define SHARE_DIR "@SHARE_DIR@" +#define MAX_DIM @max-dim@ #define CC "@CMAKE_C_COMPILER@" -/* #undef CC_FORTRAN_INT */ -#define CFLAGS "@CMAKE_C_FLAGS" +#define CFLAGS "@CMAKE_C_FLAGS@" #define CFLAGS_EXTRA "" #define CXX "@CMAKE_CXX_COMPILER@" -#define CXXFLAGS "@CMAKE_CXX_FLAGS" +#define CXXFLAGS "@CMAKE_CXX_FLAGS@" #define CXXFLAGS_EXTRA "" -/* #undef C_ALLOCA */ -/* #undef F90_ACCEPTS_LINE_NUMBERS */ #define FC "@CMAKE_Fortran_COMPILER@" -#define FCFLAGS "@CMAKE_Fortran_FLAGS" +#define FCFLAGS "@CMAKE_Fortran_FLAGS@" #define FCFLAGS_EXTRA "" +/* TODO: Deprecate old Fortran: Remove code */ #define FC_COMMAND_LINE_ARGUMENTS 2003 /* #undef FC_COMMAND_LINE_IMPLICIT */ /* #undef FC_COMMAND_LINE_INCLUDE */ /* #undef FC_COMMAND_LINE_INTRINSIC */ /* #undef FC_COMMAND_LINE_MODULE */ -/* #undef FC_DUMMY_MAIN */ -/* #undef FC_DUMMY_MAIN_EQ_F77 */ -/* #define FC_INTEGER_SIZE 4 */ +/* TODO: Deprecate old Fortran: Use ISO_C_BINDING */ #ifdef __GFORTRAN__ #define FC_FUNC(name,NAME) name/**/_ #define FC_FUNC_(name,NAME) name/**/_ @@ -35,176 +32,126 @@ #endif #define GIT_COMMIT "@GIT_HASH@" - -#define HAVE_STDINT_H 1 - +/* TODO: Might not need in modern compilers */ #define SIZEOF_VOIDP @CMAKE_SIZEOF_VOID_P@ +#define SIZEOF_SIZE_T @SIZEOF_SIZE_T@ +#define SIZEOF_UNSIGNED_INT @SIZEOF_UNSIGNED_INT@ +#define SIZEOF_UNSIGNED_LONG @SIZEOF_UNSIGNED_LONG@ +#define SIZEOF_UNSIGNED_LONG_LONG @SIZEOF_UNSIGNED_LONG_LONG@ + +/* TODO: Deprecate old C: Remove check */ +#cmakedefine HAVE_UINT32_T +#cmakedefine HAVE_UINT64_T + + +#define FC_INTEGER_SIZE @SIZEOF_Fortran_INTEGER@ + +/* TODO: Deprecate old Fortran: Always assume long_lines are accepted. Use appropriate flags */ +#define LONG_LINES 1 +/* TODO: Deprecate old Fortran: Remove check */ +#define HAVE_FC_COMPILER_VERSION 1 +#define HAVE_FC_SIZEOF 1 +#define HAVE_FLUSH 1 +#define F90_ACCEPTS_LINE_NUMBERS 1 +#define HAVE_FORTRAN_LOC 1 + +/* TODO: Deprecate old C: Remove check */ +#cmakedefine HAVE_DIRENT_H +#cmakedefine HAVE_CLOSEDIR +#cmakedefine HAVE_READDIR +#cmakedefine HAVE_STRCHR +#cmakedefine HAVE_STRTOD +#cmakedefine HAVE_GETTIMEOFDAY +#cmakedefine HAVE_NANOSLEEP +#cmakedefine HAVE_SCANDIR +#cmakedefine HAVE_ALPHASORT +#cmakedefine HAVE_ERRNO_H +#cmakedefine HAVE_GETOPT_LONG +#cmakedefine HAVE_GETPID +#define HAVE_IOCTL 1 +#cmakedefine HAVE_PERROR +#cmakedefine HAVE_SBRK +#cmakedefine HAVE_SIGACTION +#cmakedefine HAVE_SIGNAL_H +#cmakedefine HAVE_STDINT_H +#cmakedefine HAVE_STRCASESTR +#cmakedefine HAVE_STRING_H + +#cmakedefine HAVE_STRNDUP +#cmakedefine HAVE_STRSIGNAL +#cmakedefine HAVE_SYSCONF +#cmakedefine HAVE_TCGETPGRP +#cmakedefine HAVE_UNAME +#cmakedefine HAVE_WINDOWS_H +#define HAVE_VEC 1 -#define LONG_LINES +#cmakedefine MPI_MOD +#cmakedefine HAVE_MPI +#cmakedefine HAVE_OPENMP +#cmakedefine HAVE_FFTW3_MPI +#cmakedefine HAVE_FFTW3_THREADS +#cmakedefine HAVE_LIBXC5 +/* TODO: Extract the configuration */ +#define HAVE_LIBXC_FXC 1 +#define HAVE_LIBXC_KXC 1 -#cmakedefine MPI_MOD +/* Introduced in C11 */ +/* TODO: C++11 Uses thread_local instead */ +/* TODO: C23 Uses common thread_local instead */ +#define TLS_SPECIFIER _Thread_local -#cmakedefine HAVE_MPI -/* From autotools: */ +#define OCT_ARCH x86_64 "@CMAKE_SYSTEM_PROCESSOR@" -/* The size of a Fortran integer */ +/* TODO: To implement */ +/* #undef HAVE_FMA3 */ +/* #undef HAVE_FMA4 */ +/* TODO: To remove */ +/* #undef MPI_H */ /* Should not have any setups using it */ -/* #define HAVE_ALLOCA 1 */ -/* #define HAVE_ALLOCA_H 1 */ -/* #define HAVE_ALPHASORT 1 */ +/* TODO: Connect */ /* #undef HAVE_BERKELEYGW */ -/* #undef HAVE_BLACS */ -/* #define HAVE_BLAS 1 */ -/* #undef HAVE_BLUE_GENE */ -/* #undef HAVE_BLUE_GENE_Q */ -/* #undef HAVE_BOOST */ -/* #define HAVE_BUILTIN_PREFETCH 1 */ /* #undef HAVE_CGAL */ /* #undef HAVE_CLBLAS */ /* #undef HAVE_CLFFT */ -/* #define HAVE_CLOSEDIR 1 */ -/* #undef HAVE_CL_CL_H */ -/* #define HAVE_COMP_ISF 1 */ -/* #undef HAVE_COMP_METIS */ +/* #undef HAVE_PFFT */ +/* #undef HAVE_PNFFT */ /* #undef HAVE_CUDA */ /* #undef HAVE_CUDA_MPI */ /* #undef HAVE_DFTBPLUS */ /* #undef HAVE_DFTBPLUS_DEVEL */ -/* #define HAVE_DIRENT_H 1 */ -/* #undef HAVE_DLFCN_H */ /* #undef HAVE_ELPA */ -/* #define HAVE_ERRNO_H 1 */ /* #undef HAVE_ETSF_IO */ -/* #define HAVE_FC_COMPILER_VERSION 1 */ -/* #define HAVE_FC_SIZEOF 1 */ -/* #define HAVE_FFTW3 1 */ -/* #undef HAVE_FFTW3_MPI */ -/* #define HAVE_FFTW3_THREADS 1 */ -/* #define HAVE_FLUSH 1 */ -/* #undef HAVE_FMA3 */ -/* #undef HAVE_FMA4 */ -/* #define HAVE_FORTRAN_LOC 1 */ -/* #undef HAVE_FUTILE */ /* #undef HAVE_GDLIB */ -/* #undef HAVE_GD_FONTCONFIG */ -/* #undef HAVE_GD_FREETYPE */ /* #undef HAVE_GD_GIF */ /* #undef HAVE_GD_JPEG */ /* #undef HAVE_GD_PNG */ -/* #undef HAVE_GD_XPM */ -/* #define HAVE_GETOPT_LONG 1 */ -/* #define HAVE_GETPID 1 */ -/* #define HAVE_GETTIMEOFDAY 1 */ -/* #define HAVE_INTTYPES_H 1 */ -/* #define HAVE_IOCTL 1 */ -/* #define HAVE_LAPACK 1 */ -/* #undef HAVE_LIBCUBLAS */ -/* #undef HAVE_LIBCUDA */ -/* #undef HAVE_LIBCUFFT */ /* #undef HAVE_LIBFM */ /* #undef HAVE_LIBISF */ -/* #undef HAVE_LIBNVRTC */ /* #undef HAVE_LIBVDWXC */ /* #undef HAVE_LIBVDWXC_MPI */ -/* #define HAVE_LIBXC5 1 */ -/* #define HAVE_LIBXC_FXC 1 */ -/* #define HAVE_LIBXC_KXC 1 */ /* #undef HAVE_LIKWID */ -/* #define HAVE_M128D 1 */ -/* #undef HAVE_M256D */ -/* #undef HAVE_M512D */ /* #undef HAVE_METIS */ -/* #undef HAVE_MPI */ -/* #define HAVE_NANOSLEEP 1 */ -/* #undef HAVE_NDIR_H */ +/* #undef HAVE_PARMETIS */ +/* #define METIS_IDXTYPEWIDTH 32 */ /* #undef HAVE_NETCDF */ /* #undef HAVE_NFFT */ /* #undef HAVE_NLOPT */ /* #undef HAVE_NVTX */ /* #undef HAVE_OPENCL */ /* #undef HAVE_OPENCL_CL_H */ -/* #undef HAVE_OPENMP */ -/* #undef HAVE_PARMETIS */ -/* #define HAVE_PERROR 1 */ -/* #undef HAVE_PFFT */ -/* #undef HAVE_PNFFT */ /* #undef HAVE_POKE */ /* #undef HAVE_PSOLVER */ /* #undef HAVE_PSPIO */ -/* #define HAVE_READDIR 1 */ -/* #define HAVE_SBRK 1 */ /* #undef HAVE_SCALAPACK */ -/* #define HAVE_SCANDIR 1 */ -/* #define HAVE_SIGACTION 1 */ -/* #define HAVE_SIGNAL_H 1 */ /* #undef HAVE_SPARSKIT */ -/* #undef HAVE_STAT_EMPTY_STRING_BUG */ -/* #define HAVE_STDINT_H 1 */ -/* #define HAVE_STDIO_H 1 */ -/* #define HAVE_STDLIB_H 1 */ -/* #define HAVE_STRCASESTR 1 */ -/* #define HAVE_STRCHR 1 */ -/* #define HAVE_STRINGS_H 1 */ -/* #define HAVE_STRING_H 1 */ -/* #define HAVE_STRNDUP 1 */ -/* #define HAVE_STRSIGNAL 1 */ -/* #define HAVE_STRTOD 1 */ -/* #define HAVE_SYSCONF 1 */ -/* #undef HAVE_SYS_DIR_H */ -/* #undef HAVE_SYS_NDIR_H */ -/* #define HAVE_SYS_STAT_H 1 */ -/* #define HAVE_SYS_TIME_H 1 */ -/* #define HAVE_SYS_TYPES_H 1 */ -/* #define HAVE_TCGETPGRP 1 */ -/* #define HAVE_UINT32_T 1 */ -/* #define HAVE_UINT64_T 1 */ -/* #define HAVE_UNAME 1 */ -/* #define HAVE_UNISTD_H 1 */ -/* #define HAVE_VEC 1 */ -/* #undef HAVE_WINDOWS_H */ -/* #undef HAVE_YAML */ -/* #define ISO_C_BINDING 1 */ -/* #define LONG_LINES 1 */ -/* #define LSTAT_FOLLOWS_SLASHED_SYMLINK 1 */ -/* #define LT_OBJDIR ".libs/" */ -/* #define MAX_DIM 3 */ -/* #define METIS_IDXTYPEWIDTH 32 */ -/* #undef MPI_H */ -/* #undef MPI_MOD */ -/* #undef NDEBUG */ -/* #define OCT_ARCH x86_64 */ -/* #define PACKAGE "octopus" */ -/* #define PACKAGE_BUGREPORT "octopus-devel@tddft.org" */ -/* #define PACKAGE_NAME "Octopus" */ -/* #define PACKAGE_STRING "Octopus bimaculatus" */ -/* #define PACKAGE_TARNAME "octopus" */ -/* #define PACKAGE_URL "" */ -/* #define PACKAGE_VERSION "bimaculatus" */ -/* #define SIZEOF_SIZE_T 8 */ -/* #define SIZEOF_UNSIGNED_INT 4 */ -/* #define SIZEOF_UNSIGNED_LONG 8 */ -/* #define SIZEOF_UNSIGNED_LONG_LONG 8 */ -/* #define SIZEOF_VOIDP 8 */ -/* #undef STACK_DIRECTION */ -/* #define STDC_HEADERS 1 */ -/* #define TIME_WITH_SYS_TIME 1 */ -/* #define TLS_SPECIFIER __thread */ -/* #define VERSION "bimaculatus" */ -/* #undef const */ - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -/* #ifndef __cplusplus */ -/* #undef inline */ -/* #endif */ -/* #undef pid_t */ -/* #define restrict __restrict__ */ -/* #if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__ */ -/* # define _Restrict */ -/* # define __restrict__ */ -/* #endif */ -/* #undef size_t */ \ No newline at end of file + +/* TODO: To discuss */ +/* #undef HAVE_BLUE_GENE */ /* Can replace with stl? */ +/* #undef HAVE_BLUE_GENE_Q */ +/* #define HAVE_M128D 1 */ +/* #undef HAVE_M256D */ +/* #undef HAVE_M512D */ \ No newline at end of file diff --git a/src/interactions/CMakeLists.txt b/src/interactions/CMakeLists.txt new file mode 100644 index 0000000000..55ef8b2d0d --- /dev/null +++ b/src/interactions/CMakeLists.txt @@ -0,0 +1,15 @@ +target_sources(interactions_factory PRIVATE + ../grid/regridding.F90 + ../multisystem/interactions_factory_abst.F90 + ../states/states_mxll.F90 + coulomb_force.F90 + current_to_mxll_field.F90 + gravity.F90 + interactions_factory.F90 + linear_medium_to_em_field.F90 + lorentz_force.F90 + mxll_field_to_medium.F90 + ) + +target_link_libraries(interactions_factory PUBLIC + interaction multisystem grid poisson states_elec) diff --git a/src/ions/CMakeLists.txt b/src/ions/CMakeLists.txt new file mode 100644 index 0000000000..62fd9c7c3e --- /dev/null +++ b/src/ions/CMakeLists.txt @@ -0,0 +1,28 @@ +target_sources(ions PRIVATE + ions.F90 + atom.F90 + ../basic/distributed.F90 + ../hamiltonian/ion_interaction.F90 + read_coords.F90 + ../math/tdfunction.F90 + ) +target_sources(symmetries PRIVATE + symmetries.F90 + symmetries_finite.c + ../math/symm_op.F90 + ) +target_sources(ion_dynamics PRIVATE + ion_dynamics.F90) +target_sources(born_charges PRIVATE + born_charges.F90) + +target_link_libraries(ions PUBLIC + species classical_particles math_fft symmetries) +target_link_libraries(symmetries PUBLIC + math) +target_link_libraries(ion_dynamics PUBLIC + ions mesh_init) +target_link_libraries(born_charges PUBLIC + states_elec) + +target_link_libraries(symmetries PRIVATE ${spglib_Target}) \ No newline at end of file diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt new file mode 100644 index 0000000000..4caefe9b7c --- /dev/null +++ b/src/main/CMakeLists.txt @@ -0,0 +1,29 @@ +target_sources(octopus PRIVATE + ../basic/mpi_test.F90 + ../classical/charged_particle.F90 + ../math/gauss_legendre.F90 + ../sternheimer/em_resp.F90 + ../sternheimer/em_resp_calc.F90 + ../sternheimer/phonons_lr.F90 + ../sternheimer/vdw.F90 + ../sternheimer/kdotp.F90 + ../sternheimer/kdotp_calc.F90 + ../scf/unocc.F90 + ../dftbplus/dftb.F90 + ../electrons/matter.F90 + casida.F90 + ground_state.F90 + invert_ks.F90 + main.F90 + geom_opt.F90 + phonons_fd.F90 + pulpo.F90 + run.F90 + static_pol.F90 + system_factory.F90 + test.F90 + time_dependent.F90 + ) + +target_link_libraries(octopus PRIVATE + opt_control maxwell sternheimer spectrum fortran_cli) \ No newline at end of file diff --git a/src/math/CMakeLists.txt b/src/math/CMakeLists.txt new file mode 100644 index 0000000000..def8ada5b4 --- /dev/null +++ b/src/math/CMakeLists.txt @@ -0,0 +1,44 @@ +target_sources(math PRIVATE + ../basic/lattice_vectors.F90 + ../basic/space.F90 + blas.F90 + lalg_basic.F90 + loct_math.F90 + math.F90 + minimizer.F90 + minimizer_low.c + oct_gsl_f.c + dablas.c + solvers.F90 + ylm.c + ) +target_sources(math_adv PRIVATE + ../basic/blacs_proc_grid.F90 + lalg_adv.F90 + lapack.F90 + scalapack.F90 + basis_vectors.F90 + ) +target_sources(math_fft PRIVATE + fft.F90 + pfft.F90 + pnfft.F90 + fftw.F90 + fftw_low.c + ) + +target_link_libraries(math PUBLIC + base_octopus + PRIVATE BLAS::BLAS) +target_link_libraries(math_fft PUBLIC + math basic_accel + PRIVATE FFTW::Double) +target_link_libraries(math_adv PUBLIC + math + PRIVATE LAPACK::LAPACK) + + +#if (HAVE_CUDA) +# target_sources(octopus PRIVATE +# math/cufft.cc) +#endif () \ No newline at end of file diff --git a/src/maxwell/CMakeLists.txt b/src/maxwell/CMakeLists.txt new file mode 100644 index 0000000000..42588c0e3c --- /dev/null +++ b/src/maxwell/CMakeLists.txt @@ -0,0 +1,18 @@ +target_sources(maxwell PRIVATE + dispersive_medium.F90 + linear_medium.F90 + maxwell.F90 + ) +target_sources(maxwell_boundary PRIVATE + maxwell_boundary_op.F90 + ../math/maxwell_function.F90 + ../math/helmholtz_decomposition.F90 + ../states/modelmb_density_matrix.F90 + ../grid/modelmb_1part.F90 + ../grid/hypercube.F90 + ) + +target_link_libraries(maxwell PUBLIC + electrons) +target_link_libraries(maxwell_boundary PUBLIC + interactions_factory) diff --git a/src/multisystem/CMakeLists.txt b/src/multisystem/CMakeLists.txt new file mode 100644 index 0000000000..7b13d0861a --- /dev/null +++ b/src/multisystem/CMakeLists.txt @@ -0,0 +1,35 @@ +target_sources(multisystem PRIVATE + multisystem.F90 + multisystem_basic.F90 + system_factory_abst.F90 + ) +target_sources(system PRIVATE + ghost_interaction.F90 + system.F90 + propagator.F90 + propagator_beeman.F90 + propagator_exp_mid.F90 + propagator_static.F90 + propagator_verlet.F90 + ) +target_sources(interaction PRIVATE + interaction.F90 + interaction_partner.F90 + interaction_with_partner.F90 + ../interactions/force_interaction.F90 + ../interactions/density_interaction.F90 + ../interactions/potential_interaction.F90 + quantity.F90) +target_sources(multisystem_debug PRIVATE + algorithm.F90 + multisystem_debug.F90 + ) + +target_link_libraries(multisystem PUBLIC + system) +target_link_libraries(multisystem_debug PUBLIC + base_octopus) +target_link_libraries(system PUBLIC + interaction) +target_link_libraries(interaction PUBLIC + math multisystem_debug) diff --git a/src/opt_control/CMakeLists.txt b/src/opt_control/CMakeLists.txt new file mode 100644 index 0000000000..bffe59aa46 --- /dev/null +++ b/src/opt_control/CMakeLists.txt @@ -0,0 +1,13 @@ +target_sources(opt_control PRIVATE + opt_control.F90 + opt_control_global.F90 + opt_control_iter.F90 + propagation.F90 + controlfunction.F90 + filter.F90 + target.F90 + initst.F90 + ) + +target_link_libraries(opt_control PUBLIC + electrons) diff --git a/src/output/CMakeLists.txt b/src/output/CMakeLists.txt new file mode 100644 index 0000000000..51cb1c1460 --- /dev/null +++ b/src/output/CMakeLists.txt @@ -0,0 +1,17 @@ +target_sources(output PRIVATE + ../grid/basins.F90 # used only by output and local_multipoles + output.F90 + output_me.F90 + output_berkeleygw.F90 + output_modelmb.F90 + output_mxll.F90 + output_linear_medium.F90 + ../electrons/dos.F90 + ../maxwell/external_densities.F90 # used only by output and maxwell which depends on output + ../maxwell/hamiltonian_mxll.F90 # Other depend on output as well + ../maxwell/energy_mxll.F90 + ../math/young.F90 # used by otuput and modelmb_exchange_syms + ) + +target_link_libraries(output PUBLIC + v_ks elf fourier_shell maxwell_boundary states_elec_io) diff --git a/src/poisson/CMakeLists.txt b/src/poisson/CMakeLists.txt new file mode 100644 index 0000000000..912054e369 --- /dev/null +++ b/src/poisson/CMakeLists.txt @@ -0,0 +1,25 @@ +target_sources(poisson PRIVATE + poisson.F90 + photon_mode.F90 + poisson_cg.F90 + poisson_isf.F90 + ../math/sgfft.F90 # Used by poisson_isf only + poisson_fft.F90 + poisson_fmm.F90 + poisson_psolver.F90 + poisson_multigrid.F90 + poisson_no.F90 + poisson_cutoff.F90 + poisson_cutoffs.c + poisson_corrections.F90 + scaling_function.F90 + ) +target_sources(photon_mode PRIVATE + photon_mode.F90 + ) + +target_link_libraries(poisson PUBLIC + cube derivatives multigrid) +target_link_libraries(photon_mode PUBLIC + mesh) + diff --git a/src/scf/CMakeLists.txt b/src/scf/CMakeLists.txt new file mode 100644 index 0000000000..4d61f0e642 --- /dev/null +++ b/src/scf/CMakeLists.txt @@ -0,0 +1,30 @@ +target_sources(scf PRIVATE + lda_u_mixer.F90 + scf.F90 + ../hamiltonian/berry.F90 + ../multisystem/convergence_criterion.F90 + criteria_factory.F90 + eigenval_criterion.F90 + density_criterion.F90 + energy_criterion.F90 + ../states/modelmb_exchange_syms.F90 + ../math/permutations.F90 + ../electrons/stress.F90 + ) +target_sources(mix PRIVATE + mix.F90) +target_sources(electrons_ground_state PRIVATE + electrons_ground_state.F90 + rdmft.F90) +target_sources(lcao PRIVATE + lcao.F90) + +target_link_libraries(scf PUBLIC + output mix forces lcao) +target_link_libraries(mix PUBLIC + mesh derivatives) +target_link_libraries(electrons_ground_state PUBLIC + scf) +target_link_libraries(lcao PUBLIC + v_ks states_elec_io) + diff --git a/src/species/CMakeLists.txt b/src/species/CMakeLists.txt new file mode 100644 index 0000000000..5c96bb3b68 --- /dev/null +++ b/src/species/CMakeLists.txt @@ -0,0 +1,32 @@ +target_sources(species PRIVATE + ../math/spline_filter.F90 + ../math/spline_low.cc + ../math/splines.F90 + atomic.F90 + element.F90 + element_low.cc + logrid.F90 + ps.F90 + ps_cpi.F90 + ps_cpi_file.F90 + ps_fhi.F90 + ps_fhi_file.F90 + ps_hgh.F90 + ps_in_grid.F90 + ps_psf.F90 + ps_psf_file.F90 + ps_xml.F90 + pseudo.F90 + pseudo_low.cc + spline.cc + pseudo_set.F90 + pseudo_set_low.cc + share_directory.F90 + share_directory_low.cc + species.F90 + ) + +target_link_libraries(species PUBLIC + math_adv) +target_link_libraries(species PRIVATE + rapidxml ${Libxc_Target}) diff --git a/src/states/CMakeLists.txt b/src/states/CMakeLists.txt new file mode 100644 index 0000000000..75df18a3b6 --- /dev/null +++ b/src/states/CMakeLists.txt @@ -0,0 +1,37 @@ +target_sources(wfs_elec PRIVATE + wfs_elec.F90) +target_sources(states_elec PRIVATE + ../hamiltonian/singularity.F90 + ../math/pblas.F90 # Only used by states_elec_calc + linear_response.F90 + modelmb_particles.F90 + physics_op.F90 + smear.F90 + states_abst.F90 + states_elec.F90 + states_elec_calc.F90 + states_elec_dim.F90 + states_elec_group.F90 + states_elec_parallel.F90 + states_elec_restart.F90 + ) +target_sources(density PRIVATE + density.F90 + ) +target_sources(states_elec_io PRIVATE + states_elec_io.F90 + ) +target_sources(excited_states PRIVATE + excited_states.F90) + +target_link_libraries(states_elec PUBLIC + poisson grid) +target_link_libraries(wfs_elec PUBLIC + batch) +target_link_libraries(density PUBLIC + states_elec) +target_link_libraries(states_elec_io PUBLIC + states_elec orbitalset_utils) +target_link_libraries(excited_states PUBLIC + states_elec) + diff --git a/src/sternheimer/CMakeLists.txt b/src/sternheimer/CMakeLists.txt new file mode 100644 index 0000000000..43e141aad4 --- /dev/null +++ b/src/sternheimer/CMakeLists.txt @@ -0,0 +1,5 @@ +target_sources(sternheimer PRIVATE + sternheimer.F90) + +target_link_libraries(sternheimer PUBLIC + density scf_tol linear_solver mix perturbation) diff --git a/src/td/CMakeLists.txt b/src/td/CMakeLists.txt new file mode 100644 index 0000000000..056664d853 --- /dev/null +++ b/src/td/CMakeLists.txt @@ -0,0 +1,42 @@ +target_sources(td_write PRIVATE + td_write.F90 + td_calc.F90 + ../states/states_mxll_restart.F90 + ../maxwell/propagator_mxll.F90 + ) +target_sources(td PRIVATE + td.F90 + propagator_elec.F90 + propagator_base.F90 + propagator_cn.F90 + propagator_rk.F90 + propagator_etrs.F90 + propagator_expmid.F90 + propagator_magnus.F90 + propagator_qoct.F90 + propagation_ops_elec.F90 + potential_interpolation.F90 + ../math/sparskit.F90 + ../states/opt_control_state.F90 + ) +target_sources(pes PRIVATE + pes.F90 + pes_mask.F90 + pes_flux.F90 + pes_spm.F90 + ) +target_sources(spectrum PRIVATE + spectrum.F90 + ../math/compressed_sensing.F90) + +target_link_libraries(td_write PUBLIC + output excited_states forces perturbation) +target_link_libraries(td PUBLIC + td_write classical_particle electrons_ground_state pes) +target_link_libraries(pes PUBLIC + output) +target_link_libraries(spectrum PUBLIC + kick + PRIVATE bpdn) + + diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt new file mode 100644 index 0000000000..0e7b9b25f3 --- /dev/null +++ b/src/utils/CMakeLists.txt @@ -0,0 +1,83 @@ +add_executable(oct-casida_spectrum casida_spectrum.F90) +target_link_libraries(oct-casida_spectrum PRIVATE + ions fortran_cli) + +add_executable(oct-center-geom centergeom.F90) +target_link_libraries(oct-center-geom PRIVATE + ions fortran_cli) + +add_executable(oct-conductivity conductivity.F90) +target_link_libraries(oct-conductivity PRIVATE + spectrum fortran_cli) + +add_executable(oct-convert convert.F90) +target_link_libraries(oct-convert PRIVATE + electrons spectrum fortran_cli) + +add_executable(oct-dielectric-function dielectric_function.F90) +target_link_libraries(oct-dielectric-function PRIVATE + spectrum fortran_cli) + +add_executable(oct-floquet floquet.F90) +target_link_libraries(oct-floquet PRIVATE + electrons fortran_cli) + +add_executable(oct-harmonic-spectrum harmonic_spectrum.F90) +target_link_libraries(oct-harmonic-spectrum PRIVATE + math_fft spectrum fortran_cli) + +add_executable(oct-help help.F90) +target_link_libraries(oct-help PRIVATE + fortran_cli) + +add_executable(oct-infrared_spectrum infrared.F90) +target_link_libraries(oct-infrared_spectrum PRIVATE + math fortran_cli) + +add_executable(oct-local_multipoles local_multipoles.F90) +target_sources(oct-local_multipoles PRIVATE + ../boxes/box_union.F90 + ../boxes/multibox.F90 + local_write.F90) +target_link_libraries(oct-local_multipoles PRIVATE + electrons fortran_cli) + +add_executable(oct-oscillator-strength oscillator_strength.F90) +target_link_libraries(oct-oscillator-strength PRIVATE + spectrum fortran_cli) + +add_executable(oct-photoelectron_spectrum photoelectron_spectrum.F90) +target_sources(oct-photoelectron_spectrum PRIVATE + ../td/pes_out.F90) +target_link_libraries(oct-photoelectron_spectrum PRIVATE + states_elec pes fortran_cli) + +add_executable(oct-propagation_spectrum propagation_spectrum.F90) +target_link_libraries(oct-propagation_spectrum PRIVATE + spectrum fortran_cli) + +add_executable(oct-spin_susceptibility spin_susceptibility.F90) +target_link_libraries(oct-spin_susceptibility PRIVATE + ions spectrum fortran_cli) + +add_executable(oct-tdtdm tdtdm.F90) +target_link_libraries(oct-tdtdm PRIVATE + electrons spectrum fortran_cli) + +add_executable(oct-unfold unfold.F90) +target_link_libraries(oct-unfold PRIVATE + fourier_shell electrons fortran_cli) + +add_executable(oct-vibrational_spectrum vibrational.F90) +target_link_libraries(oct-vibrational_spectrum PRIVATE + spectrum fortran_cli) + +add_executable(oct-wannier90 wannier90_interface.F90) +target_sources(oct-wannier90 PRIVATE + ../math/ylm_wannier.F90) +target_link_libraries(oct-wannier90 PRIVATE + states_elec orbitalset electrons fortran_cli) + +add_executable(oct-xyz-anim xyzanim.F90) +target_link_libraries(oct-xyz-anim PRIVATE + ions fortran_cli) \ No newline at end of file -- GitLab From c7f9bde2eac161f92fd35f970ba08770846d3af3 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Mon, 23 Jan 2023 16:55:40 +0100 Subject: [PATCH 09/16] Configure external library setup - Bundle required libraries as submodule - Allow to choose between bundled, external (downloaded) or system libraries Signed-off-by: Cristian Le --- .gitmodules | 0 .pre-commit-config.yaml | 4 ++ CMakeLists.txt | 47 ++++++++++--------- cmake/helpers.cmake | 83 ++++++++++++++++++++++++++++++++++ external_libs/CMakeLists.txt | 2 + src/hamiltonian/CMakeLists.txt | 2 +- src/ions/CMakeLists.txt | 2 +- src/species/CMakeLists.txt | 2 +- third_party/.gitkeep | 0 9 files changed, 118 insertions(+), 24 deletions(-) create mode 100644 .gitmodules create mode 100644 cmake/helpers.cmake create mode 100644 third_party/.gitkeep diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..e69de29bb2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 204113b034..e203acf12b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,6 +2,7 @@ default_stages: [push, manual] exclude: | (?x)^( external_libs/| + third_party/| liboct_parser/| share/ ) @@ -29,6 +30,7 @@ repos: exclude: | (?x)( ^external_libs/| + ^third_party/| ^liboct_parser/| ^share/| ^.idea/| @@ -43,6 +45,7 @@ repos: exclude: | (?x)( ^external_libs/| + ^third_party/| ^liboct_parser/| ^share/| ^.idea/| @@ -57,6 +60,7 @@ repos: exclude: | (?x)( ^external_libs/| + ^third_party/| ^liboct_parser/| ^share/| ^.idea/| diff --git a/CMakeLists.txt b/CMakeLists.txt index 0331f0acf3..fb568a1e87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,8 @@ endif() include_directories(${CMAKE_Fortran_MODULE_DIRECTORY}) # Add options +include(cmake/helpers.cmake) +include(FetchContent) # TODO: Clarify max_dim of what set(max-dim 3 CACHE STRING "maximum number of dimensions Octopus can use; [default=3;must be>=3]") @@ -24,6 +26,20 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() +option(USE_BUNDLED "Use all bundled external libraries" OFF) +oct_add_external_library(Libxc GIT_REPO https://gitlab.com/libxc/libxc VERSION 5.2.3) +oct_add_external_library(spglib GIT_REPO https://github.com/spglib/spglib VERSION v2.1.0) + +# TODO: Build flags for the bundled cmake projects. Should be namespaced upstream or fixed with issue above +if (USE_BUNDLED OR USE_BUNDLED_Libxc OR USE_EXTERNAL_Libxc) + set(ENABLE_FORTRAN ON) +endif() +# Set namespaced build flags +set(spglib_WITH_Fortran ON) + +# TODO: Temporary fix for missing namespaces in bundled libraries +oct_fix_target_namespace(Libxc xcf03) + # Build tools find_package(PkgConfig REQUIRED) @@ -40,28 +56,17 @@ find_package(FFTW REQUIRED) ## Other installed packages ## TODO: Require cmake targets over pkg-config once these are included find_package(GSL REQUIRED) -find_package(Libxc 5.0 QUIET) -if(NOT Libxc_FOUND) - pkg_check_modules(Libxc_f03 REQUIRED libxcf03>=5.0 IMPORTED_TARGET) - set(Libxc_VERSION ${Libxc_f03_VERSION}) - set(Libxc_Target "PkgConfig::Libxc_f03") - # TODO: libxc is packaged wrong on fedora with respect to pkg-config files - include_directories(/usr/lib64/gfortran/modules) -# message(FATAL_ERROR -# "Libxc_f03_LINK_LIBRARIES = ${Libxc_f03_LINK_LIBRARIES} -# Libxc_f03_CFLAGS = ${Libxc_f03_CFLAGS} -# Libxc_f03_LIBRARIES = ${Libxc_f03_LIRARIES}") -else() - set(Libxc_Target "Libxc::xcf03") -endif () -find_package(spglib QUIET) -if(NOT spglib_FOUND) - pkg_check_modules(spglib_f08 REQUIRED spglib_f08) - set(spglib_Target "PkgConfig::spglib_f08") -else() - set(spglib_Target "spglib::spglib_f08") -endif () +find_package(Libxc 5.0 REQUIRED) +find_package(spglib REQUIRED) +# TODO: Libxc does not set Libxc_VERSION properly +if (USE_BUNDLED OR USE_BUNDLED_Libxc OR USE_EXTERNAL_Libxc) + if (USE_EXTERNAL_Libxc) + set(Libxc_VERSION ${USE_Libxc_VERSION}) + else() + set(Libxc_VERSION 5.2.3) + endif() +endif() if(Libxc_VERSION VERSION_GREATER_EQUAL 5) set(HAVE_LIBXC5 1) diff --git a/cmake/helpers.cmake b/cmake/helpers.cmake new file mode 100644 index 0000000000..77d6af504b --- /dev/null +++ b/cmake/helpers.cmake @@ -0,0 +1,83 @@ +macro(oct_add_external_library _name) + # Add options to build Octopus with either bundled or external/downloaded library + # + # Macro variables:: + # _name (string): Name of the external library to be included + # Named arguments:: + # GIT_REPO (string): Git repository of the library + # VERSION (string): Git tag/commitish to be checked-out + # + # Note: Has to be macro so that the variables are not limited to current scope + + cmake_parse_arguments(ARGS + "" # Options + "GIT_REPO;VERSION" # Single-value arguments + "" # Multiple-value arguments + ${ARGN}) + + # Basic checks + if (NOT DEFINED ARGS_GIT_REPO OR NOT DEFINED ARGS_VERSION) + message(FATAL_ERROR + "Missing arguments\n" + "ARGS_GIT_REPO = ${ARGS_GIT_REPO}\n" + "ARGS_VERSION = ${ARGS_VERSION}") + endif () + + if (EXISTS ${PROJECT_SOURCE_DIR}/third_party/${_name}) + # If the external library is bundled + option(USE_BUNDLED_${_name} "Use bundled ${_name}" OFF) + elseif (DEFINED USE_BUNDLED_${_name}) + message(WARNING "USE_BUNDLED_${_name} was defined, but ${_name} is not bundled with octopus.") + unset(USE_BUNDLED_${_name}) + endif () + option(USE_EXTERNAL_${_name} "Use external ${_name}" OFF) + # Check if we are asking for both external and bundled version which is ambiguous + if (USE_EXTERNAL_${_name} AND USE_BUNDLED_${_name}) + message(FATAL_ERROR + "Requesting both external/downloaded and bundled version of ${_name}.\n" + "Please specify either one or the other") + endif () + set(USE_${_name}_VERSION ${ARGS_VERSION} CACHE STRING "${_name} version to download and use. [default=${ARGS_VERSION}]") + if (USE_EXTERNAL_${_name} OR (DEFINED USE_BUNDLED_${_name} AND (USE_BUNDLED OR USE_BUNDLED_${_name}))) + FetchContent_Declare(${_name} + GIT_REPOSITORY ${ARGS_GIT_REPO} + GIT_TAG ${USE_${_name}_VERSION} + OVERRIDE_FIND_PACKAGE) + if (NOT USE_EXTERNAL_${_name}) + # If we want the bundled version specifically + string(TOUPPER ${_name} ${_name}_UPPER) + set(FETCHCONTENT_SOURCE_DIR_${${_name}_UPPER} ${PROJECT_SOURCE_DIR}/third_party/${_name}) + endif () + endif () +endmacro() + +# Temporary workaround for lack of namespace. Follow +# https://gitlab.kitware.com/cmake/cmake/-/issues/16414 +# https://gitlab.kitware.com/cmake/cmake/-/issues/22687 +function(oct_fix_target_namespace _name _target) + # Append namespace to target if not using bundled version + # + # Macro variables:: + # _name (string): Name of the external library to be included + # _target (string): Target name to append namespace + # Named arguments:: + # NAMESPACE (string) [${_name}]: Namespace to use + # + # Note: Please raise an issue upstream to include namespaced alias targets + # See [comment](https://gitlab.com/libxc/libxc/-/merge_requests/604#note_1269227160) for good practice + + cmake_parse_arguments(ARGS + "" # Options + "NAMESPACE" # Single-value arguments + "" # Multiple-value arguments + ${ARGN}) + if (NOT DEFINED ARGS_NAMESPACE) + set(ARGS_NAMESPACE ${_name}) + endif () + + if (USE_BUNDLED OR USE_BUNDLED_${_name} OR USE_EXTERNAL_${_name}) + set(${_name}_${target}_TARGET "${_target}" PARENT_SCOPE) + else () + set(${_name}_${target}_TARGET "${ARGS_NAMESPACE}::${_target}" PARENT_SCOPE) + endif () +endfunction() \ No newline at end of file diff --git a/external_libs/CMakeLists.txt b/external_libs/CMakeLists.txt index 30eb924e2c..6ade4da530 100644 --- a/external_libs/CMakeLists.txt +++ b/external_libs/CMakeLists.txt @@ -1,3 +1,5 @@ +# TODO: To be removed and switched to submodules + add_library(bpdn STATIC bpdn/expmm.c bpdn/heap.c diff --git a/src/hamiltonian/CMakeLists.txt b/src/hamiltonian/CMakeLists.txt index c223653c63..43769d73f9 100644 --- a/src/hamiltonian/CMakeLists.txt +++ b/src/hamiltonian/CMakeLists.txt @@ -50,7 +50,7 @@ target_sources(scf_tol PRIVATE target_link_libraries(xc_oct PUBLIC states_elec poisson - PRIVATE ${Libxc_Target}) + PUBLIC ${Libxc_xcf03_TARGET}) target_link_libraries(hamiltonian_elec PUBLIC xc_oct projector species_pot ext_partner_list kick orbitalset_utils) target_link_libraries(projector diff --git a/src/ions/CMakeLists.txt b/src/ions/CMakeLists.txt index 62fd9c7c3e..86adbb11d5 100644 --- a/src/ions/CMakeLists.txt +++ b/src/ions/CMakeLists.txt @@ -25,4 +25,4 @@ target_link_libraries(ion_dynamics PUBLIC target_link_libraries(born_charges PUBLIC states_elec) -target_link_libraries(symmetries PRIVATE ${spglib_Target}) \ No newline at end of file +target_link_libraries(symmetries PRIVATE spglib::spglib_f08) \ No newline at end of file diff --git a/src/species/CMakeLists.txt b/src/species/CMakeLists.txt index 5c96bb3b68..60021832b6 100644 --- a/src/species/CMakeLists.txt +++ b/src/species/CMakeLists.txt @@ -29,4 +29,4 @@ target_sources(species PRIVATE target_link_libraries(species PUBLIC math_adv) target_link_libraries(species PRIVATE - rapidxml ${Libxc_Target}) + rapidxml ${Libxc_xcf03_TARGET}) diff --git a/third_party/.gitkeep b/third_party/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 -- GitLab From 6b5ad8491150dbb85ee63a4bf91cae14ddc91c6a Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Mon, 20 Feb 2023 17:51:56 +0100 Subject: [PATCH 10/16] Add documentation Signed-off-by: Cristian Le --- Contributing.md | 3 ++ Development.md | 19 ++++++++++++ README | 9 +----- README.md | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ cmake/README.md | 37 +++++++++++++++++++++++ 5 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 Contributing.md create mode 100644 Development.md mode change 100644 => 120000 README create mode 100644 README.md create mode 100644 cmake/README.md diff --git a/Contributing.md b/Contributing.md new file mode 100644 index 0000000000..d48c26844f --- /dev/null +++ b/Contributing.md @@ -0,0 +1,3 @@ +# Contributing + +TBD diff --git a/Development.md b/Development.md new file mode 100644 index 0000000000..e1fefa94c2 --- /dev/null +++ b/Development.md @@ -0,0 +1,19 @@ +# Developing octopus + +## Development environment + +We recommend to setup the following development environments: + +- [`pre-commit`](#pre-commit) + +### Pre-commit + +Most of our coding standards are automatically resolved using `pre-commit`. To set it up simply run: + +```console +$ pip install pre-commit +$ pre-commit install +``` + +This installs commit hooks to various git commands, e.g. `git commit`, `git push`. We strongly +encourage developers to setup these hooks locally. diff --git a/README b/README deleted file mode 100644 index 62d7d3902b..0000000000 --- a/README +++ /dev/null @@ -1,8 +0,0 @@ -Octopus is a scientific program aimed at the ab initio virtual experimentation on a hopefully ever-increasing range of system types. -Electrons are described quantum-mechanically within density-functional theory (DFT), in its time-dependent form (TDDFT) when doing simulations in time. -Nuclei are described classically as point particles. Electron-nucleus interaction is described within the pseudopotential approximation. - -For optimal execution performance Octopus is parallelized using MPI and OpenMP and can scale to tens of thousands of processors. -It also has support for graphical processing units (GPUs) through OpenCL and CUDA. - -Octopus is free software, released under the GPL license, so you are free to download it, use it and modify it. diff --git a/README b/README new file mode 120000 index 0000000000..42061c01a1 --- /dev/null +++ b/README @@ -0,0 +1 @@ +README.md \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000..9d6e23f346 --- /dev/null +++ b/README.md @@ -0,0 +1,79 @@ +# Octopus + +Octopus is a scientific program for performing *ab-initio* simulations on a real-time, real-space grid. +The main function is to perform Time-Dependent Density Functional Theory (TD-DFT) calculations of electronic +systems, but it can also do classical simulations to extend these calculations. + + +* [Octopus](#octopus) + * [Building octopus](#building-octopus) + * [Running octopus](#running-octopus) + * [Contributing](#contributing) + * [Supported integrations](#supported-integrations) + * [License](#license) + + +## Building octopus + +The main building method for octopus going forward is using cmake, i.e.: + +```console +$ mkdir build && cd build +$ cmake .. +$ cmake --build . +``` + +For more details on how to configure the octopus build, check the [cmake documentation](cmake/README.md). + +## Running octopus + +The main interface of octopus are the `inp` files. Such a file HAS to be present in the work +directory for octopus to run, after which simply run `octopus`: + +```console +$ cat inp +CalculationMode = gs +PeriodicDimensions = 3 +a = 10.2 +BoxShape = parallelepiped +%LatticeParameters + a | a | a +% +%LatticeVectors + 0. | 0.5 | 0.5 + 0.5 | 0. | 0.5 + 0.5 | 0.5 | 0.0 +% +%ReducedCoordinates + "Si" | 0.0 | 0.0 | 0.0 + "Si" | 1/4 | 1/4 | 1/4 +% +Spacing = 0.5 +%KPointsGrid + 4 | 4 | 4 +% +Preconditioner = pre_multigrid +ConvEigenError = yes +ConvRelDens = 1e-9 +EigensolverTolerance = 1e-9 +$ octopus +``` + +Currently, there are no plans of expanding or refactoring this interface. + +## Contributing + +This project is primarily developed on gitlab.com, at [octopus-code/octopus](https://gitlab.com/octopus-code/octopus). +Issues and merge requests are welcome. See [Contributing.md](Contributing.md) for general guidelines for contributions +and [Development.md](Development.md) for recommendations on how to setup your development environment. + +## Supported integrations + +- MPI and OpenMP +- GPU computation via OpenCL and CUDA +- [Postopus](https://gitlab.com/octopus-code/postopus) + +## License + +Octopus is free software, released under the GPL license version 2 or higher. You are free to download it and use it. +You can freely modify it granted you follow the license terms and respect the attributions. diff --git a/cmake/README.md b/cmake/README.md new file mode 100644 index 0000000000..65c4521d15 --- /dev/null +++ b/cmake/README.md @@ -0,0 +1,37 @@ +# CMake configuration + +## CMake options + +Octopus exposes the following options to configure the compilation: + +| Option | Default | Description | +|:---------------------|:-----------------:|:-----------------------------------------------------------------| +| `USE_BUNDLED` | `OFF` | Use only the bundled external libraries | +| `USE_BUNDLED_` | `OFF` | Use the bundled `` library | +| `USE_EXTERNAL_` | `OFF` | Download `` library | +| `USE__VERSION` | (see main README) | Specify the `` version to dowload when `USE_EXTERNAL_` | +| `max-dim` | 3 | Maximum number of dimensions Octopus can use | + +See [Supported package flags](#supported-package-flags) for more information of the `` options. +To configure octopus with such options pass them as a cmake option (prefix them with `-D`, e.g. `-DUSE_BUNDLED=ON`) at +the configuration stage: + +```console +$ mkdir build && cd build +$ cmake .. ${CMAKE_OPTIONS} +$ cmake --build . +``` + +When using `USE_BUNDLED_` or `USE_EXTERNAL_` you may also pass additional configuration flags to configure +the `` library, e.g. `-DSPGLIB_USE_OMP=ON` + +## Supported package flags + +Not all configurations of `USE_BUNDLED_` and `USE_EXTERNAL_` are supported due to licensing, distribution or +build issues. + +| Package | Bundled | External | System | +|:--------|:-------:|:--------:|:------:| +| Libxc | ❌ | ✅ | ✅ | +| Spglib | ❌ | ✅ | ✅ | + -- GitLab From 18a54c781e172ee34633529345b6945c222fb71f Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Mon, 20 Feb 2023 17:58:10 +0100 Subject: [PATCH 11/16] Fix attribution for bundled cmake scripts - Removed TODOs in FindFFTW.cmake - Clarified attributes Signed-off-by: Cristian Le --- cmake/CheckFortranTypeSizes.cmake | 3 ++- cmake/FindFFTW.cmake | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmake/CheckFortranTypeSizes.cmake b/cmake/CheckFortranTypeSizes.cmake index 6257aa2b61..4657a910cb 100644 --- a/cmake/CheckFortranTypeSizes.cmake +++ b/cmake/CheckFortranTypeSizes.cmake @@ -1,4 +1,4 @@ -# This module perdorms several try-compiles to determine the default integer +# This module performs several try-compiles to determine the default integer # size being used by the fortran compiler # # After execution, the following variables are set. If they are un set then @@ -13,6 +13,7 @@ # Author: Chuck Atkins # Copyright 2011 # Original code: https://github.com/Reference-LAPACK/lapack/blob/f8fb0842d55c34ad2c26da58e9f55a3f10e52d0b/CMAKE/CheckFortranTypeSizes.cmake +# Additional changes by: Cristian Le #============================================================================= # Check the size of a single fortran type diff --git a/cmake/FindFFTW.cmake b/cmake/FindFFTW.cmake index f47f390d6d..fa9a548c0e 100644 --- a/cmake/FindFFTW.cmake +++ b/cmake/FindFFTW.cmake @@ -1,3 +1,8 @@ +# Upstream version: https://github.com/egpbos/findFFTW +# Removed TODOs to not interfere with local development. Otherwise the following is a direct copy of +# ac788529392825067c9118f9f099aaa1efb77589 +# Additional changes by: Cristian Le +# ---------------------------------------------------------------------------------------------------------------------- # - Find the FFTW library # # Original version of this file: @@ -33,9 +38,6 @@ # LONGDOUBLE_OPENMP_LIB # -# TODO (maybe): extend with ExternalProject download + build option -# TODO: put on conda-forge - if( NOT FFTW_ROOT AND DEFINED ENV{FFTWDIR} ) set( FFTW_ROOT $ENV{FFTWDIR} ) -- GitLab From 5425f92b61370035f4b3c7276b8c2a788370564b Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Mon, 20 Feb 2023 19:07:58 +0100 Subject: [PATCH 12/16] Add changes from review Signed-off-by: Cristian Le --- CMakeLists.txt | 35 +++++++++++++++++++---------------- cmake/helpers.cmake | 11 +++++++++-- cmake/mock_autotools.cmake | 4 ++-- external_libs/CMakeLists.txt | 2 +- src/CMakeLists.txt | 16 ++++++++-------- src/basic/CMakeLists.txt | 2 +- 6 files changed, 40 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb568a1e87..c2e94a4c4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,13 +4,14 @@ project(Octopus VERSION 12.1 DESCRIPTION "real-space, real-time, TDDFT code" LANGUAGES C Fortran CXX) -# TODO: Add the other language standards used +# Upstream: TODO: Add the other language standards used +# Currently Fortran standards are not defined in cmake set(CMAKE_CXX_STANDARD 14) # Basic setup # Add custom/third-party cmake modules set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") -# Build all fortran modules in a common module file for simpler loading +# Build all fortran modules in a common module directory for simpler loading if (NOT CMAKE_Fortran_MODULE_DIRECTORY) set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fortran_mods) endif() @@ -19,9 +20,8 @@ include_directories(${CMAKE_Fortran_MODULE_DIRECTORY}) # Add options include(cmake/helpers.cmake) include(FetchContent) -# TODO: Clarify max_dim of what -set(max-dim 3 - CACHE STRING "maximum number of dimensions Octopus can use; [default=3;must be>=3]") +set(max-dim 3 CACHE STRING + "maximum number of dimensions Octopus can use; [default=3;must be>=3]") if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() @@ -30,36 +30,39 @@ option(USE_BUNDLED "Use all bundled external libraries" OFF) oct_add_external_library(Libxc GIT_REPO https://gitlab.com/libxc/libxc VERSION 5.2.3) oct_add_external_library(spglib GIT_REPO https://github.com/spglib/spglib VERSION v2.1.0) -# TODO: Build flags for the bundled cmake projects. Should be namespaced upstream or fixed with issue above +# Build flags for the bundled cmake projects +# Upstream: TODO: Should be namespaced upstream. Please report them +## Libxc if (USE_BUNDLED OR USE_BUNDLED_Libxc OR USE_EXTERNAL_Libxc) set(ENABLE_FORTRAN ON) endif() + # Set namespaced build flags set(spglib_WITH_Fortran ON) -# TODO: Temporary fix for missing namespaces in bundled libraries +# Temporary fix for missing namespaces in bundled libraries +# Upstream: TODO: Report together with issues above oct_fix_target_namespace(Libxc xcf03) # Build tools find_package(PkgConfig REQUIRED) # Compute libraries -## TODO: remove separation headers when all libraries included -## TODO: Specify the supported versions -## Natively available libraries to cmake +## #641 TODO: Specify the supported versions + +## Cmake supported find_package(MPI) find_package(OpenMP) find_package(BLAS REQUIRED) find_package(LAPACK REQUIRED) -## Included in the cmake directory. Should deffer to packaged version or module +## Bundled Find.cmake find_package(FFTW REQUIRED) -## Other installed packages -## TODO: Require cmake targets over pkg-config once these are included +## Native upstream support find_package(GSL REQUIRED) find_package(Libxc 5.0 REQUIRED) find_package(spglib REQUIRED) -# TODO: Libxc does not set Libxc_VERSION properly +# Upstream: TODO: Libxc does not set Libxc_VERSION properly if (USE_BUNDLED OR USE_BUNDLED_Libxc OR USE_EXTERNAL_Libxc) if (USE_EXTERNAL_Libxc) set(Libxc_VERSION ${USE_Libxc_VERSION}) @@ -80,7 +83,7 @@ endif() # Note: other targets (e.g. oct-help) are defined in src/MakeLists.txt # Common octopus base included in all targets add_library(base_octopus STATIC) -# TODO: Switch to CMake native method or equivalent so that it can be indexed +# #640 TODO: Switch to CMake native method or equivalent so that it can be indexed #configure_file(include/options.h.in include/options.h) #configure_file(include/defaults.h.in include/defaults.h) add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/share/varinfo ${PROJECT_BINARY_DIR}/share/variables @@ -99,7 +102,7 @@ add_dependencies(base_octopus VarInfo) # Helper target for all fortran CLI executables add_library(fortran_cli STATIC) # Octopus library that we wish to expose -# TODO: Figure out the libraries we want to export +# #641 TODO: Figure out the libraries we want to export #add_library(liboctopus) # Main octopus executable add_executable(octopus) diff --git a/cmake/helpers.cmake b/cmake/helpers.cmake index 77d6af504b..bf8fba2017 100644 --- a/cmake/helpers.cmake +++ b/cmake/helpers.cmake @@ -6,6 +6,11 @@ macro(oct_add_external_library _name) # Named arguments:: # GIT_REPO (string): Git repository of the library # VERSION (string): Git tag/commitish to be checked-out + # Example:: + # oct_add_external_library(Libxc GIT_REPO https://gitlab.com/libxc/libxc GIT_TAG 6.0.0) + # Description:: + # This macro adds the options `USE_EXTERNAL_`, and, if bundled in `third_party`, it also adds + # `USE_BUNDLED_`, all default option to `OFF` to prioritize the available libraries on the system. # # Note: Has to be macro so that the variables are not limited to current scope @@ -34,8 +39,8 @@ macro(oct_add_external_library _name) # Check if we are asking for both external and bundled version which is ambiguous if (USE_EXTERNAL_${_name} AND USE_BUNDLED_${_name}) message(FATAL_ERROR - "Requesting both external/downloaded and bundled version of ${_name}.\n" - "Please specify either one or the other") + "Requesting both external and bundled version of ${_name}.\n" + "Please only set ONE of the options to ON: USE_EXTERNAL_${_name} or USE_BUNDLED_${_name}") endif () set(USE_${_name}_VERSION ${ARGS_VERSION} CACHE STRING "${_name} version to download and use. [default=${ARGS_VERSION}]") if (USE_EXTERNAL_${_name} OR (DEFINED USE_BUNDLED_${_name} AND (USE_BUNDLED OR USE_BUNDLED_${_name}))) @@ -62,6 +67,8 @@ function(oct_fix_target_namespace _name _target) # _target (string): Target name to append namespace # Named arguments:: # NAMESPACE (string) [${_name}]: Namespace to use + # Example:: + # oct_fix_target_namespace(Libxc xcf03) # # Note: Please raise an issue upstream to include namespaced alias targets # See [comment](https://gitlab.com/libxc/libxc/-/merge_requests/604#note_1269227160) for good practice diff --git a/cmake/mock_autotools.cmake b/cmake/mock_autotools.cmake index 76a179023a..de93b8a805 100644 --- a/cmake/mock_autotools.cmake +++ b/cmake/mock_autotools.cmake @@ -1,4 +1,4 @@ -# TODO: When removing autotools, replace flags with target_compile_define +# #639 TODO: When removing autotools, replace flags with target_compile_define string(TIMESTAMP BUILD_TIME) execute_process( @@ -32,7 +32,7 @@ check_include_file(stdint.h HAVE_STDINT_H) check_include_file(string.h HAVE_STRING_H) check_include_file(windows.h HAVE_WINDOWS_H) #check_include_file(iotcl.h HAVE_IOCTL) -# TODO: Eliminate unnecessary function checks in code +# #642 TODO: Eliminate unnecessary function checks in code # NOTE: Some files do not have checks check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) check_function_exists(nanosleep HAVE_NANOSLEEP) diff --git a/external_libs/CMakeLists.txt b/external_libs/CMakeLists.txt index 6ade4da530..6e5b159a5e 100644 --- a/external_libs/CMakeLists.txt +++ b/external_libs/CMakeLists.txt @@ -1,4 +1,4 @@ -# TODO: To be removed and switched to submodules +# !1888 TODO: To be removed and switched to submodules add_library(bpdn STATIC bpdn/expmm.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 79ed8804e4..9b0fa07b7d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,6 @@ -# Further configure the main targets -#set_target_properties(liboctopus PROPERTIES -# LIBRARY_OUTPUT_NAME liboct) - # Define additional helper interface targets -foreach (int_lib IN ITEMS +list(APPEND OctopusInternalLibs atomic_orbital basic_accel batch box box_factory classical_particles cube derivatives ext_partner_list grid hamiltonian_elec interaction interactions_factory ion_dynamics ions kick kpoints math math_adv math_fft maxwell mesh multibox multigrid multisystem multisystem_debug orbitalset output poisson projector scf species @@ -12,12 +8,16 @@ foreach (int_lib IN ITEMS exponential sternheimer scf_tol mix perturbation elf fourier_shell maxwell_boundary states_elec_io orbitalset_utils td td_write electrons forces born_charges excited_states classical_particle electrons_ground_state lcao pes opt_control spectrum) +list(APPEND sourceSubDirs + classical ions math multisystem species interactions basic scf grid boxes states electrons + poisson hamiltonian basis_set maxwell output sternheimer td opt_control main utils include) + +foreach (int_lib IN LISTS OctopusInternalLibs) add_library(${int_lib} STATIC) endforeach () -# Include specific definitions of these targets -foreach (subdir IN ITEMS classical ions math multisystem species interactions basic scf grid boxes states electrons - poisson hamiltonian basis_set maxwell output sternheimer td opt_control main utils include) +# Specify directories containing CMakeLists.txt and source code +foreach (subdir IN LISTS sourceSubDirs) add_subdirectory(${subdir}) endforeach () diff --git a/src/basic/CMakeLists.txt b/src/basic/CMakeLists.txt index 3287cc7920..481d79bfef 100644 --- a/src/basic/CMakeLists.txt +++ b/src/basic/CMakeLists.txt @@ -72,7 +72,7 @@ target_link_libraries(fortran_cli PUBLIC base_octopus) target_include_directories(base_octopus PUBLIC $ ../include) -# TODO: Not sure why this is not in /src +# #643 TODO: Not sure why this is not in /src target_include_directories(base_octopus PUBLIC ../../liboct_parser) target_link_libraries(base_octopus PUBLIC -- GitLab From 7547e03970ca2b879d953a73a51a991f2e940d43 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Tue, 21 Feb 2023 15:36:18 +0100 Subject: [PATCH 13/16] Fix oct_fix_target_namespace Signed-off-by: Cristian Le --- cmake/helpers.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/helpers.cmake b/cmake/helpers.cmake index bf8fba2017..c28a9a6195 100644 --- a/cmake/helpers.cmake +++ b/cmake/helpers.cmake @@ -83,8 +83,8 @@ function(oct_fix_target_namespace _name _target) endif () if (USE_BUNDLED OR USE_BUNDLED_${_name} OR USE_EXTERNAL_${_name}) - set(${_name}_${target}_TARGET "${_target}" PARENT_SCOPE) + set(${_name}_${_target}_TARGET "${_target}" PARENT_SCOPE) else () - set(${_name}_${target}_TARGET "${ARGS_NAMESPACE}::${_target}" PARENT_SCOPE) + set(${_name}_${_target}_TARGET "${ARGS_NAMESPACE}::${_target}" PARENT_SCOPE) endif () endfunction() \ No newline at end of file -- GitLab From 24b2f22921c235d4740252268cc9e1a722720cb7 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Thu, 9 Mar 2023 15:11:27 +0100 Subject: [PATCH 14/16] Fix VarInfo copying Only copy if contents of the files changed. Makes sure: - VarInfo is always run and it always runs `mk_varinfo.pl` - Not all downstream targets are re-built. This is due to bad design in that everything is dependent on a global header Signed-off-by: Cristian Le --- CMakeLists.txt | 19 ++++++++++++------- cmake/ChecksumCopy.cmake | 23 +++++++++++++++++++++++ cmake/helpers.cmake | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 cmake/ChecksumCopy.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c2e94a4c4d..e5ded71539 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,19 +86,24 @@ add_library(base_octopus STATIC) # #640 TODO: Switch to CMake native method or equivalent so that it can be indexed #configure_file(include/options.h.in include/options.h) #configure_file(include/defaults.h.in include/defaults.h) -add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/share/varinfo ${PROJECT_BINARY_DIR}/share/variables +# TODO: Move away from header re-generation of mk_varinfo.pl. Use static lists and dictionaries instead +file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/tmp_generated) +add_custom_target(VarInfo COMMAND ${PROJECT_SOURCE_DIR}/scripts/mk_varinfo.pl -s ${PROJECT_SOURCE_DIR} - -b ${PROJECT_BINARY_DIR} - COMMENT "Generating variable information:" - ) -add_custom_target(VarInfo DEPENDS ${PROJECT_BINARY_DIR}/share/varinfo ${PROJECT_BINARY_DIR}/share/variables) + -b ${PROJECT_BINARY_DIR}/tmp_generated + COMMENT "Generating variable information") +# Define target ChecksumCopy that copies from ${PROJECT_BINARY_DIR}/tmp_generated to ${PROJECT_BINARY_DIR} only if +# contents changed. This guarantees VarInfo is always called, but dependent targets do not rebuild unnecessarily if +# src/include/options.h and src/include/defaults.h is not *really* changed. +oct_add_checksum_copy(${PROJECT_BINARY_DIR}/tmp_generated ${PROJECT_BINARY_DIR}) +add_dependencies(ChecksumCopy VarInfo) +add_dependencies(base_octopus ChecksumCopy) + # Auxiliary files file(COPY share DESTINATION ${PROJECT_BINARY_DIR} PATTERN *.am EXCLUDE) -add_dependencies(base_octopus VarInfo) - # Helper target for all fortran CLI executables add_library(fortran_cli STATIC) # Octopus library that we wish to expose diff --git a/cmake/ChecksumCopy.cmake b/cmake/ChecksumCopy.cmake new file mode 100644 index 0000000000..2791509580 --- /dev/null +++ b/cmake/ChecksumCopy.cmake @@ -0,0 +1,23 @@ +# Script to be called by the target in `oct_add_checksum_copy` in `helpers.cmake` +# Check the checksums of all the files in `checksum_src` and copy the files if they differ from `checksum_dest` + +# Variables:: +# checksum_src (path): location of the source to copy from +# checksum_dest (path): location of the source to copy to + +# Check if directory does not exist +if (NOT EXISTS ${checksum_dest}) + # If doesn't exist can just copy everything + message(VERBOSE + "ChecksumCopy: Destination folder not found. Copying everything\n" + "${checksum_src} -> ${checksum_dest}") + file(COPY ${checksum_src} ${checksum_dest}) + return() +endif () + +# Check each file +file(GLOB_RECURSE src_files RELATIVE ${checksum_src} ${checksum_src}/*) +foreach (file IN LISTS src_files) + file(COPY_FILE ${checksum_src}/${file} ${checksum_dest}/${file} + ONLY_IF_DIFFERENT) +endforeach () diff --git a/cmake/helpers.cmake b/cmake/helpers.cmake index c28a9a6195..fe13375d59 100644 --- a/cmake/helpers.cmake +++ b/cmake/helpers.cmake @@ -87,4 +87,41 @@ function(oct_fix_target_namespace _name _target) else () set(${_name}_${_target}_TARGET "${ARGS_NAMESPACE}::${_target}" PARENT_SCOPE) endif () -endfunction() \ No newline at end of file +endfunction() + +function(oct_add_checksum_copy _src _dest) + # Add a custom target that copies the files from _src to _dest only if checksums are different + # + # Macro variables:: + # _src (path): Name of the external library to be included + # _dest (path): Target name to append namespace + # Named arguments:: + # TARGET (string) [ChecksumCopy]: Custom target that runs ChecksumCopy.cmake + # Example:: + # oct_add_checksum_copy(/path/to/generated/root /path/to/final/root) + # + # Note: This should not be necessary if we separate header and source files properly + + cmake_parse_arguments(ARGS + "" # Options + "TARGET" # Single-value arguments + "" # Multiple-value arguments + ${ARGN}) + + if (NOT DEFINED ARGS_TARGET) + set(ARGS_TARGET ChecksumCopy) + endif () + + if (CMAKE_VERSION VERSION_LESS 3.26) + add_custom_target(${ARGS_TARGET} + COMMAND ${CMAKE_COMMAND} + -Dchecksum_src=${_src} + -Dchecksum_dest=${_dest} + -P ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ChecksumCopy.cmake + COMMENT "Checking and copying files") + else () + add_custom_target(${ARGS_TARGET} + COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${_src} ${_dest} + COMMENT "Checking and copying files") + endif () +endfunction() -- GitLab From b0839d16f2bef2bccd202e1624cb20c72e208e82 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Tue, 21 Feb 2023 17:24:49 +0100 Subject: [PATCH 15/16] Bundle Libxc and Spglib Signed-off-by: Cristian Le --- .gitmodules | 6 ++++++ CMakeLists.txt | 6 +++--- src/ions/CMakeLists.txt | 2 +- third_party/Libxc | 1 + third_party/Spglib | 1 + 5 files changed, 12 insertions(+), 4 deletions(-) create mode 160000 third_party/Libxc create mode 160000 third_party/Spglib diff --git a/.gitmodules b/.gitmodules index e69de29bb2..f621b7a26b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "third_party/Libxc"] + path = third_party/Libxc + url = https://gitlab.com/libxc/libxc +[submodule "third_party/Spglib"] + path = third_party/Spglib + url = https://github.com/spglib/spglib.git diff --git a/CMakeLists.txt b/CMakeLists.txt index e5ded71539..97ba87e748 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ endif() option(USE_BUNDLED "Use all bundled external libraries" OFF) oct_add_external_library(Libxc GIT_REPO https://gitlab.com/libxc/libxc VERSION 5.2.3) -oct_add_external_library(spglib GIT_REPO https://github.com/spglib/spglib VERSION v2.1.0) +oct_add_external_library(Spglib GIT_REPO https://github.com/spglib/spglib VERSION v2.1.0) # Build flags for the bundled cmake projects # Upstream: TODO: Should be namespaced upstream. Please report them @@ -38,7 +38,7 @@ if (USE_BUNDLED OR USE_BUNDLED_Libxc OR USE_EXTERNAL_Libxc) endif() # Set namespaced build flags -set(spglib_WITH_Fortran ON) +set(SPGLIB_WITH_Fortran ON) # Temporary fix for missing namespaces in bundled libraries # Upstream: TODO: Report together with issues above @@ -60,7 +60,7 @@ find_package(FFTW REQUIRED) ## Native upstream support find_package(GSL REQUIRED) find_package(Libxc 5.0 REQUIRED) -find_package(spglib REQUIRED) +find_package(Spglib REQUIRED) # Upstream: TODO: Libxc does not set Libxc_VERSION properly if (USE_BUNDLED OR USE_BUNDLED_Libxc OR USE_EXTERNAL_Libxc) diff --git a/src/ions/CMakeLists.txt b/src/ions/CMakeLists.txt index 86adbb11d5..12f86afa07 100644 --- a/src/ions/CMakeLists.txt +++ b/src/ions/CMakeLists.txt @@ -25,4 +25,4 @@ target_link_libraries(ion_dynamics PUBLIC target_link_libraries(born_charges PUBLIC states_elec) -target_link_libraries(symmetries PRIVATE spglib::spglib_f08) \ No newline at end of file +target_link_libraries(symmetries PRIVATE Spglib::fortran) \ No newline at end of file diff --git a/third_party/Libxc b/third_party/Libxc new file mode 160000 index 0000000000..5d63dde34f --- /dev/null +++ b/third_party/Libxc @@ -0,0 +1 @@ +Subproject commit 5d63dde34f79a8f0b3ccbb5327f9191c821aa82d diff --git a/third_party/Spglib b/third_party/Spglib new file mode 160000 index 0000000000..02159eef6e --- /dev/null +++ b/third_party/Spglib @@ -0,0 +1 @@ +Subproject commit 02159eef6e7349535049a43fe2272bb634c77945 -- GitLab From 747fa0b8139055bd027309d31e5fed7e4c1f3e2f Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Tue, 7 Feb 2023 16:46:17 +0100 Subject: [PATCH 16/16] Add Doxygen documentation Signed-off-by: Cristian Le --- CMakeLists.txt | 5 ++++- doc/CMakeLists.txt | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97ba87e748..88faae3140 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() +option(WITH_DOCS "Build Doxygen documentation" ON) option(USE_BUNDLED "Use all bundled external libraries" OFF) oct_add_external_library(Libxc GIT_REPO https://gitlab.com/libxc/libxc VERSION 5.2.3) oct_add_external_library(Spglib GIT_REPO https://github.com/spglib/spglib VERSION v2.1.0) @@ -122,4 +123,6 @@ add_subdirectory(external_libs) add_subdirectory(src) # Generate documentation -add_subdirectory(doc) \ No newline at end of file +if (WITH_DOCS) + add_subdirectory(doc) +endif () diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index e69de29bb2..b9e25e4288 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -0,0 +1,5 @@ +find_package(Doxygen REQUIRED) +set(DOXYGEN_OPTIMIZE_FOR_FORTRAN YES) +set(DOXYGEN_FILE_PATTERNS "*.F90") +doxygen_add_docs(docs ${PROJECT_SOURCE_DIR}/src + ALL) -- GitLab