Skip to content

Commit

Permalink
[ProjMgr/BuildMgr] Add ldcflag and ldcxxflag support
Browse files Browse the repository at this point in the history
Signed-off-by: yvesll <[email protected]>
  • Loading branch information
yvesll authored Nov 8, 2022
1 parent 2ae4ca8 commit 37ff330
Show file tree
Hide file tree
Showing 34 changed files with 188 additions and 17 deletions.
28 changes: 28 additions & 0 deletions libs/rtemodel/include/CprjFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@ class CprjTargetElement : public RteItem
*/
const std::string &GetLdFlags(const std::string &compiler) const;

/**
* @brief determine build flags specific to C object linker for the given toolchain
* @param compiler given toolchain
* @return build flags specific to linker
*/
const std::string& GetLdCFlags(const std::string& compiler) const;

/**
* @brief determine build flags specific to Cpp object linker for the given toolchain
* @param compiler given toolchain
* @return build flags specific to linker
*/
const std::string& GetLdCxxFlags(const std::string& compiler) const;

/**
* @brief setter for target build flags depending on language tag and compiler
* @param tag tag specific to language, e.g. "cflags", "cxxflags"
Expand Down Expand Up @@ -251,6 +265,20 @@ class CprjTargetElement : public RteItem
*/
void SetLdFlags(const std::string &flags, const std::string &compiler);

/**
* @brief setter for build flags specific to C Object linker and given toolchain
* @param flags string containing build flags
* @param compiler given toolchain
*/
void SetLdCFlags(const std::string &flags, const std::string &compiler);

/**
* @brief setter for build flags specific to Cpp Object linker and given toolchain
* @param flags string containing build flags
* @param compiler given toolchain
*/
void SetLdCxxFlags(const std::string &flags, const std::string &compiler);

protected:
RteDevice* ResolveDevice(RteModel* targetModel);
void CollectEffectiveProperties(const std::string& procName);
Expand Down
16 changes: 16 additions & 0 deletions libs/rtemodel/src/CprjFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ const string &CprjTargetElement::GetLdFlags(const string &compiler) const {
return GetTargetBuildFlags("ldflags", compiler);
}

const string &CprjTargetElement::GetLdCFlags(const string &compiler) const {
return GetTargetBuildFlags("ldcflags", compiler);
}

const string &CprjTargetElement::GetLdCxxFlags(const string &compiler) const {
return GetTargetBuildFlags("ldcxxflags", compiler);
}

void CprjTargetElement::SetTargetBuildFlags(const string &tag, const string &compiler, const string &value) {
// if attribute does not exist, it'll be created and set with value
// if attribute exists and value is not empty attribute is set with value
Expand Down Expand Up @@ -325,6 +333,14 @@ void CprjTargetElement::SetLdFlags(const string &flags, const string &compiler)
SetTargetBuildFlags("ldflags", compiler, flags);
}

void CprjTargetElement::SetLdCFlags(const string &flags, const string &compiler) {
SetTargetBuildFlags("ldcflags", compiler, flags);
}

void CprjTargetElement::SetLdCxxFlags(const string &flags, const string &compiler) {
SetTargetBuildFlags("ldcxxflags", compiler, flags);
}

///////////////////////////////////////////////
CprjFile::CprjFile(RteItem* parent) :
RtePackage(parent),
Expand Down
28 changes: 23 additions & 5 deletions libs/rtemodel/test/src/RteModelTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ TEST_F(RteModelPrjTest, LoadCprjCompDep) {
#define CFLAGS "-xc -std=c99 --target=arm-arm-none-eabi -mcpu=cortex-m3"
#define CXXFLAGS "-cxx"
#define LDFLAGS "--cpu Cortex-M3"
#define LDCFLAGS "-lm"
#define LDCXXFLAGS "-lstdc++"
#define ASFLAGS "--pd \"__MICROLIB SETA 1\" --xref -g"
#define ARFLAGS "-arflag"

Expand Down Expand Up @@ -440,12 +442,16 @@ TEST_F(RteModelPrjTest, GetTargetBuildFlags)
string cflags = getflags("cflags");
string cxxflags = getflags("cxxflags");
string ldflags = getflags("ldflags");
string ldcflags = getflags("ldcflags");
string ldcxxflags = getflags("ldcxxflags");
string asflags = getflags("asflags");
string arflags = getflags("arflags");
EXPECT_TRUE(arflags.compare(te->GetArFlags(toolchain)) == 0);
EXPECT_TRUE(cflags.compare(te->GetCFlags(toolchain)) == 0);
EXPECT_TRUE(cxxflags.compare(te->GetCxxFlags(toolchain)) == 0);
EXPECT_TRUE(ldflags.compare(te->GetLdFlags(toolchain)) == 0);
EXPECT_TRUE(ldcflags.compare(te->GetLdCFlags(toolchain)) == 0);
EXPECT_TRUE(ldcxxflags.compare(te->GetLdCxxFlags(toolchain)) == 0);
EXPECT_TRUE(asflags.compare(te->GetAsFlags(toolchain)) == 0);
}

Expand Down Expand Up @@ -481,25 +487,33 @@ TEST_F(RteModelPrjTest, SetTargetBuildFlags)
te->SetCFlags(RteUtils::EMPTY_STRING, toolchain);
te->SetCxxFlags(RteUtils::EMPTY_STRING, toolchain);
te->SetLdFlags(RteUtils::EMPTY_STRING, toolchain);
te->SetLdCFlags(RteUtils::EMPTY_STRING, toolchain);
te->SetLdCxxFlags(RteUtils::EMPTY_STRING, toolchain);
te->SetAsFlags(RteUtils::EMPTY_STRING, toolchain);
te->SetArFlags(RteUtils::EMPTY_STRING, toolchain);

CheckAttributeRemoved("cflags");
CheckAttributeRemoved("cxxflags");
CheckAttributeRemoved("ldflags");
CheckAttributeRemoved("ldcflags");
CheckAttributeRemoved("ldcxxflags");
CheckAttributeRemoved("asflags");
CheckAttributeRemoved("arflags");

// test setter functions with all attributes set
te->SetCFlags(CFLAGS, toolchain);
te->SetCxxFlags(CXXFLAGS, toolchain);
te->SetLdFlags(LDFLAGS, toolchain);
te->SetLdCFlags(LDCFLAGS, toolchain);
te->SetLdCxxFlags(LDCXXFLAGS, toolchain);
te->SetAsFlags(ASFLAGS, toolchain);
te->SetArFlags(ARFLAGS, toolchain);

EXPECT_TRUE(te->GetCFlags(toolchain).compare(CFLAGS) == 0);
EXPECT_TRUE(te->GetCxxFlags(toolchain).compare(CXXFLAGS) == 0);
EXPECT_TRUE(te->GetLdFlags(toolchain).compare(LDFLAGS) == 0);
EXPECT_TRUE(te->GetLdCFlags(toolchain).compare(LDCFLAGS) == 0);
EXPECT_TRUE(te->GetLdCxxFlags(toolchain).compare(LDCXXFLAGS) == 0);
EXPECT_TRUE(te->GetAsFlags(toolchain).compare(ASFLAGS) == 0);
EXPECT_TRUE(te->GetArFlags(toolchain).compare(ARFLAGS) == 0);
}
Expand Down Expand Up @@ -529,18 +543,22 @@ TEST_F(RteModelPrjTest, UpdateCprjFile)
rteKernel.SaveActiveCprjFile();
const std::unordered_map<string, string> nothingChanged;
const std::unordered_map<string, string> changedFlags = {
{ "<ldflags", LDFLAGS },
{ "<cflags", CFLAGS },
{ "<asflags", ASFLAGS },
{ "<cxxflags", CXXFLAGS },
{ "<arflags", ARFLAGS }
{ "<ldflags", LDFLAGS },
{ "<ldcflags", LDCFLAGS },
{ "<ldcxxflags", LDCXXFLAGS },
{ "<cflags", CFLAGS },
{ "<asflags", ASFLAGS },
{ "<cxxflags", CXXFLAGS },
{ "<arflags", ARFLAGS }
};
const string newFile = cprjFile->GetPackageFileName();
const string refFile = RteModelTestConfig::PROJECTS_DIR + "/RteTestM3/RteTestM3.cprj";
compareFile(newFile, refFile, nothingChanged, toolchain); // expected: nothing changed
te->SetCFlags(CFLAGS, toolchain);
te->SetCxxFlags(CXXFLAGS, toolchain);
te->SetLdFlags(LDFLAGS, toolchain);
te->SetLdCFlags(LDCFLAGS, toolchain);
te->SetLdCxxFlags(LDCXXFLAGS, toolchain);
te->SetAsFlags(ASFLAGS, toolchain);
te->SetArFlags(ARFLAGS, toolchain);
rteKernel.SaveActiveCprjFile();
Expand Down
1 change: 1 addition & 0 deletions test/projects/RteTestM3/RteTestM3.cprj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<target Bname="RteTest Dummy board" Bvendor="Keil" Bversion="1.2.3" Ddsp="NO_DSP" Dendian="Little-endian" Dfpu="NO_FPU" Dmve="NO_MVE" Dname="RteTest_ARMCM3" Dsecure="Non-secure" Dtz="NO_TZ" Dvendor="ARM:82">
<output intdir="./" name="RteTestM3" outdir="./" type="exe"/>
<ldflags add="--callgraph --info sizes --info summarysizes --info totals --info unused --info veneers --load_addr_map_info --map --strict --summary_stderr --symbols --xref" compiler="AC6" file="./RTE/Device/RteTest_ARMCM3/ARMCM3_ac6.sct"/>
<ldcxxflags add="-lsupc++" compiler="AC6"/>
<cflags add="-Oz -ffunction-sections -fno-rtti -fshort-enums -fshort-wchar -funsigned-char -gdwarf-3 -std=c99 -xc" compiler="AC6"/>
<asflags compiler="AC6" use="armasm"/>
</target>
Expand Down
18 changes: 18 additions & 0 deletions tools/buildmgr/cbuild/include/CbuildModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ class CbuildModel {
return m_targetLdFlags;
}

/**
* @brief get C linker flags used for constructing the linker command line
* @return list of C linker flags
*/
const std::vector<std::string> &GetTargetLdCFlags() const {
return m_targetLdCFlags;
}

/**
* @brief get C++ linker flags used for constructing the linker command line
* @return list of C++ linker flags
*/
const std::vector<std::string> &GetTargetLdCxxFlags() const {
return m_targetLdCxxFlags;
}

/**
* @brief get optimize option
* @return optimize option
Expand Down Expand Up @@ -481,6 +497,8 @@ class CbuildModel {
std::vector<std::string> m_targetCxxFlags;
std::vector<std::string> m_targetAsFlags;
std::vector<std::string> m_targetLdFlags;
std::vector<std::string> m_targetLdCFlags;
std::vector<std::string> m_targetLdCxxFlags;
std::vector<std::string> m_targetIncludePaths;
std::vector<std::string> m_targetDefines;
std::map<std::string, std::vector<std::string>> m_includePaths;
Expand Down
14 changes: 14 additions & 0 deletions tools/buildmgr/cbuild/src/CbuildModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,8 @@ bool CbuildModel::EvalFlags() {
if (!use.empty()) m_Asm.insert(pair<string, bool>("", use == "armasm" || use == "gas"));
}
const RteItem* ldflags = CbuildUtils::GetItemByTagAndAttribute(target->GetChildren(), "ldflags", "compiler", m_compiler);
const RteItem* ldcflags = CbuildUtils::GetItemByTagAndAttribute(target->GetChildren(), "ldcflags", "compiler", m_compiler);
const RteItem* ldcxxflags = CbuildUtils::GetItemByTagAndAttribute(target->GetChildren(), "ldcxxflags", "compiler", m_compiler);
if (ldflags != NULL) {
m_targetLdFlags = SplitArgs(ldflags->GetAttribute("add"));
m_linkerScript = ldflags->GetAttribute("file");
Expand All @@ -1056,6 +1058,14 @@ bool CbuildModel::EvalFlags() {
}
}
}
if (ldcflags != NULL)
{
m_targetLdCFlags = SplitArgs(ldcflags->GetAttribute("add"));
}
if (ldcxxflags != NULL)
{
m_targetLdCxxFlags = SplitArgs(ldcxxflags->GetAttribute("add"));
}
}

// RTE group flags
Expand Down Expand Up @@ -1288,6 +1298,8 @@ bool CbuildModel::EvalAccessSequence() {
InsertVectorPointers(fields, m_targetCxxFlags);
InsertVectorPointers(fields, m_targetAsFlags);
InsertVectorPointers(fields, m_targetLdFlags);
InsertVectorPointers(fields, m_targetLdCFlags);
InsertVectorPointers(fields, m_targetLdCxxFlags);

// iterate over every field and evaluate access sequences
for (auto& item : fields) {
Expand Down Expand Up @@ -1380,6 +1392,8 @@ bool CbuildModel::EvalAccessSequence() {
RteUtils::RemoveVectorDuplicates<string>(m_targetCxxFlags);
RteUtils::RemoveVectorDuplicates<string>(m_targetAsFlags);
RteUtils::RemoveVectorDuplicates<string>(m_targetLdFlags);
RteUtils::RemoveVectorDuplicates<string>(m_targetLdCFlags);
RteUtils::RemoveVectorDuplicates<string>(m_targetLdCxxFlags);

return true;
}
Expand Down
6 changes: 5 additions & 1 deletion tools/buildmgr/cbuildgen/config/CPRJ.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,12 @@
<xs:choice maxOccurs="unbounded">
<!-- Build options -->
<xs:element name="output" type="OutputType" />
<!-- Linker command-line -->
<!-- C/C++ Linker command-line -->
<xs:element name="ldflags" type="LinkerFlagsType" />
<!-- C Linker command-line -->
<xs:element name="ldcflags" type="LinkerFlagsType" />
<!-- C++ linker command-line -->
<xs:element name="ldcxxflags" type="LinkerFlagsType" />
<!-- C-Compiler command-line -->
<xs:element name="cflags" type="ToolOptionType" />
<!-- C++ Compiler command-line -->
Expand Down
2 changes: 2 additions & 0 deletions tools/buildmgr/cbuildgen/include/BuildSystemGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class BuildSystemGenerator {
std::string m_cxxMscGlobal;
std::string m_asMscGlobal;
std::string m_linkerMscGlobal;
std::string m_linkerCMscGlobal;
std::string m_linkerCxxMscGlobal;
std::string m_linkerScript;
std::string m_toolchain;
std::string m_toolchainConfig;
Expand Down
2 changes: 2 additions & 0 deletions tools/buildmgr/cbuildgen/src/BuildSystemGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ bool BuildSystemGenerator::Collect(const string& inputFile, const CbuildModel *m
m_cxxMscGlobal = GetString(model->GetTargetCxxFlags());
m_asMscGlobal = GetString(model->GetTargetAsFlags());
m_linkerMscGlobal = GetString(model->GetTargetLdFlags());
m_linkerCMscGlobal = GetString(model->GetTargetLdCFlags());
m_linkerCxxMscGlobal = GetString(model->GetTargetLdCxxFlags());

MergeVecStr(model->GetTargetDefines(), m_definesList);
MergeVecStrNorm(model->GetTargetIncludePaths(), m_incPathsList);
Expand Down
12 changes: 11 additions & 1 deletion tools/buildmgr/cbuildgen/src/CMakeListsGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ bool CMakeListsGenerator::GenBuildCMakeLists(void) {
if (!m_asMscGlobal.empty()) cmakelists << EOL << "set(AS_FLAGS_GLOBAL \"" << CbuildUtils::EscapeQuotes(m_asMscGlobal) << "\")";
if (!m_ccMscGlobal.empty()) cmakelists << EOL << "set(CC_FLAGS_GLOBAL \"" << CbuildUtils::EscapeQuotes(m_ccMscGlobal) << "\")";
if (!m_cxxMscGlobal.empty()) cmakelists << EOL << "set(CXX_FLAGS_GLOBAL \"" << CbuildUtils::EscapeQuotes(m_cxxMscGlobal) << "\")";
if (!m_linkerMscGlobal.empty()) cmakelists << EOL << "set(LD_FLAGS_GLOBAL \"" << CbuildUtils::EscapeQuotes(m_linkerMscGlobal) << "\")";
// LINK, LINK-C and LINK-CPP flags
if (!(m_linkerMscGlobal.empty() && m_linkerCMscGlobal.empty() && m_linkerCxxMscGlobal.empty())) {
string separator = "";
if (!m_linkerMscGlobal.empty()) separator = " ";
if(m_cxxFilesList.empty()) {
if (!m_linkerCMscGlobal.empty()) m_linkerMscGlobal += separator + m_linkerCMscGlobal;
} else {
if (!m_linkerCxxMscGlobal.empty()) m_linkerMscGlobal += separator + m_linkerCxxMscGlobal;
}
cmakelists << EOL << "set(LD_FLAGS_GLOBAL \"" << CbuildUtils::EscapeQuotes(m_linkerMscGlobal) << "\")";
}
if (!m_linkerScript.empty()) cmakelists << EOL << "set(LD_SCRIPT \"" << m_linkerScript << "\")";

cmakelists << EOL << EOL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

<target Ddsp="NO_DSP" Dendian="Little-endian" Dfpu="NO_FPU" Dmve="NO_MVE" Dname="ARMCM3" Dsecure="Non-secure" Dtz="NO_TZ" Dvendor="ARM:82">
<output name="Build_GCC" type="exe"/>
<ldflags add="--entry=Reset_Handler --specs=nosys.specs -mcpu=cortex-m3 -mthumb" compiler="GCC" file="./RTE/Device/ARMCM3/gcc_arm.ld"/>
<ldflags compiler="GCC" file="./RTE/Device/ARMCM3/gcc_arm.ld"/>
<ldcflags add="--entry=Reset_Handler --specs=nosys.specs -mcpu=cortex-m3 -mthumb" compiler="GCC"/>
<ldcxxflags add="-will-not-be-used" compiler="GCC"/>
<cflags add="-O -Wall -gdwarf-2 -mapcs-frame -mthumb" compiler="GCC"/>
<asflags add="-Wa,--gdwarf-2 -mthumb" compiler="GCC"/>
</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

<target Ddsp="NO_DSP" Dendian="Little-endian" Dfpu="NO_FPU" Dmve="NO_MVE" Dname="ARMCM3" Dsecure="Non-secure" Dtz="NO_TZ" Dvendor="ARM:82">
<output name="Build_G++" type="exe"/>
<ldflags add="--entry=Reset_Handler --specs=nosys.specs -lstdc++ -mcpu=cortex-m3 -mthumb" compiler="GCC" file="./RTE/Device/ARMCM3/gcc_arm.ld"/>
<ldflags compiler="GCC" file="./RTE/Device/ARMCM3/gcc_arm.ld"/>
<ldcflags add="-will-not-be-used" compiler="GCC"/>
<ldcxxflags add="--entry=Reset_Handler --specs=nosys.specs -lstdc++ -mcpu=cortex-m3 -mthumb" compiler="GCC"/>
<cflags add="-O3 -Wall -gdwarf-2 -mapcs-frame -mthumb" compiler="GCC"/>
<cxxflags add="-O3 -Wall -gdwarf-2 -mapcs-frame -mthumb" compiler="GCC"/>
<asflags add="-Wa,--gdwarf-2 -mthumb" compiler="GCC"/>
Expand Down
3 changes: 2 additions & 1 deletion tools/buildmgr/test/testinput/Examples/GCC/Flags/Target.cprj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

<target Ddsp="NO_DSP" Dendian="Little-endian" Dfpu="NO_FPU" Dmve="NO_MVE" Dname="ARMCM3" Dsecure="Non-secure" Dtz="NO_TZ" Dvendor="ARM:82">
<output name="Flags" type="exe"/>
<ldflags add="--entry=Reset_Handler --specs=nosys.specs -mcpu=cortex-m3 -mthumb" compiler="GCC" file="./RTE/Device/ARMCM3/gcc_arm.ld"/>
<ldflags add="--entry=Reset_Handler --specs=nosys.specs -mcpu=cortex-m3" compiler="GCC" file="./RTE/Device/ARMCM3/gcc_arm.ld"/>
<ldcflags add="-mthumb" compiler="GCC"/>
<cflags add="-Og -Wall -gdwarf-2 -mapcs-frame -mthumb" compiler="GCC"/>
<asflags compiler="GCC"/>
<defines>DEF_TARGET_CC;DEF_RTE_Components=\"RTE_Components.h\"</defines>
Expand Down
4 changes: 4 additions & 0 deletions tools/projmgr/include/ProjMgrParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct TypeFilter {
* options for c++ compiler,
* options for c and c++ compiler,
* options for linker,
* options for linker c flags,
* options for linker c++ flags,
* options for archiver
*/
struct MiscItem {
Expand All @@ -50,6 +52,8 @@ struct MiscItem {
std::vector<std::string> cpp;
std::vector<std::string> c_cpp;
std::vector<std::string> link;
std::vector<std::string> link_c;
std::vector<std::string> link_cpp;
std::vector<std::string> lib;
};

Expand Down
2 changes: 2 additions & 0 deletions tools/projmgr/include/ProjMgrYamlParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ static constexpr const char* YAML_MISC_C_CPP = "C-CPP";
static constexpr const char* YAML_MISC_C_STAR = "C*";
static constexpr const char* YAML_MISC_LIB = "Lib";
static constexpr const char* YAML_MISC_LINK = "Link";
static constexpr const char* YAML_MISC_LINK_C = "Link-C";
static constexpr const char* YAML_MISC_LINK_CPP = "Link-CPP";
static constexpr const char* YAML_NOTFORTYPE = "not-for-type";
static constexpr const char* YAML_OPTIMIZE = "optimize";
static constexpr const char* YAML_OUTPUTTYPE = "output-type";
Expand Down
2 changes: 2 additions & 0 deletions tools/projmgr/schemas/common.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@
"C-CPP": { "$ref": "#/definitions/ArrayOfStrings", "description": "List of C & CPP flags" },
"ASM": { "$ref": "#/definitions/ArrayOfStrings", "description": "List of ASM flags" },
"Link": { "$ref": "#/definitions/ArrayOfStrings", "description": "List of Linker flags" },
"Link-C": { "$ref": "#/definitions/ArrayOfStrings", "description": "List of Linker flags for pure C project" },
"Link-CPP": { "$ref": "#/definitions/ArrayOfStrings", "description": "List of Linker flags for project with C++ files" },
"Lib": { "$ref": "#/definitions/ArrayOfStrings", "description": "List of Library Manager or Archiver flags" }
},
"additionalProperties": false
Expand Down
2 changes: 2 additions & 0 deletions tools/projmgr/src/ProjMgrGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ void ProjMgrGenerator::GenerateCprjMisc(XMLTreeElement* element, const MiscItem&
{"cflags", misc.c},
{"cxxflags", misc.cpp},
{"ldflags", misc.link},
{"ldcflags", misc.link_c},
{"ldcxxflags", misc.link_cpp},
{"arflags", misc.lib}
};
for (const auto& flags : FLAGS_MATRIX) {
Expand Down
Loading

0 comments on commit 37ff330

Please sign in to comment.