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 : #include <dlfcn.h> 28 : 29 : namespace PLMD { 30 : namespace config { 31 : 32 : namespace { 33 : /// local tool that, given a string, returns a new string which is: 34 : /// - enclosed in single quotes (') 35 : /// - with all single quotes escaped 36 0 : std::string escapeForSingleQuote(const std::string& input) { 37 : std::string escaped; 38 0 : for (char c : input) { 39 0 : if (c == '\'') { 40 : escaped += "'\\''"; 41 : } else { 42 0 : escaped += c; 43 : } 44 : } 45 0 : return "'" + escaped + "'"; 46 : } 47 : } 48 : 49 : // This is a fix to allow conda to correctly replace paths in binary files. 50 : // These functions should not be static or they will be optimized away! 51 443 : const char* plumed_root() { 52 443 : return "/home/runner/work/plumed2/plumed2/"; 53 : } 54 0 : const char* plumed_soext() { 55 0 : return "so"; 56 : } 57 0 : const char* plumed_htmldir() { 58 0 : return "xxxxNAxxxx"; 59 : } 60 0 : const char* plumed_includedir() { 61 0 : return "xxxxNAxxxx"; 62 : } 63 0 : const char* plumed_program_name() { 64 0 : return "xxxxNAxxxx"; 65 : } 66 : 67 0 : std::string getSoExt() { 68 0 : return plumed_soext(); 69 : } 70 : 71 0 : bool isInstalled() { 72 0 : return false; 73 : } 74 : 75 443 : std::string getPlumedRoot() { 76 443 : char *env = std::getenv("PLUMED_ROOT"); 77 : std::string ss; 78 443 : if( env == NULL) { 79 443 : ss=plumed_root(); 80 : } else { 81 0 : ss=std::string( env ); 82 : } 83 443 : return ss; 84 : } 85 : 86 0 : std::string getPlumedHtmldir() { 87 0 : if(!isInstalled()) { 88 0 : return getPlumedRoot(); 89 : } 90 0 : char *env = std::getenv("PLUMED_HTMLDIR"); 91 : std::string ss; 92 0 : if( env == NULL) { 93 0 : ss=plumed_htmldir(); 94 : } else { 95 0 : ss=std::string( env ); 96 : } 97 : return ss; 98 : } 99 : 100 0 : std::string getPlumedIncludedir() { 101 0 : if(!isInstalled()) { 102 0 : return getPlumedRoot()+"/src/include"; 103 : } 104 0 : char *env = std::getenv("PLUMED_INCLUDEDIR"); 105 : std::string ss; 106 0 : if( env == NULL) { 107 0 : ss=plumed_includedir(); 108 : } else { 109 0 : ss=std::string( env ); 110 : } 111 : return ss; 112 : } 113 : 114 0 : std::string getPlumedProgramName() { 115 0 : if(!isInstalled()) { 116 0 : return "plumed"; 117 : } 118 0 : char *env = std::getenv("PLUMED_PROGRAM_NAME"); 119 : std::string ss; 120 0 : if( env == NULL) { 121 0 : ss=plumed_program_name(); 122 : } else { 123 0 : ss=std::string( env ); 124 : } 125 : return ss; 126 : } 127 : 128 0 : std::string getEnvCommand() { 129 0 : return "env PLUMED_ROOT="+escapeForSingleQuote(getPlumedRoot())+ 130 0 : " PLUMED_VERSION="+escapeForSingleQuote(getVersionLong())+ 131 0 : " PLUMED_HTMLDIR="+escapeForSingleQuote(getPlumedHtmldir())+ 132 0 : " PLUMED_INCLUDEDIR="+escapeForSingleQuote(getPlumedIncludedir())+ 133 0 : " PLUMED_PROGRAM_NAME="+escapeForSingleQuote(getPlumedProgramName())+ 134 0 : " PLUMED_IS_INSTALLED='"+(false?"yes":"no")+"'"; 135 : } 136 : 137 0 : std::string getVersion() { 138 0 : return PLUMED_VERSION_SHORT; 139 : } 140 : 141 2 : std::string getVersionLong() { 142 2 : return PLUMED_VERSION_LONG; 143 : } 144 : 145 0 : std::string getVersionGit() { 146 0 : return PLUMED_VERSION_GIT; 147 : } 148 : 149 0 : std::string getMakefile() { 150 : static const unsigned char confu [] = { 151 : #include "Makefile.conf.xxd" 152 : , 0x00 153 : }; 154 : auto conf=(char*)confu; 155 0 : return std::string(conf,conf+std::strlen(conf)); 156 : } 157 : 158 0 : bool hasMatheval() { 159 : #ifdef __PLUMED_HAS_MATHEVAL 160 : return true; 161 : #else 162 0 : return false; 163 : #endif 164 : } 165 : 166 0 : bool hasDlopen() { 167 : #ifdef __PLUMED_HAS_DLOPEN 168 0 : return true; 169 : #else 170 : return false; 171 : #endif 172 : } 173 : 174 0 : bool hasMolfile() { 175 : #ifdef __PLUMED_HAS_MOLFILE_PLUGINS 176 0 : return true; 177 : #else 178 : return false; 179 : #endif 180 : } 181 : 182 0 : bool hasExternalMolfile() { 183 : #ifdef __PLUMED_HAS_EXTERNAL_MOLFILE_PLUGINS 184 : return true; 185 : #else 186 0 : return false; 187 : #endif 188 : } 189 : 190 0 : bool hasZlib() { 191 : #ifdef __PLUMED_HAS_ZLIB 192 0 : return true; 193 : #else 194 : return false; 195 : #endif 196 : } 197 : 198 0 : std::string getCompilationDate() { 199 0 : return __DATE__; 200 : } 201 : 202 0 : std::string getCompilationTime() { 203 0 : return __TIME__; 204 : } 205 : 206 0 : std::string getLibraryPath() { 207 : #ifdef __PLUMED_HAS_DLADDR 208 : Dl_info info; 209 0 : if(dladdr((void*)getLibraryPath,&info)) { 210 0 : return info.dli_fname; 211 : } else { 212 0 : return ""; 213 : } 214 : #endif 215 : 216 : } 217 : 218 : 219 : } 220 : } 221 :