cmGhsMultiTargetGenerator.cxx 24 KB

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