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