Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2011-2023 The plumed team 3 : (see the PEOPLE file at the root of the distribution for a list of names) 4 : 5 : See http://www.plumed.org for more information. 6 : 7 : This file is part of plumed, version 2. 8 : 9 : plumed is free software: you can redistribute it and/or modify 10 : it under the terms of the GNU Lesser General Public License as published by 11 : the Free Software Foundation, either version 3 of the License, or 12 : (at your option) any later version. 13 : 14 : plumed is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU Lesser General Public License for more details. 18 : 19 : You should have received a copy of the GNU Lesser General Public License 20 : along with plumed. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : 23 : #include "Config.h" 24 : #include "version.h" 25 : #include <cstdlib> 26 : #include <cstring> 27 : #ifdef __PLUMED_HAS_DLOPEN 28 : #include <dlfcn.h> 29 : #endif 30 : 31 : namespace PLMD { 32 : namespace config { 33 : 34 : namespace { 35 : /// local tool that, given a string, returns a new string which is: 36 : /// - enclosed in single quotes (') 37 : /// - with all single quotes escaped 38 4995 : std::string escapeForSingleQuote(const std::string& input) { 39 : std::string escaped; 40 100904 : for (char c : input) { 41 95909 : if (c == '\'') { 42 : escaped += "'\\''"; 43 : } else { 44 95909 : escaped += c; 45 : } 46 : } 47 9990 : return "'" + escaped + "'"; 48 : } 49 : } 50 : 51 : // This is a fix to allow conda to correctly replace paths in binary files. 52 : // These functions should not be static or they will be optimized away! 53 10388 : const char* plumed_root() { 54 10388 : return "/home/runner/opt/lib/plumed"; 55 : } 56 1663 : const char* plumed_soext() { 57 1663 : return "so"; 58 : } 59 999 : const char* plumed_htmldir() { 60 999 : return "/home/runner/opt/share/doc/plumed"; 61 : } 62 998 : const char* plumed_includedir() { 63 998 : return "/home/runner/opt/include"; 64 : } 65 999 : const char* plumed_program_name() { 66 999 : return "plumed"; 67 : } 68 : 69 1663 : std::string getSoExt() { 70 1663 : return plumed_soext(); 71 : } 72 : 73 3861 : bool isInstalled() { 74 3861 : return true; 75 : } 76 : 77 10388 : std::string getPlumedRoot() { 78 10388 : char *env = std::getenv("PLUMED_ROOT"); 79 : std::string ss; 80 10388 : if( env == NULL) { 81 10388 : ss=plumed_root(); 82 : } else { 83 0 : ss=std::string( env ); 84 : } 85 10388 : return ss; 86 : } 87 : 88 999 : std::string getPlumedHtmldir() { 89 999 : if(!isInstalled()) { 90 0 : return getPlumedRoot(); 91 : } 92 999 : char *env = std::getenv("PLUMED_HTMLDIR"); 93 : std::string ss; 94 999 : if( env == NULL) { 95 999 : ss=plumed_htmldir(); 96 : } else { 97 0 : ss=std::string( env ); 98 : } 99 : return ss; 100 : } 101 : 102 999 : std::string getPlumedIncludedir() { 103 999 : if(!isInstalled()) { 104 0 : return getPlumedRoot()+"/src/include"; 105 : } 106 999 : char *env = std::getenv("PLUMED_INCLUDEDIR"); 107 : std::string ss; 108 999 : if( env == NULL) { 109 998 : ss=plumed_includedir(); 110 : } else { 111 2 : ss=std::string( env ); 112 : } 113 : return ss; 114 : } 115 : 116 999 : std::string getPlumedProgramName() { 117 999 : if(!isInstalled()) { 118 0 : return "plumed"; 119 : } 120 999 : char *env = std::getenv("PLUMED_PROGRAM_NAME"); 121 : std::string ss; 122 999 : if( env == NULL) { 123 999 : ss=plumed_program_name(); 124 : } else { 125 0 : ss=std::string( env ); 126 : } 127 : return ss; 128 : } 129 : 130 999 : std::string getEnvCommand() { 131 1998 : return "env PLUMED_ROOT="+escapeForSingleQuote(getPlumedRoot())+ 132 3996 : " PLUMED_VERSION="+escapeForSingleQuote(getVersionLong())+ 133 3996 : " PLUMED_HTMLDIR="+escapeForSingleQuote(getPlumedHtmldir())+ 134 3996 : " PLUMED_INCLUDEDIR="+escapeForSingleQuote(getPlumedIncludedir())+ 135 3996 : " PLUMED_PROGRAM_NAME="+escapeForSingleQuote(getPlumedProgramName())+ 136 2997 : " PLUMED_IS_INSTALLED='"+(true?"yes":"no")+"'"; 137 : } 138 : 139 4 : std::string getVersion() { 140 4 : return PLUMED_VERSION_SHORT; 141 : } 142 : 143 2664 : std::string getVersionLong() { 144 2664 : return PLUMED_VERSION_LONG; 145 : } 146 : 147 1636 : std::string getVersionGit() { 148 1636 : return PLUMED_VERSION_GIT; 149 : } 150 : 151 56 : std::string getMakefile() { 152 : static const unsigned char confu [] = { 153 : #include "Makefile.conf.xxd" 154 : , 0x00 155 : }; 156 : auto conf=(char*)confu; 157 56 : return std::string(conf,conf+std::strlen(conf)); 158 : } 159 : 160 0 : bool hasMatheval() { 161 : #ifdef __PLUMED_HAS_MATHEVAL 162 : return true; 163 : #else 164 0 : return false; 165 : #endif 166 : } 167 : 168 0 : bool hasDlopen() { 169 : #ifdef __PLUMED_HAS_DLOPEN 170 0 : return true; 171 : #else 172 : return false; 173 : #endif 174 : } 175 : 176 0 : bool hasMolfile() { 177 : #ifdef __PLUMED_HAS_MOLFILE_PLUGINS 178 0 : return true; 179 : #else 180 : return false; 181 : #endif 182 : } 183 : 184 0 : bool hasExternalMolfile() { 185 : #ifdef __PLUMED_HAS_EXTERNAL_MOLFILE_PLUGINS 186 : return true; 187 : #else 188 0 : return false; 189 : #endif 190 : } 191 : 192 0 : bool hasZlib() { 193 : #ifdef __PLUMED_HAS_ZLIB 194 0 : return true; 195 : #else 196 : return false; 197 : #endif 198 : } 199 : 200 1636 : std::string getCompilationDate() { 201 1636 : return __DATE__; 202 : } 203 : 204 1636 : std::string getCompilationTime() { 205 1636 : return __TIME__; 206 : } 207 : 208 1636 : std::string getLibraryPath() { 209 : #ifdef __PLUMED_HAS_DLADDR 210 : Dl_info info; 211 1636 : if(dladdr((void*)getLibraryPath,&info)) { 212 1636 : return info.dli_fname; 213 : } else { 214 0 : return ""; 215 : } 216 : #else 217 : return ""; 218 : #endif 219 : } 220 : 221 : 222 : } 223 : } 224 :