mirror of
https://github.com/cp2k/cp2k.git
synced 2026-07-28 14:15:19 -04:00
Move __DATA_DIR to C code to avoid Fortran's line length limit
This commit is contained in:
parent
b396de2029
commit
b9da3089cf
4 changed files with 60 additions and 13 deletions
|
|
@ -35,7 +35,7 @@ endif()
|
|||
|
||||
# Baseline
|
||||
add_compile_options(
|
||||
"$<$<COMPILE_LANG_AND_ID:Fortran,GNU>:-std=f2008;-ffree-form;-ffree-line-length-none;-fimplicit-none>"
|
||||
"$<$<COMPILE_LANG_AND_ID:Fortran,GNU>:-std=f2008;-ffree-form;-fimplicit-none>"
|
||||
"$<$<COMPILE_LANG_AND_ID:Fortran,GNU>:-g;-fno-omit-frame-pointer;-fbacktrace>"
|
||||
"$<$<COMPILE_LANG_AND_ID:Fortran,GNU>:$<$<VERSION_GREATER_EQUAL:${CMAKE_Fortran_COMPILER_VERSION},11>:-fallow-argument-mismatch>>"
|
||||
"$<$<COMPILE_LANG_AND_ID:Fortran,GNU>:-Wno-deprecated-declarations;-Wno-maybe-uninitialized;-Wuninitialized;-Wuse-without-only>"
|
||||
|
|
|
|||
|
|
@ -1385,7 +1385,14 @@ list(
|
|||
xc/xc_xpbe_hole_t_c_lr.F
|
||||
xc/xc_xwpbe.F)
|
||||
|
||||
list(APPEND CP2K_SRCS_C sockets.c base/machine_cpuid.c base/openmp_trace.c)
|
||||
list(
|
||||
APPEND
|
||||
CP2K_SRCS_C
|
||||
sockets.c
|
||||
base/machine_cpuid.c
|
||||
base/openmp_trace.c
|
||||
base/openmp_trace.c
|
||||
common/cp_data_dir.c)
|
||||
|
||||
set(CP2K_OFFLOAD_SRCS_C offload/offload_buffer.c offload/offload_library.c
|
||||
offload/offload_mempool.c)
|
||||
|
|
|
|||
26
src/common/cp_data_dir.c
Normal file
26
src/common/cp_data_dir.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*----------------------------------------------------------------------------*/
|
||||
/* CP2K: A general program to perform molecular dynamics simulations */
|
||||
/* Copyright 2000-2025 CP2K developers group <https://cp2k.org> */
|
||||
/* */
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
// Since __DATA_DIR can be arbitrarily long we must not let the preprocessor
|
||||
// expand that macro in Fortran code as it could exceed the line length limit.
|
||||
static const char *data_dir = __DATA_DIR;
|
||||
|
||||
/*******************************************************************************
|
||||
* \brief Returns path of data directory if set, otherwise an empty string.
|
||||
* \author Ole Schuett
|
||||
******************************************************************************/
|
||||
const char *get_data_dir() {
|
||||
const char *overwrite = getenv("CP2K_DATA_DIR");
|
||||
if (overwrite != NULL) {
|
||||
return overwrite;
|
||||
}
|
||||
return data_dir;
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
|
@ -14,7 +14,10 @@
|
|||
!> \author Matthias Krack (MK)
|
||||
! **************************************************************************************************
|
||||
MODULE cp_files
|
||||
|
||||
USE ISO_C_BINDING, ONLY: C_CHAR,&
|
||||
C_F_POINTER,&
|
||||
C_NULL_CHAR,&
|
||||
C_PTR
|
||||
USE kinds, ONLY: default_path_length
|
||||
USE machine, ONLY: default_input_unit,&
|
||||
default_output_unit,&
|
||||
|
|
@ -551,19 +554,30 @@ CONTAINS
|
|||
!> \return ...
|
||||
!> \author Ole Schuett
|
||||
! **************************************************************************************************
|
||||
FUNCTION get_data_dir() RESULT(data_dir_path)
|
||||
CHARACTER(LEN=default_path_length) :: data_dir_path
|
||||
FUNCTION get_data_dir() RESULT(res)
|
||||
CHARACTER(len=default_path_length) :: res
|
||||
|
||||
INTEGER :: stat
|
||||
CHARACTER(LEN=1, KIND=C_CHAR), DIMENSION(:), &
|
||||
POINTER :: path_f
|
||||
INTEGER :: i
|
||||
TYPE(C_PTR) :: path_c
|
||||
INTERFACE
|
||||
FUNCTION get_data_dir_c() BIND(C, name="get_data_dir")
|
||||
IMPORT :: C_PTR
|
||||
TYPE(C_PTR) :: get_data_dir_c
|
||||
END FUNCTION get_data_dir_c
|
||||
END INTERFACE
|
||||
|
||||
CALL GET_ENVIRONMENT_VARIABLE("CP2K_DATA_DIR", data_dir_path, status=stat)
|
||||
IF (stat == 0) RETURN
|
||||
path_c = get_data_dir_c()
|
||||
CALL C_F_POINTER(path_c, path_f, shape=(/default_path_length/))
|
||||
|
||||
#if defined(__DATA_DIR)
|
||||
data_dir_path = __DATA_DIR
|
||||
#else
|
||||
data_dir_path = "" !data-dir not set
|
||||
#endif
|
||||
res = ""
|
||||
DO i = 1, default_path_length
|
||||
IF (path_f(i) == C_NULL_CHAR) RETURN
|
||||
res(i:i) = path_f(i)
|
||||
END DO
|
||||
|
||||
CPABORT("CP2K_DATA_DIR path is too long")
|
||||
|
||||
END FUNCTION get_data_dir
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue