From d52b63dc374c6968810a767750ae96cc533b2f4e Mon Sep 17 00:00:00 2001 From: Philipp Pracht Date: Thu, 7 Mar 2024 12:37:14 +0000 Subject: [PATCH 1/5] Start revising CMake --- CMakeLists.txt | 169 ++++-------------------------- config/CMakeLists.txt | 175 +++++++++++++++++++------------- src/legacy_algos/cregen_old.f90 | 2 +- 3 files changed, 128 insertions(+), 218 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 37fc48df..c40de89e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,165 +1,38 @@ -# This file is part of crest. -# SPDX-Identifier: LGPL-3.0-or-later -# -# crest is free software: you can redistribute it and/or modify it under -# the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# crest is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. - +# SPDX-License-Identifier: LGPL-3.0-or-later +# Project configuration cmake_minimum_required(VERSION 3.14) - -project( - "crest" - LANGUAGES "Fortran" "C" - VERSION "3.0" -) +project(crest VERSION 3.0 LANGUAGES Fortran C) set(SOVERSION "pre") -# Follow GNU conventions for installing directories +# Include GNU installation directories include(GNUInstallDirs) -# General configuration information -set(libs) -add_subdirectory("config") - - -# -# Libraries -# - -# OpenMP dependency -if(NOT TARGET OpenMP::OpenMP_Fortran AND WITH_OpenMP) - find_package(OpenMP REQUIRED) - list( - APPEND libs - OpenMP::OpenMP_Fortran - ) -endif() - -# BLAS and LAPACK -if(NOT TARGET BLAS::BLAS) - find_package(BLAS REQUIRED) - if(NOT TARGET BLAS::BLAS AND BLAS_FOUND) - add_library(BLAS::BLAS INTERFACE IMPORTED) - target_link_libraries(BLAS::BLAS INTERFACE "${BLAS_LIBRARIES}") - target_link_options(BLAS::BLAS INTERFACE "${BLAS_LINKER_FLAGS}") - endif() -endif() -if(NOT TARGET LAPACK::LAPACK) - find_package(LAPACK REQUIRED) - if(NOT TARGET LAPACK::LAPACK AND LAPACK_FOUND) - add_library(LAPACK::LAPACK INTERFACE IMPORTED) - target_link_libraries(LAPACK::LAPACK INTERFACE "${LAPACK_LIBRARIES}") - target_link_options(LAPACK::LAPACK INTERFACE "${LAPACK_LINKER_FLAGS}") - endif() -endif() -list( - APPEND libs - LAPACK::LAPACK - BLAS::BLAS -) - -# tblite -if(WITH_TBLITE) - find_package("tblite" REQUIRED) - add_definitions(-DWITH_TBLITE) - list( - APPEND libs - tblite::tblite - ) -endif() - - -# toml-f -if(WITH_TOMLF) - find_package("toml-f" REQUIRED) - add_definitions(-DWITH_TOMLF) - list( - APPEND libs - toml-f::toml-f - ) -endif() +# General configuration and addition of subdirectories for further configurations and source +set(libs) # external dependencies will be added +set(omp) # omp dependency +add_subdirectory(config) # For detailed compiler options, feature toggles, and dependencies +set(srcs) # sources will be added +set(prog) # src/crest_main.f90 will be added +add_subdirectory(src) # Source files -# GFN0-xTB -if(WITH_GFN0) - find_package("gfn0" REQUIRED) - add_definitions(-DWITH_GFN0) - list( - APPEND libs - gfn0::gfn0 - ) -endif() - -# GFN-FF -if(WITH_GFNFF) - find_package("gfnff" REQUIRED) - add_definitions(-DWITH_GFNFF) - list( - APPEND libs - gfnff::gfnff - ) -endif() - -# XHCFF -if(WITH_XHCFF) - find_package("xhcff" REQUIRED) - add_definitions(-DWITH_XHCFF) - list( - APPEND libs - xhcff::xhcff - ) -endif() - - - - -# -# CREST sources -# -set(prog) -set(srcs) -add_subdirectory("src") - - -# -# Executables -# -add_executable( - ${PROJECT_NAME}-exe - "${srcs}" "${prog}" -) -set_target_properties( - ${PROJECT_NAME}-exe - PROPERTIES +# Define executable with the main program source included +add_executable(${PROJECT_NAME} ${prog} ${srcs}) +set_target_properties(${PROJECT_NAME} PROPERTIES Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/include RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} - OUTPUT_NAME "${PROJECT_NAME}" -) -target_link_libraries( - ${PROJECT_NAME}-exe - PRIVATE - "${libs}" + OUTPUT_NAME ${PROJECT_NAME} ) -get_target_property(OUT ${PROJECT_NAME}-exe LINK_LIBRARIES) -message(STATUS ${OUT}) +# Link libraries +target_link_libraries(${PROJECT_NAME} PRIVATE ${libs}) -# -# Binary installing option -# -install( - TARGETS - "${PROJECT_NAME}-exe" - EXPORT - "${PROJECT_NAME}-targets" +# Installation rules for the executable +install(TARGETS ${PROJECT_NAME} + EXPORT "${PROJECT_NAME}-targets" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) + diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index 06497a99..dc5cd37f 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -13,86 +13,127 @@ # # You should have received a copy of the GNU Lesser General Public License # along with crest. If not, see . - -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules") -set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) -install( - DIRECTORY - "${CMAKE_CURRENT_SOURCE_DIR}/modules/" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" -) - -set( - module-dir - "${PROJECT_NAME}/${CMAKE_Fortran_COMPILER_ID}-${CMAKE_Fortran_COMPILER_VERSION}" -) -set(module-dir "${module-dir}" PARENT_SCOPE) - - -# Set build type as CMake does not provide defaults -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - set( - CMAKE_BUILD_TYPE "RelWithDebInfo" - CACHE STRING "Build type to be used." - FORCE - ) - message( - STATUS - "Setting build type to '${CMAKE_BUILD_TYPE}' as none was specified." - ) +# Set the module path for CMake includes +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules;${CMAKE_MODULE_PATH}") + +# Options for enabling or disabling features +option(WITH_OPENMP "Enable OpenMP support" ON) +option(WITH_TBLITE "Enable support for tblite" OFF) +option(WITH_TOMLF "Enable support for toml-f" OFF) +option(WITH_GFN0 "Enable support for GFN0-xTB" OFF) +option(WITH_GFNFF "Enable support for GFN-FF" OFF) +option(WITH_XHCFF "Enable support for XHCFF" OFF) +option(WITH_LWONIOM "Enable support for lwONIOM" OFF) + +######################################################################################### +######################################################################################### + +# Compiler settings for GNU and Intel Fortran compilers +if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") + set(dialect "-g -O0 -fbacktrace -ffree-line-length-none -fbacktrace") + set(bounds "-fbounds-check") +elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") + set(dialect "-g -O2 -r8 -align array64byte -traceback") + set(bounds "-check bounds") endif() +# Apply the compiler flags +set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${bounds}") +set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}") -### Options and defaults +######################################################################################### +######################################################################################### -include("${CMAKE_CURRENT_SOURCE_DIR}/modules/crest-utils.cmake") -set(fortran_minimal_versions "GNU;7.5" "Intel;19.0") -check_minimal_compiler_version("Fortran" "${fortran_minimal_versions}") +# Handling dependencies and features -option(WITH_OpenMP "Enable support for shared memory parallelisation with OpenMP" TRUE) - -option(WITH_TBLITE "Enable build with the lightweight tight-binding library" TRUE) - -option(WITH_TOMLF "Enable build with toml-f support" TRUE) +# Find LAPACK +find_package(LAPACK REQUIRED) +if(LAPACK_FOUND) + list(APPEND libs ${LAPACK_LIBRARIES}) +endif() -option(WITH_GFN0 "Enable build with GFN0-xTB support" TRUE) +# Find BLAS +find_package(BLAS REQUIRED) +if(BLAS_FOUND) + list(APPEND libs ${BLAS_LIBRARIES}) +endif() -option(WITH_GFNFF "Enable build with GFN-FF support" TRUE) +# OpenMP +if(WITH_OPENMP) + find_package(OpenMP REQUIRED) + if(OpenMP_Fortran_FOUND) + #list(APPEND libs OpenMP::OpenMP_Fortran) + list(APPEND libs ${OpenMP_Fortran_LIBRARIES}) + endif() +endif() -option(WITH_XHCFF "Enable build with XHCFF support" FALSE) +# tblite +if(WITH_TBLITE) + find_package(tblite REQUIRED) + if(tblite_FOUND) + add_definitions(-DWITH_TBLITE) + include_directories(${tblite_INCLUDE_DIRS}) + list(APPEND libs ${tblite_LIBRARIES}) + endif() +endif() -option(WITH_LWONIOM "Enable build with lwONIOM support" TRUE) +# toml-f +if(WITH_TOMLF) + find_package(toml-f REQUIRED) + if(toml-f_FOUND) + add_definitions(-DWITH_TOMLF) + include_directories(${toml-f_INCLUDE_DIRS}) + list(APPEND libs ${tomlf_LIBRARIES}) + endif() +endif() -if(NOT DEFINED "${PROJECT_NAME}-dependency-method") - set( - "${PROJECT_NAME}-dependency-method" - "subproject" "cmake" "pkgconf" "fetch" - ) +# GFN0-xTB +if(WITH_GFN0) + find_package(GFN0 REQUIRED) + if(GFN0_FOUND) + add_definitions(-DWITH_GFN0) + include_directories(${GFN0_INCLUDE_DIRS}) + list(APPEND libs ${GFN0_LIBRARIES}) + endif() endif() -# -# Compiler settings -# -if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") -# set(dialect "-fdefault-real-8 -fdefault-double-8 -ffree-line-length-none -fbacktrace") - set(dialect "-g -O0 -fbacktrace -ffree-line-length-none -fbacktrace") - set(bounds "-fbounds-check") +# GFN-FF +if(WITH_GFNFF) + find_package(GFNFF REQUIRED) + if(GFNFF_FOUND) + add_definitions(-DWITH_GFNFF) + include_directories(${GFNFF_INCLUDE_DIRS}) + list(APPEND libs ${GFNFF_LIBRARIES}) + endif() endif() -if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") -# set(dialect "-axAVX2 -r8 -traceback") - set(dialect "-g -O2 -r8 -align array64byte -traceback") - set(bounds "-check bounds") + +# lwONIOM +if(WITH_LWONIOM) + find_package(LWONIOM REQUIRED) + if(LWONIOM_FOUND) + add_definitions(-DWITH_LWONIOM) + include_directories(${LWONIOM_INCLUDE_DIRS}) + list(APPEND libs ${LWONIOM_LIBRARIES}) + endif() endif() -if(CMAKE_Fortran_COMPILER_ID MATCHES "PGI") - set(dialect "-Mbackslash -Mallocatable=03 -r8 -traceback") + +# XHCFF +if(WITH_XHCFF) + find_package(XHCFF REQUIRED) + if(XHCFF_FOUND) + add_definitions(-DWITH_XHCFF) + include_directories(${XHCFF_INCLUDE_DIRS}) + list(APPEND libs ${XHCFF_LIBRARIES}) + endif() endif() -set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${bounds}" PARENT_SCOPE) -set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}" PARENT_SCOPE) +# IMPORTANT +set(libs ${libs} PARENT_SCOPE) + +########################################################################################## +########################################################################################## -# # Populate crest_metadata.fh -# set(version ${PROJECT_VERSION}${SOVERSION}) execute_process(COMMAND git show -s --format=%h RESULT_VARIABLE git_return @@ -111,7 +152,7 @@ set(fcver ${CMAKE_Fortran_COMPILER_VERSION}) set(ccid ${CMAKE_C_COMPILER_ID}) set(ccver ${CMAKE_C_COMPILER_VERSION}) set(bsystem "cmake ${CMAKE_VERSION}") -set(tomlfvar "${WITH_TOMLF}")#string(TOLOWER "${MY_BOOL}" ${WITH_TOMLF})) +set(tomlfvar "${WITH_TOMLF}") set(gfn0var "${WITH_GFN0}") set(gfnffvar "${WITH_GFNFF}") set(tblitevar "${WITH_TBLITE}") @@ -123,12 +164,8 @@ configure_file( "${PROJECT_BINARY_DIR}/crest_metadata.fh" @ONLY ) -# gfortran needs the file at another place... -configure_file( - "${PROJECT_SOURCE_DIR}/assets/template/metadata.f90" - "${PROJECT_BINARY_DIR}/include/crest_metadata.fh" - @ONLY -) +######################################################################################### +######################################################################################### diff --git a/src/legacy_algos/cregen_old.f90 b/src/legacy_algos/cregen_old.f90 index 28208ff2..053f2ca4 100644 --- a/src/legacy_algos/cregen_old.f90 +++ b/src/legacy_algos/cregen_old.f90 @@ -32,7 +32,7 @@ subroutine cregen2(env) use axis_module use miscdata, only: rcov use utilities - !$ use omp_lib + use omp_lib implicit none type(systemdata) :: env ! MAIN STORAGE OS SYSTEM DATA From aebc0fc13b606de9d3a036526decf6bf86f9459f Mon Sep 17 00:00:00 2001 From: Philipp Pracht Date: Thu, 7 Mar 2024 19:17:06 +0000 Subject: [PATCH 2/5] CMake changes --- CMakeLists.txt | 12 ++- config/CMakeLists.txt | 20 ++-- config/modules/Findgfnff.cmake | 7 +- config/oldcmakelists.txt | 134 ++++++++++++++++++++++++++ oldcmakelists | 165 +++++++++++++++++++++++++++++++++ 5 files changed, 324 insertions(+), 14 deletions(-) create mode 100644 config/oldcmakelists.txt create mode 100644 oldcmakelists diff --git a/CMakeLists.txt b/CMakeLists.txt index c40de89e..507833e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,6 @@ set(prog) # src/crest_main.f90 will be added add_subdirectory(src) # Source files - # Define executable with the main program source included add_executable(${PROJECT_NAME} ${prog} ${srcs}) set_target_properties(${PROJECT_NAME} PROPERTIES @@ -25,8 +24,17 @@ set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME} ) + # Link libraries -target_link_libraries(${PROJECT_NAME} PRIVATE ${libs}) +if(STATICLINK) +# set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") +# set(BUILD_SHARED_LIBS OFF) +# set(CMAKE_EXE_LINKER_FLAGS "-static") + message(STATUS "STATIC build requested") + target_link_libraries(${PROJECT_NAME} PRIVATE -static ${libs}) +else() + target_link_libraries(${PROJECT_NAME} PRIVATE ${libs}) +endif() # Installation rules for the executable install(TARGETS ${PROJECT_NAME} diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index dc5cd37f..98496807 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -17,6 +17,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules;${CMAKE_MODULE_PATH}") # Options for enabling or disabling features +option(STATICLINK "Build a static binary" ON) option(WITH_OPENMP "Enable OpenMP support" ON) option(WITH_TBLITE "Enable support for tblite" OFF) option(WITH_TOMLF "Enable support for toml-f" OFF) @@ -46,13 +47,14 @@ set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}") # Handling dependencies and features -# Find LAPACK +# Find LAPACK & BLAS +if(STATICLINK) + set(BLA_STATIC ON) +endif() find_package(LAPACK REQUIRED) if(LAPACK_FOUND) list(APPEND libs ${LAPACK_LIBRARIES}) endif() - -# Find BLAS find_package(BLAS REQUIRED) if(BLAS_FOUND) list(APPEND libs ${BLAS_LIBRARIES}) @@ -63,7 +65,7 @@ if(WITH_OPENMP) find_package(OpenMP REQUIRED) if(OpenMP_Fortran_FOUND) #list(APPEND libs OpenMP::OpenMP_Fortran) - list(APPEND libs ${OpenMP_Fortran_LIBRARIES}) + list(APPEND omp ${OpenMP_Fortran_LIBRARIES}) endif() endif() @@ -99,11 +101,10 @@ endif() # GFN-FF if(WITH_GFNFF) - find_package(GFNFF REQUIRED) - if(GFNFF_FOUND) + find_package("gfnff" REQUIRED) + if(gfnff_FOUND) add_definitions(-DWITH_GFNFF) - include_directories(${GFNFF_INCLUDE_DIRS}) - list(APPEND libs ${GFNFF_LIBRARIES}) + list(APPEND libs gfnff::gfnff) endif() endif() @@ -128,6 +129,7 @@ if(WITH_XHCFF) endif() # IMPORTANT +set(omp ${omp} PARENT_SCOPE) set(libs ${libs} PARENT_SCOPE) ########################################################################################## @@ -167,5 +169,3 @@ configure_file( ######################################################################################### ######################################################################################### - - diff --git a/config/modules/Findgfnff.cmake b/config/modules/Findgfnff.cmake index 9308b613..10a098a9 100644 --- a/config/modules/Findgfnff.cmake +++ b/config/modules/Findgfnff.cmake @@ -22,13 +22,16 @@ if(NOT DEFINED "${_pkg}_FIND_METHOD") if(DEFINED "${PROJECT_NAME}-dependency-method") set("${_pkg}_FIND_METHOD" "${${PROJECT_NAME}-dependency-method}") else() - set("${_pkg}_FIND_METHOD" "cmake" "pkgconf" "subproject" "fetch") + #set("${_pkg}_FIND_METHOD" "cmake" "pkgconf" "subproject" "fetch") + set("${_pkg}_FIND_METHOD" "subproject" "fetch") endif() set("_${_pkg}_FIND_METHOD") endif() include("${CMAKE_CURRENT_LIST_DIR}/crest-utils.cmake") + +message(STATUS "${${_pkg}_FIND_METHOD}") crest_find_package("${_lib}" "${${_pkg}_FIND_METHOD}" "${_url}") if(TARGET "gfnff::gfnff") @@ -36,7 +39,7 @@ if(TARGET "gfnff::gfnff") else() set (found FALSE) endif() -message("-- Found GFN-FF: ${found}") +message(STATUS "Found GFN-FF: ${found}") if(DEFINED "_${_pkg}_FIND_METHOD") unset("${_pkg}_FIND_METHOD") diff --git a/config/oldcmakelists.txt b/config/oldcmakelists.txt new file mode 100644 index 00000000..06497a99 --- /dev/null +++ b/config/oldcmakelists.txt @@ -0,0 +1,134 @@ +# This file is part of crest. +# SPDX-Identifier: LGPL-3.0-or-later +# +# crest is free software: you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# crest is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with crest. If not, see . + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules") +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) +install( + DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}/modules/" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" +) + +set( + module-dir + "${PROJECT_NAME}/${CMAKE_Fortran_COMPILER_ID}-${CMAKE_Fortran_COMPILER_VERSION}" +) +set(module-dir "${module-dir}" PARENT_SCOPE) + + +# Set build type as CMake does not provide defaults +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set( + CMAKE_BUILD_TYPE "RelWithDebInfo" + CACHE STRING "Build type to be used." + FORCE + ) + message( + STATUS + "Setting build type to '${CMAKE_BUILD_TYPE}' as none was specified." + ) +endif() + + +### Options and defaults + +include("${CMAKE_CURRENT_SOURCE_DIR}/modules/crest-utils.cmake") +set(fortran_minimal_versions "GNU;7.5" "Intel;19.0") +check_minimal_compiler_version("Fortran" "${fortran_minimal_versions}") + +option(WITH_OpenMP "Enable support for shared memory parallelisation with OpenMP" TRUE) + +option(WITH_TBLITE "Enable build with the lightweight tight-binding library" TRUE) + +option(WITH_TOMLF "Enable build with toml-f support" TRUE) + +option(WITH_GFN0 "Enable build with GFN0-xTB support" TRUE) + +option(WITH_GFNFF "Enable build with GFN-FF support" TRUE) + +option(WITH_XHCFF "Enable build with XHCFF support" FALSE) + +option(WITH_LWONIOM "Enable build with lwONIOM support" TRUE) + +if(NOT DEFINED "${PROJECT_NAME}-dependency-method") + set( + "${PROJECT_NAME}-dependency-method" + "subproject" "cmake" "pkgconf" "fetch" + ) +endif() + +# +# Compiler settings +# +if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") +# set(dialect "-fdefault-real-8 -fdefault-double-8 -ffree-line-length-none -fbacktrace") + set(dialect "-g -O0 -fbacktrace -ffree-line-length-none -fbacktrace") + set(bounds "-fbounds-check") +endif() +if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") +# set(dialect "-axAVX2 -r8 -traceback") + set(dialect "-g -O2 -r8 -align array64byte -traceback") + set(bounds "-check bounds") +endif() +if(CMAKE_Fortran_COMPILER_ID MATCHES "PGI") + set(dialect "-Mbackslash -Mallocatable=03 -r8 -traceback") +endif() +set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${bounds}" PARENT_SCOPE) +set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}" PARENT_SCOPE) + + +# +# Populate crest_metadata.fh +# +set(version ${PROJECT_VERSION}${SOVERSION}) +execute_process(COMMAND git show -s --format=%h + RESULT_VARIABLE git_return + OUTPUT_VARIABLE commit + OUTPUT_STRIP_TRAILING_WHITESPACE +) +if(git_return) + set(commit "unknown-commit") +endif() +string(TIMESTAMP date "%a, %d %B %H:%M:%S, %m/%d/%Y") +set(author $ENV{USERNAME}) +execute_process(COMMAND hostname OUTPUT_VARIABLE HOSTNAME OUTPUT_STRIP_TRAILING_WHITESPACE) +set(origin ${HOSTNAME}) +set(fcid ${CMAKE_Fortran_COMPILER_ID}) +set(fcver ${CMAKE_Fortran_COMPILER_VERSION}) +set(ccid ${CMAKE_C_COMPILER_ID}) +set(ccver ${CMAKE_C_COMPILER_VERSION}) +set(bsystem "cmake ${CMAKE_VERSION}") +set(tomlfvar "${WITH_TOMLF}")#string(TOLOWER "${MY_BOOL}" ${WITH_TOMLF})) +set(gfn0var "${WITH_GFN0}") +set(gfnffvar "${WITH_GFNFF}") +set(tblitevar "${WITH_TBLITE}") +set(xhcffvar "${WITH_XHCFF}") +set(lwoniomvar "${WITH_LWONIOM}") + +configure_file( + "${PROJECT_SOURCE_DIR}/assets/template/metadata.f90" + "${PROJECT_BINARY_DIR}/crest_metadata.fh" + @ONLY +) +# gfortran needs the file at another place... +configure_file( + "${PROJECT_SOURCE_DIR}/assets/template/metadata.f90" + "${PROJECT_BINARY_DIR}/include/crest_metadata.fh" + @ONLY +) + + + diff --git a/oldcmakelists b/oldcmakelists new file mode 100644 index 00000000..37fc48df --- /dev/null +++ b/oldcmakelists @@ -0,0 +1,165 @@ +# This file is part of crest. +# SPDX-Identifier: LGPL-3.0-or-later +# +# crest is free software: you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# crest is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. + +cmake_minimum_required(VERSION 3.14) + +project( + "crest" + LANGUAGES "Fortran" "C" + VERSION "3.0" +) +set(SOVERSION "pre") + +# Follow GNU conventions for installing directories +include(GNUInstallDirs) + +# General configuration information +set(libs) +add_subdirectory("config") + + +# +# Libraries +# + +# OpenMP dependency +if(NOT TARGET OpenMP::OpenMP_Fortran AND WITH_OpenMP) + find_package(OpenMP REQUIRED) + list( + APPEND libs + OpenMP::OpenMP_Fortran + ) +endif() + +# BLAS and LAPACK +if(NOT TARGET BLAS::BLAS) + find_package(BLAS REQUIRED) + if(NOT TARGET BLAS::BLAS AND BLAS_FOUND) + add_library(BLAS::BLAS INTERFACE IMPORTED) + target_link_libraries(BLAS::BLAS INTERFACE "${BLAS_LIBRARIES}") + target_link_options(BLAS::BLAS INTERFACE "${BLAS_LINKER_FLAGS}") + endif() +endif() +if(NOT TARGET LAPACK::LAPACK) + find_package(LAPACK REQUIRED) + if(NOT TARGET LAPACK::LAPACK AND LAPACK_FOUND) + add_library(LAPACK::LAPACK INTERFACE IMPORTED) + target_link_libraries(LAPACK::LAPACK INTERFACE "${LAPACK_LIBRARIES}") + target_link_options(LAPACK::LAPACK INTERFACE "${LAPACK_LINKER_FLAGS}") + endif() +endif() +list( + APPEND libs + LAPACK::LAPACK + BLAS::BLAS +) + +# tblite +if(WITH_TBLITE) + find_package("tblite" REQUIRED) + add_definitions(-DWITH_TBLITE) + list( + APPEND libs + tblite::tblite + ) +endif() + + +# toml-f +if(WITH_TOMLF) + find_package("toml-f" REQUIRED) + add_definitions(-DWITH_TOMLF) + list( + APPEND libs + toml-f::toml-f + ) +endif() + + +# GFN0-xTB +if(WITH_GFN0) + find_package("gfn0" REQUIRED) + add_definitions(-DWITH_GFN0) + list( + APPEND libs + gfn0::gfn0 + ) +endif() + + +# GFN-FF +if(WITH_GFNFF) + find_package("gfnff" REQUIRED) + add_definitions(-DWITH_GFNFF) + list( + APPEND libs + gfnff::gfnff + ) +endif() + +# XHCFF +if(WITH_XHCFF) + find_package("xhcff" REQUIRED) + add_definitions(-DWITH_XHCFF) + list( + APPEND libs + xhcff::xhcff + ) +endif() + + + + +# +# CREST sources +# +set(prog) +set(srcs) +add_subdirectory("src") + + +# +# Executables +# +add_executable( + ${PROJECT_NAME}-exe + "${srcs}" "${prog}" +) +set_target_properties( + ${PROJECT_NAME}-exe + PROPERTIES + Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/include + RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} + OUTPUT_NAME "${PROJECT_NAME}" +) +target_link_libraries( + ${PROJECT_NAME}-exe + PRIVATE + "${libs}" +) + +get_target_property(OUT ${PROJECT_NAME}-exe LINK_LIBRARIES) +message(STATUS ${OUT}) + +# +# Binary installing option +# +install( + TARGETS + "${PROJECT_NAME}-exe" + EXPORT + "${PROJECT_NAME}-targets" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) From 6afbde11ab88b9ef410cde5bd3a651fb48a65463 Mon Sep 17 00:00:00 2001 From: Philipp Pracht Date: Fri, 8 Mar 2024 01:19:08 +0000 Subject: [PATCH 3/5] Better CMake build attempt Signed-off-by: Philipp Pracht --- CMakeLists.txt | 301 +++++++++++++++++++++++++++---- assets/template/metadata.f90 | 2 +- config/CMakeLists.txt | 147 +++++---------- config/modules/Findgfn0.cmake | 16 +- config/modules/Findgfnff.cmake | 17 +- config/modules/Findlwoniom.cmake | 18 +- config/modules/Findtblite.cmake | 16 +- config/modules/Findtoml-f.cmake | 13 +- config/modules/Findxhcff.cmake | 16 +- config/modules/crest-utils.cmake | 24 ++- src/printouts.f90 | 2 +- 11 files changed, 353 insertions(+), 219 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 507833e9..d8da2cae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,46 +1,281 @@ -# SPDX-License-Identifier: LGPL-3.0-or-later -# Project configuration -cmake_minimum_required(VERSION 3.14) -project(crest VERSION 3.0 LANGUAGES Fortran C) +# This file is part of crest. +# SPDX-Identifier: LGPL-3.0-or-later +# +# crest is free software: you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# crest is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with crest. If not, see . + +cmake_minimum_required(VERSION 3.17) +option(WITH_OBJECT "To build using object library" TRUE) +option(INSTALL_MODULES "Install Fortran module files to include directory." FALSE) + +# Buggy CMake versions +if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27.0 AND CMAKE_VERSION VERSION_LESS 3.28.0) + set(WITH_OBJECT FALSE) +endif() + +# Setup the crest Project +project( + crest + LANGUAGES "C" "Fortran" + VERSION 3.0 + DESCRIPTION "A tool for the exploration of low-energy chemical space" +) set(SOVERSION "pre") -# Include GNU installation directories +#enable_testing() + +# Follow GNU conventions for installing directories include(GNUInstallDirs) -# General configuration and addition of subdirectories for further configurations and source -set(libs) # external dependencies will be added -set(omp) # omp dependency -add_subdirectory(config) # For detailed compiler options, feature toggles, and dependencies -set(srcs) # sources will be added -set(prog) # src/crest_main.f90 will be added -add_subdirectory(src) # Source files +# Include further configurations +add_subdirectory("config") -# Define executable with the main program source included -add_executable(${PROJECT_NAME} ${prog} ${srcs}) -set_target_properties(${PROJECT_NAME} PROPERTIES - Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/include - RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} - OUTPUT_NAME ${PROJECT_NAME} -) +############################################################################### +####################### SUBPROJECTS & DEPENDENCIES ############################ +############################################################################### +# Check a specific CMake targets and execute the +# corresponding Find scripts (located in config/modules/) + +# LAPACK, BLAS, OpenMP (usually via shared dependencies) +if(STATICBUILD) + set(BLA_STATIC ON) +endif() +find_package(LAPACK REQUIRED) +find_package(BLAS REQUIRED) +if(NOT TARGET "OpenMP::OpenMP_Fortran" AND WITH_OpenMP) + find_package("OpenMP" REQUIRED) +endif() + +# TOML-F (needs to be imported before tblite) +if(NOT TARGET "toml-f::toml-f" AND WITH_TOMLF) + find_package("toml-f" REQUIRED) + add_compile_definitions(WITH_TOMLF) +endif() + +# tblite +if(NOT TARGET "tblite::tblite" AND WITH_TBLITE) + find_package("tblite" REQUIRED) + add_compile_definitions(WITH_TBLITE) +endif() + +# GFN-FF +if(NOT TARGET "gfnff::gfnff" AND WITH_GFNFF) + find_package("gfnff" REQUIRED) + add_compile_definitions(WITH_GFNFF) +endif() + +# GFN0-xTB +if(NOT TARGET "gfn0::gfn0" AND WITH_GFN0) + find_package("gfn0" REQUIRED) + add_compile_definitions(WITH_GFN0) +endif() + +# XHCFF +if(NOT TARGET "xhcff::xhcff" AND WITH_XHCFF) + find_package("xhcff" REQUIRED) + add_compile_definitions(WITH_XHCFF) +endif() + +# lwONIOM +if(NOT TARGET "lwoniom::lwoniom" AND WITH_LWONIOM) + find_package("lwoniom" REQUIRED) + add_compile_definitions(WITH_LWONIOM) +endif() + +# Sources: initialize program sources (prog) and library sources (srcs) empty +set(prog) +set(srcs) +add_subdirectory("src") + + +if(NOT EXISTS "${PROJECT_BINARY_DIR}/include") + file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/include") +endif() +############################################################################### +########################## OBJECT LIBRARY ##################################### +############################################################################### +if(WITH_OBJECT AND NOT STATICBUILD) + + add_library( + "${PROJECT_NAME}-object" + OBJECT + ${srcs} + ) -# Link libraries -if(STATICLINK) -# set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") -# set(BUILD_SHARED_LIBS OFF) -# set(CMAKE_EXE_LINKER_FLAGS "-static") - message(STATUS "STATIC build requested") - target_link_libraries(${PROJECT_NAME} PRIVATE -static ${libs}) + # customize object library + set_target_properties( + "${PROJECT_NAME}-object" + PROPERTIES + Fortran_MODULE_DIRECTORY "${PROJECT_BINARY_DIR}/include" + POSITION_INDEPENDENT_CODE ON + ) + + # link object library conditionally against required + target_link_libraries( + "${PROJECT_NAME}-object" + PUBLIC + $<$:tblite::tblite> + $<$:gfn0::gfn0> + $<$:gfnff::gfnff> + $<$:xhcff::xhcff> + $<$:toml-f::toml-f> + $<$:lwoniom::lwoniom> + $<$:OpenMP::OpenMP_Fortran> + ) + + # include directories + target_include_directories( + "${PROJECT_NAME}-object" + PUBLIC + ${crest-config-dir} + ${PROJECT_BINARY_DIR} + $ + $ + $/${CMAKE_INSTALL_INCLUDEDIR}> + ) + +endif() + +############################################################################### +############################### Static Library ################################ +############################################################################### +if(WITH_OBJECT AND NOT STATICBUILD) + add_library( + "lib-${PROJECT_NAME}-static" + STATIC + $ + ) else() - target_link_libraries(${PROJECT_NAME} PRIVATE ${libs}) + add_library( + "lib-${PROJECT_NAME}-static" + STATIC + ${srcs} + ) +endif() + +# workaround attemp. doesn't work yet +set(LINK_OpenMP FALSE) +if(WITH_OpenMP AND NOT STATICBUILD) + set(LINK_OpenMP TRUE) +endif() + +target_link_libraries( + "lib-${PROJECT_NAME}-static" + PUBLIC + ${BLAS_LIBRARIES} + ${LAPACK_LIBRARIES} + $<$:OpenMP::OpenMP_Fortran> + $<$:tblite::tblite> + $<$:gfn0::gfn0> + $<$:gfnff::gfnff> + $<$:xhcff::xhcff> + $<$:toml-f::toml-f> + $<$:lwoniom::lwoniom> + $<$:-static> +) + + +set_target_properties( + "lib-${PROJECT_NAME}-static" + PROPERTIES + Fortran_MODULE_DIRECTORY "${PROJECT_BINARY_DIR}/include" + ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}" + POSITION_INDEPENDENT_CODE ON + OUTPUT_NAME "${PROJECT_NAME}" + ) + + +target_include_directories( + "lib-${PROJECT_NAME}-static" + PUBLIC + $ + $ + $/${CMAKE_INSTALL_INCLUDEDIR}> +) + + +#################################################################################### +############################# Shared Library ####################################### +#################################################################################### +if (WITH_OBJECT AND NOT STATICBUILD) + add_library( + "lib-${PROJECT_NAME}-shared" + SHARED + $ + ) + + target_link_libraries( + "lib-${PROJECT_NAME}-shared" + PUBLIC + ${BLAS_LIBRARIES} + ${LAPACK_LIBRARIES} + $<$:OpenMP::OpenMP_Fortran> + $<$:tblite::tblite> + $<$:gfn0::gfn0> + $<$:gfnff::gfnff> + $<$:xhcff::xhcff> + $<$:toml-f::toml-f> + $<$:lwoniom::lwoniom> + ) + + set_target_properties( + "lib-${PROJECT_NAME}-shared" + PROPERTIES + Fortran_MODULE_DIRECTORY "${PROJECT_BINARY_DIR}/include" + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}" + OUTPUT_NAME "${PROJECT_NAME}" + VERSION "${PROJECT_VERSION}" + SOVERSION "${PROJECT_VERSION_MAJOR}" + ) + + target_include_directories( + "lib-${PROJECT_NAME}-shared" + PUBLIC + $ + $ + $/${CMAKE_INSTALL_INCLUDEDIR}> + ) endif() -# Installation rules for the executable -install(TARGETS ${PROJECT_NAME} - EXPORT "${PROJECT_NAME}-targets" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" +############################################################################### +############################### Executables ################################### +############################################################################### +add_executable( + ${PROJECT_NAME}-exe + ${prog} +) + +target_link_libraries( + ${PROJECT_NAME}-exe + PRIVATE + "lib-${PROJECT_NAME}-static" + $<$:-static> +) + +set_target_properties( + ${PROJECT_NAME}-exe + PROPERTIES + Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/include + RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} + OUTPUT_NAME "${PROJECT_NAME}" +) + +target_include_directories( + ${PROJECT_NAME}-exe + PRIVATE + ${PROJECT_SOURCE_DIR}/include + $ ) diff --git a/assets/template/metadata.f90 b/assets/template/metadata.f90 index b2e4da29..38a4e74b 100644 --- a/assets/template/metadata.f90 +++ b/assets/template/metadata.f90 @@ -10,4 +10,4 @@ character(len=*),parameter :: gfnffvar = "@gfnffvar@" character(len=*),parameter :: tblitevar = "@tblitevar@" character(len=*),parameter :: xhcffvar = "@xhcffvar@" - +character(len=*),parameter :: lwoniomvar = "@lwoniomvar@" diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index 98496807..e6a7e09d 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -14,17 +14,46 @@ # You should have received a copy of the GNU Lesser General Public License # along with crest. If not, see . # Set the module path for CMake includes -set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules;${CMAKE_MODULE_PATH}") + +######################################################################################### +######################################################################################### +# Add modules to the CMake build +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules") +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) + +# specify module installation directory +install( + DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}/modules/" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" +) # Options for enabling or disabling features -option(STATICLINK "Build a static binary" ON) -option(WITH_OPENMP "Enable OpenMP support" ON) -option(WITH_TBLITE "Enable support for tblite" OFF) -option(WITH_TOMLF "Enable support for toml-f" OFF) -option(WITH_GFN0 "Enable support for GFN0-xTB" OFF) -option(WITH_GFNFF "Enable support for GFN-FF" OFF) -option(WITH_XHCFF "Enable support for XHCFF" OFF) -option(WITH_LWONIOM "Enable support for lwONIOM" OFF) +option(WITH_OpenMP "Enable OpenMP support" TRUE) +option(WITH_TBLITE "Enable support for tblite" TRUE) +option(WITH_TOMLF "Enable support for toml-f" TRUE) +option(WITH_GFN0 "Enable support for GFN0-xTB" TRUE) +option(WITH_GFNFF "Enable support for GFN-FF" TRUE) +option(WITH_XHCFF "Enable support for XHCFF" FALSE) +option(WITH_LWONIOM "Enable support for lwONIOM" TRUE) + +option(STATICBUILD "Attempt to link everything statically" FALSE) # doesn't work yet + +######################################################################################### +######################################################################################### + +# Set build type as CMake does not provide defaults +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set( + CMAKE_BUILD_TYPE "RelWithDebInfo" + CACHE STRING "Build type to be used." + FORCE + ) + message( + STATUS + "Setting build type to '${CMAKE_BUILD_TYPE}' as none was specified." + ) +endif() ######################################################################################### ######################################################################################### @@ -32,109 +61,21 @@ option(WITH_LWONIOM "Enable support for lwONIOM" OFF) # Compiler settings for GNU and Intel Fortran compilers if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") set(dialect "-g -O0 -fbacktrace -ffree-line-length-none -fbacktrace") - set(bounds "-fbounds-check") + set(bounds "-fbounds-check -ffpe-trap=invalid,zero,overflow") elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") set(dialect "-g -O2 -r8 -align array64byte -traceback") - set(bounds "-check bounds") + set(bounds "-check all -fpe0") +else() + message(FATAL_ERROR "Please use an Intel or GNU compiler!") endif() # Apply the compiler flags -set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${bounds}") -set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}") +set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${bounds}" PARENT_SCOPE) +set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}" PARENT_SCOPE) ######################################################################################### ######################################################################################### -# Handling dependencies and features - -# Find LAPACK & BLAS -if(STATICLINK) - set(BLA_STATIC ON) -endif() -find_package(LAPACK REQUIRED) -if(LAPACK_FOUND) - list(APPEND libs ${LAPACK_LIBRARIES}) -endif() -find_package(BLAS REQUIRED) -if(BLAS_FOUND) - list(APPEND libs ${BLAS_LIBRARIES}) -endif() - -# OpenMP -if(WITH_OPENMP) - find_package(OpenMP REQUIRED) - if(OpenMP_Fortran_FOUND) - #list(APPEND libs OpenMP::OpenMP_Fortran) - list(APPEND omp ${OpenMP_Fortran_LIBRARIES}) - endif() -endif() - -# tblite -if(WITH_TBLITE) - find_package(tblite REQUIRED) - if(tblite_FOUND) - add_definitions(-DWITH_TBLITE) - include_directories(${tblite_INCLUDE_DIRS}) - list(APPEND libs ${tblite_LIBRARIES}) - endif() -endif() - -# toml-f -if(WITH_TOMLF) - find_package(toml-f REQUIRED) - if(toml-f_FOUND) - add_definitions(-DWITH_TOMLF) - include_directories(${toml-f_INCLUDE_DIRS}) - list(APPEND libs ${tomlf_LIBRARIES}) - endif() -endif() - -# GFN0-xTB -if(WITH_GFN0) - find_package(GFN0 REQUIRED) - if(GFN0_FOUND) - add_definitions(-DWITH_GFN0) - include_directories(${GFN0_INCLUDE_DIRS}) - list(APPEND libs ${GFN0_LIBRARIES}) - endif() -endif() - -# GFN-FF -if(WITH_GFNFF) - find_package("gfnff" REQUIRED) - if(gfnff_FOUND) - add_definitions(-DWITH_GFNFF) - list(APPEND libs gfnff::gfnff) - endif() -endif() - -# lwONIOM -if(WITH_LWONIOM) - find_package(LWONIOM REQUIRED) - if(LWONIOM_FOUND) - add_definitions(-DWITH_LWONIOM) - include_directories(${LWONIOM_INCLUDE_DIRS}) - list(APPEND libs ${LWONIOM_LIBRARIES}) - endif() -endif() - -# XHCFF -if(WITH_XHCFF) - find_package(XHCFF REQUIRED) - if(XHCFF_FOUND) - add_definitions(-DWITH_XHCFF) - include_directories(${XHCFF_INCLUDE_DIRS}) - list(APPEND libs ${XHCFF_LIBRARIES}) - endif() -endif() - -# IMPORTANT -set(omp ${omp} PARENT_SCOPE) -set(libs ${libs} PARENT_SCOPE) - -########################################################################################## -########################################################################################## - # Populate crest_metadata.fh set(version ${PROJECT_VERSION}${SOVERSION}) execute_process(COMMAND git show -s --format=%h diff --git a/config/modules/Findgfn0.cmake b/config/modules/Findgfn0.cmake index f5699b7a..a44f8c8d 100644 --- a/config/modules/Findgfn0.cmake +++ b/config/modules/Findgfn0.cmake @@ -19,29 +19,19 @@ set(_pkg "GFN0") set(_url "https://github.com/pprcht/gfn0") if(NOT DEFINED "${_pkg}_FIND_METHOD") - if(DEFINED "${PROJECT_NAME}-dependency-method") - set("${_pkg}_FIND_METHOD" "${${PROJECT_NAME}-dependency-method}") - else() - set("${_pkg}_FIND_METHOD" "cmake" "pkgconf" "subproject" "fetch") - endif() - set("_${_pkg}_FIND_METHOD") + set("${_pkg}_FIND_METHOD" "subproject" "cmake" "fetch" "pkgconf") endif() include("${CMAKE_CURRENT_LIST_DIR}/crest-utils.cmake") crest_find_package("${_lib}" "${${_pkg}_FIND_METHOD}" "${_url}") +set (found FALSE) if(TARGET "gfn0::gfn0") set (found TRUE) -else() - set (found FALSE) endif() -message("-- Found GFN0: ${found}") +message(STATUS "Found GFN0-xTB: ${found}") -if(DEFINED "_${_pkg}_FIND_METHOD") - unset("${_pkg}_FIND_METHOD") - unset("_${_pkg}_FIND_METHOD") -endif() unset(_lib) unset(_pkg) unset(_url) diff --git a/config/modules/Findgfnff.cmake b/config/modules/Findgfnff.cmake index 10a098a9..faf16024 100644 --- a/config/modules/Findgfnff.cmake +++ b/config/modules/Findgfnff.cmake @@ -19,32 +19,19 @@ set(_pkg "GFNFF") set(_url "https://github.com/pprcht/gfnff") if(NOT DEFINED "${_pkg}_FIND_METHOD") - if(DEFINED "${PROJECT_NAME}-dependency-method") - set("${_pkg}_FIND_METHOD" "${${PROJECT_NAME}-dependency-method}") - else() - #set("${_pkg}_FIND_METHOD" "cmake" "pkgconf" "subproject" "fetch") - set("${_pkg}_FIND_METHOD" "subproject" "fetch") - endif() - set("_${_pkg}_FIND_METHOD") + set("${_pkg}_FIND_METHOD" "subproject" "cmake" "fetch" "pkgconf") endif() include("${CMAKE_CURRENT_LIST_DIR}/crest-utils.cmake") - -message(STATUS "${${_pkg}_FIND_METHOD}") crest_find_package("${_lib}" "${${_pkg}_FIND_METHOD}" "${_url}") +set(found FALSE) if(TARGET "gfnff::gfnff") set (found TRUE) -else() - set (found FALSE) endif() message(STATUS "Found GFN-FF: ${found}") -if(DEFINED "_${_pkg}_FIND_METHOD") - unset("${_pkg}_FIND_METHOD") - unset("_${_pkg}_FIND_METHOD") -endif() unset(_lib) unset(_pkg) unset(_url) diff --git a/config/modules/Findlwoniom.cmake b/config/modules/Findlwoniom.cmake index 8c131dbe..1f825b13 100644 --- a/config/modules/Findlwoniom.cmake +++ b/config/modules/Findlwoniom.cmake @@ -16,32 +16,22 @@ set(_lib "lwoniom") set(_pkg "LWONIOM") -set(_url "https://github.com/pprcht/lwoniom") +set(_url "https://github.com/crest-lab/lwoniom") if(NOT DEFINED "${_pkg}_FIND_METHOD") - if(DEFINED "${PROJECT_NAME}-dependency-method") - set("${_pkg}_FIND_METHOD" "${${PROJECT_NAME}-dependency-method}") - else() - set("${_pkg}_FIND_METHOD" "cmake" "pkgconf" "subproject" "fetch") - endif() - set("_${_pkg}_FIND_METHOD") + set("${_pkg}_FIND_METHOD" "subproject" "cmake" "fetch" "pkgconf") endif() include("${CMAKE_CURRENT_LIST_DIR}/crest-utils.cmake") crest_find_package("${_lib}" "${${_pkg}_FIND_METHOD}" "${_url}") +set(found FALSE) if(TARGET "lwoniom::lwoniom") set (found TRUE) -else() - set (found FALSE) endif() -message("-- Found lwONIOM: ${found}") +message(STATUS "Found lwONIOM: ${found}") -if(DEFINED "_${_pkg}_FIND_METHOD") - unset("${_pkg}_FIND_METHOD") - unset("_${_pkg}_FIND_METHOD") -endif() unset(_lib) unset(_pkg) unset(_url) diff --git a/config/modules/Findtblite.cmake b/config/modules/Findtblite.cmake index 51464b5d..9ca3cfc3 100644 --- a/config/modules/Findtblite.cmake +++ b/config/modules/Findtblite.cmake @@ -19,29 +19,19 @@ set(_pkg "TBLITE") set(_url "https://github.com/tblite/tblite") if(NOT DEFINED "${_pkg}_FIND_METHOD") - if(DEFINED "${PROJECT_NAME}-dependency-method") - set("${_pkg}_FIND_METHOD" "${${PROJECT_NAME}-dependency-method}") - else() - set("${_pkg}_FIND_METHOD" "cmake" "pkgconf" "subproject" "fetch") - endif() - set("_${_pkg}_FIND_METHOD") + set("${_pkg}_FIND_METHOD" "subproject" "cmake" "fetch" "pkgconf") endif() include("${CMAKE_CURRENT_LIST_DIR}/crest-utils.cmake") crest_find_package("${_lib}" "${${_pkg}_FIND_METHOD}" "${_url}") +set(found FALSE) if(TARGET "tblite::tblite") set (found TRUE) -else() - set (found FALSE) endif() -message("-- Found tblite: ${found}") +message(STATUS "Found tblite: ${found}") -if(DEFINED "_${_pkg}_FIND_METHOD") - unset("${_pkg}_FIND_METHOD") - unset("_${_pkg}_FIND_METHOD") -endif() unset(_lib) unset(_pkg) unset(_url) diff --git a/config/modules/Findtoml-f.cmake b/config/modules/Findtoml-f.cmake index 81eeb159..ca1da4cb 100644 --- a/config/modules/Findtoml-f.cmake +++ b/config/modules/Findtoml-f.cmake @@ -19,12 +19,7 @@ set(_pkg "TOML-F") set(_url "https://github.com/toml-f/toml-f") if(NOT DEFINED "${_pkg}_FIND_METHOD") - if(DEFINED "${PROJECT_NAME}-dependency-method") - set("${_pkg}_FIND_METHOD" "${${PROJECT_NAME}-dependency-method}") - else() - set("${_pkg}_FIND_METHOD" "cmake" "pkgconf" "subproject" "fetch") - endif() - set("_${_pkg}_FIND_METHOD") + set("${_pkg}_FIND_METHOD" "subproject" "cmake" "fetch" "pkgconf") endif() include("${CMAKE_CURRENT_LIST_DIR}/crest-utils.cmake") @@ -36,12 +31,8 @@ if(TARGET "toml-f::toml-f") else() set (found FALSE) endif() -message("-- Found toml-f: ${found}") +message(STATUS "Found toml-f: ${found}") -if(DEFINED "_${_pkg}_FIND_METHOD") - unset("${_pkg}_FIND_METHOD") - unset("_${_pkg}_FIND_METHOD") -endif() unset(_lib) unset(_pkg) unset(_url) diff --git a/config/modules/Findxhcff.cmake b/config/modules/Findxhcff.cmake index bcfaae4e..fff680e1 100644 --- a/config/modules/Findxhcff.cmake +++ b/config/modules/Findxhcff.cmake @@ -19,29 +19,19 @@ set(_pkg "XHCFF") set(_url "https://github.com/zellerf/xhcff-lib") if(NOT DEFINED "${_pkg}_FIND_METHOD") - if(DEFINED "${PROJECT_NAME}-dependency-method") - set("${_pkg}_FIND_METHOD" "${${PROJECT_NAME}-dependency-method}") - else() - set("${_pkg}_FIND_METHOD" "cmake" "pkgconf" "subproject" "fetch") - endif() - set("_${_pkg}_FIND_METHOD") + set("${_pkg}_FIND_METHOD" "subproject" "cmake" "fetch" "pkgconf" ) endif() include("${CMAKE_CURRENT_LIST_DIR}/crest-utils.cmake") crest_find_package("${_lib}" "${${_pkg}_FIND_METHOD}" "${_url}") +set(found FALSE) if(TARGET "xhcff::xhcff") set (found TRUE) -else() - set (found FALSE) endif() -message("-- Found xhcff: ${found}") +message(STATUS "Found xhcff: ${found}") -if(DEFINED "_${_pkg}_FIND_METHOD") - unset("${_pkg}_FIND_METHOD") - unset("_${_pkg}_FIND_METHOD") -endif() unset(_lib) unset(_pkg) unset(_url) diff --git a/config/modules/crest-utils.cmake b/config/modules/crest-utils.cmake index dfc38046..375714a2 100644 --- a/config/modules/crest-utils.cmake +++ b/config/modules/crest-utils.cmake @@ -14,6 +14,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with crest. If not, see . +######################################################################################### +######################################################################################### + # Handling of subproject dependencies macro( "crest_find_package" @@ -24,12 +27,17 @@ macro( string(TOLOWER "${package}" _pkg_lc) string(TOUPPER "${package}" _pkg_uc) + + # iterate through lookup types in order foreach(method ${methods}) if(TARGET "${package}::${package}") break() endif() +######################################################################################### + + # look for a -config.cmake on the system if("${method}" STREQUAL "cmake") if(DEFINED "${_pkg_uc}_DIR") set("_${_pkg_uc}_DIR") @@ -42,6 +50,9 @@ macro( endif() endif() +######################################################################################### + + # look for dependency via pkgconf if("${method}" STREQUAL "pkgconf") find_package(PkgConfig QUIET) pkg_check_modules("${_pkg_uc}" QUIET "${package}") @@ -63,6 +74,9 @@ macro( endif() endif() +######################################################################################### + + # look for SOURCE in the subprojects directory (we usually prefer this one) if("${method}" STREQUAL "subproject") if(NOT DEFINED "${_pkg_uc}_SUBPROJECT") set("_${_pkg_uc}_SUBPROJECT") @@ -89,6 +103,9 @@ macro( endif() endif() +######################################################################################### + + # finally, we can try to download sources if("${method}" STREQUAL "fetch") message(STATUS "Retrieving ${package} from ${url}") include(FetchContent) @@ -112,6 +129,8 @@ macro( break() endif() +######################################################################################### + endforeach() if(TARGET "${package}::${package}") @@ -138,9 +157,10 @@ macro( endif() endmacro() -# +######################################################################################### +######################################################################################### + # Check current compiler version requirements. -# function (check_minimal_compiler_version lang compiler_versions) while(compiler_versions) list(POP_FRONT compiler_versions compiler version) diff --git a/src/printouts.f90 b/src/printouts.f90 index c48458fb..7d738c20 100644 --- a/src/printouts.f90 +++ b/src/printouts.f90 @@ -719,7 +719,7 @@ subroutine print_crest_metadata() write (*,'(2x,a,1x,a)') '-DWITH_GFNFF :',gfnffvar write (*,'(2x,a,1x,a)') '-DWITH_TBLITE :',tblitevar write (*,'(2x,a,1x,a)') '-DWITH_XHCFF :',xhcffvar - + write (*,'(2x,a,1x,a)') '-DWITH_LWONIOM :',lwoniomvar end subroutine print_crest_metadata !========================================================================================! From 679854715deaaedc117da1958cca01218dda93df Mon Sep 17 00:00:00 2001 From: Philipp Pracht Date: Fri, 8 Mar 2024 10:43:44 +0000 Subject: [PATCH 4/5] Update README.md --- README.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 10e009f7..f078223d 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,26 @@ For more information about builds including subprojects see [here](./subprojects Some basic build instructions can be found in the following dropdown tabs: + +
+

CMake build

+ + +Building CREST with CMake works with the following chain of commands (in this example with `gfortran/gcc` compilers): +```bash +export FC=gfortran CC=gcc +cmake -B _build -DCMAKE_BUILD_TYPE=Release +``` +and then to build the CREST binary +```bash +make -C _build +``` + +The `CMake` build typically requires access to shared libraries of LAPACK and OpenMP. They must be present in the library paths at compile and runtime. +
+ +

meson build

@@ -97,25 +116,6 @@ When attempting to build with `gfortran` and `gcc`, add `-Dla_backend=mkl` to th By default the `meson` build will create a **statically** linked binary.
-
-

CMake build

- - -For the setup of CMake see also the [CMake setup](https://github.com/grimme-lab/xtb/blob/master/cmake/README.adoc) page hosted at the `xtb` repository. -Building CREST with CMake works with the following chain of commands: -```bash -export FC=gfortran CC=gcc -cmake -B _build -DCMAKE_BUILD_TYPE=Release -``` -and then to build the CREST binary -```bash -make -C _build -``` - -The CMake build of CREST is focused on and tested with the GNU `gfortran`/`gcc` compilers. The Intel compilers could technically be used as well, but in our experience the respective build is more fragile than its static `meson` counterpart. - -By default the `CMake` build will create a **dynamically** linked binary. -

Conda build

From 1c76d443ee20761bedb82d651c4e93a800bc9c23 Mon Sep 17 00:00:00 2001 From: Philipp Pracht Date: Fri, 8 Mar 2024 10:47:20 +0000 Subject: [PATCH 5/5] remove temporary copies from git tracking --- config/oldcmakelists.txt | 134 ------------------------------- oldcmakelists | 165 --------------------------------------- 2 files changed, 299 deletions(-) delete mode 100644 config/oldcmakelists.txt delete mode 100644 oldcmakelists diff --git a/config/oldcmakelists.txt b/config/oldcmakelists.txt deleted file mode 100644 index 06497a99..00000000 --- a/config/oldcmakelists.txt +++ /dev/null @@ -1,134 +0,0 @@ -# This file is part of crest. -# SPDX-Identifier: LGPL-3.0-or-later -# -# crest is free software: you can redistribute it and/or modify it under -# the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# crest is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with crest. If not, see . - -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules") -set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) -install( - DIRECTORY - "${CMAKE_CURRENT_SOURCE_DIR}/modules/" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" -) - -set( - module-dir - "${PROJECT_NAME}/${CMAKE_Fortran_COMPILER_ID}-${CMAKE_Fortran_COMPILER_VERSION}" -) -set(module-dir "${module-dir}" PARENT_SCOPE) - - -# Set build type as CMake does not provide defaults -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - set( - CMAKE_BUILD_TYPE "RelWithDebInfo" - CACHE STRING "Build type to be used." - FORCE - ) - message( - STATUS - "Setting build type to '${CMAKE_BUILD_TYPE}' as none was specified." - ) -endif() - - -### Options and defaults - -include("${CMAKE_CURRENT_SOURCE_DIR}/modules/crest-utils.cmake") -set(fortran_minimal_versions "GNU;7.5" "Intel;19.0") -check_minimal_compiler_version("Fortran" "${fortran_minimal_versions}") - -option(WITH_OpenMP "Enable support for shared memory parallelisation with OpenMP" TRUE) - -option(WITH_TBLITE "Enable build with the lightweight tight-binding library" TRUE) - -option(WITH_TOMLF "Enable build with toml-f support" TRUE) - -option(WITH_GFN0 "Enable build with GFN0-xTB support" TRUE) - -option(WITH_GFNFF "Enable build with GFN-FF support" TRUE) - -option(WITH_XHCFF "Enable build with XHCFF support" FALSE) - -option(WITH_LWONIOM "Enable build with lwONIOM support" TRUE) - -if(NOT DEFINED "${PROJECT_NAME}-dependency-method") - set( - "${PROJECT_NAME}-dependency-method" - "subproject" "cmake" "pkgconf" "fetch" - ) -endif() - -# -# Compiler settings -# -if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") -# set(dialect "-fdefault-real-8 -fdefault-double-8 -ffree-line-length-none -fbacktrace") - set(dialect "-g -O0 -fbacktrace -ffree-line-length-none -fbacktrace") - set(bounds "-fbounds-check") -endif() -if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") -# set(dialect "-axAVX2 -r8 -traceback") - set(dialect "-g -O2 -r8 -align array64byte -traceback") - set(bounds "-check bounds") -endif() -if(CMAKE_Fortran_COMPILER_ID MATCHES "PGI") - set(dialect "-Mbackslash -Mallocatable=03 -r8 -traceback") -endif() -set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${bounds}" PARENT_SCOPE) -set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}" PARENT_SCOPE) - - -# -# Populate crest_metadata.fh -# -set(version ${PROJECT_VERSION}${SOVERSION}) -execute_process(COMMAND git show -s --format=%h - RESULT_VARIABLE git_return - OUTPUT_VARIABLE commit - OUTPUT_STRIP_TRAILING_WHITESPACE -) -if(git_return) - set(commit "unknown-commit") -endif() -string(TIMESTAMP date "%a, %d %B %H:%M:%S, %m/%d/%Y") -set(author $ENV{USERNAME}) -execute_process(COMMAND hostname OUTPUT_VARIABLE HOSTNAME OUTPUT_STRIP_TRAILING_WHITESPACE) -set(origin ${HOSTNAME}) -set(fcid ${CMAKE_Fortran_COMPILER_ID}) -set(fcver ${CMAKE_Fortran_COMPILER_VERSION}) -set(ccid ${CMAKE_C_COMPILER_ID}) -set(ccver ${CMAKE_C_COMPILER_VERSION}) -set(bsystem "cmake ${CMAKE_VERSION}") -set(tomlfvar "${WITH_TOMLF}")#string(TOLOWER "${MY_BOOL}" ${WITH_TOMLF})) -set(gfn0var "${WITH_GFN0}") -set(gfnffvar "${WITH_GFNFF}") -set(tblitevar "${WITH_TBLITE}") -set(xhcffvar "${WITH_XHCFF}") -set(lwoniomvar "${WITH_LWONIOM}") - -configure_file( - "${PROJECT_SOURCE_DIR}/assets/template/metadata.f90" - "${PROJECT_BINARY_DIR}/crest_metadata.fh" - @ONLY -) -# gfortran needs the file at another place... -configure_file( - "${PROJECT_SOURCE_DIR}/assets/template/metadata.f90" - "${PROJECT_BINARY_DIR}/include/crest_metadata.fh" - @ONLY -) - - - diff --git a/oldcmakelists b/oldcmakelists deleted file mode 100644 index 37fc48df..00000000 --- a/oldcmakelists +++ /dev/null @@ -1,165 +0,0 @@ -# This file is part of crest. -# SPDX-Identifier: LGPL-3.0-or-later -# -# crest is free software: you can redistribute it and/or modify it under -# the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# crest is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. - -cmake_minimum_required(VERSION 3.14) - -project( - "crest" - LANGUAGES "Fortran" "C" - VERSION "3.0" -) -set(SOVERSION "pre") - -# Follow GNU conventions for installing directories -include(GNUInstallDirs) - -# General configuration information -set(libs) -add_subdirectory("config") - - -# -# Libraries -# - -# OpenMP dependency -if(NOT TARGET OpenMP::OpenMP_Fortran AND WITH_OpenMP) - find_package(OpenMP REQUIRED) - list( - APPEND libs - OpenMP::OpenMP_Fortran - ) -endif() - -# BLAS and LAPACK -if(NOT TARGET BLAS::BLAS) - find_package(BLAS REQUIRED) - if(NOT TARGET BLAS::BLAS AND BLAS_FOUND) - add_library(BLAS::BLAS INTERFACE IMPORTED) - target_link_libraries(BLAS::BLAS INTERFACE "${BLAS_LIBRARIES}") - target_link_options(BLAS::BLAS INTERFACE "${BLAS_LINKER_FLAGS}") - endif() -endif() -if(NOT TARGET LAPACK::LAPACK) - find_package(LAPACK REQUIRED) - if(NOT TARGET LAPACK::LAPACK AND LAPACK_FOUND) - add_library(LAPACK::LAPACK INTERFACE IMPORTED) - target_link_libraries(LAPACK::LAPACK INTERFACE "${LAPACK_LIBRARIES}") - target_link_options(LAPACK::LAPACK INTERFACE "${LAPACK_LINKER_FLAGS}") - endif() -endif() -list( - APPEND libs - LAPACK::LAPACK - BLAS::BLAS -) - -# tblite -if(WITH_TBLITE) - find_package("tblite" REQUIRED) - add_definitions(-DWITH_TBLITE) - list( - APPEND libs - tblite::tblite - ) -endif() - - -# toml-f -if(WITH_TOMLF) - find_package("toml-f" REQUIRED) - add_definitions(-DWITH_TOMLF) - list( - APPEND libs - toml-f::toml-f - ) -endif() - - -# GFN0-xTB -if(WITH_GFN0) - find_package("gfn0" REQUIRED) - add_definitions(-DWITH_GFN0) - list( - APPEND libs - gfn0::gfn0 - ) -endif() - - -# GFN-FF -if(WITH_GFNFF) - find_package("gfnff" REQUIRED) - add_definitions(-DWITH_GFNFF) - list( - APPEND libs - gfnff::gfnff - ) -endif() - -# XHCFF -if(WITH_XHCFF) - find_package("xhcff" REQUIRED) - add_definitions(-DWITH_XHCFF) - list( - APPEND libs - xhcff::xhcff - ) -endif() - - - - -# -# CREST sources -# -set(prog) -set(srcs) -add_subdirectory("src") - - -# -# Executables -# -add_executable( - ${PROJECT_NAME}-exe - "${srcs}" "${prog}" -) -set_target_properties( - ${PROJECT_NAME}-exe - PROPERTIES - Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/include - RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} - OUTPUT_NAME "${PROJECT_NAME}" -) -target_link_libraries( - ${PROJECT_NAME}-exe - PRIVATE - "${libs}" -) - -get_target_property(OUT ${PROJECT_NAME}-exe LINK_LIBRARIES) -message(STATUS ${OUT}) - -# -# Binary installing option -# -install( - TARGETS - "${PROJECT_NAME}-exe" - EXPORT - "${PROJECT_NAME}-targets" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" -)