summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Baksik <frodak17@gmail.com>2019-04-08 13:55:34 (GMT)
committerFred Baksik <frodak17@gmail.com>2019-04-11 17:15:50 (GMT)
commit39ee9718d9a56e7b8b15f63576f042415a2771f8 (patch)
tree3a63e90cd4ced8beaf7c41756bde12a071b3bb6d
parent8d3dad9a76591ae0426335d039b8aaacb95862cd (diff)
downloadCMake-39ee9718d9a56e7b8b15f63576f042415a2771f8.zip
CMake-39ee9718d9a56e7b8b15f63576f042415a2771f8.tar.gz
CMake-39ee9718d9a56e7b8b15f63576f042415a2771f8.tar.bz2
GHS: Support add_custom_target() command
-- add new project type that runs shell scripts in proper order
-rw-r--r--Source/cmGhsMultiGpj.cxx4
-rw-r--r--Source/cmGhsMultiGpj.h3
-rw-r--r--Source/cmGhsMultiTargetGenerator.cxx94
-rw-r--r--Source/cmGlobalGhsMultiGenerator.cxx150
-rw-r--r--Source/cmGlobalGhsMultiGenerator.h12
5 files changed, 184 insertions, 79 deletions
diff --git a/Source/cmGhsMultiGpj.cxx b/Source/cmGhsMultiGpj.cxx
index 8b69b51..da27971 100644
--- a/Source/cmGhsMultiGpj.cxx
+++ b/Source/cmGhsMultiGpj.cxx
@@ -9,7 +9,8 @@ static const char* GHS_TAG[] = { "[INTEGRITY Application]",
"[Project]",
"[Program]",
"[Reference]",
- "[Subproject]" };
+ "[Subproject]",
+ "[Custom Target]" };
const char* GhsMultiGpj::GetGpjTag(Types gpjType)
{
@@ -21,6 +22,7 @@ const char* GhsMultiGpj::GetGpjTag(Types gpjType)
case PROGRAM:
case REFERENCE:
case SUBPROJECT:
+ case CUSTOM_TARGET:
tag = GHS_TAG[gpjType];
break;
default:
diff --git a/Source/cmGhsMultiGpj.h b/Source/cmGhsMultiGpj.h
index 420eab1..e588150 100644
--- a/Source/cmGhsMultiGpj.h
+++ b/Source/cmGhsMultiGpj.h
@@ -16,7 +16,8 @@ public:
PROJECT,
PROGRAM,
REFERENCE,
- SUBPROJECT
+ SUBPROJECT,
+ CUSTOM_TARGET
};
static void WriteGpjTag(Types gpjType, std::ostream& fout);
diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx
index 9d0d195..725c4b4 100644
--- a/Source/cmGhsMultiTargetGenerator.cxx
+++ b/Source/cmGhsMultiTargetGenerator.cxx
@@ -90,10 +90,9 @@ void cmGhsMultiTargetGenerator::Generate()
return;
}
case cmStateEnums::UTILITY: {
- std::string msg = "add_custom_target(<name> ...) not supported: ";
- msg += this->Name;
- cmSystemTools::Message(msg);
- return;
+ this->TargetNameReal = this->GeneratorTarget->GetName();
+ this->TagType = GhsMultiGpj::CUSTOM_TARGET;
+ break;
}
default:
return;
@@ -124,13 +123,15 @@ void cmGhsMultiTargetGenerator::GenerateTarget()
const std::string language(
this->GeneratorTarget->GetLinkerLanguage(this->ConfigName));
- this->WriteTargetSpecifics(fout, this->ConfigName);
- this->SetCompilerFlags(this->ConfigName, language);
- this->WriteCompilerFlags(fout, this->ConfigName, language);
- this->WriteCompilerDefinitions(fout, this->ConfigName, language);
- this->WriteIncludes(fout, this->ConfigName, language);
- this->WriteTargetLinkLine(fout, this->ConfigName);
- this->WriteBuildEvents(fout);
+ if (this->TagType != GhsMultiGpj::CUSTOM_TARGET) {
+ this->WriteTargetSpecifics(fout, this->ConfigName);
+ this->SetCompilerFlags(this->ConfigName, language);
+ this->WriteCompilerFlags(fout, this->ConfigName, language);
+ this->WriteCompilerDefinitions(fout, this->ConfigName, language);
+ this->WriteIncludes(fout, this->ConfigName, language);
+ this->WriteTargetLinkLine(fout, this->ConfigName);
+ this->WriteBuildEvents(fout);
+ }
this->WriteSources(fout);
this->WriteReferences(fout);
fout.Close();
@@ -315,9 +316,11 @@ void cmGhsMultiTargetGenerator::WriteBuildEvents(std::ostream& fout)
fout, this->GeneratorTarget->GetPreBuildCommands(),
std::string("prebuild"), std::string("preexecShell"));
- this->WriteBuildEventsHelper(
- fout, this->GeneratorTarget->GetPreLinkCommands(), std::string("prelink"),
- std::string("preexecShell"));
+ if (this->TagType != GhsMultiGpj::CUSTOM_TARGET) {
+ this->WriteBuildEventsHelper(
+ fout, this->GeneratorTarget->GetPreLinkCommands(),
+ std::string("prelink"), std::string("preexecShell"));
+ }
this->WriteBuildEventsHelper(
fout, this->GeneratorTarget->GetPostBuildCommands(),
@@ -343,7 +346,12 @@ void cmGhsMultiTargetGenerator::WriteBuildEventsHelper(
f.SetCopyIfDifferent(true);
this->WriteCustomCommandsHelper(f, ccg);
f.Close();
- fout << " :" << cmd << "=\"" << fname << "\"" << std::endl;
+ if (this->TagType != GhsMultiGpj::CUSTOM_TARGET) {
+ fout << " :" << cmd << "=\"" << fname << "\"" << std::endl;
+ } else {
+ fout << fname << std::endl;
+ fout << " :outputName=\"" << fname << ".rule\"" << std::endl;
+ }
for (auto& byp : ccg.GetByproducts()) {
fout << " :extraOutputFile=\"" << byp << "\"" << std::endl;
}
@@ -499,6 +507,14 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj)
groupFilesList[i] = *n;
i += 1;
groupNames.erase(gn);
+ } else if (this->TagType == GhsMultiGpj::CUSTOM_TARGET &&
+ gn == "CMake Rules") {
+ /* make sure that rules folder always exists in case of custom targets
+ * that have no custom commands except for pre or post build events.
+ */
+ groupFilesList.resize(groupFilesList.size() + 1);
+ groupFilesList[i] = gn;
+ i += 1;
}
}
@@ -575,37 +591,46 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj)
if (sg != "CMake Rules") {
/* output rule for each source file */
for (const cmSourceFile* si : groupFiles[sg]) {
-
+ bool compile = true;
// Convert filename to native system
// WORKAROUND: GHS MULTI 6.1.4 and 6.1.6 are known to need backslash on
// windows when opening some files from the search window.
std::string fname(si->GetFullPath());
cmSystemTools::ConvertToOutputSlashes(fname);
- /* Comment out any custom command dependencies to prevent from
- * being considered part of the build.
+ /* For custom targets list any associated sources,
+ * comment out source code to prevent it from being
+ * compiled when processing this target.
+ * Otherwise, comment out any custom command (main) dependencies that
+ * are listed as source files to prevent them from being considered
+ * part of the build.
*/
std::string comment;
- if (si->GetCustomCommand()) {
+ if ((this->TagType == GhsMultiGpj::CUSTOM_TARGET &&
+ !si->GetLanguage().empty()) ||
+ si->GetCustomCommand()) {
comment = "{comment} ";
+ compile = false;
}
- *fout << comment << fname << std::endl;
- if ("ld" != si->GetExtension() && "int" != si->GetExtension() &&
- "bsp" != si->GetExtension()) {
- WriteObjectLangOverride(*fout, si);
- }
+ *fout << comment << fname << std::endl;
+ if (compile) {
+ if ("ld" != si->GetExtension() && "int" != si->GetExtension() &&
+ "bsp" != si->GetExtension()) {
+ WriteObjectLangOverride(*fout, si);
+ }
- this->WriteSourceProperty(*fout, si, "INCLUDE_DIRECTORIES", "-I");
- this->WriteSourceProperty(*fout, si, "COMPILE_DEFINITIONS", "-D");
- this->WriteSourceProperty(*fout, si, "COMPILE_OPTIONS", "");
+ this->WriteSourceProperty(*fout, si, "INCLUDE_DIRECTORIES", "-I");
+ this->WriteSourceProperty(*fout, si, "COMPILE_DEFINITIONS", "-D");
+ this->WriteSourceProperty(*fout, si, "COMPILE_OPTIONS", "");
- /* to avoid clutter in the gui only print out the objectName if it has
- * been renamed */
- std::string objectName = this->GeneratorTarget->GetObjectName(si);
- if (!objectName.empty() &&
- this->GeneratorTarget->HasExplicitObjectName(si)) {
- *fout << " -o " << objectName << std::endl;
+ /* to avoid clutter in the GUI only print out the objectName if it
+ * has been renamed */
+ std::string objectName = this->GeneratorTarget->GetObjectName(si);
+ if (!objectName.empty() &&
+ this->GeneratorTarget->HasExplicitObjectName(si)) {
+ *fout << " -o " << objectName << std::endl;
+ }
}
}
} else {
@@ -649,6 +674,9 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj)
this->WriteCustomCommandLine(*fout, fname, ccg);
}
}
+ if (this->TagType == GhsMultiGpj::CUSTOM_TARGET) {
+ this->WriteBuildEvents(*fout);
+ }
}
}
diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx
index a2138d1..2180770 100644
--- a/Source/cmGlobalGhsMultiGenerator.cxx
+++ b/Source/cmGlobalGhsMultiGenerator.cxx
@@ -308,8 +308,21 @@ void cmGlobalGhsMultiGenerator::WriteCustomRuleBOD(std::ostream& fout)
"}\n";
}
+void cmGlobalGhsMultiGenerator::WriteCustomTargetBOD(std::ostream& fout)
+{
+ fout << "FileTypes {\n"
+ " CmakeTarget {\n"
+ " name = \"Custom Target\"\n"
+ " action = \"&Execute\"\n"
+ " grepable = false\n"
+ " outputType = \"None\"\n"
+ " color = \"#800080\"\n"
+ " }\n"
+ "}\n";
+}
+
void cmGlobalGhsMultiGenerator::WriteTopLevelProject(
- std::ostream& fout, cmLocalGenerator* root,
+ std::ostream& fout, std::string& ename, cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators)
{
WriteFileHeader(fout);
@@ -342,13 +355,15 @@ void cmGlobalGhsMultiGenerator::WriteTopLevelProject(
fout << "\"" << this->OsDir << "\"" << std::endl;
}
- WriteSubProjects(fout, root, generators);
+ WriteSubProjects(fout, ename, root, generators);
}
void cmGlobalGhsMultiGenerator::WriteSubProjects(
- std::ostream& fout, cmLocalGenerator* root,
+ std::ostream& fout, std::string& ename, cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators)
{
+ this->ExcludedTargets.clear();
+
// Collect all targets under this root generator and the transitive
// closure of their dependencies.
TargetDependSet projectTargets;
@@ -356,50 +371,75 @@ void cmGlobalGhsMultiGenerator::WriteSubProjects(
this->GetTargetSets(projectTargets, originalTargets, root, generators);
OrderedTargetDependSet orderedProjectTargets(projectTargets, "");
- // write out all the sub-projects
+ // write out all the targets for ALL target
std::string rootBinaryDir = root->GetCurrentBinaryDirectory();
for (cmGeneratorTarget const* target : orderedProjectTargets) {
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
+ if (cmSystemTools::IsOn(target->GetProperty("EXCLUDE_FROM_ALL"))) {
+ this->ExcludedTargets.push_back(target);
+ continue;
+ }
+ this->WriteProjectLine(fout, target, root, rootBinaryDir);
+ }
+ if (!this->ExcludedTargets.empty()) {
+ fout << "{nobuild} " << ename << " [Project]" << std::endl;
+ }
+}
- const char* projName = target->GetProperty("GENERATOR_FILE_NAME");
- const char* projType = target->GetProperty("GENERATOR_FILE_NAME_EXT");
- if (projName && projType) {
- cmLocalGenerator* lg = target->GetLocalGenerator();
- std::string dir = lg->GetCurrentBinaryDirectory();
- dir = root->MaybeConvertToRelativePath(rootBinaryDir, dir);
- if (dir == ".") {
- dir.clear();
- } else {
- if (dir.back() != '/') {
- dir += "/";
- }
- }
+void cmGlobalGhsMultiGenerator::WriteExcludedProjects(
+ std::ostream& fout, cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators)
+{
+ // write out all the excluded targets
+ std::string rootBinaryDir = root->GetCurrentBinaryDirectory();
+ for (cmGeneratorTarget const* target : this->ExcludedTargets) {
+ if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ continue;
+ }
+ this->WriteProjectLine(fout, target, root, rootBinaryDir);
+ }
+ this->ExcludedTargets.clear();
+}
- if (cmSystemTools::IsOn(target->GetProperty("EXCLUDE_FROM_ALL"))) {
- fout << "{comment} ";
+void cmGlobalGhsMultiGenerator::WriteProjectLine(
+ std::ostream& fout, cmGeneratorTarget const* target, cmLocalGenerator* root,
+ std::string& rootBinaryDir)
+{
+ const char* projName = target->GetProperty("GENERATOR_FILE_NAME");
+ const char* projType = target->GetProperty("GENERATOR_FILE_NAME_EXT");
+ if (projName && projType) {
+ cmLocalGenerator* lg = target->GetLocalGenerator();
+ std::string dir = lg->GetCurrentBinaryDirectory();
+ dir = root->MaybeConvertToRelativePath(rootBinaryDir, dir.c_str());
+ if (dir == ".") {
+ dir.clear();
+ } else {
+ if (dir.back() != '/') {
+ dir += "/";
}
- std::string projFile = dir + projName + FILE_EXTENSION;
- fout << projFile;
- fout << " " << projType << std::endl;
+ }
- if (cmSystemTools::IsOn(target->GetProperty("GHS_REFERENCE_PROJECT"))) {
- // create reference project
- std::string fname = dir;
- fname += target->GetName();
- fname += "REF";
- fname += FILE_EXTENSION;
+ std::string projFile = dir + projName + FILE_EXTENSION;
+ fout << projFile;
+ fout << " " << projType << std::endl;
- cmGeneratedFileStream fref(fname);
- fref.SetCopyIfDifferent(true);
+ if (cmSystemTools::IsOn(target->GetProperty("GHS_REFERENCE_PROJECT"))) {
+ // create reference project
+ std::string fname = dir;
+ fname += target->GetName();
+ fname += "REF";
+ fname += FILE_EXTENSION;
- this->WriteFileHeader(fref);
- GhsMultiGpj::WriteGpjTag(GhsMultiGpj::REFERENCE, fref);
- fref << " :reference=" << projFile << std::endl;
+ cmGeneratedFileStream fref(fname);
+ fref.SetCopyIfDifferent(true);
- fref.Close();
- }
+ this->WriteFileHeader(fref);
+ GhsMultiGpj::WriteGpjTag(GhsMultiGpj::REFERENCE, fref);
+ fref << " :reference=" << projFile << std::endl;
+
+ fref.Close();
}
}
}
@@ -424,11 +464,23 @@ void cmGlobalGhsMultiGenerator::Generate()
this->WriteFileHeader(frule);
this->WriteCustomRuleBOD(frule);
frule.Close();
+
+ // create custom target BOD file
+ fname = this->GetCMakeInstance()->GetHomeOutputDirectory() +
+ "/CMakeFiles/custom_target.bod";
+ cmGeneratedFileStream ftarget(fname.c_str());
+ ftarget.SetCopyIfDifferent(true);
+ this->WriteFileHeader(ftarget);
+ this->WriteCustomTargetBOD(ftarget);
+ ftarget.Close();
}
void cmGlobalGhsMultiGenerator::OutputTopLevelProject(
cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
{
+ std::string fname;
+ std::string ename;
+
if (generators.empty()) {
return;
}
@@ -437,18 +489,30 @@ void cmGlobalGhsMultiGenerator::OutputTopLevelProject(
* with target projects. This avoid the issue where the project has
* the same name as the executable target.
*/
- std::string fname = root->GetCurrentBinaryDirectory();
+ fname = root->GetCurrentBinaryDirectory();
fname += "/";
fname += root->GetProjectName();
fname += ".top";
fname += FILE_EXTENSION;
- cmGeneratedFileStream fout(fname);
- fout.SetCopyIfDifferent(true);
-
- this->WriteTopLevelProject(fout, root, generators);
-
- fout.Close();
+ ename = root->GetProjectName();
+ ename += ".nobuild";
+ ename += FILE_EXTENSION;
+
+ cmGeneratedFileStream top(fname);
+ top.SetCopyIfDifferent(true);
+ this->WriteTopLevelProject(top, ename, root, generators);
+ top.Close();
+
+ if (!this->ExcludedTargets.empty()) {
+ ename = root->GetCurrentBinaryDirectory() + "/" + ename;
+ cmGeneratedFileStream exclude(ename);
+ exclude.SetCopyIfDifferent(true);
+ WriteFileHeader(exclude);
+ GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, exclude);
+ this->WriteExcludedProjects(exclude, root, generators);
+ exclude.Close();
+ }
}
std::vector<cmGlobalGenerator::GeneratedMakeCommand>
@@ -543,6 +607,8 @@ void cmGlobalGhsMultiGenerator::WriteHighLevelDirectives(
fout << "primaryTarget=" << tgt << std::endl;
fout << "customization=" << root->GetBinaryDirectory()
<< "/CMakeFiles/custom_rule.bod" << std::endl;
+ fout << "customization=" << root->GetBinaryDirectory()
+ << "/CMakeFiles/custom_target.bod" << std::endl;
char const* const customization =
this->GetCMakeInstance()->GetCacheDefinition("GHS_CUSTOMIZATION");
diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h
index 1dd951a..a987205 100644
--- a/Source/cmGlobalGhsMultiGenerator.h
+++ b/Source/cmGlobalGhsMultiGenerator.h
@@ -111,19 +111,27 @@ private:
/* top-level project */
void OutputTopLevelProject(cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators);
- void WriteTopLevelProject(std::ostream& fout, cmLocalGenerator* root,
+ void WriteTopLevelProject(std::ostream& fout, std::string& ename,
+ cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators);
void WriteMacros(std::ostream& fout);
void WriteHighLevelDirectives(cmLocalGenerator* root, std::ostream& fout);
- void WriteSubProjects(std::ostream& fout, cmLocalGenerator* root,
+ void WriteSubProjects(std::ostream& fout, std::string& ename,
+ cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators);
+ void WriteExcludedProjects(std::ostream& fout, cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators);
+ void WriteProjectLine(std::ostream& fout, cmGeneratorTarget const* target,
+ cmLocalGenerator* root, std::string& rootBinaryDir);
void WriteCustomRuleBOD(std::ostream& fout);
+ void WriteCustomTargetBOD(std::ostream& fout);
std::string trimQuotes(std::string const& str);
std::string OsDir;
static const char* DEFAULT_BUILD_PROGRAM;
static const char* DEFAULT_TOOLSET_ROOT;
+ std::vector<cmGeneratorTarget const*> ExcludedTargets;
};
class cmGlobalGhsMultiGenerator::OrderedTargetDependSet