Bring resource compilation up to date and fix extension handling

This commit is contained in:
Dimitry Sibiryakov 2023-06-14 17:36:44 +02:00
parent 45ebbce139
commit 4a3afbb144
6 changed files with 39 additions and 12 deletions

View File

@ -824,7 +824,7 @@ void CGNUWindowsResourceCompiler::Reset(const CPlatform::OS_Type OS)
m_Alias = "gnu_windres_compiler";
m_Description = "GNU Windows Resource Compiler";
m_MakeVariable = "WINDRES";
m_CommandTemplate = "$rescomp -i $file -J rc -o $resource_output -O coff $includes";
m_CommandTemplate = "$rescomp $res_options -i $file -o $resource_output -O coff $res_includes";
m_SourceExtensions.Clear()<<"rc"<<"res"<<"coff";
m_TargetExtension = "o";
if (CPlatform::OS_Windows==OS) m_Program = "windres.exe";

View File

@ -660,6 +660,7 @@ static const CString TPL_RES_COMPILER = "$rescomp";
static const CString TPL_LINKER = "$linker";
static const CString TPL_LIB_LINKER = "$lib_linker";
static const CString TPL_OPTIONS = "$options";
static const CString TPL_RES_OPTIONS = "$res_options";
static const CString TPL_RES_INCLUDES = "$res_includes";
static const CString TPL_INCLUDES = "$includes";
static const CString TPL_FILE = "$file";

View File

@ -215,6 +215,10 @@ void CCodeBlocksProject::Read(const TiXmlElement *ProjectRoot)
if (0!=option)
{
char *value = 0;
if ((value = (char *)option->Attribute("option")))
{
m_ResourceCompilerOptions.Insert(value);
}
if ((value = (char *)option->Attribute("directory")))
{
m_ResourceCompilerDirectories.Insert(value);
@ -406,6 +410,16 @@ void CCodeBlocksProject::Show(void)
{
std::cout<<"Directory #"<<(i+1)<<": "<<m_CompilerDirectories[i].GetString()<<std::endl;
}
std::cout<<"Resource compiler options: "<<m_ResourceCompilerOptions.GetCount()<<std::endl;
for (int i = 0, n = m_ResourceCompilerOptions.GetCount(); i < n; i++)
{
std::cout<<"Option #"<<(i+1)<<": "<<m_ResourceCompilerOptions[i].GetString()<<std::endl;
}
std::cout<<"Resource compiler directories: "<<m_ResourceCompilerDirectories.GetCount()<<std::endl;
for (int i = 0, n = m_ResourceCompilerDirectories.GetCount(); i < n; i++)
{
std::cout<<"Directory #"<<(i+1)<<": "<<m_ResourceCompilerDirectories[i].GetString()<<std::endl;
}
std::cout<<"Linker options: "<<m_LinkerOptions.GetCount()<<std::endl;
for (int i = 0, n = m_LinkerOptions.GetCount(); i < n; i++)
{
@ -774,8 +788,18 @@ bool CCodeBlocksProject::GenerateMakefile
line = JoinStr(line,m_CompilerOptions[i],' ');
}
m_Makefile.AddMacro(STR_CFLAGS+tc_suffix,CGlobalVariable::Convert(line,Config.MacroVariableCase()),section);
line.Clear();
for (int i = 0; i < m_ResourceCompilerOptions.GetCount(); i++)
{
line = JoinStr(line,m_ResourceCompilerOptions[i],' ');
}
m_Makefile.AddMacro(STR_RCFLAGS+tc_suffix,CGlobalVariable::Convert(line,Config.MacroVariableCase()),section);
line.Clear();
for (int i = 0; i < m_ResourceCompilerDirectories.GetCount(); i++)
{
line = JoinStr(line,tc->IncludeDirSwitch()+pl->ProtectPath(pl->Pd(m_ResourceCompilerDirectories[i]),Config.QuotePathMode()),' ');
}
m_Makefile.AddMacro(STR_RESINC+tc_suffix,"",section);
//m_Makefile.AddMacro("RCFLAGS","",section);//not supported by CB build system
line.Clear();
for (int i = 0; i < m_LinkerDirectories.GetCount(); i++)
{
@ -1016,7 +1040,6 @@ bool CCodeBlocksProject::GenerateMakefile
clean_target_directories.Insert(pl->ProtectPath(pl->Pd(binary_path),Config.QuotePathMode()));
}
}
CString object_extension = "x";
//
cmd_args.SetStringVariable(TPL_LIB_DIRS,"$("+target->Name(STR_LIBDIR+"_",Config.MacroVariableCase())+")");
cmd_args.SetStringVariable(TPL_LIBS,"$("+target->Name(STR_LIB+"_",Config.MacroVariableCase())+")");
@ -1038,7 +1061,6 @@ bool CCodeBlocksProject::GenerateMakefile
line = linker->MakeCommand(cmd_args);
//
rule_target_out.Commands().Insert(line);
object_extension = linker->ObjectExtension();
}
else
{
@ -1063,7 +1085,6 @@ bool CCodeBlocksProject::GenerateMakefile
line = linker->MakeCommand(cmd_args);
//
rule_target_out.Commands().Insert(line);
object_extension = linker->ObjectExtension();
}
else
{
@ -1093,7 +1114,6 @@ bool CCodeBlocksProject::GenerateMakefile
line = linker->MakeCommand(cmd_args);
//
rule_target_out.Commands().Insert(line);
object_extension = linker->ObjectExtension();
}
else
{
@ -1130,7 +1150,6 @@ bool CCodeBlocksProject::GenerateMakefile
line = linker->MakeCommand(cmd_args);
//
rule_target_out.Commands().Insert(line);
object_extension = linker->ObjectExtension();
}
else
{
@ -1142,7 +1161,6 @@ bool CCodeBlocksProject::GenerateMakefile
}
case CBuildTarget::ttCommands: break;
}
if (!object_extension.IsEmpty()) object_extension = "."+object_extension;
// build units
CCompiler default_compler;
for (size_t i = 0; i < m_UnitIndex.size(); i++)
@ -1206,11 +1224,11 @@ bool CCodeBlocksProject::GenerateMakefile
CString object_name;
if (m_ExtendedObjectNames)
{
object_name = pl->Pd(unit->FileName()+object_extension);
object_name = pl->Pd(unit->FileName()+'.'+compiler->TargetExtension());
}
else
{
object_name = pl->Pd(ChangeFileExt(unit->FileName(),object_extension));
object_name = pl->Pd(ChangeFileExt(unit->FileName(),'.'+compiler->TargetExtension()));
}
// quick fix for relative paths outside project tree
object_name = FindReplaceStr(object_name,"..","__");
@ -1261,6 +1279,7 @@ bool CCodeBlocksProject::GenerateMakefile
cmd_args.SetStringVariable(TPL_FILE,unit_name);
cmd_args.SetStringVariable(TPL_OBJECT,object_prefix_name);
cmd_args.SetStringVariable(TPL_RES_COMPILER,"$("+DecorateVariableName(compiler_var+tc_suffix,Config.MacroVariableCase())+")");
cmd_args.SetStringVariable(TPL_RES_OPTIONS,"$("+target->Name(STR_RCFLAGS+"_",Config.MacroVariableCase())+")");
cmd_args.SetStringVariable(TPL_RES_INCLUDES,"$("+target->Name(STR_RESINC+"_",Config.MacroVariableCase())+")");
cmd_args.SetStringVariable(TPL_RES_OUTPUT,object_prefix_name);
line = compiler->MakeCommand(cmd_args);

View File

@ -51,6 +51,7 @@ class CCodeBlocksProject
CStringList m_LinkerOptions;
CStringList m_LinkerLibraries;
CStringList m_LinkerDirectories;
CStringList m_ResourceCompilerOptions;
CStringList m_ResourceCompilerDirectories;
CStringList m_BeforeBuildCommands;
CStringList m_AfterBuildCommands;

View File

@ -221,7 +221,8 @@ CString CBuildTarget::RCFlags(void)
CString CBuildTarget::RCFlags(const CString& ProjectRCFlags)
{
return MakeOptions(m_ResourceCompilerOptionsRelation,ProjectRCFlags,RCFlags());
// C::B uses common option relations for compiler and resources compiler
return MakeOptions(m_CompilerOptionsRelation,ProjectRCFlags,RCFlags());
}
CString CBuildTarget::LdFlags(void)
@ -455,6 +456,10 @@ void CBuildTarget::Read(const TiXmlElement *TargetRoot)
if (0!=option)
{
char *value = 0;
if ((value = (char *)option->Attribute("option")))
{
m_ResourceCompilerOptions.Insert(value);
}
if ((value = (char *)option->Attribute("directory")))
{
m_ResourceCompilerDirectories.Insert(value);
@ -594,6 +599,7 @@ void CBuildTarget::Show(void)
<<OptionsRelationName(m_LibraryDirectoriesRelation).GetCString()<<std::endl;
ShowStringList("Compiler options","Option",m_CompilerOptions);
ShowStringList("Compiler directories","Directory",m_CompilerDirectories);
ShowStringList("Resource compiler options","Option",m_ResourceCompilerOptions);
ShowStringList("Resource compiler directories","Directory",m_ResourceCompilerDirectories);
ShowStringList("Linker options","Option",m_LinkerOptions);
ShowStringList("Linker directories","Directory",m_LinkerDirectories);

View File

@ -74,7 +74,7 @@ class CBuildTarget
OptionsRelation m_IncludeDirectoriesRelation;
OptionsRelation m_ResourceIncludeDirectoriesRelation;
OptionsRelation m_LibraryDirectoriesRelation;
OptionsRelation m_ResourceCompilerOptionsRelation;
// OptionsRelation m_ResourceCompilerOptionsRelation;
//
int m_NameCase;
CString m_UCName;