cmGhsMultiTargetGenerator.cxx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmGhsMultiTargetGenerator.h"
  4. #include "cmGeneratedFileStream.h"
  5. #include "cmGeneratorTarget.h"
  6. #include "cmGlobalGhsMultiGenerator.h"
  7. #include "cmLocalGhsMultiGenerator.h"
  8. #include "cmMakefile.h"
  9. #include "cmSourceFile.h"
  10. #include "cmTarget.h"
  11. #include <assert.h>
  12. std::string const cmGhsMultiTargetGenerator::DDOption("-dynamic");
  13. cmGhsMultiTargetGenerator::cmGhsMultiTargetGenerator(cmGeneratorTarget* target)
  14. : GeneratorTarget(target)
  15. , LocalGenerator(
  16. static_cast<cmLocalGhsMultiGenerator*>(target->GetLocalGenerator()))
  17. , Makefile(target->Target->GetMakefile())
  18. , TargetGroup(DetermineIfTargetGroup(target))
  19. , DynamicDownload(false)
  20. {
  21. this->RelBuildFilePath = this->GetRelBuildFilePath(target);
  22. this->RelOutputFileName = this->RelBuildFilePath + target->GetName() + ".a";
  23. this->RelBuildFileName = this->RelBuildFilePath;
  24. this->RelBuildFileName += this->GetBuildFileName(target);
  25. std::string absPathToRoot = this->GetAbsPathToRoot(target);
  26. absPathToRoot = this->AddSlashIfNeededToPath(absPathToRoot);
  27. this->AbsBuildFilePath = absPathToRoot + this->RelBuildFilePath;
  28. this->AbsBuildFileName = absPathToRoot + this->RelBuildFileName;
  29. this->AbsOutputFileName = absPathToRoot + this->RelOutputFileName;
  30. }
  31. cmGhsMultiTargetGenerator::~cmGhsMultiTargetGenerator()
  32. {
  33. cmDeleteAll(this->FolderBuildStreams);
  34. }
  35. std::string cmGhsMultiTargetGenerator::GetRelBuildFilePath(
  36. const cmGeneratorTarget* target)
  37. {
  38. std::string output;
  39. char const* folderProp = target->GetProperty("FOLDER");
  40. output = NULL == folderProp ? "" : folderProp;
  41. cmSystemTools::ConvertToUnixSlashes(output);
  42. if (!output.empty()) {
  43. output += "/";
  44. }
  45. output += target->GetName() + "/";
  46. return output;
  47. }
  48. std::string cmGhsMultiTargetGenerator::GetAbsPathToRoot(
  49. const cmGeneratorTarget* target)
  50. {
  51. return target->GetLocalGenerator()->GetBinaryDirectory();
  52. }
  53. std::string cmGhsMultiTargetGenerator::GetAbsBuildFilePath(
  54. const cmGeneratorTarget* target)
  55. {
  56. std::string output;
  57. output = cmGhsMultiTargetGenerator::GetAbsPathToRoot(target);
  58. output = cmGhsMultiTargetGenerator::AddSlashIfNeededToPath(output);
  59. output += cmGhsMultiTargetGenerator::GetRelBuildFilePath(target);
  60. return output;
  61. }
  62. std::string cmGhsMultiTargetGenerator::GetRelBuildFileName(
  63. const cmGeneratorTarget* target)
  64. {
  65. std::string output;
  66. output = cmGhsMultiTargetGenerator::GetRelBuildFilePath(target);
  67. output = cmGhsMultiTargetGenerator::AddSlashIfNeededToPath(output);
  68. output += cmGhsMultiTargetGenerator::GetBuildFileName(target);
  69. return output;
  70. }
  71. std::string cmGhsMultiTargetGenerator::GetBuildFileName(
  72. const cmGeneratorTarget* target)
  73. {
  74. std::string output;
  75. output = target->GetName();
  76. output += cmGlobalGhsMultiGenerator::FILE_EXTENSION;
  77. return output;
  78. }
  79. std::string cmGhsMultiTargetGenerator::AddSlashIfNeededToPath(
  80. std::string const& input)
  81. {
  82. std::string output(input);
  83. if (!cmHasLiteralSuffix(output, "/")) {
  84. output += "/";
  85. }
  86. return output;
  87. }
  88. void cmGhsMultiTargetGenerator::Generate()
  89. {
  90. std::vector<cmSourceFile*> objectSources = this->GetSources();
  91. if (!objectSources.empty() && this->IncludeThisTarget()) {
  92. if (!cmSystemTools::FileExists(this->AbsBuildFilePath.c_str())) {
  93. cmSystemTools::MakeDirectory(this->AbsBuildFilePath.c_str());
  94. }
  95. cmGlobalGhsMultiGenerator::Open(std::string(""), this->AbsBuildFileName,
  96. &this->FolderBuildStreams);
  97. cmGlobalGhsMultiGenerator::OpenBuildFileStream(
  98. this->GetFolderBuildStreams());
  99. std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  100. if (0 == config.length()) {
  101. config = "RELEASE";
  102. }
  103. const std::string language(
  104. this->GeneratorTarget->GetLinkerLanguage(config));
  105. config = cmSystemTools::UpperCase(config);
  106. this->DynamicDownload = this->DetermineIfDynamicDownload(config, language);
  107. if (this->DynamicDownload) {
  108. *this->GetFolderBuildStreams() << "#component integrity_dynamic_download"
  109. << std::endl;
  110. }
  111. GhsMultiGpj::WriteGpjTag(this->GetGpjTag(), this->GetFolderBuildStreams());
  112. cmGlobalGhsMultiGenerator::WriteDisclaimer(this->GetFolderBuildStreams());
  113. bool const notKernel = this->IsNotKernel(config, language);
  114. this->WriteTypeSpecifics(config, notKernel);
  115. this->SetCompilerFlags(config, language, notKernel);
  116. this->WriteCompilerFlags(config, language);
  117. this->WriteCompilerDefinitions(config, language);
  118. this->WriteIncludes(config, language);
  119. if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE) {
  120. this->WriteTargetLinkLibraries(config, language);
  121. }
  122. this->WriteCustomCommands();
  123. std::map<const cmSourceFile*, std::string> objectNames =
  124. cmGhsMultiTargetGenerator::GetObjectNames(
  125. &objectSources, this->LocalGenerator, this->GeneratorTarget);
  126. this->WriteSources(objectSources, objectNames);
  127. }
  128. }
  129. bool cmGhsMultiTargetGenerator::IncludeThisTarget()
  130. {
  131. bool output = true;
  132. char const* excludeFromAll =
  133. this->GeneratorTarget->GetProperty("EXCLUDE_FROM_ALL");
  134. if (NULL != excludeFromAll && '1' == excludeFromAll[0] &&
  135. '\0' == excludeFromAll[1]) {
  136. output = false;
  137. }
  138. return output;
  139. }
  140. std::vector<cmSourceFile*> cmGhsMultiTargetGenerator::GetSources() const
  141. {
  142. std::vector<cmSourceFile*> output;
  143. std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  144. this->GeneratorTarget->GetSourceFiles(output, config);
  145. return output;
  146. }
  147. GhsMultiGpj::Types cmGhsMultiTargetGenerator::GetGpjTag() const
  148. {
  149. return cmGhsMultiTargetGenerator::GetGpjTag(this->GeneratorTarget);
  150. }
  151. GhsMultiGpj::Types cmGhsMultiTargetGenerator::GetGpjTag(
  152. const cmGeneratorTarget* target)
  153. {
  154. GhsMultiGpj::Types output;
  155. if (cmGhsMultiTargetGenerator::DetermineIfTargetGroup(target)) {
  156. output = GhsMultiGpj::INTERGRITY_APPLICATION;
  157. } else if (target->GetType() == cmState::STATIC_LIBRARY) {
  158. output = GhsMultiGpj::LIBRARY;
  159. } else {
  160. output = GhsMultiGpj::PROGRAM;
  161. }
  162. return output;
  163. }
  164. cmGlobalGhsMultiGenerator* cmGhsMultiTargetGenerator::GetGlobalGenerator()
  165. const
  166. {
  167. return static_cast<cmGlobalGhsMultiGenerator*>(
  168. this->LocalGenerator->GetGlobalGenerator());
  169. }
  170. void cmGhsMultiTargetGenerator::WriteTypeSpecifics(const std::string& config,
  171. bool const notKernel)
  172. {
  173. std::string outputDir(this->GetOutputDirectory(config));
  174. std::string outputFilename(this->GetOutputFilename(config));
  175. if (this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY) {
  176. std::string const static_library_suffix =
  177. this->Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  178. *this->GetFolderBuildStreams() << " -o \"" << outputDir
  179. << outputFilename << static_library_suffix
  180. << "\"" << std::endl;
  181. } else if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE) {
  182. if (notKernel && !this->IsTargetGroup()) {
  183. *this->GetFolderBuildStreams() << " -relprog" << std::endl;
  184. }
  185. if (this->IsTargetGroup()) {
  186. *this->GetFolderBuildStreams()
  187. << " -o \"" << outputDir << outputFilename << ".elf\"" << std::endl;
  188. *this->GetFolderBuildStreams() << " :extraOutputFile=\"" << outputDir
  189. << outputFilename << ".elf.ael\""
  190. << std::endl;
  191. } else {
  192. std::string const executable_suffix =
  193. this->Makefile->GetSafeDefinition("CMAKE_EXECUTABLE_SUFFIX");
  194. *this->GetFolderBuildStreams() << " -o \"" << outputDir
  195. << outputFilename << executable_suffix
  196. << "\"" << std::endl;
  197. }
  198. }
  199. }
  200. void cmGhsMultiTargetGenerator::SetCompilerFlags(std::string const& config,
  201. const std::string& language,
  202. bool const notKernel)
  203. {
  204. std::map<std::string, std::string>::iterator i =
  205. this->FlagsByLanguage.find(language);
  206. if (i == this->FlagsByLanguage.end()) {
  207. std::string flags;
  208. const char* lang = language.c_str();
  209. if (notKernel) {
  210. this->LocalGenerator->AddLanguageFlags(flags, lang, config);
  211. } else {
  212. this->LocalGenerator->AddLanguageFlags(
  213. flags, lang + std::string("_GHS_KERNEL"), config);
  214. }
  215. this->LocalGenerator->AddCMP0018Flags(flags, this->GeneratorTarget, lang,
  216. config);
  217. this->LocalGenerator->AddVisibilityPresetFlags(
  218. flags, this->GeneratorTarget, lang);
  219. // Append old-style preprocessor definition flags.
  220. if (std::string(" ") != std::string(this->Makefile->GetDefineFlags())) {
  221. this->LocalGenerator->AppendFlags(flags,
  222. this->Makefile->GetDefineFlags());
  223. }
  224. // Add target-specific flags.
  225. this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, lang,
  226. config);
  227. std::map<std::string, std::string>::value_type entry(language, flags);
  228. i = this->FlagsByLanguage.insert(entry).first;
  229. }
  230. }
  231. std::string cmGhsMultiTargetGenerator::GetDefines(const std::string& language,
  232. std::string const& config)
  233. {
  234. std::map<std::string, std::string>::iterator i =
  235. this->DefinesByLanguage.find(language);
  236. if (i == this->DefinesByLanguage.end()) {
  237. std::set<std::string> defines;
  238. const char* lang = language.c_str();
  239. // Add the export symbol definition for shared library objects.
  240. if (const char* exportMacro = this->GeneratorTarget->GetExportMacro()) {
  241. this->LocalGenerator->AppendDefines(defines, exportMacro);
  242. }
  243. // Add preprocessor definitions for this target and configuration.
  244. this->LocalGenerator->AddCompileDefinitions(defines, this->GeneratorTarget,
  245. config, language);
  246. std::string definesString;
  247. this->LocalGenerator->JoinDefines(defines, definesString, lang);
  248. std::map<std::string, std::string>::value_type entry(language,
  249. definesString);
  250. i = this->DefinesByLanguage.insert(entry).first;
  251. }
  252. return i->second;
  253. }
  254. void cmGhsMultiTargetGenerator::WriteCompilerFlags(std::string const&,
  255. const std::string& language)
  256. {
  257. std::map<std::string, std::string>::iterator flagsByLangI =
  258. this->FlagsByLanguage.find(language);
  259. if (flagsByLangI != this->FlagsByLanguage.end()) {
  260. if (!flagsByLangI->second.empty()) {
  261. *this->GetFolderBuildStreams() << " " << flagsByLangI->second
  262. << std::endl;
  263. }
  264. }
  265. }
  266. void cmGhsMultiTargetGenerator::WriteCompilerDefinitions(
  267. const std::string& config, const std::string& language)
  268. {
  269. std::vector<std::string> compileDefinitions;
  270. this->GeneratorTarget->GetCompileDefinitions(compileDefinitions, config,
  271. language);
  272. for (std::vector<std::string>::const_iterator cdI =
  273. compileDefinitions.begin();
  274. cdI != compileDefinitions.end(); ++cdI) {
  275. *this->GetFolderBuildStreams() << " -D" << (*cdI) << std::endl;
  276. }
  277. }
  278. void cmGhsMultiTargetGenerator::WriteIncludes(const std::string& config,
  279. const std::string& language)
  280. {
  281. std::vector<std::string> includes;
  282. this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
  283. language, config);
  284. for (std::vector<std::string>::const_iterator includes_i = includes.begin();
  285. includes_i != includes.end(); ++includes_i) {
  286. *this->GetFolderBuildStreams() << " -I\"" << *includes_i << "\""
  287. << std::endl;
  288. }
  289. }
  290. void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries(
  291. std::string const& config, std::string const& language)
  292. {
  293. // library directories
  294. cmTargetDependSet tds =
  295. this->GetGlobalGenerator()->GetTargetDirectDepends(this->GeneratorTarget);
  296. for (cmTargetDependSet::iterator tdsI = tds.begin(); tdsI != tds.end();
  297. ++tdsI) {
  298. const cmGeneratorTarget* tg = *tdsI;
  299. *this->GetFolderBuildStreams() << " -L\"" << GetAbsBuildFilePath(tg)
  300. << "\"" << std::endl;
  301. }
  302. // library targets
  303. cmTarget::LinkLibraryVectorType llv =
  304. this->GeneratorTarget->Target->GetOriginalLinkLibraries();
  305. for (cmTarget::LinkLibraryVectorType::const_iterator llvI = llv.begin();
  306. llvI != llv.end(); ++llvI) {
  307. std::string libName = llvI->first;
  308. // if it is a user defined target get the full path to the lib
  309. cmTarget* tg(GetGlobalGenerator()->FindTarget(libName));
  310. if (NULL != tg) {
  311. libName = tg->GetName() + ".a";
  312. }
  313. *this->GetFolderBuildStreams() << " -l\"" << libName << "\""
  314. << std::endl;
  315. }
  316. if (!this->TargetGroup) {
  317. std::string linkLibraries;
  318. std::string flags;
  319. std::string linkFlags;
  320. std::string frameworkPath;
  321. std::string linkPath;
  322. std::string createRule =
  323. this->GeneratorTarget->GetCreateRuleVariable(language, config);
  324. bool useWatcomQuote =
  325. this->Makefile->IsOn(createRule + "_USE_WATCOM_QUOTE");
  326. this->LocalGenerator->GetTargetFlags(
  327. config, linkLibraries, flags, linkFlags, frameworkPath, linkPath,
  328. this->GeneratorTarget, useWatcomQuote);
  329. linkFlags = cmSystemTools::TrimWhitespace(linkFlags);
  330. if (!linkPath.empty()) {
  331. linkPath = " " + linkPath.substr(0U, linkPath.size() - 1U);
  332. *this->GetFolderBuildStreams() << linkPath;
  333. }
  334. if (!linkFlags.empty()) {
  335. *this->GetFolderBuildStreams() << " " << linkFlags << std::endl;
  336. }
  337. }
  338. }
  339. void cmGhsMultiTargetGenerator::WriteCustomCommands()
  340. {
  341. WriteCustomCommandsHelper(this->GeneratorTarget->GetPreBuildCommands(),
  342. cmTarget::PRE_BUILD);
  343. WriteCustomCommandsHelper(this->GeneratorTarget->GetPostBuildCommands(),
  344. cmTarget::POST_BUILD);
  345. }
  346. void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper(
  347. std::vector<cmCustomCommand> const& commandsSet,
  348. cmTarget::CustomCommandType const commandType)
  349. {
  350. for (std::vector<cmCustomCommand>::const_iterator commandsSetI =
  351. commandsSet.begin();
  352. commandsSetI != commandsSet.end(); ++commandsSetI) {
  353. cmCustomCommandLines const& commands = commandsSetI->GetCommandLines();
  354. for (cmCustomCommandLines::const_iterator commandI = commands.begin();
  355. commandI != commands.end(); ++commandI) {
  356. switch (commandType) {
  357. case cmTarget::PRE_BUILD:
  358. *this->GetFolderBuildStreams() << " :preexecShellSafe=";
  359. break;
  360. case cmTarget::POST_BUILD:
  361. *this->GetFolderBuildStreams() << " :postexecShellSafe=";
  362. break;
  363. default:
  364. assert("Only pre and post are supported");
  365. }
  366. cmCustomCommandLine const& command = *commandI;
  367. for (cmCustomCommandLine::const_iterator commandLineI = command.begin();
  368. commandLineI != command.end(); ++commandLineI) {
  369. std::string subCommandE =
  370. this->LocalGenerator->EscapeForShell(*commandLineI, true);
  371. if (!command.empty()) {
  372. *this->GetFolderBuildStreams()
  373. << (command.begin() == commandLineI ? "'" : " ");
  374. // Need to double escape backslashes
  375. cmSystemTools::ReplaceString(subCommandE, "\\", "\\\\");
  376. }
  377. *this->GetFolderBuildStreams() << subCommandE;
  378. }
  379. if (!command.empty()) {
  380. *this->GetFolderBuildStreams() << "'" << std::endl;
  381. }
  382. }
  383. }
  384. }
  385. std::map<const cmSourceFile*, std::string>
  386. cmGhsMultiTargetGenerator::GetObjectNames(
  387. std::vector<cmSourceFile*>* const objectSources,
  388. cmLocalGhsMultiGenerator* const localGhsMultiGenerator,
  389. cmGeneratorTarget* const generatorTarget)
  390. {
  391. std::map<std::string, std::vector<cmSourceFile*> > filenameToSource;
  392. std::map<cmSourceFile*, std::string> sourceToFilename;
  393. for (std::vector<cmSourceFile*>::const_iterator sf = objectSources->begin();
  394. sf != objectSources->end(); ++sf) {
  395. const std::string filename =
  396. cmSystemTools::GetFilenameName((*sf)->GetFullPath());
  397. const std::string lower_filename = cmSystemTools::LowerCase(filename);
  398. filenameToSource[lower_filename].push_back(*sf);
  399. sourceToFilename[*sf] = lower_filename;
  400. }
  401. std::vector<cmSourceFile*> duplicateSources;
  402. for (std::map<std::string, std::vector<cmSourceFile*> >::const_iterator
  403. msvSourceI = filenameToSource.begin();
  404. msvSourceI != filenameToSource.end(); ++msvSourceI) {
  405. if (msvSourceI->second.size() > 1) {
  406. duplicateSources.insert(duplicateSources.end(),
  407. msvSourceI->second.begin(),
  408. msvSourceI->second.end());
  409. }
  410. }
  411. std::map<const cmSourceFile*, std::string> objectNamesCorrected;
  412. for (std::vector<cmSourceFile*>::const_iterator sf =
  413. duplicateSources.begin();
  414. sf != duplicateSources.end(); ++sf) {
  415. std::string const longestObjectDirectory(
  416. cmGhsMultiTargetGenerator::ComputeLongestObjectDirectory(
  417. localGhsMultiGenerator, generatorTarget, *sf));
  418. std::string objFilenameName =
  419. localGhsMultiGenerator->GetObjectFileNameWithoutTarget(
  420. **sf, longestObjectDirectory);
  421. cmsys::SystemTools::ReplaceString(objFilenameName, "/", "_");
  422. objectNamesCorrected[*sf] = objFilenameName;
  423. }
  424. return objectNamesCorrected;
  425. }
  426. void cmGhsMultiTargetGenerator::WriteSources(
  427. std::vector<cmSourceFile*> const& objectSources,
  428. std::map<const cmSourceFile*, std::string> const& objectNames)
  429. {
  430. for (std::vector<cmSourceFile*>::const_iterator si = objectSources.begin();
  431. si != objectSources.end(); ++si) {
  432. std::vector<cmSourceGroup> sourceGroups(this->Makefile->GetSourceGroups());
  433. char const* sourceFullPath = (*si)->GetFullPath().c_str();
  434. cmSourceGroup* sourceGroup =
  435. this->Makefile->FindSourceGroup(sourceFullPath, sourceGroups);
  436. std::string sgPath(sourceGroup->GetFullName());
  437. cmSystemTools::ConvertToUnixSlashes(sgPath);
  438. cmGlobalGhsMultiGenerator::AddFilesUpToPath(
  439. this->GetFolderBuildStreams(), &this->FolderBuildStreams,
  440. this->LocalGenerator->GetBinaryDirectory(), sgPath,
  441. GhsMultiGpj::SUBPROJECT, this->RelBuildFilePath);
  442. std::string fullSourcePath((*si)->GetFullPath());
  443. if ((*si)->GetExtension() == "int" || (*si)->GetExtension() == "bsp") {
  444. *this->FolderBuildStreams[sgPath] << fullSourcePath << std::endl;
  445. } else {
  446. // WORKAROUND: GHS MULTI needs the path to use backslashes without quotes
  447. // to open files in search as of version 6.1.6
  448. cmsys::SystemTools::ReplaceString(fullSourcePath, "/", "\\");
  449. *this->FolderBuildStreams[sgPath] << fullSourcePath << std::endl;
  450. }
  451. if ("ld" != (*si)->GetExtension() && "int" != (*si)->GetExtension() &&
  452. "bsp" != (*si)->GetExtension()) {
  453. this->WriteObjectLangOverride(this->FolderBuildStreams[sgPath], (*si));
  454. if (objectNames.end() != objectNames.find(*si)) {
  455. *this->FolderBuildStreams[sgPath]
  456. << " -o \"" << objectNames.find(*si)->second << "\"" << std::endl;
  457. }
  458. this->WriteObjectDir(this->FolderBuildStreams[sgPath],
  459. this->AbsBuildFilePath + sgPath);
  460. }
  461. }
  462. }
  463. void cmGhsMultiTargetGenerator::WriteObjectLangOverride(
  464. cmGeneratedFileStream* fileStream, cmSourceFile* sourceFile)
  465. {
  466. const char* rawLangProp = sourceFile->GetProperty("LANGUAGE");
  467. if (NULL != rawLangProp) {
  468. std::string sourceLangProp(rawLangProp);
  469. std::string extension(sourceFile->GetExtension());
  470. if ("CXX" == sourceLangProp && ("c" == extension || "C" == extension)) {
  471. *fileStream << " -dotciscxx" << std::endl;
  472. }
  473. }
  474. }
  475. void cmGhsMultiTargetGenerator::WriteObjectDir(
  476. cmGeneratedFileStream* fileStream, std::string const& dir)
  477. {
  478. std::string workingDir(dir);
  479. cmSystemTools::ConvertToUnixSlashes(workingDir);
  480. if (!workingDir.empty()) {
  481. workingDir += "/";
  482. }
  483. workingDir += "Objs";
  484. *fileStream << " -object_dir=\"" << workingDir << "\"" << std::endl;
  485. }
  486. std::string cmGhsMultiTargetGenerator::GetOutputDirectory(
  487. const std::string& config) const
  488. {
  489. std::string outputDir(AbsBuildFilePath);
  490. const char* runtimeOutputProp =
  491. this->GeneratorTarget->GetProperty("RUNTIME_OUTPUT_DIRECTORY");
  492. if (NULL != runtimeOutputProp) {
  493. outputDir = runtimeOutputProp;
  494. }
  495. std::string configCapped(cmSystemTools::UpperCase(config));
  496. const char* runtimeOutputSProp = this->GeneratorTarget->GetProperty(
  497. "RUNTIME_OUTPUT_DIRECTORY_" + configCapped);
  498. if (NULL != runtimeOutputSProp) {
  499. outputDir = runtimeOutputSProp;
  500. }
  501. cmSystemTools::ConvertToUnixSlashes(outputDir);
  502. if (!outputDir.empty()) {
  503. outputDir += "/";
  504. }
  505. return outputDir;
  506. }
  507. std::string cmGhsMultiTargetGenerator::GetOutputFilename(
  508. const std::string& config) const
  509. {
  510. std::string outputFilename(this->GeneratorTarget->GetName());
  511. const char* outputNameProp =
  512. this->GeneratorTarget->GetProperty("OUTPUT_NAME");
  513. if (NULL != outputNameProp) {
  514. outputFilename = outputNameProp;
  515. }
  516. std::string configCapped(cmSystemTools::UpperCase(config));
  517. const char* outputNameSProp =
  518. this->GeneratorTarget->GetProperty(configCapped + "_OUTPUT_NAME");
  519. if (NULL != outputNameSProp) {
  520. outputFilename = outputNameSProp;
  521. }
  522. return outputFilename;
  523. }
  524. std::string cmGhsMultiTargetGenerator::ComputeLongestObjectDirectory(
  525. cmLocalGhsMultiGenerator const* localGhsMultiGenerator,
  526. cmGeneratorTarget* const generatorTarget, cmSourceFile* const sourceFile)
  527. {
  528. std::string dir_max;
  529. dir_max +=
  530. localGhsMultiGenerator->GetMakefile()->GetCurrentBinaryDirectory();
  531. dir_max += "/";
  532. dir_max += generatorTarget->Target->GetName();
  533. dir_max += "/";
  534. std::vector<cmSourceGroup> sourceGroups(
  535. localGhsMultiGenerator->GetMakefile()->GetSourceGroups());
  536. char const* const sourceFullPath = sourceFile->GetFullPath().c_str();
  537. cmSourceGroup* sourceGroup =
  538. localGhsMultiGenerator->GetMakefile()->FindSourceGroup(sourceFullPath,
  539. sourceGroups);
  540. std::string const sgPath(sourceGroup->GetFullName());
  541. dir_max += sgPath;
  542. dir_max += "/Objs/libs/";
  543. dir_max += generatorTarget->Target->GetName();
  544. dir_max += "/";
  545. return dir_max;
  546. }
  547. bool cmGhsMultiTargetGenerator::IsNotKernel(std::string const& config,
  548. const std::string& language)
  549. {
  550. bool output;
  551. std::vector<std::string> options;
  552. this->GeneratorTarget->GetCompileOptions(options, config, language);
  553. output =
  554. options.end() == std::find(options.begin(), options.end(), "-kernel");
  555. return output;
  556. }
  557. bool cmGhsMultiTargetGenerator::DetermineIfTargetGroup(
  558. const cmGeneratorTarget* target)
  559. {
  560. bool output = false;
  561. std::vector<cmSourceFile*> sources;
  562. std::string config =
  563. target->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
  564. target->GetSourceFiles(sources, config);
  565. for (std::vector<cmSourceFile*>::const_iterator sources_i = sources.begin();
  566. sources.end() != sources_i; ++sources_i) {
  567. if ("int" == (*sources_i)->GetExtension()) {
  568. output = true;
  569. }
  570. }
  571. return output;
  572. }
  573. bool cmGhsMultiTargetGenerator::DetermineIfDynamicDownload(
  574. std::string const& config, const std::string& language)
  575. {
  576. std::vector<std::string> options;
  577. bool output = false;
  578. this->GeneratorTarget->GetCompileOptions(options, config, language);
  579. for (std::vector<std::string>::const_iterator options_i = options.begin();
  580. options_i != options.end(); ++options_i) {
  581. std::string option = *options_i;
  582. if (this->DDOption == option) {
  583. output = true;
  584. }
  585. }
  586. return output;
  587. }