1 #ifndef PROJECT_TREE_BUILDER__PROJECT_CONTEXT__HPP
2 #define PROJECT_TREE_BUILDER__PROJECT_CONTEXT__HPP
3 
4 /* $Id: msvc_project_context.hpp 554978 2018-01-11 15:08:49Z gouriano $
5  * ===========================================================================
6  *
7  *                            PUBLIC DOMAIN NOTICE
8  *               National Center for Biotechnology Information
9  *
10  *  This software/database is a "United States Government Work" under the
11  *  terms of the United States Copyright Act.  It was written as part of
12  *  the author's official duties as a United States Government employee and
13  *  thus cannot be copyrighted.  This software/database is freely available
14  *  to the public for use. The National Library of Medicine and the U.S.
15  *  Government have not placed any restriction on its use or reproduction.
16  *
17  *  Although all reasonable efforts have been taken to ensure the accuracy
18  *  and reliability of the software and data, the NLM and the U.S.
19  *  Government do not and cannot warrant the performance or results that
20  *  may be obtained by using this software or data. The NLM and the U.S.
21  *  Government disclaim all warranties, express or implied, including
22  *  warranties of performance, merchantability or fitness for any particular
23  *  purpose.
24  *
25  *  Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author:  Viatcheslav Gorelenkov
30  *
31  */
32 
33 #include<list>
34 #include<string>
35 #include<map>
36 
37 #include "proj_item.hpp"
38 #include "msvc_prj_utils.hpp"
39 #include "msvc_makefile.hpp"
40 #include "proj_builder_app.hpp"
41 
42 #include <corelib/ncbienv.hpp>
43 
44 BEGIN_NCBI_SCOPE
45 
46 
47 /////////////////////////////////////////////////////////////////////////////
48 ///
49 /// CMsvcPrjProjectContext --
50 ///
51 /// Abstraction of MSVC project-specific context.
52 ///
53 /// Project context provides project-specific information for
54 /// project generation.
55 
56 class CMsvcPrjProjectContext
57 {
58 public:
59     //no value type	semantics
60     CMsvcPrjProjectContext(const CProjItem& project);
61 
62     //Compiler::General
63     string AdditionalIncludeDirectories(const SConfigInfo& cfg_info) const;
64 
ProjectName(void) const65     const string& ProjectName(void) const
66     {
67         return m_ProjectName;
68     }
ProjectId(void) const69     const string& ProjectId(void) const
70     {
71         return m_ProjectId;
72     }
73 
74 
75     string AdditionalLinkerOptions(const SConfigInfo& cfg_info) const;
76 
77 #if 0
78     string AdditionalLibrarianOptions(const SConfigInfo& cfg_info) const;
79 #endif
80 
81 
82     string AdditionalLibraryDirectories(const SConfigInfo& cfg_info) const;
83 
84 
ProjectDir(void) const85     const string& ProjectDir(void) const
86     {
87         return m_ProjectDir;
88     }
89 
ProjectType(void) const90     CProjItem::TProjType ProjectType(void) const
91     {
92         return m_ProjType;
93     }
94 
SourcesDirsAbs(void) const95     const list<string>& SourcesDirsAbs(void) const
96     {
97         return m_SourcesDirsAbs;
98     }
99 
IncludeDirsAbs(void) const100     const list<string>& IncludeDirsAbs(void) const
101     {
102         return m_IncludeDirsAbs;
103     }
104 
InlineDirsAbs(void) const105     const list<string>& InlineDirsAbs(void) const
106     {
107         return m_InlineDirsAbs;
108     }
109 
110 
111     const CMsvcCombinedProjectMakefile& GetMsvcProjectMakefile(void) const;
112 
113 
114     static bool IsRequiresOk(const CProjItem& prj, string* unmet);
115 
116 
117     bool IsConfigEnabled(const SConfigInfo& config, string* unmet, string* unmet_req) const;
118 
119 
GetCustomBuildInfo(void) const120     const list<SCustomBuildInfo>& GetCustomBuildInfo(void) const
121     {
122         return m_CustomBuildInfo;
123     }
124 
125 
126     const list<string> Defines(const SConfigInfo& cfg_info) const;
127 
128 
PreBuilds(void) const129     const list<CProjKey>& PreBuilds(void) const
130     {
131         return m_PreBuilds;
132     }
133 
GetMakeType(void) const134     EMakeFileType GetMakeType(void) const
135     {
136         return m_MakeType;
137     }
138 
GetEnabledPackages(const string & config_name)139     static const set<string>& GetEnabledPackages(const string& config_name)
140     {
141         return s_EnabledPackages[config_name];
142     }
GetDisabledPackages(const string & config_name)143     static const set<string>& GetDisabledPackages(const string& config_name)
144     {
145         return s_DisabledPackages[config_name];
146     }
GetSrcRoot(void) const147     const string& GetSrcRoot(void) const
148     {
149         return m_SrcRoot;
150     }
151     bool IsPchEnabled(const SConfigInfo& config) const;
152     string GetPchHeader(
153         const string& project_id,
154         const string& source_file_full_path,
155         const string& tree_src_dir, const SConfigInfo& config) const;
156     string GetConfigData( const string& section, const string& entry,
157                           const SConfigInfo& config) const;
158 
159 private:
160     // Prohibited to:
161     CMsvcPrjProjectContext(void);
162     CMsvcPrjProjectContext(const CMsvcPrjProjectContext&);
163     CMsvcPrjProjectContext&	operator= (const CMsvcPrjProjectContext&);
164 
165 
166     string   m_ProjectName;
167     string   m_ProjectId;
168 
169     string m_AdditionalLibrarianOptions;
170 
171     string m_ProjectDir;
172 
173     CProjItem::TProjType m_ProjType;
174 
175     list<string> m_SourcesDirsAbs;
176     list<string> m_IncludeDirsAbs;
177     list<string> m_InlineDirsAbs;
178 
179     list<string> m_ProjectIncludeDirs;
180     list<string> m_ProjectLibs;
181 
182     void CreateLibsList(list<string>* libs_list) const;
183 
184     unique_ptr<CMsvcProjectMakefile>         m_MsvcProjectMakefile;
185     unique_ptr<CMsvcCombinedProjectMakefile> m_MsvcCombinedProjectMakefile;
186 
187     string       m_SourcesBaseDir;
188     list<string> m_Requires;
189 
190     list<SCustomBuildInfo> m_CustomBuildInfo;
191 
192     list<string> m_Defines;
193 
194     list<CProjKey> m_PreBuilds;
195 
196     list<string> m_NcbiCLibs;
197 
198     EMakeFileType m_MakeType;
199 
200     string m_StaticLibRoot;
201     string m_DynamicLibRoot;
202     string m_SrcRoot;
203     const CProjItem& m_Project;
204 
205     static map<string, set<string> > s_EnabledPackages;
206     static map<string, set<string> > s_DisabledPackages;
207 };
208 
209 
210 /////////////////////////////////////////////////////////////////////////////
211 ///
212 /// CMsvcPrjGeneralContext --
213 ///
214 /// Abstraction of MSVC project "general" context.
215 ///
216 /// Project context provides specific information for particular type of
217 /// project (Exe, Lib, Dll). This information not project-specific, but
218 /// more project type specific.
219 
220 class CMsvcPrjGeneralContext
221 {
222 public:
223     //no value type semantics
224     CMsvcPrjGeneralContext(const SConfigInfo& config,
225                            const CMsvcPrjProjectContext& prj_context);
226 
227     typedef enum {
228         eExe,
229         eLib,
230         eDll,
231         eDataSpec,
232         eOther } TTargetType;
233     TTargetType m_Type;
234 
235     SConfigInfo m_Config;
236 
237     //Configuration::General
OutputDirectory(void) const238     string OutputDirectory(void) const
239     {
240         return m_OutputDirectory;
241     }
242 
ConfigurationName(void) const243     string ConfigurationName(void) const
244     {
245         return m_Config.GetConfigFullName();
246     }
247 
GetMsvcMetaMakefile(void) const248     const CMsvcMetaMakefile& GetMsvcMetaMakefile(void) const
249     {
250         return m_MsvcMetaMakefile;
251     }
252 
253 private:
254     /// Prohibited to:
255     CMsvcPrjGeneralContext(void);
256     CMsvcPrjGeneralContext(const CMsvcPrjGeneralContext&);
257     CMsvcPrjGeneralContext& operator= (const CMsvcPrjGeneralContext&);
258 
259     string m_OutputDirectory;
260     string m_ConfigurationName;
261 
262     const CMsvcMetaMakefile& m_MsvcMetaMakefile;
263 };
264 
265 
266 /////////////////////////////////////////////////////////////////////////////
267 ///
268 /// ITool --
269 ///
270 /// Base class for all MSVC tools.
271 ///
272 /// Polymorphic hierarchy base class.
273 
274 struct ITool
275 {
276     virtual string Name(void) const = 0;
277 
~IToolITool278     virtual ~ITool(void)
279     {
280     }
281 };
282 
283 
284 /////////////////////////////////////////////////////////////////////////////
285 ///
286 /// IConfiguration --
287 ///
288 /// "Configuration" interface.
289 ///
290 /// Abstract class.
291 
292 struct IConfiguration : public ITool
293 {
294     //Name : Configuration+'|'+"Win32"
295     virtual string OutputDirectory(void)		const = 0;
296     virtual string IntermediateDirectory(void)	const = 0;
297     virtual string ConfigurationType(void)		const = 0;
298     virtual string CharacterSet(void)			const = 0;
299     virtual string PlatformToolset(void)    	const = 0;
300     virtual string BuildLogFile(void)			const = 0;
301 };
302 
303 
304 /////////////////////////////////////////////////////////////////////////////
305 ///
306 /// ICompilerTool --
307 ///
308 /// "CompilerTool" interface.
309 ///
310 /// Abstract class.
311 
312 struct ICompilerTool : public ITool
313 {
314     //string Name : "VCCLCompilerTool"
315     virtual string Optimization(void)					const = 0;
316     virtual string AdditionalIncludeDirectories(void)	const = 0;
317 
318     // Preprocessor definition:
319     // LIB (Debug)		WIN32;_DEBUG;_LIB
320     // LIB (Release)	WIN32;NDEBUG;_LIB
321     // APP (Debug)		WIN32;_DEBUG;_CONSOLE
322     // APP (Release)	WIN32;NDEBUG;_CONSOLE
323     // DLL (Debug)		WIN32;_DEBUG;_WINDOWS;_USRDLL;XNCBI_EXPORTS
324     //                                    (project_name(uppercase)+"_EXPORTS")
325 
326     // DLL (Relese)		WIN32;NDEBUG;_WINDOWS;_USRDLL;XNCBI_EXPORTS
327     //                                    (project_name(uppercase)+"_EXPORTS")
328 
329     // All configurations:
330     virtual string PreprocessorDefinitions(void)		 const = 0;
331 
332     virtual string MinimalRebuild(void)					 const = 0;
333     virtual string BasicRuntimeChecks(void)				 const = 0;
334     virtual string RuntimeLibrary(void)					 const = 0;
335     virtual string RuntimeTypeInfo(void)                 const = 0;
336     virtual string UsePrecompiledHeader(void)			 const = 0;
337     virtual string WarningLevel(void)					 const = 0;
338     virtual string Detect64BitPortabilityProblems(void)  const = 0;
339     virtual string DebugInformationFormat(void)			 const = 0;
340     virtual string CompileAs(void)                       const = 0;
341 
342     //For release - EXE DLL LIB
343     virtual string InlineFunctionExpansion(void)		 const = 0;
344     virtual string OmitFramePointers(void)				 const = 0;
345     virtual string StringPooling(void)					 const = 0;
346     virtual string EnableFunctionLevelLinking(void)		 const = 0;
347 
348     //Latest additions
349     virtual string OptimizeForProcessor(void)		     const = 0;
350     virtual string StructMemberAlignment(void)		     const = 0;
351     virtual string CallingConvention(void)		         const = 0;
352     virtual string IgnoreStandardIncludePath(void)	     const = 0;
353     virtual string ExceptionHandling(void)		         const = 0;
354     virtual string BufferSecurityCheck(void)		     const = 0;
355     virtual string DisableSpecificWarnings(void)		 const = 0;
356     virtual string UndefinePreprocessorDefinitions(void) const = 0;
357     virtual string AdditionalOptions(void)		         const = 0;
358 
359     virtual string GlobalOptimizations(void)		     const = 0;
360     virtual string FavorSizeOrSpeed(void)		         const = 0;
361     virtual string BrowseInformation(void)		         const = 0;
362     virtual string ProgramDataBaseFileName(void)	     const = 0;
363 };
364 
365 
366 /////////////////////////////////////////////////////////////////////////////
367 ///
368 /// ILinkerTool --
369 ///
370 /// "LinkerTool" interface.
371 ///
372 /// Abstract class.
373 
374 struct ILinkerTool : public ITool
375 {
376     //string Name : "VCLinkerTool"
377     virtual string AdditionalDependencies(void)		  const = 0;
378     virtual string AdditionalOptions(void)			  const = 0;
379     virtual string OutputFile(void)					  const = 0;
380     virtual string LinkIncremental(void)			  const = 0;
381     virtual string LargeAddressAware(void)            const = 0;
382     virtual string GenerateDebugInformation(void)	  const = 0;
383     virtual string ProgramDatabaseFile(void)		  const = 0;
384     virtual string SubSystem(void)					  const = 0;
385     virtual string ImportLibrary(void)				  const = 0;
386     virtual string TargetMachine(void)				  const = 0;
387     virtual string ImageHasSafeExceptionHandlers(void) const = 0;
388 
389     //release - EXE DLL +=
390     virtual string OptimizeReferences(void)			  const = 0;
391     virtual string EnableCOMDATFolding(void)		  const = 0;
392 
393     //Latest additions
394     virtual string IgnoreAllDefaultLibraries(void)	  const = 0;
395     virtual string IgnoreDefaultLibraryNames(void)	  const = 0;
396     virtual string AdditionalLibraryDirectories(void) const = 0;
397     virtual string FixedBaseAddress(void)			  const = 0;
398     virtual string GenerateManifest(void)			  const = 0;
399     virtual string EmbedManifest(void)			      const = 0;
400 };
401 
402 
403 /////////////////////////////////////////////////////////////////////////////
404 ///
405 /// ILibrarianTool --
406 ///
407 /// "LibrarianTool" interface.
408 ///
409 /// Abstract class.
410 
411 struct ILibrarianTool : public ITool
412 {
413     //string Name : "VCLibrarianTool"
414     virtual string AdditionalOptions(void)			  const = 0;
415     virtual string OutputFile(void)					  const = 0;
416     virtual string IgnoreAllDefaultLibraries(void)	  const = 0;
417     virtual string IgnoreDefaultLibraryNames(void)	  const = 0;
418 
419     //Latest additions
420     virtual string AdditionalLibraryDirectories(void) const = 0;
421     virtual string TargetMachine(void)                const = 0;
422 };
423 
424 /// Dummies - Name - only tools. Must present in msvc proj:
425 struct ICustomBuildTool : public ITool
426 {
427     //Name : "VCCustomBuildTool"
428 };
429 struct IMIDLTool : public ITool
430 {
431     //Name : "VCMIDLTool"
432 };
433 struct IPostBuildEventTool : public ITool
434 {
435     //Name : "VCPostBuildEventTool"
436 };
437 
438 /// Not a dummy for lib projects
439 struct IPreBuildEventTool : public ITool
440 {
441     //Name : "VCPreBuildEventTool"
442     virtual string CommandLine(void) const = 0;
443 };
444 
445 struct IPreLinkEventTool : public ITool
446 {
447     //Name : "VCPreLinkEventTool"
448 };
449 
450 
451 /////////////////////////////////////////////////////////////////////////////
452 ///
453 /// IResourceCompilerTool --
454 ///
455 /// "ResourceCompilerTool" interface.
456 ///
457 /// Abstract class.
458 
459 struct IResourceCompilerTool : public ITool
460 {
461     //Name : "VCResourceCompilerTool"
462     //must be implemented for Dll and Windows apps
463     virtual string AdditionalIncludeDirectories(void)  const = 0;
464     virtual string AdditionalOptions(void)	           const = 0;
465     virtual string Culture(void)                       const = 0;
466     virtual string PreprocessorDefinitions(void)       const = 0;
467 };
468 
469 
470 /// Dummies - Name - only tools. Must present in msvc proj:
471 struct IWebServiceProxyGeneratorTool : public ITool
472 {
473     //Name : "VCWebServiceProxyGeneratorTool"
474 };
475 struct IXMLDataGeneratorTool : public ITool
476 {
477     //Name : "VCXMLDataGeneratorTool"
478 };
479 struct IManagedWrapperGeneratorTool : public ITool
480 {
481     //Name : "VCManagedWrapperGeneratorTool"
482 };
483 struct IAuxiliaryManagedWrapperGeneratorTool : public ITool
484 {
485     //Name : "VCAuxiliaryManagedWrapperGeneratorTool"
486 };
487 
488 
489 /////////////////////////////////////////////////////////////////////////////
490 ///
491 /// CMsvcTools --
492 ///
493 /// Abstraction of MSVC 7.10 C++ project build tools.
494 ///
495 /// Provides all tools interfaces. Tools implementation will depends upon
496 /// project general and project specific contexts.
497 
498 class CMsvcTools
499 {
500 public:
501     CMsvcTools(const CMsvcPrjGeneralContext& general_context,
502                const CMsvcPrjProjectContext& project_context);
503 
504     ~CMsvcTools();
505 
506     IConfiguration      * Configuration	(void) const;
507     ICompilerTool       * Compiler      (void) const;
508     ILinkerTool         * Linker        (void) const;
509     ILibrarianTool      * Librarian     (void) const;
510     ICustomBuildTool	* CustomBuid    (void) const;
511     IMIDLTool			* MIDL		    (void) const;
512     IPostBuildEventTool * PostBuildEvent(void) const;
513     IPreBuildEventTool	* PreBuildEvent (void) const;
514     IPreLinkEventTool	* PreLinkEvent  (void) const;
515 
516     IResourceCompilerTool *
517                           ResourceCompiler          (void) const;
518 
519     IWebServiceProxyGeneratorTool *
520                           WebServiceProxyGenerator	(void) const;
521 
522     IXMLDataGeneratorTool *
523                           XMLDataGenerator          (void) const;
524 
525     IManagedWrapperGeneratorTool *
526                           ManagedWrapperGenerator	(void) const;
527 
528     IAuxiliaryManagedWrapperGeneratorTool *
529                           AuxiliaryManagedWrapperGenerator(void) const;
530 
531 private:
532     unique_ptr<IConfiguration>        m_Configuration;
533     unique_ptr<ICompilerTool>         m_Compiler;
534     unique_ptr<ILinkerTool>           m_Linker;
535     unique_ptr<ILibrarianTool>        m_Librarian;
536 
537     unique_ptr<ICustomBuildTool>      m_CustomBuid;
538     unique_ptr<IMIDLTool>             m_MIDL;
539     unique_ptr<IPostBuildEventTool>	m_PostBuildEvent;
540     unique_ptr<IPreBuildEventTool>	m_PreBuildEvent;
541     unique_ptr<IPreLinkEventTool>		m_PreLinkEvent;
542 
543     unique_ptr<IResourceCompilerTool>	m_ResourceCompiler;
544 
545     unique_ptr<IWebServiceProxyGeneratorTool>
546                                     m_WebServiceProxyGenerator;
547 
548     unique_ptr<IXMLDataGeneratorTool>	m_XMLDataGenerator;
549 
550     unique_ptr<IManagedWrapperGeneratorTool>
551                                     m_ManagedWrapperGenerator;
552 
553     unique_ptr<IAuxiliaryManagedWrapperGeneratorTool>
554                                     m_AuxiliaryManagedWrapperGenerator;
555 
556     //this is not a value-type class
557     CMsvcTools();
558     CMsvcTools(const CMsvcTools&);
559     CMsvcTools& operator= (const CMsvcTools&);
560 };
561 
562 
563 END_NCBI_SCOPE
564 
565 #endif //PROJECT_TREE_BUILDER__PROJECT_CONTEXT__HPP
566