patch from Gregor Brunmar (gregor dot brunmar at home dot se)

* Added folder support for msvc+solution generation in rbuild
 * map up pch .h file as include file in vc project files.


svn path=/trunk/; revision=28571
This commit is contained in:
Magnus Olsen 2007-08-26 09:57:30 +00:00
parent 63872a8e79
commit 718e6afb4c
2 changed files with 93 additions and 28 deletions

View file

@ -83,7 +83,7 @@ MSVCBackend::_generate_dsp ( const Module& module )
// TODO FIXME - what's diff. betw. 'c_srcs' and 'source_files'?
string dsp_path = module.GetBasePath();
vector<string> c_srcs, source_files, resource_files, includes, libraries;
vector<string> c_srcs, source_files, header_files, resource_files, includes, libraries;
StringSet common_defines;
vector<const IfableData*> ifs_list;
ifs_list.push_back ( &module.project.non_if_data );
@ -108,6 +108,8 @@ MSVCBackend::_generate_dsp ( const Module& module )
source_files.push_back ( file );
if ( !stricmp ( Right(file,2).c_str(), ".c" ) )
c_srcs.push_back ( file );
if ( !stricmp ( Right(file,2).c_str(), ".h" ) )
header_files.push_back ( file );
if ( !stricmp ( Right(file,3).c_str(), ".rc" ) )
resource_files.push_back ( file );
}
@ -144,7 +146,7 @@ MSVCBackend::_generate_dsp ( const Module& module )
}
// TODO FIXME - we don't include header files in our build system
//my @header_files = @{module->{header_files}};
vector<string> header_files;
//vector<string> header_files;
// TODO FIXME - wine hack?
/*if (module.name !~ /^wine(?:_unicode|build|runtests|test)?$/ &&

View file

@ -41,6 +41,14 @@ typedef set<string> StringSet;
#undef OUT
#endif//OUT
struct SortFilesAscending
{
bool operator()(const string& rhs, const string& lhs)
{
return rhs < lhs;
}
};
MSVCConfiguration::MSVCConfiguration ( const OptimizationType optimization, const HeadersType headers, const std::string &name )
{
this->optimization = optimization;
@ -124,7 +132,7 @@ MSVCBackend::_generate_vcproj ( const Module& module )
bool include_idl = false;
string vcproj_path = module.GetBasePath();
vector<string> source_files, resource_files, includes, includes_ros, libraries;
vector<string> source_files, resource_files, header_files, includes, includes_ros, libraries;
StringSet common_defines;
vector<const IfableData*> ifs_list;
ifs_list.push_back ( &module.project.non_if_data );
@ -154,6 +162,8 @@ MSVCBackend::_generate_vcproj ( const Module& module )
if ( !stricmp ( Right(file,3).c_str(), ".rc" ) )
resource_files.push_back ( file );
else if ( !stricmp ( Right(file,2).c_str(), ".h" ) )
header_files.push_back ( file );
else
source_files.push_back ( file );
}
@ -211,8 +221,6 @@ MSVCBackend::_generate_vcproj ( const Module& module )
}
}
vector<string> header_files;
string include_string;
fprintf ( OUT, "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\r\n" );
@ -372,6 +380,11 @@ MSVCBackend::_generate_vcproj ( const Module& module )
if ( pos != string::npos )
pch_path.erase(0, pos+1);
fprintf ( OUT, "\t\t\t\tPrecompiledHeaderThrough=\"%s\"\r\n", pch_path.c_str() );
// Only include from the same module
pos = pch_path.find("../");
if (pos == string::npos && std::find(header_files.begin(), header_files.end(), pch_path) == header_files.end())
header_files.push_back(pch_path);
}
else
{
@ -583,11 +596,54 @@ MSVCBackend::_generate_vcproj ( const Module& module )
fprintf ( OUT, "\t\t<Filter\r\n" );
fprintf ( OUT, "\t\t\tName=\"Source Files\"\r\n" );
fprintf ( OUT, "\t\t\tFilter=\"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;S\">\r\n" );
std::sort(source_files.begin(), source_files.end(), SortFilesAscending());
vector<string> last_folder;
vector<string> split_path;
string indent_tab("\t\t\t");
for ( size_t isrcfile = 0; isrcfile < source_files.size(); isrcfile++ )
{
string source_file = DosSeparator(source_files[isrcfile]);
fprintf ( OUT, "\t\t\t<File\r\n" );
fprintf ( OUT, "\t\t\t\tRelativePath=\"%s\">\r\n", source_file.c_str() );
Path::Split(split_path, source_file, false);
size_t same_folder_index = 0;
for ( size_t ifolder = 0; ifolder < last_folder.size(); ifolder++ )
{
if ( ifolder < split_path.size() && last_folder[ifolder] == split_path[ifolder] )
++same_folder_index;
else
break;
}
if ( same_folder_index < split_path.size() )
{
if ( split_path.size() > last_folder.size() )
{
for ( size_t ifolder = last_folder.size(); ifolder < split_path.size(); ifolder++ )
indent_tab.push_back('\t');
}
else if ( split_path.size() < last_folder.size() )
{
indent_tab.resize( split_path.size() + 3 );
}
for ( size_t ifolder = last_folder.size(); ifolder > same_folder_index; ifolder-- )
{
fprintf ( OUT, "%s</Filter>\r\n", indent_tab.substr(0, indent_tab.size() - 1).c_str() );
}
for ( size_t ifolder = same_folder_index; ifolder < split_path.size(); ifolder++ )
{
fprintf ( OUT, "%s<Filter\r\n", indent_tab.substr(0, indent_tab.size() - 1).c_str() );
fprintf ( OUT, "%sName=\"%s\">\r\n", indent_tab.c_str(), split_path[ifolder].c_str() );
}
last_folder = split_path;
}
fprintf ( OUT, "%s<File\r\n", indent_tab.c_str() );
fprintf ( OUT, "%s\tRelativePath=\"%s\">\r\n", indent_tab.c_str(), source_file.c_str() );
for ( size_t iconfig = 0; iconfig < m_configurations.size(); iconfig++ )
{
@ -596,24 +652,24 @@ MSVCBackend::_generate_vcproj ( const Module& module )
if (( isrcfile == 0 ) && ( module.pch != NULL ))
{
/* little hack to speed up PCH */
fprintf ( OUT, "\t\t\t\t<FileConfiguration\r\n" );
fprintf ( OUT, "\t\t\t\t\tName=\"" );
fprintf ( OUT, "%s\t<FileConfiguration\r\n", indent_tab.c_str() );
fprintf ( OUT, "%s\t\tName=\"", indent_tab.c_str() );
fprintf ( OUT, config.name.c_str() );
fprintf ( OUT, "|Win32\">\r\n" );
fprintf ( OUT, "\t\t\t\t\t<Tool\r\n" );
fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCLCompilerTool\"\r\n" );
fprintf ( OUT, "\t\t\t\t\t\tUsePrecompiledHeader=\"1\"/>\r\n" );
fprintf ( OUT, "\t\t\t\t</FileConfiguration>\r\n" );
fprintf ( OUT, "%s\t\t<Tool\r\n", indent_tab.c_str() );
fprintf ( OUT, "%s\t\t\tName=\"VCCLCompilerTool\"\r\n", indent_tab.c_str() );
fprintf ( OUT, "%s\t\t\tUsePrecompiledHeader=\"1\"/>\r\n", indent_tab.c_str() );
fprintf ( OUT, "%s\t</FileConfiguration>\r\n", indent_tab.c_str() );
}
//if (configuration.VSProjectVersion < "8.00") {
if ((source_file.find(".idl") != string::npos) || ((source_file.find(".asm") != string::npos || tolower(source_file.at(source_file.size() - 1)) == 's')))
{
fprintf ( OUT, "\t\t\t\t<FileConfiguration\r\n" );
fprintf ( OUT, "\t\t\t\t\tName=\"" );
fprintf ( OUT, "%s\t<FileConfiguration\r\n", indent_tab.c_str() );
fprintf ( OUT, "%s\t\tName=\"", indent_tab.c_str() );
fprintf ( OUT, config.name.c_str() );
fprintf ( OUT, "|Win32\">\r\n" );
fprintf ( OUT, "\t\t\t\t\t<Tool\r\n" );
fprintf ( OUT, "%s\t\t<Tool\r\n", indent_tab.c_str() );
if (source_file.find(".idl") != string::npos)
{
string src = source_file.substr (0, source_file.find(".idl"));
@ -621,43 +677,50 @@ MSVCBackend::_generate_vcproj ( const Module& module )
if ( src.find (".\\") != string::npos )
src.erase (0, 2);
fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCustomBuildTool\"\r\n" );
fprintf ( OUT, "%s\t\t\tName=\"VCCustomBuildTool\"\r\n", indent_tab.c_str() );
if ( module.type == RpcClient )
{
fprintf ( OUT, "\t\t\t\t\t\tCommandLine=\"midl.exe /cstub %s_c.c /header %s_c.h /server none &quot;$(InputPath)&quot; /out &quot;$(IntDir)&quot;", src.c_str (), src.c_str () );
fprintf ( OUT, "%s\t\t\tCommandLine=\"midl.exe /cstub %s_c.c /header %s_c.h /server none &quot;$(InputPath)&quot; /out &quot;$(IntDir)&quot;", indent_tab.c_str(), src.c_str (), src.c_str () );
fprintf ( OUT, "&#x0D;&#x0A;");
fprintf ( OUT, "cl.exe /Od /D &quot;WIN32&quot; /D &quot;_DEBUG&quot; /D &quot;_WINDOWS&quot; /D &quot;_WIN32_WINNT=0x502&quot; /D &quot;_UNICODE&quot; /D &quot;UNICODE&quot; /Gm /EHsc /RTC1 /MDd /Fo&quot;$(IntDir)\\%s.obj&quot; /W3 /c /Wp64 /ZI /TC &quot;$(IntDir)\\%s_c.c&quot; /nologo /errorReport:prompt", src.c_str (), src.c_str () );
}
else
{
fprintf ( OUT, "\t\t\t\t\t\tCommandLine=\"midl.exe /sstub %s_s.c /header %s_s.h /client none &quot;$(InputPath)&quot; /out &quot;$(IntDir)&quot;", src.c_str (), src.c_str () );
fprintf ( OUT, "%s\t\t\tCommandLine=\"midl.exe /sstub %s_s.c /header %s_s.h /client none &quot;$(InputPath)&quot; /out &quot;$(IntDir)&quot;", indent_tab.c_str(), src.c_str (), src.c_str () );
fprintf ( OUT, "&#x0D;&#x0A;");
fprintf ( OUT, "cl.exe /Od /D &quot;WIN32&quot; /D &quot;_DEBUG&quot; /D &quot;_WINDOWS&quot; /D &quot;_WIN32_WINNT=0x502&quot; /D &quot;_UNICODE&quot; /D &quot;UNICODE&quot; /Gm /EHsc /RTC1 /MDd /Fo&quot;$(IntDir)\\%s.obj&quot; /W3 /c /Wp64 /ZI /TC &quot;$(IntDir)\\%s_s.c&quot; /nologo /errorReport:prompt", src.c_str (), src.c_str () );
}
fprintf ( OUT, "&#x0D;&#x0A;");
fprintf ( OUT, "lib.exe /OUT:&quot;$(OutDir)\\%s.lib&quot; &quot;$(IntDir)\\%s.obj&quot;&#x0D;&#x0A;\"\r\n", module.name.c_str (), src.c_str () );
fprintf ( OUT, "\t\t\t\t\t\tOutputs=\"$(IntDir)\\$(InputName).obj\"/>\r\n" );
fprintf ( OUT, "%s\t\t\tOutputs=\"$(IntDir)\\$(InputName).obj\"/>\r\n", indent_tab.c_str() );
}
else if ((source_file.find(".asm") != string::npos))
{
fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCustomBuildTool\"\r\n" );
fprintf ( OUT, "\t\t\t\t\t\tCommandLine=\"nasmw $(InputPath) -f coff -o &quot;$(OutDir)\\$(InputName).obj&quot;\"\r\n");
fprintf ( OUT, "\t\t\t\t\t\tOutputs=\"$(OutDir)\\$(InputName).obj\"/>\r\n" );
fprintf ( OUT, "%s\t\t\tName=\"VCCustomBuildTool\"\r\n", indent_tab.c_str() );
fprintf ( OUT, "%s\t\t\tCommandLine=\"nasmw $(InputPath) -f coff -o &quot;$(OutDir)\\$(InputName).obj&quot;\"\r\n", indent_tab.c_str() );
fprintf ( OUT, "%s\t\t\tOutputs=\"$(OutDir)\\$(InputName).obj\"/>\r\n", indent_tab.c_str() );
}
else if ((tolower(source_file.at(source_file.size() - 1)) == 's'))
{
fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCustomBuildTool\"\r\n" );
fprintf ( OUT, "\t\t\t\t\t\tCommandLine=\"cl /E &quot;$(InputPath)&quot; %s /D__ASM__ | as -o &quot;$(OutDir)\\$(InputName).obj&quot;\"\r\n",include_string.c_str() );
fprintf ( OUT, "\t\t\t\t\t\tOutputs=\"$(OutDir)\\$(InputName).obj\"/>\r\n" );
fprintf ( OUT, "%s\t\t\tName=\"VCCustomBuildTool\"\r\n", indent_tab.c_str() );
fprintf ( OUT, "%s\t\t\tCommandLine=\"cl /E &quot;$(InputPath)&quot; %s /D__ASM__ | as -o &quot;$(OutDir)\\$(InputName).obj&quot;\"\r\n", indent_tab.c_str(), include_string.c_str() );
fprintf ( OUT, "%s\t\t\tOutputs=\"$(OutDir)\\$(InputName).obj\"/>\r\n", indent_tab.c_str() );
}
fprintf ( OUT, "\t\t\t\t</FileConfiguration>\r\n" );
fprintf ( OUT, "%s\t</FileConfiguration>\r\n", indent_tab.c_str() );
}
//}
}
fprintf ( OUT, "\t\t\t</File>\r\n" );
fprintf ( OUT, "%s</File>\r\n", indent_tab.c_str() );
}
for ( size_t ifolder = last_folder.size(); ifolder > 0; ifolder-- )
{
indent_tab.resize( ifolder + 3 );
fprintf ( OUT, "%s</Filter>\r\n", indent_tab.c_str() );
}
fprintf ( OUT, "\t\t</Filter>\r\n" );
// Header files