@@ -64,63 +64,73 @@ bool ProjectGenerator::outputProjectDCE(const StaticList& includeDirs)
6464 if (!loadFromFile (*itFile, file)) {
6565 return false ;
6666 }
67- bool requiresPreProcess = false ;
68- outputProjectDCEFindFunctions (file, *itFile, foundDCEUsage, requiresPreProcess, nonDCEUsage);
69- if (requiresPreProcess) {
70- preProcFiles.push_back (*itFile);
71- }
7267
7368 // Check if this file includes additional source files
7469 vector<string> extensions = {" .c\" " , " .h\" " };
7570 for (auto & ext : extensions) {
7671 uint findPos = file.find (ext);
7772 while (findPos != string::npos) {
7873 // Check if this is an include
79- uint findPos2 = file.rfind (" #include \" " , findPos);
80- if ((findPos2 != string::npos) && (findPos - findPos2 < 50 )) {
81- // Get the name of the file
82- findPos2 += 10 ;
83- findPos += 2 ;
84- string templateFile = file.substr (findPos2, findPos - findPos2);
85- // Split filename from any directory structures
86- replace (templateFile.begin (), templateFile.end (), ' \\ ' , ' /' );
87- uint projName = templateFile.rfind (m_projectName + ' /' );
88- if (projName != string::npos) {
89- templateFile = templateFile.substr (projName + 1 + m_projectName.length ());
90- }
91- if (templateFile.length () >= 3 ) {
92- string found;
93- string back = templateFile;
94- templateFile = m_projectDir + back;
95- if (!findFile (templateFile, found)) {
96- templateFile = (m_configHelper.m_rootDirectory .length () > 0 ) ?
97- m_configHelper.m_rootDirectory + ' /' + back :
98- back;
74+ uint findPos3 = file.rfind (" #include" , findPos);
75+ if (findPos3 != string::npos) {
76+ uint findPos2 = file.find_first_not_of (g_whiteSpace, findPos3 + 8 );
77+ if (findPos2 != string::npos && file[findPos2] == ' \" ' &&
78+ file.find_first_of (" \" ." , findPos2 + 2 ) == findPos) {
79+ // Get the name of the file
80+ ++findPos2;
81+ findPos += 2 ;
82+ string templateFile = file.substr (findPos2, findPos - findPos2);
83+ // Split filename from any directory structures
84+ replace (templateFile.begin (), templateFile.end (), ' \\ ' , ' /' );
85+ uint projName = templateFile.rfind (m_projectName + ' /' );
86+ if (projName != string::npos) {
87+ templateFile = templateFile.substr (projName + 1 + m_projectName.length ());
88+ }
89+ if (templateFile.length () >= 3 ) {
90+ string found;
91+ string back = templateFile;
92+ templateFile = m_projectDir + back;
9993 if (!findFile (templateFile, found)) {
100- templateFile = m_configHelper.m_solutionDirectory + m_projectName + ' /' + back;
94+ templateFile = (m_configHelper.m_rootDirectory .length () > 0 ) ?
95+ m_configHelper.m_rootDirectory + ' /' + back :
96+ back;
10197 if (!findFile (templateFile, found)) {
102- templateFile = itFile-> substr ( 0 , itFile-> rfind ( ' / ' ) + 1 ) + back;
98+ templateFile = m_configHelper. m_solutionDirectory + m_projectName + ' / ' + back;
10399 if (!findFile (templateFile, found)) {
104- templateFile = m_configHelper. m_solutionDirectory + back;
100+ templateFile = itFile-> substr ( 0 , itFile-> rfind ( ' / ' ) + 1 ) + back;
105101 if (!findFile (templateFile, found)) {
106- // Fail only if this is a c file
107- if (ext == extensions[0 ]) {
108- outputError (" Failed to find included file " + back);
109- return false ;
102+ templateFile = m_configHelper.m_solutionDirectory + back;
103+ if (!findFile (templateFile, found)) {
104+ // Fail only if this is a c file
105+ if (ext == extensions[0 ]) {
106+ outputError (" Failed to find included file " + back);
107+ return false ;
108+ }
109+ templateFile = " " ;
110110 }
111- templateFile = " " ;
112111 }
113112 }
114113 }
115114 }
116- }
117- // Add the file to the list
118- if (templateFile.length () >= 3 ) {
119- if (templateFile.find (" ./" ) == 0 ) {
120- templateFile = templateFile.substr (2 );
121- }
122- if (find (searchFiles.begin (), searchFiles.end (), templateFile) == searchFiles.end ()) {
123- searchFiles.push_back (templateFile);
115+ // Add the file to the list
116+ if (templateFile.length () >= 3 ) {
117+ if (templateFile.find (" ./" ) == 0 ) {
118+ templateFile = templateFile.substr (2 );
119+ }
120+ if (ext == extensions[0 ]) {
121+ // If it's a source file then insert directly into existing file so we can find any
122+ // nested DCE between files
123+ string file2;
124+ if (!loadFromFile (templateFile, file2, false , false )) {
125+ outputError (" Failed to open included file " + templateFile);
126+ return false ;
127+ }
128+ file.replace (findPos3, findPos + 1 , file2);
129+ findPos += file2.length ();
130+ } else if (find (searchFiles.begin (), searchFiles.end (), templateFile) ==
131+ searchFiles.end ()) {
132+ searchFiles.push_back (templateFile);
133+ }
124134 }
125135 }
126136 }
@@ -129,6 +139,12 @@ bool ProjectGenerator::outputProjectDCE(const StaticList& includeDirs)
129139 findPos = file.find (ext, findPos + 1 );
130140 }
131141 }
142+
143+ bool requiresPreProcess = false ;
144+ outputProjectDCEFindFunctions (file, *itFile, foundDCEUsage, requiresPreProcess, nonDCEUsage);
145+ if (requiresPreProcess) {
146+ preProcFiles.push_back (*itFile);
147+ }
132148 }
133149#if !FORCEALLDCE
134150 // Get a list of all files in current project directory (including subdirectories)
0 commit comments