1 #ifndef PROJECT_TREE_BUILDER_MSVC_SITE__HPP 2 #define PROJECT_TREE_BUILDER_MSVC_SITE__HPP 3 /* $Id: msvc_site.hpp 455052 2014-12-22 18:23:09Z gouriano $ 4 * =========================================================================== 5 * 6 * PUBLIC DOMAIN NOTICE 7 * National Center for Biotechnology Information 8 * 9 * This software/database is a "United States Government Work" under the 10 * terms of the United States Copyright Act. It was written as part of 11 * the author's official duties as a United States Government employee and 12 * thus cannot be copyrighted. This software/database is freely available 13 * to the public for use. The National Library of Medicine and the U.S. 14 * Government have not placed any restriction on its use or reproduction. 15 * 16 * Although all reasonable efforts have been taken to ensure the accuracy 17 * and reliability of the software and data, the NLM and the U.S. 18 * Government do not and cannot warrant the performance or results that 19 * may be obtained by using this software or data. The NLM and the U.S. 20 * Government disclaim all warranties, express or implied, including 21 * warranties of performance, merchantability or fitness for any particular 22 * purpose. 23 * 24 * Please cite the author in any work or product based on this material. 25 * 26 * =========================================================================== 27 * 28 * Author: Viatcheslav Gorelenkov 29 * 30 */ 31 #include "ptb_registry.hpp" 32 #include <set> 33 #include "msvc_prj_utils.hpp" 34 #include "resolver.hpp" 35 #include <corelib/ncbienv.hpp> 36 BEGIN_NCBI_SCOPE 37 38 ///////////////////////////////////////////////////////////////////////////// 39 /// 40 /// SLibInfo -- 41 /// 42 /// Abstraction of lib description in site. 43 /// 44 /// Provides information about 45 /// additional include dir, library path and libs list. 46 47 struct SLibInfo 48 { 49 bool valid; 50 list<string> m_IncludeDir; 51 list<string> m_LibDefines; 52 string m_LibPath; 53 string m_BinPath; 54 list<string> m_Libs; 55 list<string> m_StdLibs; 56 list<string> m_Macro; 57 list<string> m_Files; 58 string m_libinfokey; 59 bool m_good; 60 SLibInfoSLibInfo61 SLibInfo(void) 62 { 63 valid = false; 64 m_good = false; 65 } SLibInfoSLibInfo66 SLibInfo(const SLibInfo& info) 67 { 68 valid = info.valid; 69 m_IncludeDir = info.m_IncludeDir; 70 m_LibDefines = info.m_LibDefines; 71 m_LibPath = info.m_LibPath; 72 m_BinPath = info.m_BinPath; 73 m_Libs = info.m_Libs; 74 m_StdLibs = info.m_StdLibs; 75 m_Macro = info.m_Macro; 76 m_Files = info.m_Files; 77 m_libinfokey = info.m_libinfokey; 78 m_good = info.m_good; 79 } operator =SLibInfo80 SLibInfo& operator= (const SLibInfo& info) 81 { 82 valid = info.valid; 83 m_IncludeDir = info.m_IncludeDir; 84 m_LibDefines = info.m_LibDefines; 85 m_LibPath = info.m_LibPath; 86 m_BinPath = info.m_BinPath; 87 m_Libs = info.m_Libs; 88 m_StdLibs = info.m_StdLibs; 89 m_Macro = info.m_Macro; 90 m_Files = info.m_Files; 91 m_libinfokey = info.m_libinfokey; 92 m_good = info.m_good; 93 return *this; 94 } IsEmptySLibInfo95 bool IsEmpty(void) const 96 { 97 return valid && 98 m_IncludeDir.empty() && 99 m_LibDefines.empty() && 100 m_LibPath.empty() && 101 m_BinPath.empty() && 102 m_Libs.empty() && 103 m_StdLibs.empty() && 104 m_Macro.empty() && 105 m_Files.empty(); 106 } ClearSLibInfo107 void Clear(void) 108 { 109 valid = false; 110 m_IncludeDir.clear(); 111 m_LibDefines.clear(); 112 m_LibPath.erase(); 113 m_BinPath.erase(); 114 m_Libs.clear(); 115 m_StdLibs.clear(); 116 m_Macro.clear(); 117 m_Files.clear(); 118 } 119 }; 120 121 ///////////////////////////////////////////////////////////////////////////// 122 /// 123 /// CMsvcSite -- 124 /// 125 /// Abstraction of user site for building of C++ projects. 126 /// 127 /// Provides information about libraries availability as well as implicit 128 /// exclusion of some branches from project tree. 129 130 class CMsvcSite 131 { 132 public: 133 CMsvcSite(const string& reg_path); 134 135 void InitializeLibChoices(void); 136 // Is REQUIRES provided? 137 bool IsProvided(const string& thing, bool deep=true) const; 138 139 bool IsBanned(const string& thing) const; 140 141 /// Get components from site 142 void GetComponents(const string& entry, list<string>* components) const; 143 144 /// Is section present in site registry? 145 bool IsDescribed(const string& section) const; 146 147 string ProcessMacros(string data, bool preserve_unresolved=true) const; 148 // Get library (LIBS) description 149 void GetLibInfo(const string& lib, 150 const SConfigInfo& config, SLibInfo* libinfo) const; 151 // Is this lib available in certain config 152 bool IsLibEnabledInConfig(const string& lib, 153 const SConfigInfo& config) const; 154 155 // Resolve define (now from CPPFLAGS) 156 bool ResolveDefine(const string& define, string& resolved) const; 157 158 // Configure related: 159 // Path from tree root to file where configure defines must be. 160 string GetConfigureDefinesPath(void) const; 161 // What we have to define: 162 void GetConfigureDefines (list<string>* defines) const; 163 164 // Lib Choices related: 165 enum ELibChoice { 166 eUnknown, 167 eLib, 168 e3PartyLib 169 }; 170 struct SLibChoice 171 { 172 SLibChoice(void); 173 174 SLibChoice(const CMsvcSite& site, 175 const string& lib, 176 const string& lib_3party); 177 178 ELibChoice m_Choice; 179 string m_LibId; 180 string m_3PartyLib; 181 }; 182 bool IsLibWithChoice (const string& lib_id) const; 183 bool Is3PartyLib (const string& lib_id) const; 184 bool Is3PartyLibWithChoice (const string& lib3party_id) const; 185 186 ELibChoice GetChoiceForLib (const string& lib_id) const; 187 ELibChoice GetChoiceFor3PartyLib(const string& lib3party_id, 188 const SConfigInfo& cfg_info) const; 189 190 void GetLibChoiceIncludes(const string& cpp_flags_define, 191 list<string>* abs_includes) const; 192 void GetLibChoiceIncludes(const string& cpp_flags_define, 193 const SConfigInfo& cfg_info, 194 list<string>* abs_includes) const; 195 void GetLibInclude(const string& lib_id, 196 const SConfigInfo& cfg_info, 197 list<string>* includes) const; 198 199 SLibChoice GetLibChoiceForLib (const string& lib_id) const; 200 SLibChoice GetLibChoiceFor3PartyLib (const string& lib3party_id) const; 201 202 203 204 string GetAppDefaultResource(void) const; 205 206 207 void GetThirdPartyLibsToInstall (list<string>* libs) const; 208 string GetThirdPartyLibsBinPathSuffix(void) const; 209 string GetThirdPartyLibsBinSubDir (void) const; 210 void SetThirdPartyLibBin(const string& lib, const string& bin); 211 string GetThirdPartyLibBin(const string& lib) const; 212 213 void GetStandardFeatures (list<string>& features) const; 214 215 void ProcessMacros (const list<SConfigInfo>& configs); GetMacros(void) const216 const CSymResolver& GetMacros(void) const 217 { 218 return m_Macros; 219 } 220 221 bool IsLibOk(const SLibInfo& lib_info, bool silent = false) const; 222 223 static string ToOSPath(const string& path); 224 225 string GetConfigureEntry(const string& entry) const; 226 string GetDefinesEntry(const string& entry) const; 227 string GetPlatformInfo(const string& sysname, 228 const string& type, const string& orig) const; 229 bool IsCppflagDescribed(const string& value) const; 230 231 private: 232 string m_RegPath; 233 CPtbRegistry m_Registry; 234 CSimpleMakeFileContents m_UnixMakeDef; 235 236 set<string> m_ProvidedThing; 237 set<string> m_NotProvidedThing; 238 239 list<SLibChoice> m_LibChoices; 240 241 CSymResolver m_Macros; 242 mutable map<string,SLibInfo> m_AllLibInfo; 243 map<string, string> m_ThirdPartyLibBin; 244 245 /// cache of directories and their existence 246 typedef map<string, bool> TDirectoryExistenceMap; 247 static TDirectoryExistenceMap sm_DirExists; 248 static bool x_DirExists(const string& dir_name); 249 string x_GetConfigureEntry(const string& entry) const; 250 string x_GetDefinesEntry(const string& entry) const; 251 252 /// Prohibited to: 253 CMsvcSite(void); 254 CMsvcSite(const CMsvcSite&); 255 CMsvcSite& operator= (const CMsvcSite&); 256 }; 257 258 END_NCBI_SCOPE 259 260 #endif //PROJECT_TREE_BUILDER_MSVC_SITE__HPP 261