diff --git a/reactos/tools/rbuild/backend/msvc/msvcmaker.cpp b/reactos/tools/rbuild/backend/msvc/msvcmaker.cpp index 4597f5f5282..99dc2ecafdb 100644 --- a/reactos/tools/rbuild/backend/msvc/msvcmaker.cpp +++ b/reactos/tools/rbuild/backend/msvc/msvcmaker.cpp @@ -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 c_srcs, source_files, resource_files, includes, libraries; + vector c_srcs, source_files, header_files, resource_files, includes, libraries; StringSet common_defines; vector 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 header_files; + //vector header_files; // TODO FIXME - wine hack? /*if (module.name !~ /^wine(?:_unicode|build|runtests|test)?$/ && diff --git a/reactos/tools/rbuild/backend/msvc/vcprojmaker.cpp b/reactos/tools/rbuild/backend/msvc/vcprojmaker.cpp index 931dbab36f3..159a1df2b96 100644 --- a/reactos/tools/rbuild/backend/msvc/vcprojmaker.cpp +++ b/reactos/tools/rbuild/backend/msvc/vcprojmaker.cpp @@ -41,6 +41,14 @@ typedef set 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 source_files, resource_files, includes, includes_ros, libraries; + vector source_files, resource_files, header_files, includes, includes_ros, libraries; StringSet common_defines; vector 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 header_files; - string include_string; fprintf ( OUT, "\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\r\n" ); + + std::sort(source_files.begin(), source_files.end(), SortFilesAscending()); + vector last_folder; + vector 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\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\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\r\n", indent_tab.c_str(), split_path[ifolder].c_str() ); + } + + last_folder = split_path; + } + + fprintf ( OUT, "%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\r\n" ); - fprintf ( OUT, "\t\t\t\t\t\r\n" ); - fprintf ( OUT, "\t\t\t\t\r\n" ); + fprintf ( OUT, "%s\t\t\r\n", indent_tab.c_str() ); + fprintf ( OUT, "%s\t\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\r\n" ); - fprintf ( OUT, "\t\t\t\t\t\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 "$(OutDir)\\$(InputName).obj"\"\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 "$(OutDir)\\$(InputName).obj"\"\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 "$(InputPath)" %s /D__ASM__ | as -o "$(OutDir)\\$(InputName).obj"\"\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 "$(InputPath)" %s /D__ASM__ | as -o "$(OutDir)\\$(InputName).obj"\"\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\r\n" ); + fprintf ( OUT, "%s\t\r\n", indent_tab.c_str() ); } //} } - fprintf ( OUT, "\t\t\t\r\n" ); + fprintf ( OUT, "%s\r\n", indent_tab.c_str() ); } + + for ( size_t ifolder = last_folder.size(); ifolder > 0; ifolder-- ) + { + indent_tab.resize( ifolder + 3 ); + fprintf ( OUT, "%s\r\n", indent_tab.c_str() ); + } + fprintf ( OUT, "\t\t\r\n" ); // Header files