Skip to content

Commit f90eb9b

Browse files
committed
Properly handle '--projdir', '--rootdir' and '--prefix' command line options.
Fixes #43
1 parent 4c292fd commit f90eb9b

File tree

3 files changed

+109
-22
lines changed

3 files changed

+109
-22
lines changed

include/projectGenerator.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,19 @@ class ProjectGenerator
277277
bool findProjectFiles(const StaticList& includes, StaticList& includesC, StaticList& includesCPP,
278278
StaticList& includesASM, StaticList& includesH, StaticList& includesCU) const;
279279

280+
/**
281+
* Replace occurrences of known tags in string.
282+
* @param [in,out] projectTemplate The project file in string form.
283+
* @param winrt Whether this is a winrt project file.
284+
*/
280285
void outputTemplateTags(string& projectTemplate, bool winrt = false) const;
281286

287+
/**
288+
* Replace occurrences of features in a props file.
289+
* @param [in,out] projectTemplate The project file in string form.
290+
*/
291+
void outputPropsTags(string& projectTemplate) const;
292+
282293
void outputSourceFileType(StaticList& fileList, const string& type, const string& filterType,
283294
string& projectTemplate, string& filterTemplate, StaticList& foundObjects, set<string>& foundFilters,
284295
bool checkExisting, bool staticOnly = false, bool sharedOnly = false) const;

source/projectGenerator.cpp

Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,27 @@
3838

3939
bool ProjectGenerator::passAllMake()
4040
{
41-
// Copy the required header files to output directory
42-
if (!copyResourceFile(TEMPLATE_PROPS_ID, m_configHelper.m_solutionDirectory + "smp_deps.props", true)) {
41+
// Copy the required props files to output directory
42+
string propsFile, propsFileWinRT;
43+
if (!loadFromResourceFile(TEMPLATE_PROPS_ID, propsFile) ||
44+
!loadFromResourceFile(TEMPLATE_PROPS_WINRT_ID, propsFileWinRT)) {
45+
return false;
46+
}
47+
48+
// Update template tags
49+
outputPropsTags(propsFile);
50+
outputPropsTags(propsFileWinRT);
51+
52+
// Write output props
53+
string outPropsFile = m_configHelper.m_solutionDirectory + "smp_deps.props";
54+
if (!writeToFile(outPropsFile, propsFile, true)) {
4355
outputError("Failed writing to output location. Make sure you have the appropriate user permissions.");
4456
return false;
4557
}
46-
copyResourceFile(TEMPLATE_PROPS_WINRT_ID, m_configHelper.m_solutionDirectory + "smp_winrt_deps.props", true);
58+
outPropsFile = m_configHelper.m_solutionDirectory + "smp_winrt_deps.props";
59+
if (!writeToFile(outPropsFile, propsFileWinRT, true)) {
60+
return false;
61+
}
4762

4863
// Loop through each library make file
4964
vector<string> libraries;
@@ -727,6 +742,34 @@ void ProjectGenerator::outputTemplateTags(string& projectTemplate, const bool wi
727742
findPos = projectTemplate.find(shortSearchTag, findPos + 1);
728743
}
729744

745+
// Change all occurrences of template_outdir with configured output directory
746+
string outDir = m_configHelper.m_outDirectory;
747+
replace(outDir.begin(), outDir.end(), '/', '\\');
748+
if (outDir.at(0) == '.') {
749+
outDir = "$(ProjectDir)" + outDir; // Make any relative paths based on project dir
750+
}
751+
const string outSearchTag = "template_outdir";
752+
findPos = projectTemplate.find(outSearchTag);
753+
while (findPos != string::npos) {
754+
// Replace
755+
projectTemplate.replace(findPos, outSearchTag.length(), outDir);
756+
// Get next
757+
findPos = projectTemplate.find(outSearchTag, findPos + 1);
758+
}
759+
760+
// Change all occurrences of template_rootdir with configured output directory
761+
string rootDir = m_configHelper.m_rootDirectory;
762+
m_configHelper.makeFileProjectRelative(rootDir, rootDir);
763+
replace(rootDir.begin(), rootDir.end(), '/', '\\');
764+
const string rootSearchTag = "template_rootdir";
765+
findPos = projectTemplate.find(rootSearchTag);
766+
while (findPos != string::npos) {
767+
// Replace
768+
projectTemplate.replace(findPos, rootSearchTag.length(), rootDir);
769+
// Get next
770+
findPos = projectTemplate.find(rootSearchTag, findPos + 1);
771+
}
772+
730773
// Set the project key
731774
string projectName = m_projectName;
732775
if (winrt) {
@@ -742,6 +785,26 @@ void ProjectGenerator::outputTemplateTags(string& projectTemplate, const bool wi
742785
}
743786
}
744787

788+
void ProjectGenerator::outputPropsTags(string& projectTemplate) const
789+
{
790+
// Since we reuse props file from SMP they do not contain standard tags and instead we must do a string replace
791+
792+
// Change all occurrences of template_outdir with configured output directory
793+
string outDir = m_configHelper.m_outDirectory;
794+
replace(outDir.begin(), outDir.end(), '/', '\\');
795+
if (outDir.at(0) == '.') {
796+
outDir = "$(ProjectDir)" + outDir; // Make any relative paths based on project dir
797+
}
798+
const string outSearchTag = R"($(ProjectDir)..\..\..\msvc\)";
799+
uint findPos = projectTemplate.find(outSearchTag);
800+
while (findPos != string::npos) {
801+
// Replace
802+
projectTemplate.replace(findPos, outSearchTag.length(), outDir);
803+
// Get next
804+
findPos = projectTemplate.find(outSearchTag, findPos + 1);
805+
}
806+
}
807+
745808
void ProjectGenerator::outputSourceFileType(StaticList& fileList, const string& type, const string& filterType,
746809
string& projectTemplate, string& filterTemplate, StaticList& foundObjects, set<string>& foundFilters,
747810
bool checkExisting, bool staticOnly, bool sharedOnly) const
@@ -1233,20 +1296,23 @@ mkdir \"$(OutDir)\"\\include\\";
12331296
transform(licenseName.begin(), licenseName.end(), licenseName.begin(), tolower);
12341297
const string licenseEnd = " \"$(OutDir)\"\\licenses\\" + licenseName + ".txt";
12351298
const string prebuild = "\r\n <PreBuildEvent>\r\n\
1236-
<Command>if exist ..\\config.h (\r\n\
1237-
del ..\\config.h\r\n\
1299+
<Command>if exist template_rootdirconfig.h (\r\n\
1300+
del template_rootdirconfig.h\r\n\
1301+
)\r\n\
1302+
if exist template_rootdirversion.h (\r\n\
1303+
del template_rootdirversion.h\r\n\
12381304
)\r\n\
1239-
if exist ..\\version.h (\r\n\
1240-
del ..\\version.h\r\n\
1305+
if exist template_rootdirconfig.asm (\r\n\
1306+
del template_rootdirconfig.asm\r\n\
12411307
)\r\n\
1242-
if exist ..\\config.asm (\r\n\
1243-
del ..\\config.asm\r\n\
1308+
if exist template_rootdirconfig_components.h (\r\n\
1309+
del template_rootdirconfig_components.h\r\n\
12441310
)\r\n\
1245-
if exist ..\\libavutil\\avconfig.h (\r\n\
1246-
del ..\\libavutil\\avconfig.h\r\n\
1311+
if exist template_rootdirlibavutil\\avconfig.h (\r\n\
1312+
del template_rootdirlibavutil\\avconfig.h\r\n\
12471313
)\r\n\
1248-
if exist ..\\libavutil\\ffversion.h (\r\n\
1249-
del ..\\libavutil\\ffversion.h\r\n\
1314+
if exist template_rootdirlibavutil\\ffversion.h (\r\n\
1315+
del template_rootdirlibavutil\\ffversion.h\r\n\
12501316
)";
12511317
const string prebuildDir = "\r\nif exist \"$(OutDir)\"\\include\\" + m_projectName + " (\r\n\
12521318
rd /s /q \"$(OutDir)\"\\include\\" +
@@ -1258,16 +1324,16 @@ cd $(ProjectDir)\r\n\
12581324
// Get the correct license file
12591325
string licenseFile;
12601326
if (m_configHelper.isConfigOptionEnabled("nonfree")) {
1261-
licenseFile = "..\\COPYING.GPLv3"; // Technically this has no license as it is unredistributable
1262-
// but we get the closest thing for now
1327+
licenseFile = "template_rootdirCOPYING.GPLv3"; // Technically this has no license as it is unredistributable
1328+
// but we get the closest thing for now
12631329
} else if (m_configHelper.isConfigOptionEnabled("gplv3")) {
1264-
licenseFile = "..\\COPYING.GPLv3";
1330+
licenseFile = "template_rootdirCOPYING.GPLv3";
12651331
} else if (m_configHelper.isConfigOptionEnabled("lgplv3")) {
1266-
licenseFile = "..\\COPYING.LGPLv3";
1332+
licenseFile = "template_rootdirCOPYING.LGPLv3";
12671333
} else if (m_configHelper.isConfigOptionEnabled("gpl")) {
1268-
licenseFile = "..\\COPYING.GPLv2";
1334+
licenseFile = "template_rootdirCOPYING.GPLv2";
12691335
} else {
1270-
licenseFile = "..\\COPYING.LGPLv2.1";
1336+
licenseFile = "template_rootdirCOPYING.LGPLv2.1";
12711337
}
12721338
// Generate the pre build and post build string
12731339
string additional;
@@ -1423,7 +1489,7 @@ void ProjectGenerator::outputASMTools(string& projectTemplate) const
14231489
if (m_configHelper.isASMEnabled() && (m_includesASM.size() > 0)) {
14241490
string definesASM = "\r\n\
14251491
<NASM>\r\n\
1426-
<IncludePaths>$(ProjectDir);$(ProjectDir)\\..\\;$(ProjectDir)\\..\\template_in\\x86;%(IncludePaths)</IncludePaths>\r\n\
1492+
<IncludePaths>$(ProjectDir);$(ProjectDir)\\template_rootdir;$(ProjectDir)\\template_rootdir\\$(ProjectName)\\x86;%(IncludePaths)</IncludePaths>\r\n\
14271493
<PreIncludeFiles>config.asm;%(PreIncludeFiles)</PreIncludeFiles>\r\n\
14281494
<GenerateDebugInformation>false</GenerateDebugInformation>\r\n\
14291495
</NASM>";

source/projectGenerator_build.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,18 @@ void ProjectGenerator::buildDependencyValues(StaticList& includeDirs, StaticList
245245
{
246246
// Add hard dependencies
247247
string dep;
248-
if (findFile(m_configHelper.m_rootDirectory + "compat/atomics/win32/stdatomic.h", dep)) {
249-
includeDirs.push_back("$(ProjectDir)/../compat/atomics/win32/");
248+
string atomicCompatFile = m_configHelper.m_rootDirectory + "compat/atomics/win32/stdatomic.h";
249+
if (findFile(atomicCompatFile, dep)) {
250+
m_configHelper.makeFileProjectRelative(atomicCompatFile, atomicCompatFile);
251+
uint pos = atomicCompatFile.rfind('/'); // Get path only
252+
atomicCompatFile = atomicCompatFile.substr(0, ++pos);
253+
includeDirs.push_back("$(ProjectDir)/" + atomicCompatFile);
254+
}
255+
256+
// Add root directory
257+
if (m_configHelper.m_rootDirectory != "./" && m_configHelper.m_rootDirectory != "../") {
258+
m_configHelper.makeFileProjectRelative(m_configHelper.m_rootDirectory, dep);
259+
includeDirs.push_back("$(ProjectDir)/" + dep);
250260
}
251261

252262
// Determine only those dependencies that are valid for current project

0 commit comments

Comments
 (0)