3838
3939bool 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+
745808void 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\n if exist \" $(OutDir)\"\\ include\\ " + m_projectName + " (\r\n \
12521318rd /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>" ;
0 commit comments