cmGhsMultiTargetGenerator.cxx 23 KB

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