39c7839348553877cc059aa1def5180dc8d1ac99
2 * Copyright (C) 2005 Trevor McCort
3 * Copyright (C) 2005 Casper S. Hornstrup
4 * Copyright (C) 2005 Steven Edwards
5 * Copyright (C) 2005 Royce Mitchell
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #pragma warning ( disable : 4786 )
30 #include "../mingw/mingw.h"
34 static class MSVCFactory
: public Backend::Factory
38 MSVCFactory() : Factory("MSVC") {}
39 Backend
*operator() (Project
&project
,
40 Configuration
& configuration
)
42 return new MSVCBackend(project
, configuration
);
48 MSVCBackend::MSVCBackend(Project
&project
,
49 Configuration
& configuration
) : Backend(project
, configuration
)
54 void MSVCBackend::Process()
56 string filename_dsw
= ProjectNode
.name
+ ".dsw";
57 string filename_sln
= ProjectNode
.name
+ ".sln";
59 printf ( "Creating MSVC workspace: %s\n", filename_dsw
.c_str() );
60 printf ( "Creating MSVC workspace: %s\n", filename_sln
.c_str() );
64 m_dswFile
= fopen ( filename_dsw
.c_str(), "wb" );
65 m_slnFile
= fopen ( filename_sln
.c_str(), "wb" );
69 printf ( "Could not create file '%s'.\n", filename_dsw
.c_str() );
72 _generate_wine_dsw ( m_dswFile
);
77 printf ( "Could not create file '%s'.\n", filename_sln
.c_str() );
80 _generate_sln ( m_slnFile
);
88 void MSVCBackend::ProcessModules()
90 for(size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++)
92 Module
&module
= *ProjectNode
.modules
[i
];
94 module
.guid
= _gen_guid();
95 this->_generate_dsp ( module
);
96 this->_generate_vcproj ( module
);
99 /*for(size_t k = 0; k < module.non_if_data.files.size(); k++)
101 File &file = *module.non_if_data.files[k];
103 ProcessFile(file.name);
108 static bool FileExists(string
&filename
)
110 ifstream
file(filename
.c_str());
119 void MSVCBackend::ProcessFile(string
&filepath
)
121 // Remove the .\ at the start of the filenames
122 if ( filepath
[0] == '.' && strchr ( "/\\", filepath
[1] ) )
123 filepath
.erase(0, 2);
125 if(!FileExists(filepath
))
129 for(size_t i
= 0; i
< filepath
.length(); i
++)
131 if(filepath
[i
] == '\\')
135 // Remove the filename from the path
138 size_t pos
= filepath
.rfind(string("/"), filepath
.length() - 1);
140 if(pos
!= string::npos
)
143 folder
.erase(pos
, folder
.length() - pos
);
147 fileUnit
.filename
= filepath
;
148 fileUnit
.folder
= folder
;
150 m_fileUnits
.push_back(fileUnit
);
158 bool MSVCBackend::CheckFolderAdded(string
&folder
)
160 for(size_t i
= 0; i
< m_folders
.size(); i
++)
162 if(m_folders
[i
] == folder
)
169 void MSVCBackend::AddFolders(string
&folder
)
171 // Check if this folder was already added. true if it was, false otherwise.
172 if(CheckFolderAdded(folder
))
175 m_folders
.push_back(folder
);
177 size_t pos
= folder
.rfind(string("/"), folder
.length() - 1);
179 if(pos
== string::npos
)
182 folder
.erase(pos
, folder
.length() - pos
);
186 void MSVCBackend::OutputFolders()
189 m_devFile
<< "Folders=";
191 for(size_t i
= 0; i
< m_folders
.size(); i
++)
196 m_devFile
<< m_folders
[i
];
202 MSVCBackend::DspFileName ( const Module
& module
) const
205 ReplaceExtension ( module
.GetPath(), ".dsp" )
210 MSVCBackend::VcprojFileName ( const Module
& module
) const
213 ReplaceExtension ( module
.GetPath(), ".vcproj" )