Skip to content

Commit 4c9e531

Browse files
committed
Handle files with conditional excludes that can be handled by VS.
1 parent 8c5528f commit 4c9e531

File tree

3 files changed

+99
-11
lines changed

3 files changed

+99
-11
lines changed

include/projectGenerator.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,23 @@ class ProjectGenerator
3131
private:
3232
using StaticList = vector<string>;
3333
using UnknownList = map<string, StaticList>;
34+
struct ConfigConds
35+
{
36+
bool isStatic = false;
37+
bool isShared = false;
38+
bool is32 = false;
39+
bool is64 = false;
40+
};
41+
using ConditionalList = map<string, ConfigConds>;
3442
ifstream m_inputFile;
3543
string m_inLine;
3644
StaticList m_includes;
3745
StaticList m_includesCPP;
3846
StaticList m_includesC;
3947
StaticList m_includesASM;
48+
ConditionalList m_includesConditionalCPP;
49+
ConditionalList m_includesConditionalC;
50+
ConditionalList m_includesConditionalASM;
4051
StaticList m_includesH;
4152
StaticList m_includesRC;
4253
StaticList m_includesCU;
@@ -299,7 +310,14 @@ class ProjectGenerator
299310

300311
bool checkProjectFiles();
301312

302-
bool createReplaceFiles(const StaticList& replaceIncludes, StaticList& existingIncludes);
313+
/**
314+
* Builds '_wrap' files to wrap source files in a conditional compilation statement.
315+
* @param replaceIncludes The list of files to scan.
316+
* @param [in,out] existingIncludes The list of existing processed files.
317+
* @param [in,out] conditionalIncludes The list of existing conditional files.
318+
*/
319+
bool createReplaceFiles(
320+
const StaticList& replaceIncludes, StaticList& existingIncludes, ConditionalList& conditionalIncludes);
303321

304322
bool findProjectFiles(const StaticList& includes, StaticList& includesC, StaticList& includesCPP,
305323
StaticList& includesASM, StaticList& includesH, StaticList& includesRC, StaticList& includesCU) const;

source/projectGenerator.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ void ProjectGenerator::outputProjectCleanup()
422422
m_includesCPP.clear();
423423
m_includesC.clear();
424424
m_includesASM.clear();
425+
m_includesConditionalCPP.clear();
426+
m_includesConditionalC.clear();
427+
m_includesConditionalASM.clear();
425428
m_includesH.clear();
426429
m_includesRC.clear();
427430
m_includesCU.clear();
@@ -914,9 +917,9 @@ void ProjectGenerator::outputSourceFileType(StaticList& fileList, const string&
914917
closed = true;
915918
typeFilesTemp += excludeConfigPlatform;
916919
if (bit32Only) {
917-
typeFilesTemp += "Win32";
918-
} else if (bit64Only) {
919920
typeFilesTemp += "x64";
921+
} else {
922+
typeFilesTemp += "Win32";
920923
}
921924
typeFilesTemp += excludeConfigEnd;
922925
}
@@ -1004,14 +1007,41 @@ void ProjectGenerator::outputSourceFiles(string& projectTemplate, string& filter
10041007
outputError("Assembly files found in project but assembly is disabled");
10051008
}
10061009
}
1010+
if (!m_includesConditionalASM.empty()) {
1011+
if (m_configHelper.isASMEnabled()) {
1012+
StaticList fileList;
1013+
for (auto& i : m_includesConditionalASM) {
1014+
fileList.clear();
1015+
fileList.emplace_back(i.first);
1016+
outputSourceFileType(fileList, (m_configHelper.m_useNASM) ? "NASM" : "YASM", "Source", projectTemplate,
1017+
filterTemplate, foundObjects, foundFilters, false, i.second.isStatic, i.second.isShared,
1018+
i.second.is32, i.second.is64);
1019+
}
1020+
} else {
1021+
outputError("Assembly files found in project but assembly is disabled");
1022+
}
1023+
}
10071024

10081025
// Output C files
10091026
outputSourceFileType(
10101027
m_includesC, "ClCompile", "Source", projectTemplate, filterTemplate, foundObjects, foundFilters, true);
1028+
StaticList fileList;
1029+
for (auto& i : m_includesConditionalC) {
1030+
fileList.clear();
1031+
fileList.emplace_back(i.first);
1032+
outputSourceFileType(fileList, "ClCompile", "Source", projectTemplate, filterTemplate, foundObjects,
1033+
foundFilters, true, i.second.isStatic, i.second.isShared, i.second.is32, i.second.is64);
1034+
}
10111035

10121036
// Output C++ files
10131037
outputSourceFileType(
10141038
m_includesCPP, "ClCompile", "Source", projectTemplate, filterTemplate, foundObjects, foundFilters, true);
1039+
for (auto& i : m_includesConditionalCPP) {
1040+
fileList.clear();
1041+
fileList.emplace_back(i.first);
1042+
outputSourceFileType(fileList, "ClCompile", "Source", projectTemplate, filterTemplate, foundObjects,
1043+
foundFilters, true, i.second.isStatic, i.second.isShared, i.second.is32, i.second.is64);
1044+
}
10151045

10161046
// Output CUDA files
10171047
if (!m_includesCU.empty()) {

source/projectGenerator_files.cpp

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)