* Bring back rbuild build to be used until bug 6372 is fixed.
[reactos.git] / tools / rbuild / backend / msvc / slnmaker.cpp
1 /*
2 * Copyright (C) 2002 Patrik Stridvall
3 * Copyright (C) 2005 Royce Mitchell III
4 * Copyright (C) 2006 Hervé Poussineau
5 * Copyright (C) 2006 Christoph von Wittich
6 * Copyright (C) 2009 Ged Murphy
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #ifdef _MSC_VER
24 #pragma warning ( disable : 4786 )
25 #endif//_MSC_VER
26
27 #include <string>
28 #include <vector>
29 #include <set>
30 #include <algorithm>
31 #include <fstream>
32 #include <iostream>
33
34 #include <stdio.h>
35
36 #include "msvc.h"
37
38 using std::string;
39 using std::vector;
40 using std::set;
41
42
43
44 SlnMaker::SlnMaker ( Configuration& buildConfig,
45 const std::vector<MSVCConfiguration*>& configurations,
46 std::string filename_sln,
47 std::string solution_version,
48 std::string studio_version)
49 {
50 m_configuration = buildConfig;
51 m_configurations = configurations;
52
53 OUT = fopen ( filename_sln.c_str(), "wb" );
54
55 if ( !OUT )
56 {
57 printf ( "Could not create file '%s'.\n", filename_sln.c_str() );
58 }
59
60 _generate_sln_header( solution_version, studio_version);
61 }
62
63 SlnMaker::~SlnMaker()
64 {
65 _generate_sln_footer ( );
66 fclose ( OUT );
67 }
68
69 void
70 SlnMaker::_generate_sln_header ( std::string solution_version, std::string studio_version )
71 {
72 //fprintf ( OUT, "Microsoft Visual Studio Solution File, Format Version %s\r\n", _get_solution_version().c_str() );
73 //fprintf ( OUT, "# Visual Studio %s\r\n", _get_studio_version().c_str() );
74 fprintf ( OUT, "Microsoft Visual Studio Solution File, Format Version %s\r\n", solution_version.c_str() );
75 fprintf ( OUT, "# Visual Studio %s\r\n", studio_version.c_str() );
76 fprintf ( OUT, "\r\n" );
77 }
78
79 void
80 SlnMaker::_generate_sln_footer ( )
81 {
82 fprintf ( OUT, "Global\r\n" );
83 fprintf ( OUT, "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n" );
84 for ( size_t i = 0; i < m_configurations.size(); i++ )
85 fprintf ( OUT, "\t\t%s = %s\r\n", m_configurations[i]->name.c_str(), m_configurations[i]->name.c_str() );
86 fprintf ( OUT, "\tEndGlobalSection\r\n" );
87
88 fprintf ( OUT, "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n" );
89 for ( size_t i = 0; i < modules.size (); i++)
90 {
91 _generate_sln_configurations ( modules[i]->guid.c_str() );
92 }
93 fprintf ( OUT, "\tEndGlobalSection\r\n" );
94 /*
95 fprintf ( OUT, "\tGlobalSection(ExtensibilityGlobals) = postSolution\r\n" );
96 fprintf ( OUT, "\tEndGlobalSection\r\n" );
97 fprintf ( OUT, "\tGlobalSection(ExtensibilityAddIns) = postSolution\r\n" );
98 fprintf ( OUT, "\tEndGlobalSection\r\n" );
99 */
100
101 if (m_configuration.VSProjectVersion == "7.00") {
102 fprintf ( OUT, "\tGlobalSection(ProjectDependencies) = postSolution\r\n" );
103 //FIXME: Add dependencies for VS 2002
104 fprintf ( OUT, "\tEndGlobalSection\r\n" );
105 }
106 else {
107 fprintf ( OUT, "\tGlobalSection(SolutionProperties) = preSolution\r\n" );
108 fprintf ( OUT, "\t\tHideSolutionNode = FALSE\r\n" );
109 fprintf ( OUT, "\tEndGlobalSection\r\n" );
110 }
111
112 fprintf ( OUT, "EndGlobal\r\n" );
113 fprintf ( OUT, "\r\n" );
114 }
115
116
117 void
118 SlnMaker::_generate_sln_configurations ( std::string vcproj_guid )
119 {
120 for ( size_t i = 0; i < m_configurations.size (); i++)
121 {
122 const MSVCConfiguration& cfg = *m_configurations[i];
123 fprintf ( OUT, "\t\t%s.%s|Win32.ActiveCfg = %s|Win32\r\n", vcproj_guid.c_str(), cfg.name.c_str(), cfg.name.c_str() );
124 fprintf ( OUT, "\t\t%s.%s|Win32.Build.0 = %s|Win32\r\n", vcproj_guid.c_str(), cfg.name.c_str(), cfg.name.c_str() );
125 }
126 }
127
128 void
129 SlnMaker::_add_project(ProjMaker &project, Module &module)
130 {
131 string sln_guid = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
132
133 fprintf ( OUT, "Project(\"%s\") = \"%s\", \".\\%s\",\"%s\"\n", sln_guid.c_str(), module.name.c_str() , project.VcprojFileName(module).c_str() , module.guid.c_str());
134 fprintf ( OUT, "EndProject\r\n" );
135
136 modules.push_back(&module);
137 }