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