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 : #if defined(__PLUMED_HAS_DLOPEN) || defined(__PLUMED_HAS_DLADDR) 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 6235 : std::string escapeForSingleQuote(const std::string& input) { 39 : std::string escaped; 40 130940 : for (char c : input) { 41 124705 : if (c == '\'') { 42 : escaped += "'\\''"; 43 : } else { 44 : escaped += c; 45 : } 46 : } 47 12470 : 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 13688 : const char* plumed_root() { 54 13688 : return "/home/runner/opt/lib/plumed"; 55 : } 56 2101 : const char* plumed_soext() { 57 2101 : return "so"; 58 : } 59 1249 : const char* plumed_htmldir() { 60 1249 : return "/home/runner/opt/share/doc/plumed"; 61 : } 62 1247 : const char* plumed_includedir() { 63 1247 : return "/home/runner/opt/include"; 64 : } 65 1248 : const char* plumed_program_name() { 66 1248 : return "plumed"; 67 : } 68 : 69 2101 : std::string getSoExt() { 70 2101 : return plumed_soext(); 71 : } 72 : 73 4865 : bool isInstalled() { 74 4865 : return true; 75 : } 76 : 77 13688 : std::string getPlumedRoot() { 78 13688 : char *env = std::getenv("PLUMED_ROOT"); 79 : std::string ss; 80 13688 : if( env == NULL) { 81 13688 : ss=plumed_root(); 82 : } else { 83 0 : ss=std::string( env ); 84 : } 85 13688 : return ss; 86 : } 87 : 88 1249 : std::string getPlumedHtmldir() { 89 1249 : if(!isInstalled()) { 90 0 : return getPlumedRoot(); 91 : } 92 1249 : char *env = std::getenv("PLUMED_HTMLDIR"); 93 : std::string ss; 94 1249 : if( env == NULL) { 95 1249 : ss=plumed_htmldir(); 96 : } else { 97 0 : ss=std::string( env ); 98 : } 99 1249 : return ss; 100 : } 101 : 102 1248 : std::string getPlumedIncludedir() { 103 1248 : if(!isInstalled()) { 104 0 : return getPlumedRoot()+"/src/include"; 105 : } 106 1248 : char *env = std::getenv("PLUMED_INCLUDEDIR"); 107 : std::string ss; 108 1248 : if( env == NULL) { 109 1247 : ss=plumed_includedir(); 110 : } else { 111 2 : ss=std::string( env ); 112 : } 113 1248 : return ss; 114 : } 115 : 116 1248 : std::string getPlumedProgramName() { 117 1248 : if(!isInstalled()) { 118 0 : return "plumed"; 119 : } 120 1248 : char *env = std::getenv("PLUMED_PROGRAM_NAME"); 121 : std::string ss; 122 1248 : if( env == NULL) { 123 1248 : ss=plumed_program_name(); 124 : } else { 125 0 : ss=std::string( env ); 126 : } 127 1248 : return ss; 128 : } 129 : 130 1247 : std::string getEnvCommand() { 131 2494 : return "env PLUMED_ROOT="+escapeForSingleQuote(getPlumedRoot())+ 132 3741 : " PLUMED_VERSION="+escapeForSingleQuote(getVersionLong())+ 133 3741 : " PLUMED_HTMLDIR="+escapeForSingleQuote(getPlumedHtmldir())+ 134 3741 : " PLUMED_INCLUDEDIR="+escapeForSingleQuote(getPlumedIncludedir())+ 135 2494 : " PLUMED_PROGRAM_NAME="+escapeForSingleQuote(getPlumedProgramName())+ 136 1247 : " PLUMED_IS_INSTALLED='"+(true?"yes":"no")+"'"; 137 : } 138 : 139 3 : std::string getVersion() { 140 3 : return PLUMED_VERSION_SHORT; 141 : } 142 : 143 3573 : std::string getVersionLong() { 144 3573 : return PLUMED_VERSION_LONG; 145 : } 146 : 147 2286 : std::string getVersionGit() { 148 2286 : return PLUMED_VERSION_GIT; 149 : } 150 : 151 97 : std::string getMakefile() { 152 : static const unsigned char confu [] = { 153 : #include "Makefile.conf.xxd" 154 : , 0x00 155 : }; 156 : auto conf=(char*)confu; 157 97 : 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 2285 : std::string getCompilationDate() { 201 2285 : return __DATE__; 202 : } 203 : 204 2285 : std::string getCompilationTime() { 205 2285 : return __TIME__; 206 : } 207 : 208 2285 : std::string getLibraryPath() { 209 : #ifdef __PLUMED_HAS_DLADDR 210 : Dl_info info; 211 2285 : if(dladdr((void*)getLibraryPath,&info) && info.dli_fname) { 212 2285 : return info.dli_fname; 213 : } else { 214 0 : return ""; 215 : } 216 : #else 217 : return ""; 218 : #endif 219 : } 220 : 221 : 222 : } 223 : } 224 :