@@ -119,35 +119,36 @@ bool ProjectGenerator::checkProjectFiles()
119119 return false ;
120120 }
121121 // Need to create local files for any replace objects
122- if (!createReplaceFiles (replaceCIncludes, m_includesC)) {
122+ if (!createReplaceFiles (replaceCIncludes, m_includesC, m_includesConditionalC )) {
123123 return false ;
124124 }
125- if (!createReplaceFiles (replaceCPPIncludes, m_includesCPP)) {
125+ if (!createReplaceFiles (replaceCPPIncludes, m_includesCPP, m_includesConditionalCPP )) {
126126 return false ;
127127 }
128- if (!createReplaceFiles (replaceASMIncludes, m_includesASM)) {
128+ if (!createReplaceFiles (replaceASMIncludes, m_includesASM, m_includesConditionalASM )) {
129129 return false ;
130130 }
131131 return true ;
132132}
133133
134- bool ProjectGenerator::createReplaceFiles (const StaticList& replaceIncludes, StaticList& existingIncludes)
134+ bool ProjectGenerator::createReplaceFiles (
135+ const StaticList& replaceIncludes, StaticList& existingIncludes, ConditionalList& conditionalIncludes)
135136{
136137 for (const auto & replaceInclude : replaceIncludes) {
137- // Check hasnt already been included as a fixed object
138+ // Check hasn't already been included as a fixed object
138139 if (find (existingIncludes.begin (), existingIncludes.end (), replaceInclude) != existingIncludes.end ()) {
139140 // skip this item
140141 continue ;
141142 }
142143 // Convert file to format required to search ReplaceIncludes
143144 const uint extPos = replaceInclude.rfind (' .' );
144- const uint cutPos = replaceInclude.rfind (' /' ) + 1 ;
145+ const uint cutPos = replaceInclude.find (' /' , 5 ) + 1 ;
145146 string filename = replaceInclude.substr (cutPos, extPos - cutPos);
146147 string extension = replaceInclude.substr (extPos);
147148 string outFile = m_configHelper.m_solutionDirectory + m_projectName + " /" + filename + " _wrap" + extension;
148149 string newOutFile;
149150 m_configHelper.makeFileProjectRelative (outFile, newOutFile);
150- // Check hasnt already been included as a wrapped object
151+ // Check hasn't already been included as a wrapped object
151152 if (find (existingIncludes.begin (), existingIncludes.end (), newOutFile) != existingIncludes.end ()) {
152153 // skip this item
153154 outputInfo (newOutFile);
@@ -167,26 +168,65 @@ bool ProjectGenerator::createReplaceFiles(const StaticList& replaceIncludes, Sta
167168 }
168169 // Get the files dynamic config requirement
169170 string idents;
171+ bool isStatic = false ;
172+ bool isShared = false ;
173+ bool is32 = false ;
174+ bool is64 = false ;
175+ bool hasOther = false ;
170176 for (auto include = m_replaceIncludes[origName].begin (); include < m_replaceIncludes[origName].end ();
171177 ++include) {
172178 idents += *include;
173179 if ((include + 1 ) < m_replaceIncludes[origName].end ()) {
174180 idents += " || " ;
175181 }
182+ if (*include == " ARCH_X86_32" || *include == " !ARCH_X86_64" ) {
183+ is32 = true ;
184+ } else if (*include == " ARCH_X86_64" || *include == " !ARCH_X86_32" ) {
185+ is64 = true ;
186+ } else if (*include == " CONFIG_SHARED" || *include == " !CONFIG_STATIC" ) {
187+ isShared = true ;
188+ } else if (*include == " CONFIG_STATIC" || *include == " !CONFIG_SHARED" ) {
189+ isStatic = true ;
190+ } else {
191+ hasOther = true ;
192+ }
193+ }
194+ // Check for config requirement that can be handled by VS (i.e. static/shared|32/64bit)
195+ if ((isShared || isStatic || is32 || is64) && !hasOther) {
196+ // Check if already a conditional file
197+ auto j = conditionalIncludes.find (replaceInclude);
198+ if (j != conditionalIncludes.end ()) {
199+ if (j->second .isStatic != isStatic || j->second .isShared != isShared || j->second .is32 != is32 ||
200+ j->second .is64 != is64) {
201+ outputError (" Duplicate conditional files found with different conditions (" + replaceInclude + " )" );
202+ // TODO: Remove and make wrapped
203+ return false ;
204+ }
205+ }
206+ conditionalIncludes.emplace (replaceInclude, ConfigConds{isStatic, isShared, is32, is64});
207+ continue ;
176208 }
177209 // Create new file to wrap input object
178210 string prettyFile = " ../" + replaceInclude;
179211 string newFile = getCopywriteHeader (filename + extension + " file wrapper for " + m_projectName);
180212 newFile += " \n \
181213\n \
182214#include \" config.h\"\n " ;
183- if (m_configHelper.m_configComponentsStart > 0 ) {
215+ if (m_configHelper.m_configComponentsStart > 0 && extension != " .asm " ) {
184216 newFile += " #include \" config_components.h\"\n " ;
185217 }
186218 newFile += " #if " + idents + " \n \
187219# include \" " +
188220 prettyFile + " \"\n \
189221#endif" ;
222+ // Check if assembly file
223+ if (extension == " .asm" ) {
224+ replace (newFile.begin (), newFile.end (), ' #' , ' %' );
225+ findAndReplace (newFile, " .h" , " .asm" );
226+ findAndReplace (newFile, " /**" , " ;" );
227+ findAndReplace (newFile, " */" , " ;" );
228+ findAndReplace (newFile, " *" , " ;" );
229+ }
190230 // Write output project
191231 if (!makeDirectory (m_configHelper.m_solutionDirectory + m_projectName)) {
192232 outputError (" Failed creating local " + m_projectName + " directory" );
0 commit comments