cmLocalGenerator.cxx 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807
  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 "cmLocalGenerator.h"
  4. #include "cmAlgorithms.h"
  5. #include "cmComputeLinkInformation.h"
  6. #include "cmCustomCommandGenerator.h"
  7. #include "cmGeneratedFileStream.h"
  8. #include "cmGeneratorExpressionEvaluationFile.h"
  9. #include "cmGeneratorTarget.h"
  10. #include "cmGlobalGenerator.h"
  11. #include "cmInstallGenerator.h"
  12. #include "cmInstallScriptGenerator.h"
  13. #include "cmInstallTargetGenerator.h"
  14. #include "cmMakefile.h"
  15. #include "cmSourceFile.h"
  16. #include "cmSystemTools.h"
  17. #include "cmTarget.h"
  18. #include "cmTestGenerator.h"
  19. #include "cmVersion.h"
  20. #include "cmake.h"
  21. #if defined(CMAKE_BUILD_WITH_CMAKE)
  22. #define CM_LG_ENCODE_OBJECT_NAMES
  23. #include <cmsys/MD5.h>
  24. #endif
  25. #include <algorithm>
  26. #include <assert.h>
  27. #include <cmsys/RegularExpression.hxx>
  28. #include <ctype.h>
  29. #include <iterator>
  30. #include <sstream>
  31. #include <stdio.h>
  32. #include <utility>
  33. #if defined(__HAIKU__)
  34. #include <FindDirectory.h>
  35. #include <StorageDefs.h>
  36. #endif
  37. cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
  38. : cmOutputConverter(makefile->GetStateSnapshot())
  39. , StateSnapshot(makefile->GetStateSnapshot())
  40. , DirectoryBacktrace(makefile->GetBacktrace())
  41. {
  42. this->GlobalGenerator = gg;
  43. this->Makefile = makefile;
  44. this->AliasTargets = makefile->GetAliasTargets();
  45. this->EmitUniversalBinaryFlags = true;
  46. this->BackwardsCompatibility = 0;
  47. this->BackwardsCompatibilityFinal = false;
  48. this->ComputeObjectMaxPath();
  49. }
  50. cmLocalGenerator::~cmLocalGenerator()
  51. {
  52. cmDeleteAll(this->GeneratorTargets);
  53. cmDeleteAll(this->OwnedImportedGeneratorTargets);
  54. }
  55. void cmLocalGenerator::IssueMessage(cmake::MessageType t,
  56. std::string const& text) const
  57. {
  58. this->GetCMakeInstance()->IssueMessage(t, text, this->DirectoryBacktrace);
  59. }
  60. void cmLocalGenerator::ComputeObjectMaxPath()
  61. {
  62. // Choose a maximum object file name length.
  63. #if defined(_WIN32) || defined(__CYGWIN__)
  64. this->ObjectPathMax = 250;
  65. #else
  66. this->ObjectPathMax = 1000;
  67. #endif
  68. const char* plen = this->Makefile->GetDefinition("CMAKE_OBJECT_PATH_MAX");
  69. if (plen && *plen) {
  70. unsigned int pmax;
  71. if (sscanf(plen, "%u", &pmax) == 1) {
  72. if (pmax >= 128) {
  73. this->ObjectPathMax = pmax;
  74. } else {
  75. std::ostringstream w;
  76. w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
  77. << ", which is less than the minimum of 128. "
  78. << "The value will be ignored.";
  79. this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  80. }
  81. } else {
  82. std::ostringstream w;
  83. w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
  84. << "\", which fails to parse as a positive integer. "
  85. << "The value will be ignored.";
  86. this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  87. }
  88. }
  89. this->ObjectMaxPathViolations.clear();
  90. }
  91. void cmLocalGenerator::TraceDependencies()
  92. {
  93. std::vector<std::string> configs;
  94. this->Makefile->GetConfigurations(configs);
  95. if (configs.empty()) {
  96. configs.push_back("");
  97. }
  98. for (std::vector<std::string>::const_iterator ci = configs.begin();
  99. ci != configs.end(); ++ci) {
  100. this->GlobalGenerator->CreateEvaluationSourceFiles(*ci);
  101. }
  102. // Generate the rule files for each target.
  103. std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
  104. for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
  105. t != targets.end(); ++t) {
  106. if ((*t)->GetType() == cmState::INTERFACE_LIBRARY) {
  107. continue;
  108. }
  109. (*t)->TraceDependencies();
  110. }
  111. }
  112. void cmLocalGenerator::GenerateTestFiles()
  113. {
  114. if (!this->Makefile->IsOn("CMAKE_TESTING_ENABLED")) {
  115. return;
  116. }
  117. // Compute the set of configurations.
  118. std::vector<std::string> configurationTypes;
  119. const std::string& config =
  120. this->Makefile->GetConfigurations(configurationTypes, false);
  121. std::string file = this->StateSnapshot.GetDirectory().GetCurrentBinary();
  122. file += "/";
  123. file += "CTestTestfile.cmake";
  124. cmGeneratedFileStream fout(file.c_str());
  125. fout.SetCopyIfDifferent(true);
  126. fout << "# CMake generated Testfile for " << std::endl
  127. << "# Source directory: "
  128. << this->StateSnapshot.GetDirectory().GetCurrentSource() << std::endl
  129. << "# Build directory: "
  130. << this->StateSnapshot.GetDirectory().GetCurrentBinary() << std::endl
  131. << "# " << std::endl
  132. << "# This file includes the relevant testing commands "
  133. << "required for " << std::endl
  134. << "# testing this directory and lists subdirectories to "
  135. << "be tested as well." << std::endl;
  136. const char* testIncludeFile =
  137. this->Makefile->GetProperty("TEST_INCLUDE_FILE");
  138. if (testIncludeFile) {
  139. fout << "include(\"" << testIncludeFile << "\")" << std::endl;
  140. }
  141. // Ask each test generator to write its code.
  142. std::vector<cmTestGenerator*> const& testers =
  143. this->Makefile->GetTestGenerators();
  144. for (std::vector<cmTestGenerator*>::const_iterator gi = testers.begin();
  145. gi != testers.end(); ++gi) {
  146. (*gi)->Compute(this);
  147. (*gi)->Generate(fout, config, configurationTypes);
  148. }
  149. typedef std::vector<cmState::Snapshot> vec_t;
  150. vec_t const& children = this->Makefile->GetStateSnapshot().GetChildren();
  151. std::string parentBinDir = this->GetCurrentBinaryDirectory();
  152. for (vec_t::const_iterator i = children.begin(); i != children.end(); ++i) {
  153. // TODO: Use add_subdirectory instead?
  154. std::string outP = i->GetDirectory().GetCurrentBinary();
  155. outP = this->ConvertToRelativePath(parentBinDir, outP);
  156. outP = cmOutputConverter::EscapeForCMake(outP);
  157. fout << "subdirs(" << outP << ")" << std::endl;
  158. }
  159. }
  160. void cmLocalGenerator::CreateEvaluationFileOutputs(std::string const& config)
  161. {
  162. std::vector<cmGeneratorExpressionEvaluationFile*> ef =
  163. this->Makefile->GetEvaluationFiles();
  164. for (std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator li =
  165. ef.begin();
  166. li != ef.end(); ++li) {
  167. (*li)->CreateOutputFile(this, config);
  168. }
  169. }
  170. void cmLocalGenerator::ProcessEvaluationFiles(
  171. std::vector<std::string>& generatedFiles)
  172. {
  173. std::vector<cmGeneratorExpressionEvaluationFile*> ef =
  174. this->Makefile->GetEvaluationFiles();
  175. for (std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator li =
  176. ef.begin();
  177. li != ef.end(); ++li) {
  178. (*li)->Generate(this);
  179. if (cmSystemTools::GetFatalErrorOccured()) {
  180. return;
  181. }
  182. std::vector<std::string> files = (*li)->GetFiles();
  183. std::sort(files.begin(), files.end());
  184. std::vector<std::string> intersection;
  185. std::set_intersection(files.begin(), files.end(), generatedFiles.begin(),
  186. generatedFiles.end(),
  187. std::back_inserter(intersection));
  188. if (!intersection.empty()) {
  189. cmSystemTools::Error("Files to be generated by multiple different "
  190. "commands: ",
  191. cmWrap('"', intersection, '"', " ").c_str());
  192. return;
  193. }
  194. generatedFiles.insert(generatedFiles.end(), files.begin(), files.end());
  195. std::vector<std::string>::iterator newIt =
  196. generatedFiles.end() - files.size();
  197. std::inplace_merge(generatedFiles.begin(), newIt, generatedFiles.end());
  198. }
  199. }
  200. void cmLocalGenerator::GenerateInstallRules()
  201. {
  202. // Compute the install prefix.
  203. const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
  204. #if defined(_WIN32) && !defined(__CYGWIN__)
  205. std::string prefix_win32;
  206. if (!prefix) {
  207. if (!cmSystemTools::GetEnv("SystemDrive", prefix_win32)) {
  208. prefix_win32 = "C:";
  209. }
  210. const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
  211. if (project_name && project_name[0]) {
  212. prefix_win32 += "/Program Files/";
  213. prefix_win32 += project_name;
  214. } else {
  215. prefix_win32 += "/InstalledCMakeProject";
  216. }
  217. prefix = prefix_win32.c_str();
  218. }
  219. #elif defined(__HAIKU__)
  220. char dir[B_PATH_NAME_LENGTH];
  221. if (!prefix) {
  222. if (find_directory(B_SYSTEM_DIRECTORY, -1, false, dir, sizeof(dir)) ==
  223. B_OK) {
  224. prefix = dir;
  225. } else {
  226. prefix = "/boot/system";
  227. }
  228. }
  229. #else
  230. if (!prefix) {
  231. prefix = "/usr/local";
  232. }
  233. #endif
  234. if (const char* stagingPrefix =
  235. this->Makefile->GetDefinition("CMAKE_STAGING_PREFIX")) {
  236. prefix = stagingPrefix;
  237. }
  238. // Compute the set of configurations.
  239. std::vector<std::string> configurationTypes;
  240. const std::string& config =
  241. this->Makefile->GetConfigurations(configurationTypes, false);
  242. // Choose a default install configuration.
  243. std::string default_config = config;
  244. const char* default_order[] = { "RELEASE", "MINSIZEREL", "RELWITHDEBINFO",
  245. "DEBUG", CM_NULLPTR };
  246. for (const char** c = default_order; *c && default_config.empty(); ++c) {
  247. for (std::vector<std::string>::iterator i = configurationTypes.begin();
  248. i != configurationTypes.end(); ++i) {
  249. if (cmSystemTools::UpperCase(*i) == *c) {
  250. default_config = *i;
  251. }
  252. }
  253. }
  254. if (default_config.empty() && !configurationTypes.empty()) {
  255. default_config = configurationTypes[0];
  256. }
  257. // Create the install script file.
  258. std::string file = this->StateSnapshot.GetDirectory().GetCurrentBinary();
  259. std::string homedir = this->GetState()->GetBinaryDirectory();
  260. int toplevel_install = 0;
  261. if (file == homedir) {
  262. toplevel_install = 1;
  263. }
  264. file += "/cmake_install.cmake";
  265. cmGeneratedFileStream fout(file.c_str());
  266. fout.SetCopyIfDifferent(true);
  267. // Write the header.
  268. fout << "# Install script for directory: "
  269. << this->StateSnapshot.GetDirectory().GetCurrentSource() << std::endl
  270. << std::endl;
  271. fout << "# Set the install prefix" << std::endl
  272. << "if(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  273. << " set(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
  274. << "endif()" << std::endl
  275. << "string(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
  276. << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
  277. << std::endl;
  278. // Write support code for generating per-configuration install rules.
  279. /* clang-format off */
  280. fout <<
  281. "# Set the install configuration name.\n"
  282. "if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  283. " if(BUILD_TYPE)\n"
  284. " string(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
  285. " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
  286. " else()\n"
  287. " set(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
  288. " endif()\n"
  289. " message(STATUS \"Install configuration: "
  290. "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
  291. "endif()\n"
  292. "\n";
  293. /* clang-format on */
  294. // Write support code for dealing with component-specific installs.
  295. /* clang-format off */
  296. fout <<
  297. "# Set the component getting installed.\n"
  298. "if(NOT CMAKE_INSTALL_COMPONENT)\n"
  299. " if(COMPONENT)\n"
  300. " message(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
  301. " set(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
  302. " else()\n"
  303. " set(CMAKE_INSTALL_COMPONENT)\n"
  304. " endif()\n"
  305. "endif()\n"
  306. "\n";
  307. /* clang-format on */
  308. // Copy user-specified install options to the install code.
  309. if (const char* so_no_exe =
  310. this->Makefile->GetDefinition("CMAKE_INSTALL_SO_NO_EXE")) {
  311. /* clang-format off */
  312. fout <<
  313. "# Install shared libraries without execute permission?\n"
  314. "if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
  315. " set(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe << "\")\n"
  316. "endif()\n"
  317. "\n";
  318. /* clang-format on */
  319. }
  320. // Ask each install generator to write its code.
  321. std::vector<cmInstallGenerator*> const& installers =
  322. this->Makefile->GetInstallGenerators();
  323. for (std::vector<cmInstallGenerator*>::const_iterator gi =
  324. installers.begin();
  325. gi != installers.end(); ++gi) {
  326. (*gi)->Generate(fout, config, configurationTypes);
  327. }
  328. // Write rules from old-style specification stored in targets.
  329. this->GenerateTargetInstallRules(fout, config, configurationTypes);
  330. // Include install scripts from subdirectories.
  331. std::vector<cmState::Snapshot> children =
  332. this->Makefile->GetStateSnapshot().GetChildren();
  333. if (!children.empty()) {
  334. fout << "if(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
  335. fout << " # Include the install script for each subdirectory.\n";
  336. for (std::vector<cmState::Snapshot>::const_iterator ci = children.begin();
  337. ci != children.end(); ++ci) {
  338. if (!ci->GetDirectory().GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
  339. std::string odir = ci->GetDirectory().GetCurrentBinary();
  340. cmSystemTools::ConvertToUnixSlashes(odir);
  341. fout << " include(\"" << odir << "/cmake_install.cmake\")"
  342. << std::endl;
  343. }
  344. }
  345. fout << "\n";
  346. fout << "endif()\n\n";
  347. }
  348. // Record the install manifest.
  349. if (toplevel_install) {
  350. /* clang-format off */
  351. fout <<
  352. "if(CMAKE_INSTALL_COMPONENT)\n"
  353. " set(CMAKE_INSTALL_MANIFEST \"install_manifest_"
  354. "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
  355. "else()\n"
  356. " set(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
  357. "endif()\n"
  358. "\n"
  359. "string(REPLACE \";\" \"\\n\" CMAKE_INSTALL_MANIFEST_CONTENT\n"
  360. " \"${CMAKE_INSTALL_MANIFEST_FILES}\")\n"
  361. "file(WRITE \"" << homedir << "/${CMAKE_INSTALL_MANIFEST}\"\n"
  362. " \"${CMAKE_INSTALL_MANIFEST_CONTENT}\")\n";
  363. /* clang-format on */
  364. }
  365. }
  366. void cmLocalGenerator::AddGeneratorTarget(cmGeneratorTarget* gt)
  367. {
  368. this->GeneratorTargets.push_back(gt);
  369. this->GlobalGenerator->IndexGeneratorTarget(gt);
  370. }
  371. void cmLocalGenerator::AddImportedGeneratorTarget(cmGeneratorTarget* gt)
  372. {
  373. this->ImportedGeneratorTargets.push_back(gt);
  374. this->GlobalGenerator->IndexGeneratorTarget(gt);
  375. }
  376. void cmLocalGenerator::AddOwnedImportedGeneratorTarget(cmGeneratorTarget* gt)
  377. {
  378. this->OwnedImportedGeneratorTargets.push_back(gt);
  379. }
  380. struct NamedGeneratorTargetFinder
  381. {
  382. NamedGeneratorTargetFinder(std::string const& name)
  383. : Name(name)
  384. {
  385. }
  386. bool operator()(cmGeneratorTarget* tgt)
  387. {
  388. return tgt->GetName() == this->Name;
  389. }
  390. private:
  391. std::string Name;
  392. };
  393. cmGeneratorTarget* cmLocalGenerator::FindLocalNonAliasGeneratorTarget(
  394. const std::string& name) const
  395. {
  396. std::vector<cmGeneratorTarget*>::const_iterator ti =
  397. std::find_if(this->GeneratorTargets.begin(), this->GeneratorTargets.end(),
  398. NamedGeneratorTargetFinder(name));
  399. if (ti != this->GeneratorTargets.end()) {
  400. return *ti;
  401. }
  402. return CM_NULLPTR;
  403. }
  404. void cmLocalGenerator::ComputeTargetManifest()
  405. {
  406. // Collect the set of configuration types.
  407. std::vector<std::string> configNames;
  408. this->Makefile->GetConfigurations(configNames);
  409. if (configNames.empty()) {
  410. configNames.push_back("");
  411. }
  412. // Add our targets to the manifest for each configuration.
  413. std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
  414. for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
  415. t != targets.end(); ++t) {
  416. cmGeneratorTarget* target = *t;
  417. if (target->GetType() == cmState::INTERFACE_LIBRARY) {
  418. continue;
  419. }
  420. for (std::vector<std::string>::iterator ci = configNames.begin();
  421. ci != configNames.end(); ++ci) {
  422. const char* config = ci->c_str();
  423. target->ComputeTargetManifest(config);
  424. }
  425. }
  426. }
  427. bool cmLocalGenerator::IsRootMakefile() const
  428. {
  429. return !this->StateSnapshot.GetBuildsystemDirectoryParent().IsValid();
  430. }
  431. cmState* cmLocalGenerator::GetState() const
  432. {
  433. return this->GlobalGenerator->GetCMakeInstance()->GetState();
  434. }
  435. cmState::Snapshot cmLocalGenerator::GetStateSnapshot() const
  436. {
  437. return this->Makefile->GetStateSnapshot();
  438. }
  439. // List of variables that are replaced when
  440. // rules are expanced. These variables are
  441. // replaced in the form <var> with GetSafeDefinition(var).
  442. // ${LANG} is replaced in the variable first with all enabled
  443. // languages.
  444. static const char* ruleReplaceVars[] = {
  445. "CMAKE_${LANG}_COMPILER",
  446. "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
  447. "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
  448. "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
  449. "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
  450. "CMAKE_${LANG}_LINK_FLAGS",
  451. "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
  452. "CMAKE_${LANG}_ARCHIVE",
  453. "CMAKE_AR",
  454. "CMAKE_CURRENT_SOURCE_DIR",
  455. "CMAKE_CURRENT_BINARY_DIR",
  456. "CMAKE_RANLIB",
  457. "CMAKE_LINKER",
  458. "CMAKE_CL_SHOWINCLUDES_PREFIX",
  459. CM_NULLPTR
  460. };
  461. std::string cmLocalGenerator::ExpandRuleVariable(
  462. std::string const& variable, const RuleVariables& replaceValues)
  463. {
  464. if (replaceValues.LinkFlags) {
  465. if (variable == "LINK_FLAGS") {
  466. return replaceValues.LinkFlags;
  467. }
  468. }
  469. if (replaceValues.Manifests) {
  470. if (variable == "MANIFESTS") {
  471. return replaceValues.Manifests;
  472. }
  473. }
  474. if (replaceValues.Flags) {
  475. if (variable == "FLAGS") {
  476. return replaceValues.Flags;
  477. }
  478. }
  479. if (replaceValues.Source) {
  480. if (variable == "SOURCE") {
  481. return replaceValues.Source;
  482. }
  483. }
  484. if (replaceValues.PreprocessedSource) {
  485. if (variable == "PREPROCESSED_SOURCE") {
  486. return replaceValues.PreprocessedSource;
  487. }
  488. }
  489. if (replaceValues.AssemblySource) {
  490. if (variable == "ASSEMBLY_SOURCE") {
  491. return replaceValues.AssemblySource;
  492. }
  493. }
  494. if (replaceValues.Object) {
  495. if (variable == "OBJECT") {
  496. return replaceValues.Object;
  497. }
  498. }
  499. if (replaceValues.ObjectDir) {
  500. if (variable == "OBJECT_DIR") {
  501. return replaceValues.ObjectDir;
  502. }
  503. }
  504. if (replaceValues.ObjectFileDir) {
  505. if (variable == "OBJECT_FILE_DIR") {
  506. return replaceValues.ObjectFileDir;
  507. }
  508. }
  509. if (replaceValues.Objects) {
  510. if (variable == "OBJECTS") {
  511. return replaceValues.Objects;
  512. }
  513. }
  514. if (replaceValues.ObjectsQuoted) {
  515. if (variable == "OBJECTS_QUOTED") {
  516. return replaceValues.ObjectsQuoted;
  517. }
  518. }
  519. if (replaceValues.Defines && variable == "DEFINES") {
  520. return replaceValues.Defines;
  521. }
  522. if (replaceValues.Includes && variable == "INCLUDES") {
  523. return replaceValues.Includes;
  524. }
  525. if (replaceValues.TargetPDB) {
  526. if (variable == "TARGET_PDB") {
  527. return replaceValues.TargetPDB;
  528. }
  529. }
  530. if (replaceValues.TargetCompilePDB) {
  531. if (variable == "TARGET_COMPILE_PDB") {
  532. return replaceValues.TargetCompilePDB;
  533. }
  534. }
  535. if (replaceValues.DependencyFile) {
  536. if (variable == "DEP_FILE") {
  537. return replaceValues.DependencyFile;
  538. }
  539. }
  540. if (replaceValues.Target) {
  541. if (variable == "TARGET_QUOTED") {
  542. std::string targetQuoted = replaceValues.Target;
  543. if (!targetQuoted.empty() && targetQuoted[0] != '\"') {
  544. targetQuoted = '\"';
  545. targetQuoted += replaceValues.Target;
  546. targetQuoted += '\"';
  547. }
  548. return targetQuoted;
  549. }
  550. if (variable == "TARGET_UNQUOTED") {
  551. std::string unquoted = replaceValues.Target;
  552. std::string::size_type sz = unquoted.size();
  553. if (sz > 2 && unquoted[0] == '\"' && unquoted[sz - 1] == '\"') {
  554. unquoted = unquoted.substr(1, sz - 2);
  555. }
  556. return unquoted;
  557. }
  558. if (replaceValues.LanguageCompileFlags) {
  559. if (variable == "LANGUAGE_COMPILE_FLAGS") {
  560. return replaceValues.LanguageCompileFlags;
  561. }
  562. }
  563. if (replaceValues.Target) {
  564. if (variable == "TARGET") {
  565. return replaceValues.Target;
  566. }
  567. }
  568. if (variable == "TARGET_IMPLIB") {
  569. return this->TargetImplib;
  570. }
  571. if (variable == "TARGET_VERSION_MAJOR") {
  572. if (replaceValues.TargetVersionMajor) {
  573. return replaceValues.TargetVersionMajor;
  574. }
  575. return "0";
  576. }
  577. if (variable == "TARGET_VERSION_MINOR") {
  578. if (replaceValues.TargetVersionMinor) {
  579. return replaceValues.TargetVersionMinor;
  580. }
  581. return "0";
  582. }
  583. if (replaceValues.Target) {
  584. if (variable == "TARGET_BASE") {
  585. // Strip the last extension off the target name.
  586. std::string targetBase = replaceValues.Target;
  587. std::string::size_type pos = targetBase.rfind('.');
  588. if (pos != targetBase.npos) {
  589. return targetBase.substr(0, pos);
  590. }
  591. return targetBase;
  592. }
  593. }
  594. }
  595. if (variable == "TARGET_SONAME" || variable == "SONAME_FLAG" ||
  596. variable == "TARGET_INSTALLNAME_DIR") {
  597. // All these variables depend on TargetSOName
  598. if (replaceValues.TargetSOName) {
  599. if (variable == "TARGET_SONAME") {
  600. return replaceValues.TargetSOName;
  601. }
  602. if (variable == "SONAME_FLAG" && replaceValues.SONameFlag) {
  603. return replaceValues.SONameFlag;
  604. }
  605. if (replaceValues.TargetInstallNameDir &&
  606. variable == "TARGET_INSTALLNAME_DIR") {
  607. return replaceValues.TargetInstallNameDir;
  608. }
  609. }
  610. return "";
  611. }
  612. if (replaceValues.LinkLibraries) {
  613. if (variable == "LINK_LIBRARIES") {
  614. return replaceValues.LinkLibraries;
  615. }
  616. }
  617. if (replaceValues.Language) {
  618. if (variable == "LANGUAGE") {
  619. return replaceValues.Language;
  620. }
  621. }
  622. if (replaceValues.CMTarget) {
  623. if (variable == "TARGET_NAME") {
  624. return replaceValues.CMTarget->GetName();
  625. }
  626. if (variable == "TARGET_TYPE") {
  627. return cmState::GetTargetTypeName(replaceValues.CMTarget->GetType());
  628. }
  629. }
  630. if (replaceValues.Output) {
  631. if (variable == "OUTPUT") {
  632. return replaceValues.Output;
  633. }
  634. }
  635. if (variable == "CMAKE_COMMAND") {
  636. return this->ConvertToOutputFormat(
  637. cmSystemTools::CollapseFullPath(cmSystemTools::GetCMakeCommand()),
  638. SHELL);
  639. }
  640. std::vector<std::string> enabledLanguages =
  641. this->GetState()->GetEnabledLanguages();
  642. // loop over language specific replace variables
  643. int pos = 0;
  644. while (ruleReplaceVars[pos]) {
  645. for (std::vector<std::string>::iterator i = enabledLanguages.begin();
  646. i != enabledLanguages.end(); ++i) {
  647. const char* lang = i->c_str();
  648. std::string actualReplace = ruleReplaceVars[pos];
  649. // If this is the compiler then look for the extra variable
  650. // _COMPILER_ARG1 which must be the first argument to the compiler
  651. const char* compilerArg1 = CM_NULLPTR;
  652. const char* compilerTarget = CM_NULLPTR;
  653. const char* compilerOptionTarget = CM_NULLPTR;
  654. const char* compilerExternalToolchain = CM_NULLPTR;
  655. const char* compilerOptionExternalToolchain = CM_NULLPTR;
  656. const char* compilerSysroot = CM_NULLPTR;
  657. const char* compilerOptionSysroot = CM_NULLPTR;
  658. if (actualReplace == "CMAKE_${LANG}_COMPILER") {
  659. std::string arg1 = actualReplace + "_ARG1";
  660. cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
  661. compilerArg1 = this->Makefile->GetDefinition(arg1);
  662. compilerTarget = this->Makefile->GetDefinition(
  663. std::string("CMAKE_") + lang + "_COMPILER_TARGET");
  664. compilerOptionTarget = this->Makefile->GetDefinition(
  665. std::string("CMAKE_") + lang + "_COMPILE_OPTIONS_TARGET");
  666. compilerExternalToolchain = this->Makefile->GetDefinition(
  667. std::string("CMAKE_") + lang + "_COMPILER_EXTERNAL_TOOLCHAIN");
  668. compilerOptionExternalToolchain =
  669. this->Makefile->GetDefinition(std::string("CMAKE_") + lang +
  670. "_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN");
  671. compilerSysroot = this->Makefile->GetDefinition("CMAKE_SYSROOT");
  672. compilerOptionSysroot = this->Makefile->GetDefinition(
  673. std::string("CMAKE_") + lang + "_COMPILE_OPTIONS_SYSROOT");
  674. }
  675. if (actualReplace.find("${LANG}") != actualReplace.npos) {
  676. cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
  677. }
  678. if (actualReplace == variable) {
  679. std::string replace = this->Makefile->GetSafeDefinition(variable);
  680. // if the variable is not a FLAG then treat it like a path
  681. if (variable.find("_FLAG") == variable.npos) {
  682. std::string ret = this->ConvertToOutputForExisting(replace);
  683. // if there is a required first argument to the compiler add it
  684. // to the compiler string
  685. if (compilerArg1) {
  686. ret += " ";
  687. ret += compilerArg1;
  688. }
  689. if (compilerTarget && compilerOptionTarget) {
  690. ret += " ";
  691. ret += compilerOptionTarget;
  692. ret += compilerTarget;
  693. }
  694. if (compilerExternalToolchain && compilerOptionExternalToolchain) {
  695. ret += " ";
  696. ret += compilerOptionExternalToolchain;
  697. ret += this->EscapeForShell(compilerExternalToolchain, true);
  698. }
  699. if (compilerSysroot && compilerOptionSysroot) {
  700. ret += " ";
  701. ret += compilerOptionSysroot;
  702. ret += this->EscapeForShell(compilerSysroot, true);
  703. }
  704. return ret;
  705. }
  706. return replace;
  707. }
  708. }
  709. pos++;
  710. }
  711. return variable;
  712. }
  713. void cmLocalGenerator::ExpandRuleVariables(std::string& s,
  714. const RuleVariables& replaceValues)
  715. {
  716. if (replaceValues.RuleLauncher) {
  717. this->InsertRuleLauncher(s, replaceValues.CMTarget,
  718. replaceValues.RuleLauncher);
  719. }
  720. std::string::size_type start = s.find('<');
  721. // no variables to expand
  722. if (start == s.npos) {
  723. return;
  724. }
  725. std::string::size_type pos = 0;
  726. std::string expandedInput;
  727. while (start != s.npos && start < s.size() - 2) {
  728. std::string::size_type end = s.find('>', start);
  729. // if we find a < with no > we are done
  730. if (end == s.npos) {
  731. return;
  732. }
  733. char c = s[start + 1];
  734. // if the next char after the < is not A-Za-z then
  735. // skip it and try to find the next < in the string
  736. if (!isalpha(c)) {
  737. start = s.find('<', start + 1);
  738. } else {
  739. // extract the var
  740. std::string var = s.substr(start + 1, end - start - 1);
  741. std::string replace = this->ExpandRuleVariable(var, replaceValues);
  742. expandedInput += s.substr(pos, start - pos);
  743. expandedInput += replace;
  744. // move to next one
  745. start = s.find('<', start + var.size() + 2);
  746. pos = end + 1;
  747. }
  748. }
  749. // add the rest of the input
  750. expandedInput += s.substr(pos, s.size() - pos);
  751. s = expandedInput;
  752. }
  753. const char* cmLocalGenerator::GetRuleLauncher(cmGeneratorTarget* target,
  754. const std::string& prop)
  755. {
  756. if (target) {
  757. return target->GetProperty(prop);
  758. }
  759. return this->Makefile->GetProperty(prop);
  760. }
  761. void cmLocalGenerator::InsertRuleLauncher(std::string& s,
  762. cmGeneratorTarget* target,
  763. const std::string& prop)
  764. {
  765. if (const char* val = this->GetRuleLauncher(target, prop)) {
  766. std::ostringstream wrapped;
  767. wrapped << val << " " << s;
  768. s = wrapped.str();
  769. }
  770. }
  771. std::string cmLocalGenerator::ConvertToIncludeReference(
  772. std::string const& path, OutputFormat format, bool forceFullPaths)
  773. {
  774. static_cast<void>(forceFullPaths);
  775. return this->ConvertToOutputForExisting(path, format);
  776. }
  777. std::string cmLocalGenerator::GetIncludeFlags(
  778. const std::vector<std::string>& includes, cmGeneratorTarget* target,
  779. const std::string& lang, bool forceFullPaths, bool forResponseFile,
  780. const std::string& config)
  781. {
  782. if (lang.empty()) {
  783. return "";
  784. }
  785. OutputFormat shellFormat = forResponseFile ? RESPONSE : SHELL;
  786. std::ostringstream includeFlags;
  787. std::string flagVar = "CMAKE_INCLUDE_FLAG_";
  788. flagVar += lang;
  789. const char* includeFlag = this->Makefile->GetSafeDefinition(flagVar);
  790. flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
  791. flagVar += lang;
  792. const char* sep = this->Makefile->GetDefinition(flagVar);
  793. bool quotePaths = false;
  794. if (this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS")) {
  795. quotePaths = true;
  796. }
  797. bool repeatFlag = true;
  798. // should the include flag be repeated like ie. -IA -IB
  799. if (!sep) {
  800. sep = " ";
  801. } else {
  802. // if there is a separator then the flag is not repeated but is only
  803. // given once i.e. -classpath a:b:c
  804. repeatFlag = false;
  805. }
  806. // Support special system include flag if it is available and the
  807. // normal flag is repeated for each directory.
  808. std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
  809. sysFlagVar += lang;
  810. const char* sysIncludeFlag = CM_NULLPTR;
  811. if (repeatFlag) {
  812. sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar);
  813. }
  814. std::string fwSearchFlagVar = "CMAKE_";
  815. fwSearchFlagVar += lang;
  816. fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
  817. const char* fwSearchFlag = this->Makefile->GetDefinition(fwSearchFlagVar);
  818. std::string sysFwSearchFlagVar = "CMAKE_";
  819. sysFwSearchFlagVar += lang;
  820. sysFwSearchFlagVar += "_SYSTEM_FRAMEWORK_SEARCH_FLAG";
  821. const char* sysFwSearchFlag =
  822. this->Makefile->GetDefinition(sysFwSearchFlagVar);
  823. bool flagUsed = false;
  824. std::set<std::string> emitted;
  825. #ifdef __APPLE__
  826. emitted.insert("/System/Library/Frameworks");
  827. #endif
  828. std::vector<std::string>::const_iterator i;
  829. for (i = includes.begin(); i != includes.end(); ++i) {
  830. if (fwSearchFlag && *fwSearchFlag && this->Makefile->IsOn("APPLE") &&
  831. cmSystemTools::IsPathToFramework(i->c_str())) {
  832. std::string frameworkDir = *i;
  833. frameworkDir += "/../";
  834. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
  835. if (emitted.insert(frameworkDir).second) {
  836. if (sysFwSearchFlag && target &&
  837. target->IsSystemIncludeDirectory(*i, config)) {
  838. includeFlags << sysFwSearchFlag;
  839. } else {
  840. includeFlags << fwSearchFlag;
  841. }
  842. includeFlags << this->ConvertToOutputFormat(frameworkDir, shellFormat)
  843. << " ";
  844. }
  845. continue;
  846. }
  847. if (!flagUsed || repeatFlag) {
  848. if (sysIncludeFlag && target &&
  849. target->IsSystemIncludeDirectory(*i, config)) {
  850. includeFlags << sysIncludeFlag;
  851. } else {
  852. includeFlags << includeFlag;
  853. }
  854. flagUsed = true;
  855. }
  856. std::string includePath =
  857. this->ConvertToIncludeReference(*i, shellFormat, forceFullPaths);
  858. if (quotePaths && !includePath.empty() && includePath[0] != '\"') {
  859. includeFlags << "\"";
  860. }
  861. includeFlags << includePath;
  862. if (quotePaths && !includePath.empty() && includePath[0] != '\"') {
  863. includeFlags << "\"";
  864. }
  865. includeFlags << sep;
  866. }
  867. std::string flags = includeFlags.str();
  868. // remove trailing separators
  869. if ((sep[0] != ' ') && !flags.empty() && flags[flags.size() - 1] == sep[0]) {
  870. flags[flags.size() - 1] = ' ';
  871. }
  872. return flags;
  873. }
  874. void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines,
  875. cmGeneratorTarget const* target,
  876. const std::string& config,
  877. const std::string& lang) const
  878. {
  879. std::vector<std::string> targetDefines;
  880. target->GetCompileDefinitions(targetDefines, config, lang);
  881. this->AppendDefines(defines, targetDefines);
  882. }
  883. void cmLocalGenerator::AddCompileOptions(std::string& flags,
  884. cmGeneratorTarget* target,
  885. const std::string& lang,
  886. const std::string& config)
  887. {
  888. std::string langFlagRegexVar = std::string("CMAKE_") + lang + "_FLAG_REGEX";
  889. if (const char* langFlagRegexStr =
  890. this->Makefile->GetDefinition(langFlagRegexVar)) {
  891. // Filter flags acceptable to this language.
  892. cmsys::RegularExpression r(langFlagRegexStr);
  893. std::vector<std::string> opts;
  894. if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) {
  895. cmSystemTools::ParseWindowsCommandLine(targetFlags, opts);
  896. }
  897. target->GetCompileOptions(opts, config, lang);
  898. for (std::vector<std::string>::const_iterator i = opts.begin();
  899. i != opts.end(); ++i) {
  900. if (r.find(i->c_str())) {
  901. // (Re-)Escape this flag. COMPILE_FLAGS were already parsed
  902. // as a command line above, and COMPILE_OPTIONS are escaped.
  903. this->AppendFlagEscape(flags, *i);
  904. }
  905. }
  906. } else {
  907. // Use all flags.
  908. if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) {
  909. // COMPILE_FLAGS are not escaped for historical reasons.
  910. this->AppendFlags(flags, targetFlags);
  911. }
  912. std::vector<std::string> opts;
  913. target->GetCompileOptions(opts, config, lang);
  914. for (std::vector<std::string>::const_iterator i = opts.begin();
  915. i != opts.end(); ++i) {
  916. // COMPILE_OPTIONS are escaped.
  917. this->AppendFlagEscape(flags, *i);
  918. }
  919. }
  920. std::vector<std::string> features;
  921. target->GetCompileFeatures(features, config);
  922. for (std::vector<std::string>::const_iterator it = features.begin();
  923. it != features.end(); ++it) {
  924. if (!this->Makefile->AddRequiredTargetFeature(target->Target, *it)) {
  925. return;
  926. }
  927. }
  928. for (std::map<std::string, std::string>::const_iterator it =
  929. target->GetMaxLanguageStandards().begin();
  930. it != target->GetMaxLanguageStandards().end(); ++it) {
  931. const char* standard = target->GetProperty(it->first + "_STANDARD");
  932. if (!standard) {
  933. continue;
  934. }
  935. if (this->Makefile->IsLaterStandard(it->first, standard, it->second)) {
  936. std::ostringstream e;
  937. e << "The COMPILE_FEATURES property of target \"" << target->GetName()
  938. << "\" was evaluated when computing the link "
  939. "implementation, and the \""
  940. << it->first << "_STANDARD\" was \"" << it->second
  941. << "\" for that computation. Computing the "
  942. "COMPILE_FEATURES based on the link implementation resulted in a "
  943. "higher \""
  944. << it->first << "_STANDARD\" \"" << standard
  945. << "\". "
  946. "This is not permitted. The COMPILE_FEATURES may not both depend "
  947. "on "
  948. "and be depended on by the link implementation."
  949. << std::endl;
  950. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  951. return;
  952. }
  953. }
  954. this->AddCompilerRequirementFlag(flags, target, lang);
  955. }
  956. void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
  957. cmGeneratorTarget const* target,
  958. const std::string& lang,
  959. const std::string& config,
  960. bool stripImplicitInclDirs) const
  961. {
  962. // Need to decide whether to automatically include the source and
  963. // binary directories at the beginning of the include path.
  964. bool includeSourceDir = false;
  965. bool includeBinaryDir = false;
  966. // When automatic include directories are requested for a build then
  967. // include the source and binary directories at the beginning of the
  968. // include path to approximate include file behavior for an
  969. // in-source build. This does not account for the case of a source
  970. // file in a subdirectory of the current source directory but we
  971. // cannot fix this because not all native build tools support
  972. // per-source-file include paths.
  973. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR")) {
  974. includeSourceDir = true;
  975. includeBinaryDir = true;
  976. }
  977. // Do not repeat an include path.
  978. std::set<std::string> emitted;
  979. // Store the automatic include paths.
  980. if (includeBinaryDir) {
  981. std::string binDir = this->StateSnapshot.GetDirectory().GetCurrentBinary();
  982. if (emitted.find(binDir) == emitted.end()) {
  983. dirs.push_back(binDir);
  984. emitted.insert(binDir);
  985. }
  986. }
  987. if (includeSourceDir) {
  988. std::string srcDir = this->StateSnapshot.GetDirectory().GetCurrentSource();
  989. if (emitted.find(srcDir) == emitted.end()) {
  990. dirs.push_back(srcDir);
  991. emitted.insert(srcDir);
  992. }
  993. }
  994. if (!target) {
  995. return;
  996. }
  997. std::string rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
  998. std::vector<std::string> implicitDirs;
  999. // Load implicit include directories for this language.
  1000. std::string impDirVar = "CMAKE_";
  1001. impDirVar += lang;
  1002. impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES";
  1003. if (const char* value = this->Makefile->GetDefinition(impDirVar)) {
  1004. std::vector<std::string> impDirVec;
  1005. cmSystemTools::ExpandListArgument(value, impDirVec);
  1006. for (std::vector<std::string>::const_iterator i = impDirVec.begin();
  1007. i != impDirVec.end(); ++i) {
  1008. std::string d = rootPath + *i;
  1009. cmSystemTools::ConvertToUnixSlashes(d);
  1010. emitted.insert(d);
  1011. if (!stripImplicitInclDirs) {
  1012. implicitDirs.push_back(*i);
  1013. }
  1014. }
  1015. }
  1016. // Get the target-specific include directories.
  1017. std::vector<std::string> includes;
  1018. includes = target->GetIncludeDirectories(config, lang);
  1019. // Support putting all the in-project include directories first if
  1020. // it is requested by the project.
  1021. if (this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE")) {
  1022. const char* topSourceDir = this->GetState()->GetSourceDirectory();
  1023. const char* topBinaryDir = this->GetState()->GetBinaryDirectory();
  1024. for (std::vector<std::string>::const_iterator i = includes.begin();
  1025. i != includes.end(); ++i) {
  1026. // Emit this directory only if it is a subdirectory of the
  1027. // top-level source or binary tree.
  1028. if (cmSystemTools::ComparePath(*i, topSourceDir) ||
  1029. cmSystemTools::ComparePath(*i, topBinaryDir) ||
  1030. cmSystemTools::IsSubDirectory(*i, topSourceDir) ||
  1031. cmSystemTools::IsSubDirectory(*i, topBinaryDir)) {
  1032. if (emitted.insert(*i).second) {
  1033. dirs.push_back(*i);
  1034. }
  1035. }
  1036. }
  1037. }
  1038. // Construct the final ordered include directory list.
  1039. for (std::vector<std::string>::const_iterator i = includes.begin();
  1040. i != includes.end(); ++i) {
  1041. if (emitted.insert(*i).second) {
  1042. dirs.push_back(*i);
  1043. }
  1044. }
  1045. for (std::vector<std::string>::const_iterator i = implicitDirs.begin();
  1046. i != implicitDirs.end(); ++i) {
  1047. if (std::find(includes.begin(), includes.end(), *i) != includes.end()) {
  1048. dirs.push_back(*i);
  1049. }
  1050. }
  1051. }
  1052. void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
  1053. std::string const& config,
  1054. cmGeneratorTarget* target)
  1055. {
  1056. this->AppendFlags(
  1057. flags, this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS"));
  1058. if (!config.empty()) {
  1059. std::string name = "CMAKE_STATIC_LINKER_FLAGS_" + config;
  1060. this->AppendFlags(flags, this->Makefile->GetSafeDefinition(name));
  1061. }
  1062. this->AppendFlags(flags, target->GetProperty("STATIC_LIBRARY_FLAGS"));
  1063. if (!config.empty()) {
  1064. std::string name = "STATIC_LIBRARY_FLAGS_" + config;
  1065. this->AppendFlags(flags, target->GetProperty(name));
  1066. }
  1067. }
  1068. void cmLocalGenerator::GetTargetFlags(
  1069. const std::string& config, std::string& linkLibs, std::string& flags,
  1070. std::string& linkFlags, std::string& frameworkPath, std::string& linkPath,
  1071. cmGeneratorTarget* target, bool useWatcomQuote)
  1072. {
  1073. const std::string buildType = cmSystemTools::UpperCase(config);
  1074. const char* libraryLinkVariable =
  1075. "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
  1076. switch (target->GetType()) {
  1077. case cmState::STATIC_LIBRARY:
  1078. this->GetStaticLibraryFlags(linkFlags, buildType, target);
  1079. break;
  1080. case cmState::MODULE_LIBRARY:
  1081. libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
  1082. case cmState::SHARED_LIBRARY: {
  1083. linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
  1084. linkFlags += " ";
  1085. if (!buildType.empty()) {
  1086. std::string build = libraryLinkVariable;
  1087. build += "_";
  1088. build += buildType;
  1089. linkFlags += this->Makefile->GetSafeDefinition(build);
  1090. linkFlags += " ";
  1091. }
  1092. if (this->Makefile->IsOn("WIN32") &&
  1093. !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW"))) {
  1094. std::vector<cmSourceFile*> sources;
  1095. target->GetSourceFiles(sources, buildType);
  1096. for (std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1097. i != sources.end(); ++i) {
  1098. cmSourceFile* sf = *i;
  1099. if (sf->GetExtension() == "def") {
  1100. linkFlags +=
  1101. this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1102. linkFlags += this->ConvertToOutputFormat(
  1103. cmSystemTools::CollapseFullPath(sf->GetFullPath()), SHELL);
  1104. linkFlags += " ";
  1105. }
  1106. }
  1107. }
  1108. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  1109. if (targetLinkFlags) {
  1110. linkFlags += targetLinkFlags;
  1111. linkFlags += " ";
  1112. }
  1113. if (!buildType.empty()) {
  1114. std::string configLinkFlags = "LINK_FLAGS_";
  1115. configLinkFlags += buildType;
  1116. targetLinkFlags = target->GetProperty(configLinkFlags);
  1117. if (targetLinkFlags) {
  1118. linkFlags += targetLinkFlags;
  1119. linkFlags += " ";
  1120. }
  1121. }
  1122. this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath, *target,
  1123. false, false, useWatcomQuote);
  1124. } break;
  1125. case cmState::EXECUTABLE: {
  1126. linkFlags += this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1127. linkFlags += " ";
  1128. if (!buildType.empty()) {
  1129. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1130. build += buildType;
  1131. linkFlags += this->Makefile->GetSafeDefinition(build);
  1132. linkFlags += " ";
  1133. }
  1134. std::string linkLanguage = target->GetLinkerLanguage(buildType);
  1135. if (linkLanguage.empty()) {
  1136. cmSystemTools::Error(
  1137. "CMake can not determine linker language for target: ",
  1138. target->GetName().c_str());
  1139. return;
  1140. }
  1141. this->AddLanguageFlags(flags, linkLanguage, buildType);
  1142. this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath, *target,
  1143. false, false, useWatcomQuote);
  1144. if (cmSystemTools::IsOn(
  1145. this->Makefile->GetDefinition("BUILD_SHARED_LIBS"))) {
  1146. std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_") +
  1147. linkLanguage + std::string("_FLAGS");
  1148. linkFlags += this->Makefile->GetSafeDefinition(sFlagVar);
  1149. linkFlags += " ";
  1150. }
  1151. if (target->GetPropertyAsBool("WIN32_EXECUTABLE")) {
  1152. linkFlags +=
  1153. this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1154. linkFlags += " ";
  1155. } else {
  1156. linkFlags +=
  1157. this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1158. linkFlags += " ";
  1159. }
  1160. if (target->IsExecutableWithExports()) {
  1161. std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
  1162. exportFlagVar += linkLanguage;
  1163. exportFlagVar += "_FLAG";
  1164. linkFlags += this->Makefile->GetSafeDefinition(exportFlagVar);
  1165. linkFlags += " ";
  1166. }
  1167. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  1168. if (targetLinkFlags) {
  1169. linkFlags += targetLinkFlags;
  1170. linkFlags += " ";
  1171. }
  1172. if (!buildType.empty()) {
  1173. std::string configLinkFlags = "LINK_FLAGS_";
  1174. configLinkFlags += buildType;
  1175. targetLinkFlags = target->GetProperty(configLinkFlags);
  1176. if (targetLinkFlags) {
  1177. linkFlags += targetLinkFlags;
  1178. linkFlags += " ";
  1179. }
  1180. }
  1181. } break;
  1182. default:
  1183. break;
  1184. }
  1185. }
  1186. void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target,
  1187. std::string const& config,
  1188. std::string const& lang,
  1189. std::string& flags)
  1190. {
  1191. cmMakefile* mf = this->GetMakefile();
  1192. // Add language-specific flags.
  1193. this->AddLanguageFlags(flags, lang, config);
  1194. if (target->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION", config)) {
  1195. this->AppendFeatureOptions(flags, lang, "IPO");
  1196. }
  1197. this->AddArchitectureFlags(flags, target, lang, config);
  1198. if (lang == "Fortran") {
  1199. this->AppendFlags(flags, this->GetTargetFortranFlags(target, config));
  1200. }
  1201. this->AddCMP0018Flags(flags, target, lang, config);
  1202. this->AddVisibilityPresetFlags(flags, target, lang);
  1203. this->AppendFlags(flags, mf->GetDefineFlags());
  1204. this->AppendFlags(flags, this->GetFrameworkFlags(lang, config, target));
  1205. this->AddCompileOptions(flags, target, lang, config);
  1206. }
  1207. static std::string GetFrameworkFlags(const std::string& lang,
  1208. const std::string& config,
  1209. cmGeneratorTarget* target)
  1210. {
  1211. cmLocalGenerator* lg = target->GetLocalGenerator();
  1212. cmMakefile* mf = lg->GetMakefile();
  1213. if (!mf->IsOn("APPLE")) {
  1214. return std::string();
  1215. }
  1216. std::string fwSearchFlagVar = "CMAKE_" + lang + "_FRAMEWORK_SEARCH_FLAG";
  1217. const char* fwSearchFlag = mf->GetDefinition(fwSearchFlagVar);
  1218. if (!(fwSearchFlag && *fwSearchFlag)) {
  1219. return std::string();
  1220. }
  1221. std::set<std::string> emitted;
  1222. #ifdef __APPLE__ /* don't insert this when crosscompiling e.g. to iphone */
  1223. emitted.insert("/System/Library/Frameworks");
  1224. #endif
  1225. std::vector<std::string> includes;
  1226. lg->GetIncludeDirectories(includes, target, "C", config);
  1227. // check all include directories for frameworks as this
  1228. // will already have added a -F for the framework
  1229. for (std::vector<std::string>::iterator i = includes.begin();
  1230. i != includes.end(); ++i) {
  1231. if (lg->GetGlobalGenerator()->NameResolvesToFramework(*i)) {
  1232. std::string frameworkDir = *i;
  1233. frameworkDir += "/../";
  1234. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
  1235. emitted.insert(frameworkDir);
  1236. }
  1237. }
  1238. std::string flags;
  1239. if (cmComputeLinkInformation* cli = target->GetLinkInformation(config)) {
  1240. std::vector<std::string> const& frameworks = cli->GetFrameworkPaths();
  1241. for (std::vector<std::string>::const_iterator i = frameworks.begin();
  1242. i != frameworks.end(); ++i) {
  1243. if (emitted.insert(*i).second) {
  1244. flags += fwSearchFlag;
  1245. flags += lg->ConvertToOutputFormat(*i, cmOutputConverter::SHELL);
  1246. flags += " ";
  1247. }
  1248. }
  1249. }
  1250. return flags;
  1251. }
  1252. std::string cmLocalGenerator::GetFrameworkFlags(std::string const& l,
  1253. std::string const& config,
  1254. cmGeneratorTarget* target)
  1255. {
  1256. return ::GetFrameworkFlags(l, config, target);
  1257. }
  1258. void cmLocalGenerator::GetTargetDefines(cmGeneratorTarget const* target,
  1259. std::string const& config,
  1260. std::string const& lang,
  1261. std::set<std::string>& defines) const
  1262. {
  1263. // Add the export symbol definition for shared library objects.
  1264. if (const char* exportMacro = target->GetExportMacro()) {
  1265. this->AppendDefines(defines, exportMacro);
  1266. }
  1267. // Add preprocessor definitions for this target and configuration.
  1268. this->AddCompileDefinitions(defines, target, config, lang);
  1269. }
  1270. std::string cmLocalGenerator::GetTargetFortranFlags(
  1271. cmGeneratorTarget const* /*unused*/, std::string const& /*unused*/)
  1272. {
  1273. // Implemented by specific generators that override this.
  1274. return std::string();
  1275. }
  1276. std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib,
  1277. OutputFormat format)
  1278. {
  1279. #if defined(_WIN32) && !defined(__CYGWIN__)
  1280. // Work-ardound command line parsing limitations in MSVC 6.0
  1281. if (this->Makefile->IsOn("MSVC60")) {
  1282. // Search for the last space.
  1283. std::string::size_type pos = lib.rfind(' ');
  1284. if (pos != lib.npos) {
  1285. // Find the slash after the last space, if any.
  1286. pos = lib.find('/', pos);
  1287. // Convert the portion of the path with a space to a short path.
  1288. std::string sp;
  1289. if (cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp)) {
  1290. // Append the rest of the path with no space.
  1291. sp += lib.substr(pos);
  1292. // Convert to an output path.
  1293. return this->ConvertToOutputFormat(sp.c_str(), format);
  1294. }
  1295. }
  1296. }
  1297. #endif
  1298. // Normal behavior.
  1299. return this->ConvertToOutputFormat(
  1300. this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), lib),
  1301. format);
  1302. }
  1303. /**
  1304. * Output the linking rules on a command line. For executables,
  1305. * targetLibrary should be a NULL pointer. For libraries, it should point
  1306. * to the name of the library. This will not link a library against itself.
  1307. */
  1308. void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
  1309. std::string& frameworkPath,
  1310. std::string& linkPath,
  1311. cmGeneratorTarget& tgt, bool relink,
  1312. bool forResponseFile,
  1313. bool useWatcomQuote)
  1314. {
  1315. OutputFormat shellFormat =
  1316. (forResponseFile) ? RESPONSE : ((useWatcomQuote) ? WATCOMQUOTE : SHELL);
  1317. bool escapeAllowMakeVars = !forResponseFile;
  1318. std::ostringstream fout;
  1319. std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1320. cmComputeLinkInformation* pcli = tgt.GetLinkInformation(config);
  1321. if (!pcli) {
  1322. return;
  1323. }
  1324. cmComputeLinkInformation& cli = *pcli;
  1325. std::string linkLanguage = cli.GetLinkLanguage();
  1326. std::string linkLibs = this->GetLinkLibsCMP0065(linkLanguage, tgt);
  1327. std::string libPathFlag =
  1328. this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
  1329. std::string libPathTerminator =
  1330. this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
  1331. // Append the framework search path flags.
  1332. std::string fwSearchFlagVar = "CMAKE_";
  1333. fwSearchFlagVar += linkLanguage;
  1334. fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
  1335. const char* fwSearchFlag = this->Makefile->GetDefinition(fwSearchFlagVar);
  1336. if (fwSearchFlag && *fwSearchFlag) {
  1337. std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
  1338. for (std::vector<std::string>::const_iterator fdi = fwDirs.begin();
  1339. fdi != fwDirs.end(); ++fdi) {
  1340. frameworkPath += fwSearchFlag;
  1341. frameworkPath += this->ConvertToOutputFormat(*fdi, shellFormat);
  1342. frameworkPath += " ";
  1343. }
  1344. }
  1345. // Append the library search path flags.
  1346. std::vector<std::string> const& libDirs = cli.GetDirectories();
  1347. for (std::vector<std::string>::const_iterator libDir = libDirs.begin();
  1348. libDir != libDirs.end(); ++libDir) {
  1349. std::string libpath =
  1350. this->ConvertToOutputForExisting(*libDir, shellFormat);
  1351. linkPath += " " + libPathFlag;
  1352. linkPath += libpath;
  1353. linkPath += libPathTerminator;
  1354. linkPath += " ";
  1355. }
  1356. // Append the link items.
  1357. typedef cmComputeLinkInformation::ItemVector ItemVector;
  1358. ItemVector const& items = cli.GetItems();
  1359. for (ItemVector::const_iterator li = items.begin(); li != items.end();
  1360. ++li) {
  1361. if (li->Target && li->Target->GetType() == cmState::INTERFACE_LIBRARY) {
  1362. continue;
  1363. }
  1364. if (li->IsPath) {
  1365. linkLibs += this->ConvertToLinkReference(li->Value, shellFormat);
  1366. } else {
  1367. linkLibs += li->Value;
  1368. }
  1369. linkLibs += " ";
  1370. }
  1371. // Check what kind of rpath flags to use.
  1372. if (cli.GetRuntimeSep().empty()) {
  1373. // Each rpath entry gets its own option ("-R a -R b -R c")
  1374. std::vector<std::string> runtimeDirs;
  1375. cli.GetRPath(runtimeDirs, relink);
  1376. std::string rpath;
  1377. for (std::vector<std::string>::iterator ri = runtimeDirs.begin();
  1378. ri != runtimeDirs.end(); ++ri) {
  1379. rpath += cli.GetRuntimeFlag();
  1380. rpath += this->ConvertToOutputFormat(*ri, shellFormat);
  1381. rpath += " ";
  1382. }
  1383. fout << rpath;
  1384. } else {
  1385. // All rpath entries are combined ("-Wl,-rpath,a:b:c").
  1386. std::string rpath = cli.GetRPathString(relink);
  1387. // Store the rpath option in the stream.
  1388. if (!rpath.empty()) {
  1389. fout << cli.GetRuntimeFlag();
  1390. fout << this->EscapeForShell(rpath, escapeAllowMakeVars);
  1391. fout << " ";
  1392. }
  1393. }
  1394. // Write the library flags to the build rule.
  1395. fout << linkLibs;
  1396. // Add the linker runtime search path if any.
  1397. std::string rpath_link = cli.GetRPathLinkString();
  1398. if (!cli.GetRPathLinkFlag().empty() && !rpath_link.empty()) {
  1399. fout << cli.GetRPathLinkFlag();
  1400. fout << this->EscapeForShell(rpath_link, escapeAllowMakeVars);
  1401. fout << " ";
  1402. }
  1403. // Add standard libraries for this language.
  1404. std::string standardLibsVar = "CMAKE_";
  1405. standardLibsVar += cli.GetLinkLanguage();
  1406. standardLibsVar += "_STANDARD_LIBRARIES";
  1407. if (const char* stdLibs = this->Makefile->GetDefinition(standardLibsVar)) {
  1408. fout << stdLibs << " ";
  1409. }
  1410. linkLibraries = fout.str();
  1411. }
  1412. std::string cmLocalGenerator::GetLinkLibsCMP0065(
  1413. std::string const& linkLanguage, cmGeneratorTarget& tgt) const
  1414. {
  1415. std::string linkFlags;
  1416. // Flags to link an executable to shared libraries.
  1417. if (tgt.GetType() == cmState::EXECUTABLE &&
  1418. this->StateSnapshot.GetState()->GetGlobalPropertyAsBool(
  1419. "TARGET_SUPPORTS_SHARED_LIBS")) {
  1420. bool add_shlib_flags = false;
  1421. switch (tgt.GetPolicyStatusCMP0065()) {
  1422. case cmPolicies::WARN:
  1423. if (!tgt.GetPropertyAsBool("ENABLE_EXPORTS") &&
  1424. this->Makefile->PolicyOptionalWarningEnabled(
  1425. "CMAKE_POLICY_WARNING_CMP0065")) {
  1426. std::ostringstream w;
  1427. /* clang-format off */
  1428. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0065) << "\n"
  1429. "For compatibility with older versions of CMake, "
  1430. "additional flags may be added to export symbols on all "
  1431. "executables regardless of their ENABLE_EXPORTS property.";
  1432. /* clang-format on */
  1433. this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  1434. }
  1435. case cmPolicies::OLD:
  1436. // OLD behavior is to always add the flags
  1437. add_shlib_flags = true;
  1438. break;
  1439. case cmPolicies::REQUIRED_IF_USED:
  1440. case cmPolicies::REQUIRED_ALWAYS:
  1441. this->IssueMessage(
  1442. cmake::FATAL_ERROR,
  1443. cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0065));
  1444. case cmPolicies::NEW:
  1445. // NEW behavior is to only add the flags if ENABLE_EXPORTS is on
  1446. add_shlib_flags = tgt.GetPropertyAsBool("ENABLE_EXPORTS");
  1447. break;
  1448. }
  1449. if (add_shlib_flags) {
  1450. std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
  1451. linkFlagsVar += linkLanguage;
  1452. linkFlagsVar += "_FLAGS";
  1453. linkFlags = this->Makefile->GetSafeDefinition(linkFlagsVar);
  1454. }
  1455. }
  1456. return linkFlags;
  1457. }
  1458. void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
  1459. cmGeneratorTarget const* target,
  1460. const std::string& lang,
  1461. const std::string& config)
  1462. {
  1463. // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone):
  1464. if (this->Makefile->IsOn("APPLE") && this->EmitUniversalBinaryFlags) {
  1465. std::vector<std::string> archs;
  1466. target->GetAppleArchs(config, archs);
  1467. const char* sysroot = this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
  1468. if (sysroot && sysroot[0] == '/' && !sysroot[1]) {
  1469. sysroot = CM_NULLPTR;
  1470. }
  1471. std::string sysrootFlagVar =
  1472. std::string("CMAKE_") + lang + "_SYSROOT_FLAG";
  1473. const char* sysrootFlag = this->Makefile->GetDefinition(sysrootFlagVar);
  1474. const char* deploymentTarget =
  1475. this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
  1476. std::string deploymentTargetFlagVar =
  1477. std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG";
  1478. const char* deploymentTargetFlag =
  1479. this->Makefile->GetDefinition(deploymentTargetFlagVar);
  1480. if (!archs.empty() && !lang.empty() &&
  1481. (lang[0] == 'C' || lang[0] == 'F')) {
  1482. for (std::vector<std::string>::iterator i = archs.begin();
  1483. i != archs.end(); ++i) {
  1484. flags += " -arch ";
  1485. flags += *i;
  1486. }
  1487. }
  1488. if (sysrootFlag && *sysrootFlag && sysroot && *sysroot) {
  1489. flags += " ";
  1490. flags += sysrootFlag;
  1491. flags += " ";
  1492. flags += this->ConvertToOutputFormat(sysroot, SHELL);
  1493. }
  1494. if (deploymentTargetFlag && *deploymentTargetFlag && deploymentTarget &&
  1495. *deploymentTarget) {
  1496. flags += " ";
  1497. flags += deploymentTargetFlag;
  1498. flags += deploymentTarget;
  1499. }
  1500. }
  1501. }
  1502. void cmLocalGenerator::AddLanguageFlags(std::string& flags,
  1503. const std::string& lang,
  1504. const std::string& config)
  1505. {
  1506. // Add language-specific flags.
  1507. std::string flagsVar = "CMAKE_";
  1508. flagsVar += lang;
  1509. flagsVar += "_FLAGS";
  1510. this->AddConfigVariableFlags(flags, flagsVar, config);
  1511. }
  1512. cmGeneratorTarget* cmLocalGenerator::FindGeneratorTargetToUse(
  1513. const std::string& name) const
  1514. {
  1515. std::vector<cmGeneratorTarget*>::const_iterator imported = std::find_if(
  1516. this->ImportedGeneratorTargets.begin(),
  1517. this->ImportedGeneratorTargets.end(), NamedGeneratorTargetFinder(name));
  1518. if (imported != this->ImportedGeneratorTargets.end()) {
  1519. return *imported;
  1520. }
  1521. if (cmGeneratorTarget* t = this->FindLocalNonAliasGeneratorTarget(name)) {
  1522. return t;
  1523. }
  1524. return this->GetGlobalGenerator()->FindGeneratorTarget(name);
  1525. }
  1526. bool cmLocalGenerator::GetRealDependency(const std::string& inName,
  1527. const std::string& config,
  1528. std::string& dep)
  1529. {
  1530. // Older CMake code may specify the dependency using the target
  1531. // output file rather than the target name. Such code would have
  1532. // been written before there was support for target properties that
  1533. // modify the name so stripping down to just the file name should
  1534. // produce the target name in this case.
  1535. std::string name = cmSystemTools::GetFilenameName(inName);
  1536. // If the input name is the empty string, there is no real
  1537. // dependency. Short-circuit the other checks:
  1538. if (name == "") {
  1539. return false;
  1540. }
  1541. if (cmSystemTools::GetFilenameLastExtension(name) == ".exe") {
  1542. name = cmSystemTools::GetFilenameWithoutLastExtension(name);
  1543. }
  1544. // Look for a CMake target with the given name.
  1545. if (cmGeneratorTarget* target = this->FindGeneratorTargetToUse(name)) {
  1546. // make sure it is not just a coincidence that the target name
  1547. // found is part of the inName
  1548. if (cmSystemTools::FileIsFullPath(inName.c_str())) {
  1549. std::string tLocation;
  1550. if (target->GetType() >= cmState::EXECUTABLE &&
  1551. target->GetType() <= cmState::MODULE_LIBRARY) {
  1552. tLocation = target->GetLocation(config);
  1553. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1554. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  1555. }
  1556. std::string depLocation =
  1557. cmSystemTools::GetFilenamePath(std::string(inName));
  1558. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  1559. if (depLocation != tLocation) {
  1560. // it is a full path to a depend that has the same name
  1561. // as a target but is in a different location so do not use
  1562. // the target as the depend
  1563. dep = inName;
  1564. return true;
  1565. }
  1566. }
  1567. switch (target->GetType()) {
  1568. case cmState::EXECUTABLE:
  1569. case cmState::STATIC_LIBRARY:
  1570. case cmState::SHARED_LIBRARY:
  1571. case cmState::MODULE_LIBRARY:
  1572. case cmState::UNKNOWN_LIBRARY:
  1573. dep = target->GetLocation(config);
  1574. return true;
  1575. case cmState::OBJECT_LIBRARY:
  1576. // An object library has no single file on which to depend.
  1577. // This was listed to get the target-level dependency.
  1578. return false;
  1579. case cmState::INTERFACE_LIBRARY:
  1580. // An interface library has no file on which to depend.
  1581. // This was listed to get the target-level dependency.
  1582. return false;
  1583. case cmState::UTILITY:
  1584. case cmState::GLOBAL_TARGET:
  1585. // A utility target has no file on which to depend. This was listed
  1586. // only to get the target-level dependency.
  1587. return false;
  1588. }
  1589. }
  1590. // The name was not that of a CMake target. It must name a file.
  1591. if (cmSystemTools::FileIsFullPath(inName.c_str())) {
  1592. // This is a full path. Return it as given.
  1593. dep = inName;
  1594. return true;
  1595. }
  1596. // Check for a source file in this directory that matches the
  1597. // dependency.
  1598. if (cmSourceFile* sf = this->Makefile->GetSource(inName)) {
  1599. dep = sf->GetFullPath();
  1600. return true;
  1601. }
  1602. // Treat the name as relative to the source directory in which it
  1603. // was given.
  1604. dep = this->StateSnapshot.GetDirectory().GetCurrentSource();
  1605. dep += "/";
  1606. dep += inName;
  1607. return true;
  1608. }
  1609. void cmLocalGenerator::AddSharedFlags(std::string& flags,
  1610. const std::string& lang, bool shared)
  1611. {
  1612. std::string flagsVar;
  1613. // Add flags for dealing with shared libraries for this language.
  1614. if (shared) {
  1615. flagsVar = "CMAKE_SHARED_LIBRARY_";
  1616. flagsVar += lang;
  1617. flagsVar += "_FLAGS";
  1618. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  1619. }
  1620. }
  1621. void cmLocalGenerator::AddCompilerRequirementFlag(
  1622. std::string& flags, cmGeneratorTarget const* target, const std::string& lang)
  1623. {
  1624. if (lang.empty()) {
  1625. return;
  1626. }
  1627. const char* defaultStd =
  1628. this->Makefile->GetDefinition("CMAKE_" + lang + "_STANDARD_DEFAULT");
  1629. if (!defaultStd || !*defaultStd) {
  1630. // This compiler has no notion of language standard levels.
  1631. return;
  1632. }
  1633. std::string stdProp = lang + "_STANDARD";
  1634. const char* standardProp = target->GetProperty(stdProp);
  1635. if (!standardProp) {
  1636. return;
  1637. }
  1638. std::string extProp = lang + "_EXTENSIONS";
  1639. std::string type = "EXTENSION";
  1640. bool ext = true;
  1641. if (const char* extPropValue = target->GetProperty(extProp)) {
  1642. if (cmSystemTools::IsOff(extPropValue)) {
  1643. ext = false;
  1644. type = "STANDARD";
  1645. }
  1646. }
  1647. if (target->GetPropertyAsBool(lang + "_STANDARD_REQUIRED")) {
  1648. std::string option_flag =
  1649. "CMAKE_" + lang + standardProp + "_" + type + "_COMPILE_OPTION";
  1650. const char* opt =
  1651. target->Target->GetMakefile()->GetDefinition(option_flag);
  1652. if (!opt) {
  1653. std::ostringstream e;
  1654. e << "Target \"" << target->GetName() << "\" requires the language "
  1655. "dialect \""
  1656. << lang << standardProp << "\" "
  1657. << (ext ? "(with compiler extensions)" : "")
  1658. << ", but CMake "
  1659. "does not know the compile flags to use to enable it.";
  1660. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  1661. } else {
  1662. this->AppendFlagEscape(flags, opt);
  1663. }
  1664. return;
  1665. }
  1666. static std::map<std::string, std::vector<std::string> > langStdMap;
  1667. if (langStdMap.empty()) {
  1668. // Maintain sorted order, most recent first.
  1669. langStdMap["CXX"].push_back("14");
  1670. langStdMap["CXX"].push_back("11");
  1671. langStdMap["CXX"].push_back("98");
  1672. langStdMap["C"].push_back("11");
  1673. langStdMap["C"].push_back("99");
  1674. langStdMap["C"].push_back("90");
  1675. }
  1676. std::string standard(standardProp);
  1677. std::vector<std::string>& stds = langStdMap[lang];
  1678. std::vector<std::string>::const_iterator stdIt =
  1679. std::find(stds.begin(), stds.end(), standard);
  1680. if (stdIt == stds.end()) {
  1681. std::string e =
  1682. lang + "_STANDARD is set to invalid value '" + standard + "'";
  1683. this->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
  1684. cmake::FATAL_ERROR, e, target->GetBacktrace());
  1685. return;
  1686. }
  1687. std::vector<std::string>::const_iterator defaultStdIt =
  1688. std::find(stds.begin(), stds.end(), defaultStd);
  1689. if (defaultStdIt == stds.end()) {
  1690. std::string e = "CMAKE_" + lang +
  1691. "_STANDARD_DEFAULT is set to invalid value '" + std::string(defaultStd) +
  1692. "'";
  1693. this->IssueMessage(cmake::INTERNAL_ERROR, e);
  1694. return;
  1695. }
  1696. // Greater or equal because the standards are stored in
  1697. // backward chronological order.
  1698. if (stdIt >= defaultStdIt) {
  1699. std::string option_flag =
  1700. "CMAKE_" + lang + *stdIt + "_" + type + "_COMPILE_OPTION";
  1701. const char* opt =
  1702. target->Target->GetMakefile()->GetRequiredDefinition(option_flag);
  1703. this->AppendFlagEscape(flags, opt);
  1704. return;
  1705. }
  1706. for (; stdIt < defaultStdIt; ++stdIt) {
  1707. std::string option_flag =
  1708. "CMAKE_" + lang + *stdIt + "_" + type + "_COMPILE_OPTION";
  1709. if (const char* opt =
  1710. target->Target->GetMakefile()->GetDefinition(option_flag)) {
  1711. this->AppendFlagEscape(flags, opt);
  1712. return;
  1713. }
  1714. }
  1715. }
  1716. static void AddVisibilityCompileOption(std::string& flags,
  1717. cmGeneratorTarget const* target,
  1718. cmLocalGenerator* lg,
  1719. const std::string& lang,
  1720. std::string* warnCMP0063)
  1721. {
  1722. std::string compileOption = "CMAKE_" + lang + "_COMPILE_OPTIONS_VISIBILITY";
  1723. const char* opt = lg->GetMakefile()->GetDefinition(compileOption);
  1724. if (!opt) {
  1725. return;
  1726. }
  1727. std::string flagDefine = lang + "_VISIBILITY_PRESET";
  1728. const char* prop = target->GetProperty(flagDefine);
  1729. if (!prop) {
  1730. return;
  1731. }
  1732. if (warnCMP0063) {
  1733. *warnCMP0063 += " " + flagDefine + "\n";
  1734. return;
  1735. }
  1736. if (strcmp(prop, "hidden") != 0 && strcmp(prop, "default") != 0 &&
  1737. strcmp(prop, "protected") != 0 && strcmp(prop, "internal") != 0) {
  1738. std::ostringstream e;
  1739. e << "Target " << target->GetName() << " uses unsupported value \"" << prop
  1740. << "\" for " << flagDefine << ".";
  1741. cmSystemTools::Error(e.str().c_str());
  1742. return;
  1743. }
  1744. std::string option = std::string(opt) + prop;
  1745. lg->AppendFlags(flags, option);
  1746. }
  1747. static void AddInlineVisibilityCompileOption(std::string& flags,
  1748. cmGeneratorTarget const* target,
  1749. cmLocalGenerator* lg,
  1750. std::string* warnCMP0063)
  1751. {
  1752. std::string compileOption =
  1753. "CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN";
  1754. const char* opt = lg->GetMakefile()->GetDefinition(compileOption);
  1755. if (!opt) {
  1756. return;
  1757. }
  1758. bool prop = target->GetPropertyAsBool("VISIBILITY_INLINES_HIDDEN");
  1759. if (!prop) {
  1760. return;
  1761. }
  1762. if (warnCMP0063) {
  1763. *warnCMP0063 += " VISIBILITY_INLINES_HIDDEN\n";
  1764. return;
  1765. }
  1766. lg->AppendFlags(flags, opt);
  1767. }
  1768. void cmLocalGenerator::AddVisibilityPresetFlags(
  1769. std::string& flags, cmGeneratorTarget const* target, const std::string& lang)
  1770. {
  1771. if (lang.empty()) {
  1772. return;
  1773. }
  1774. std::string warnCMP0063;
  1775. std::string* pWarnCMP0063 = CM_NULLPTR;
  1776. if (target->GetType() != cmState::SHARED_LIBRARY &&
  1777. target->GetType() != cmState::MODULE_LIBRARY &&
  1778. !target->IsExecutableWithExports()) {
  1779. switch (target->GetPolicyStatusCMP0063()) {
  1780. case cmPolicies::OLD:
  1781. return;
  1782. case cmPolicies::WARN:
  1783. pWarnCMP0063 = &warnCMP0063;
  1784. break;
  1785. default:
  1786. break;
  1787. }
  1788. }
  1789. AddVisibilityCompileOption(flags, target, this, lang, pWarnCMP0063);
  1790. if (lang == "CXX") {
  1791. AddInlineVisibilityCompileOption(flags, target, this, pWarnCMP0063);
  1792. }
  1793. if (!warnCMP0063.empty() && this->WarnCMP0063.insert(target).second) {
  1794. std::ostringstream w;
  1795. /* clang-format off */
  1796. w <<
  1797. cmPolicies::GetPolicyWarning(cmPolicies::CMP0063) << "\n"
  1798. "Target \"" << target->GetName() << "\" of "
  1799. "type \"" << cmState::GetTargetTypeName(target->GetType()) << "\" "
  1800. "has the following visibility properties set for " << lang << ":\n" <<
  1801. warnCMP0063 <<
  1802. "For compatibility CMake is not honoring them for this target.";
  1803. /* clang-format on */
  1804. target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  1805. cmake::AUTHOR_WARNING, w.str(), target->GetBacktrace());
  1806. }
  1807. }
  1808. void cmLocalGenerator::AddCMP0018Flags(std::string& flags,
  1809. cmGeneratorTarget const* target,
  1810. std::string const& lang,
  1811. const std::string& config)
  1812. {
  1813. int targetType = target->GetType();
  1814. bool shared = ((targetType == cmState::SHARED_LIBRARY) ||
  1815. (targetType == cmState::MODULE_LIBRARY));
  1816. if (this->GetShouldUseOldFlags(shared, lang)) {
  1817. this->AddSharedFlags(flags, lang, shared);
  1818. } else {
  1819. if (target->GetType() == cmState::OBJECT_LIBRARY) {
  1820. if (target->GetPropertyAsBool("POSITION_INDEPENDENT_CODE")) {
  1821. this->AddPositionIndependentFlags(flags, lang, targetType);
  1822. }
  1823. return;
  1824. }
  1825. if (target->GetLinkInterfaceDependentBoolProperty(
  1826. "POSITION_INDEPENDENT_CODE", config)) {
  1827. this->AddPositionIndependentFlags(flags, lang, targetType);
  1828. }
  1829. if (shared) {
  1830. this->AppendFeatureOptions(flags, lang, "DLL");
  1831. }
  1832. }
  1833. }
  1834. bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
  1835. const std::string& lang) const
  1836. {
  1837. std::string originalFlags =
  1838. this->GlobalGenerator->GetSharedLibFlagsForLanguage(lang);
  1839. if (shared) {
  1840. std::string flagsVar = "CMAKE_SHARED_LIBRARY_";
  1841. flagsVar += lang;
  1842. flagsVar += "_FLAGS";
  1843. const char* flags = this->Makefile->GetSafeDefinition(flagsVar);
  1844. if (flags && flags != originalFlags) {
  1845. switch (this->GetPolicyStatus(cmPolicies::CMP0018)) {
  1846. case cmPolicies::WARN: {
  1847. std::ostringstream e;
  1848. e << "Variable " << flagsVar
  1849. << " has been modified. CMake "
  1850. "will ignore the POSITION_INDEPENDENT_CODE target property for "
  1851. "shared libraries and will use the "
  1852. << flagsVar
  1853. << " variable "
  1854. "instead. This may cause errors if the original content of "
  1855. << flagsVar << " was removed.\n"
  1856. << cmPolicies::GetPolicyWarning(cmPolicies::CMP0018);
  1857. this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  1858. // fall through to OLD behaviour
  1859. }
  1860. case cmPolicies::OLD:
  1861. return true;
  1862. case cmPolicies::REQUIRED_IF_USED:
  1863. case cmPolicies::REQUIRED_ALWAYS:
  1864. case cmPolicies::NEW:
  1865. return false;
  1866. }
  1867. }
  1868. }
  1869. return false;
  1870. }
  1871. void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
  1872. std::string const& lang,
  1873. int targetType)
  1874. {
  1875. const char* picFlags = CM_NULLPTR;
  1876. if (targetType == cmState::EXECUTABLE) {
  1877. std::string flagsVar = "CMAKE_";
  1878. flagsVar += lang;
  1879. flagsVar += "_COMPILE_OPTIONS_PIE";
  1880. picFlags = this->Makefile->GetSafeDefinition(flagsVar);
  1881. }
  1882. if (!picFlags) {
  1883. std::string flagsVar = "CMAKE_";
  1884. flagsVar += lang;
  1885. flagsVar += "_COMPILE_OPTIONS_PIC";
  1886. picFlags = this->Makefile->GetSafeDefinition(flagsVar);
  1887. }
  1888. if (picFlags) {
  1889. std::vector<std::string> options;
  1890. cmSystemTools::ExpandListArgument(picFlags, options);
  1891. for (std::vector<std::string>::const_iterator oi = options.begin();
  1892. oi != options.end(); ++oi) {
  1893. this->AppendFlagEscape(flags, *oi);
  1894. }
  1895. }
  1896. }
  1897. void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
  1898. const std::string& var,
  1899. const std::string& config)
  1900. {
  1901. // Add the flags from the variable itself.
  1902. std::string flagsVar = var;
  1903. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  1904. // Add the flags from the build-type specific variable.
  1905. if (!config.empty()) {
  1906. flagsVar += "_";
  1907. flagsVar += cmSystemTools::UpperCase(config);
  1908. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  1909. }
  1910. }
  1911. void cmLocalGenerator::AppendFlags(std::string& flags,
  1912. const std::string& newFlags)
  1913. {
  1914. if (!newFlags.empty()) {
  1915. if (!flags.empty()) {
  1916. flags += " ";
  1917. }
  1918. flags += newFlags;
  1919. }
  1920. }
  1921. void cmLocalGenerator::AppendFlags(std::string& flags, const char* newFlags)
  1922. {
  1923. if (newFlags && *newFlags) {
  1924. this->AppendFlags(flags, std::string(newFlags));
  1925. }
  1926. }
  1927. void cmLocalGenerator::AppendFlagEscape(std::string& flags,
  1928. const std::string& rawFlag)
  1929. {
  1930. this->AppendFlags(flags, this->EscapeForShell(rawFlag));
  1931. }
  1932. void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
  1933. const char* defines_list) const
  1934. {
  1935. // Short-circuit if there are no definitions.
  1936. if (!defines_list) {
  1937. return;
  1938. }
  1939. // Expand the list of definitions.
  1940. std::vector<std::string> defines_vec;
  1941. cmSystemTools::ExpandListArgument(defines_list, defines_vec);
  1942. this->AppendDefines(defines, defines_vec);
  1943. }
  1944. void cmLocalGenerator::AppendDefines(
  1945. std::set<std::string>& defines,
  1946. const std::vector<std::string>& defines_vec) const
  1947. {
  1948. for (std::vector<std::string>::const_iterator di = defines_vec.begin();
  1949. di != defines_vec.end(); ++di) {
  1950. // Skip unsupported definitions.
  1951. if (!this->CheckDefinition(*di)) {
  1952. continue;
  1953. }
  1954. defines.insert(*di);
  1955. }
  1956. }
  1957. void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
  1958. std::string& definesString,
  1959. const std::string& lang)
  1960. {
  1961. // Lookup the define flag for the current language.
  1962. std::string dflag = "-D";
  1963. if (!lang.empty()) {
  1964. std::string defineFlagVar = "CMAKE_";
  1965. defineFlagVar += lang;
  1966. defineFlagVar += "_DEFINE_FLAG";
  1967. const char* df = this->Makefile->GetDefinition(defineFlagVar);
  1968. if (df && *df) {
  1969. dflag = df;
  1970. }
  1971. }
  1972. std::set<std::string>::const_iterator defineIt = defines.begin();
  1973. const std::set<std::string>::const_iterator defineEnd = defines.end();
  1974. const char* itemSeparator = definesString.empty() ? "" : " ";
  1975. for (; defineIt != defineEnd; ++defineIt) {
  1976. // Append the definition with proper escaping.
  1977. std::string def = dflag;
  1978. if (this->GetState()->UseWatcomWMake()) {
  1979. // The Watcom compiler does its own command line parsing instead
  1980. // of using the windows shell rules. Definitions are one of
  1981. // -DNAME
  1982. // -DNAME=<cpp-token>
  1983. // -DNAME="c-string with spaces and other characters(?@#$)"
  1984. //
  1985. // Watcom will properly parse each of these cases from the
  1986. // command line without any escapes. However we still have to
  1987. // get the '$' and '#' characters through WMake as '$$' and
  1988. // '$#'.
  1989. for (const char* c = defineIt->c_str(); *c; ++c) {
  1990. if (*c == '$' || *c == '#') {
  1991. def += '$';
  1992. }
  1993. def += *c;
  1994. }
  1995. } else {
  1996. // Make the definition appear properly on the command line. Use
  1997. // -DNAME="value" instead of -D"NAME=value" for historical reasons.
  1998. std::string::size_type eq = defineIt->find("=");
  1999. def += defineIt->substr(0, eq);
  2000. if (eq != defineIt->npos) {
  2001. def += "=";
  2002. def += this->EscapeForShell(defineIt->c_str() + eq + 1, true);
  2003. }
  2004. }
  2005. definesString += itemSeparator;
  2006. itemSeparator = " ";
  2007. definesString += def;
  2008. }
  2009. }
  2010. void cmLocalGenerator::AppendFeatureOptions(std::string& flags,
  2011. const std::string& lang,
  2012. const char* feature)
  2013. {
  2014. std::string optVar = "CMAKE_";
  2015. optVar += lang;
  2016. optVar += "_COMPILE_OPTIONS_";
  2017. optVar += feature;
  2018. if (const char* optionList = this->Makefile->GetDefinition(optVar)) {
  2019. std::vector<std::string> options;
  2020. cmSystemTools::ExpandListArgument(optionList, options);
  2021. for (std::vector<std::string>::const_iterator oi = options.begin();
  2022. oi != options.end(); ++oi) {
  2023. this->AppendFlagEscape(flags, *oi);
  2024. }
  2025. }
  2026. }
  2027. const char* cmLocalGenerator::GetFeature(const std::string& feature,
  2028. const std::string& config)
  2029. {
  2030. std::string featureName = feature;
  2031. // TODO: Define accumulation policy for features (prepend, append, replace).
  2032. // Currently we always replace.
  2033. if (!config.empty()) {
  2034. featureName += "_";
  2035. featureName += cmSystemTools::UpperCase(config);
  2036. }
  2037. cmState::Snapshot snp = this->StateSnapshot;
  2038. while (snp.IsValid()) {
  2039. if (const char* value = snp.GetDirectory().GetProperty(featureName)) {
  2040. return value;
  2041. }
  2042. snp = snp.GetBuildsystemDirectoryParent();
  2043. }
  2044. return CM_NULLPTR;
  2045. }
  2046. std::string cmLocalGenerator::GetProjectName() const
  2047. {
  2048. return this->StateSnapshot.GetProjectName();
  2049. }
  2050. std::string cmLocalGenerator::ConstructComment(
  2051. cmCustomCommandGenerator const& ccg, const char* default_comment)
  2052. {
  2053. // Check for a comment provided with the command.
  2054. if (ccg.GetComment()) {
  2055. return ccg.GetComment();
  2056. }
  2057. // Construct a reasonable default comment if possible.
  2058. if (!ccg.GetOutputs().empty()) {
  2059. std::string comment;
  2060. comment = "Generating ";
  2061. const char* sep = "";
  2062. std::string currentBinaryDir = this->GetCurrentBinaryDirectory();
  2063. for (std::vector<std::string>::const_iterator o = ccg.GetOutputs().begin();
  2064. o != ccg.GetOutputs().end(); ++o) {
  2065. comment += sep;
  2066. comment += this->ConvertToRelativePath(currentBinaryDir, *o);
  2067. sep = ", ";
  2068. }
  2069. return comment;
  2070. }
  2071. // Otherwise use the provided default.
  2072. return default_comment;
  2073. }
  2074. class cmInstallTargetGeneratorLocal : public cmInstallTargetGenerator
  2075. {
  2076. public:
  2077. cmInstallTargetGeneratorLocal(cmLocalGenerator* lg, std::string const& t,
  2078. const char* dest, bool implib)
  2079. : cmInstallTargetGenerator(
  2080. t, dest, implib, "", std::vector<std::string>(), "Unspecified",
  2081. cmInstallGenerator::SelectMessageLevel(lg->GetMakefile()), false,
  2082. false)
  2083. {
  2084. this->Compute(lg);
  2085. }
  2086. };
  2087. void cmLocalGenerator::GenerateTargetInstallRules(
  2088. std::ostream& os, const std::string& config,
  2089. std::vector<std::string> const& configurationTypes)
  2090. {
  2091. // Convert the old-style install specification from each target to
  2092. // an install generator and run it.
  2093. std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
  2094. for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
  2095. l != tgts.end(); ++l) {
  2096. if ((*l)->GetType() == cmState::INTERFACE_LIBRARY) {
  2097. continue;
  2098. }
  2099. // Include the user-specified pre-install script for this target.
  2100. if (const char* preinstall = (*l)->GetProperty("PRE_INSTALL_SCRIPT")) {
  2101. cmInstallScriptGenerator g(preinstall, false, CM_NULLPTR, false);
  2102. g.Generate(os, config, configurationTypes);
  2103. }
  2104. // Install this target if a destination is given.
  2105. if ((*l)->Target->GetInstallPath() != "") {
  2106. // Compute the full install destination. Note that converting
  2107. // to unix slashes also removes any trailing slash.
  2108. // We also skip over the leading slash given by the user.
  2109. std::string destination = (*l)->Target->GetInstallPath().substr(1);
  2110. cmSystemTools::ConvertToUnixSlashes(destination);
  2111. if (destination.empty()) {
  2112. destination = ".";
  2113. }
  2114. // Generate the proper install generator for this target type.
  2115. switch ((*l)->GetType()) {
  2116. case cmState::EXECUTABLE:
  2117. case cmState::STATIC_LIBRARY:
  2118. case cmState::MODULE_LIBRARY: {
  2119. // Use a target install generator.
  2120. cmInstallTargetGeneratorLocal g(this, (*l)->GetName(),
  2121. destination.c_str(), false);
  2122. g.Generate(os, config, configurationTypes);
  2123. } break;
  2124. case cmState::SHARED_LIBRARY: {
  2125. #if defined(_WIN32) || defined(__CYGWIN__)
  2126. // Special code to handle DLL. Install the import library
  2127. // to the normal destination and the DLL to the runtime
  2128. // destination.
  2129. cmInstallTargetGeneratorLocal g1(this, (*l)->GetName(),
  2130. destination.c_str(), true);
  2131. g1.Generate(os, config, configurationTypes);
  2132. // We also skip over the leading slash given by the user.
  2133. destination = (*l)->Target->GetRuntimeInstallPath().substr(1);
  2134. cmSystemTools::ConvertToUnixSlashes(destination);
  2135. cmInstallTargetGeneratorLocal g2(this, (*l)->GetName(),
  2136. destination.c_str(), false);
  2137. g2.Generate(os, config, configurationTypes);
  2138. #else
  2139. // Use a target install generator.
  2140. cmInstallTargetGeneratorLocal g(this, (*l)->GetName(),
  2141. destination.c_str(), false);
  2142. g.Generate(os, config, configurationTypes);
  2143. #endif
  2144. } break;
  2145. default:
  2146. break;
  2147. }
  2148. }
  2149. // Include the user-specified post-install script for this target.
  2150. if (const char* postinstall = (*l)->GetProperty("POST_INSTALL_SCRIPT")) {
  2151. cmInstallScriptGenerator g(postinstall, false, CM_NULLPTR, false);
  2152. g.Generate(os, config, configurationTypes);
  2153. }
  2154. }
  2155. }
  2156. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2157. static std::string cmLocalGeneratorMD5(const char* input)
  2158. {
  2159. char md5out[32];
  2160. cmsysMD5* md5 = cmsysMD5_New();
  2161. cmsysMD5_Initialize(md5);
  2162. cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
  2163. cmsysMD5_FinalizeHex(md5, md5out);
  2164. cmsysMD5_Delete(md5);
  2165. return std::string(md5out, 32);
  2166. }
  2167. static bool cmLocalGeneratorShortenObjectName(std::string& objName,
  2168. std::string::size_type max_len)
  2169. {
  2170. // Replace the beginning of the path portion of the object name with
  2171. // its own md5 sum.
  2172. std::string::size_type pos =
  2173. objName.find('/', objName.size() - max_len + 32);
  2174. if (pos != objName.npos) {
  2175. std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
  2176. md5name += objName.substr(pos);
  2177. objName = md5name;
  2178. // The object name is now short enough.
  2179. return true;
  2180. }
  2181. // The object name could not be shortened enough.
  2182. return false;
  2183. }
  2184. bool cmLocalGeneratorCheckObjectName(std::string& objName,
  2185. std::string::size_type dir_len,
  2186. std::string::size_type max_total_len)
  2187. {
  2188. // Enforce the maximum file name length if possible.
  2189. std::string::size_type max_obj_len = max_total_len;
  2190. if (dir_len < max_total_len) {
  2191. max_obj_len = max_total_len - dir_len;
  2192. if (objName.size() > max_obj_len) {
  2193. // The current object file name is too long. Try to shorten it.
  2194. return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
  2195. }
  2196. // The object file name is short enough.
  2197. return true;
  2198. }
  2199. // The build directory in which the object will be stored is
  2200. // already too deep.
  2201. return false;
  2202. }
  2203. #endif
  2204. std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName(
  2205. const std::string& sin, std::string const& dir_max)
  2206. {
  2207. // Look for an existing mapped name for this object file.
  2208. std::map<std::string, std::string>::iterator it =
  2209. this->UniqueObjectNamesMap.find(sin);
  2210. // If no entry exists create one.
  2211. if (it == this->UniqueObjectNamesMap.end()) {
  2212. // Start with the original name.
  2213. std::string ssin = sin;
  2214. // Avoid full paths by removing leading slashes.
  2215. ssin.erase(0, ssin.find_first_not_of('/'));
  2216. // Avoid full paths by removing colons.
  2217. std::replace(ssin.begin(), ssin.end(), ':', '_');
  2218. // Avoid relative paths that go up the tree.
  2219. cmSystemTools::ReplaceString(ssin, "../", "__/");
  2220. // Avoid spaces.
  2221. std::replace(ssin.begin(), ssin.end(), ' ', '_');
  2222. // Mangle the name if necessary.
  2223. if (this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES")) {
  2224. bool done;
  2225. int cc = 0;
  2226. char rpstr[100];
  2227. sprintf(rpstr, "_p_");
  2228. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2229. std::string sssin = sin;
  2230. do {
  2231. done = true;
  2232. for (it = this->UniqueObjectNamesMap.begin();
  2233. it != this->UniqueObjectNamesMap.end(); ++it) {
  2234. if (it->second == ssin) {
  2235. done = false;
  2236. }
  2237. }
  2238. if (done) {
  2239. break;
  2240. }
  2241. sssin = ssin;
  2242. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2243. sprintf(rpstr, "_p%d_", cc++);
  2244. } while (!done);
  2245. }
  2246. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2247. if (!cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
  2248. this->ObjectPathMax)) {
  2249. // Warn if this is the first time the path has been seen.
  2250. if (this->ObjectMaxPathViolations.insert(dir_max).second) {
  2251. std::ostringstream m;
  2252. /* clang-format off */
  2253. m << "The object file directory\n"
  2254. << " " << dir_max << "\n"
  2255. << "has " << dir_max.size() << " characters. "
  2256. << "The maximum full path to an object file is "
  2257. << this->ObjectPathMax << " characters "
  2258. << "(see CMAKE_OBJECT_PATH_MAX). "
  2259. << "Object file\n"
  2260. << " " << ssin << "\n"
  2261. << "cannot be safely placed under this directory. "
  2262. << "The build may not work correctly.";
  2263. /* clang-format on */
  2264. this->IssueMessage(cmake::WARNING, m.str());
  2265. }
  2266. }
  2267. #else
  2268. (void)dir_max;
  2269. #endif
  2270. // Insert the newly mapped object file name.
  2271. std::map<std::string, std::string>::value_type e(sin, ssin);
  2272. it = this->UniqueObjectNamesMap.insert(e).first;
  2273. }
  2274. // Return the map entry.
  2275. return it->second;
  2276. }
  2277. void cmLocalGenerator::ComputeObjectFilenames(
  2278. std::map<cmSourceFile const*, std::string>& /*unused*/,
  2279. cmGeneratorTarget const* /*unused*/)
  2280. {
  2281. }
  2282. bool cmLocalGenerator::IsWindowsShell() const
  2283. {
  2284. return this->GetState()->UseWindowsShell();
  2285. }
  2286. bool cmLocalGenerator::IsWatcomWMake() const
  2287. {
  2288. return this->GetState()->UseWatcomWMake();
  2289. }
  2290. bool cmLocalGenerator::IsMinGWMake() const
  2291. {
  2292. return this->GetState()->UseMinGWMake();
  2293. }
  2294. bool cmLocalGenerator::IsNMake() const
  2295. {
  2296. return this->GetState()->UseNMake();
  2297. }
  2298. std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
  2299. const cmSourceFile& source, std::string const& dir_max,
  2300. bool* hasSourceExtension)
  2301. {
  2302. // Construct the object file name using the full path to the source
  2303. // file which is its only unique identification.
  2304. const char* fullPath = source.GetFullPath().c_str();
  2305. // Try referencing the source relative to the source tree.
  2306. std::string relFromSource =
  2307. this->ConvertToRelativePath(this->GetCurrentSourceDirectory(), fullPath);
  2308. assert(!relFromSource.empty());
  2309. bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
  2310. bool subSource = relSource && relFromSource[0] != '.';
  2311. // Try referencing the source relative to the binary tree.
  2312. std::string relFromBinary =
  2313. this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), fullPath);
  2314. assert(!relFromBinary.empty());
  2315. bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
  2316. bool subBinary = relBinary && relFromBinary[0] != '.';
  2317. // Select a nice-looking reference to the source file to construct
  2318. // the object file name.
  2319. std::string objectName;
  2320. if ((relSource && !relBinary) || (subSource && !subBinary)) {
  2321. objectName = relFromSource;
  2322. } else if ((relBinary && !relSource) || (subBinary && !subSource)) {
  2323. objectName = relFromBinary;
  2324. } else if (relFromBinary.length() < relFromSource.length()) {
  2325. objectName = relFromBinary;
  2326. } else {
  2327. objectName = relFromSource;
  2328. }
  2329. // if it is still a full path check for the try compile case
  2330. // try compile never have in source sources, and should not
  2331. // have conflicting source file names in the same target
  2332. if (cmSystemTools::FileIsFullPath(objectName.c_str())) {
  2333. if (this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile()) {
  2334. objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
  2335. }
  2336. }
  2337. // Replace the original source file extension with the object file
  2338. // extension.
  2339. bool keptSourceExtension = true;
  2340. if (!source.GetPropertyAsBool("KEEP_EXTENSION")) {
  2341. // Decide whether this language wants to replace the source
  2342. // extension with the object extension. For CMake 2.4
  2343. // compatibility do this by default.
  2344. bool replaceExt = this->NeedBackwardsCompatibility_2_4();
  2345. if (!replaceExt) {
  2346. std::string lang = source.GetLanguage();
  2347. if (!lang.empty()) {
  2348. std::string repVar = "CMAKE_";
  2349. repVar += lang;
  2350. repVar += "_OUTPUT_EXTENSION_REPLACE";
  2351. replaceExt = this->Makefile->IsOn(repVar);
  2352. }
  2353. }
  2354. // Remove the source extension if it is to be replaced.
  2355. if (replaceExt) {
  2356. keptSourceExtension = false;
  2357. std::string::size_type dot_pos = objectName.rfind('.');
  2358. if (dot_pos != std::string::npos) {
  2359. objectName = objectName.substr(0, dot_pos);
  2360. }
  2361. }
  2362. // Store the new extension.
  2363. objectName += this->GlobalGenerator->GetLanguageOutputExtension(source);
  2364. }
  2365. if (hasSourceExtension) {
  2366. *hasSourceExtension = keptSourceExtension;
  2367. }
  2368. // Convert to a safe name.
  2369. return this->CreateSafeUniqueObjectFileName(objectName, dir_max);
  2370. }
  2371. std::string cmLocalGenerator::GetSourceFileLanguage(const cmSourceFile& source)
  2372. {
  2373. return source.GetLanguage();
  2374. }
  2375. cmake* cmLocalGenerator::GetCMakeInstance() const
  2376. {
  2377. return this->GlobalGenerator->GetCMakeInstance();
  2378. }
  2379. const char* cmLocalGenerator::GetSourceDirectory() const
  2380. {
  2381. return this->GetCMakeInstance()->GetHomeDirectory();
  2382. }
  2383. const char* cmLocalGenerator::GetBinaryDirectory() const
  2384. {
  2385. return this->GetCMakeInstance()->GetHomeOutputDirectory();
  2386. }
  2387. const char* cmLocalGenerator::GetCurrentBinaryDirectory() const
  2388. {
  2389. return this->StateSnapshot.GetDirectory().GetCurrentBinary();
  2390. }
  2391. const char* cmLocalGenerator::GetCurrentSourceDirectory() const
  2392. {
  2393. return this->StateSnapshot.GetDirectory().GetCurrentSource();
  2394. }
  2395. std::string cmLocalGenerator::GetTargetDirectory(
  2396. const cmGeneratorTarget* /*unused*/) const
  2397. {
  2398. cmSystemTools::Error("GetTargetDirectory"
  2399. " called on cmLocalGenerator");
  2400. return "";
  2401. }
  2402. KWIML_INT_uint64_t cmLocalGenerator::GetBackwardsCompatibility()
  2403. {
  2404. // The computed version may change until the project is fully
  2405. // configured.
  2406. if (!this->BackwardsCompatibilityFinal) {
  2407. unsigned int major = 0;
  2408. unsigned int minor = 0;
  2409. unsigned int patch = 0;
  2410. if (const char* value =
  2411. this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY")) {
  2412. switch (sscanf(value, "%u.%u.%u", &major, &minor, &patch)) {
  2413. case 2:
  2414. patch = 0;
  2415. break;
  2416. case 1:
  2417. minor = 0;
  2418. patch = 0;
  2419. break;
  2420. default:
  2421. break;
  2422. }
  2423. }
  2424. this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
  2425. this->BackwardsCompatibilityFinal = true;
  2426. }
  2427. return this->BackwardsCompatibility;
  2428. }
  2429. bool cmLocalGenerator::NeedBackwardsCompatibility_2_4()
  2430. {
  2431. // Check the policy to decide whether to pay attention to this
  2432. // variable.
  2433. switch (this->GetPolicyStatus(cmPolicies::CMP0001)) {
  2434. case cmPolicies::WARN:
  2435. // WARN is just OLD without warning because user code does not
  2436. // always affect whether this check is done.
  2437. case cmPolicies::OLD:
  2438. // Old behavior is to check the variable.
  2439. break;
  2440. case cmPolicies::NEW:
  2441. // New behavior is to ignore the variable.
  2442. return false;
  2443. case cmPolicies::REQUIRED_IF_USED:
  2444. case cmPolicies::REQUIRED_ALWAYS:
  2445. // This will never be the case because the only way to require
  2446. // the setting is to require the user to specify version policy
  2447. // 2.6 or higher. Once we add that requirement then this whole
  2448. // method can be removed anyway.
  2449. return false;
  2450. }
  2451. // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
  2452. // equal to or lower than the given version.
  2453. KWIML_INT_uint64_t actual_compat = this->GetBackwardsCompatibility();
  2454. return (actual_compat && actual_compat <= CMake_VERSION_ENCODE(2, 4, 255));
  2455. }
  2456. cmPolicies::PolicyStatus cmLocalGenerator::GetPolicyStatus(
  2457. cmPolicies::PolicyID id) const
  2458. {
  2459. return this->Makefile->GetPolicyStatus(id);
  2460. }
  2461. bool cmLocalGenerator::CheckDefinition(std::string const& define) const
  2462. {
  2463. // Many compilers do not support -DNAME(arg)=sdf so we disable it.
  2464. std::string::size_type pos = define.find_first_of("(=");
  2465. if (pos != std::string::npos) {
  2466. if (define[pos] == '(') {
  2467. std::ostringstream e;
  2468. /* clang-format off */
  2469. e << "WARNING: Function-style preprocessor definitions may not be "
  2470. << "passed on the compiler command line because many compilers "
  2471. << "do not support it.\n"
  2472. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2473. << "Consider defining the macro in a (configured) header file.\n";
  2474. /* clang-format on */
  2475. cmSystemTools::Message(e.str().c_str());
  2476. return false;
  2477. }
  2478. }
  2479. // Many compilers do not support # in the value so we disable it.
  2480. if (define.find_first_of('#') != define.npos) {
  2481. std::ostringstream e;
  2482. /* clang-format off */
  2483. e << "WARNING: Preprocessor definitions containing '#' may not be "
  2484. << "passed on the compiler command line because many compilers "
  2485. << "do not support it.\n"
  2486. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2487. << "Consider defining the macro in a (configured) header file.\n";
  2488. /* clang-format on */
  2489. cmSystemTools::Message(e.str().c_str());
  2490. return false;
  2491. }
  2492. // Assume it is supported.
  2493. return true;
  2494. }
  2495. static void cmLGInfoProp(cmMakefile* mf, cmGeneratorTarget* target,
  2496. const std::string& prop)
  2497. {
  2498. if (const char* val = target->GetProperty(prop)) {
  2499. mf->AddDefinition(prop, val);
  2500. }
  2501. }
  2502. void cmLocalGenerator::GenerateAppleInfoPList(cmGeneratorTarget* target,
  2503. const std::string& targetName,
  2504. const char* fname)
  2505. {
  2506. // Find the Info.plist template.
  2507. const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
  2508. std::string inFile = (in && *in) ? in : "MacOSXBundleInfo.plist.in";
  2509. if (!cmSystemTools::FileIsFullPath(inFile.c_str())) {
  2510. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2511. if (!inMod.empty()) {
  2512. inFile = inMod;
  2513. }
  2514. }
  2515. if (!cmSystemTools::FileExists(inFile.c_str(), true)) {
  2516. std::ostringstream e;
  2517. e << "Target " << target->GetName() << " Info.plist template \"" << inFile
  2518. << "\" could not be found.";
  2519. cmSystemTools::Error(e.str().c_str());
  2520. return;
  2521. }
  2522. // Convert target properties to variables in an isolated makefile
  2523. // scope to configure the file. If properties are set they will
  2524. // override user make variables. If not the configuration will fall
  2525. // back to the directory-level values set by the user.
  2526. cmMakefile* mf = this->Makefile;
  2527. cmMakefile::ScopePushPop varScope(mf);
  2528. mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName.c_str());
  2529. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING");
  2530. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE");
  2531. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
  2532. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
  2533. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_NAME");
  2534. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
  2535. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
  2536. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
  2537. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2538. }
  2539. void cmLocalGenerator::GenerateFrameworkInfoPList(
  2540. cmGeneratorTarget* target, const std::string& targetName, const char* fname)
  2541. {
  2542. // Find the Info.plist template.
  2543. const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
  2544. std::string inFile = (in && *in) ? in : "MacOSXFrameworkInfo.plist.in";
  2545. if (!cmSystemTools::FileIsFullPath(inFile.c_str())) {
  2546. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2547. if (!inMod.empty()) {
  2548. inFile = inMod;
  2549. }
  2550. }
  2551. if (!cmSystemTools::FileExists(inFile.c_str(), true)) {
  2552. std::ostringstream e;
  2553. e << "Target " << target->GetName() << " Info.plist template \"" << inFile
  2554. << "\" could not be found.";
  2555. cmSystemTools::Error(e.str().c_str());
  2556. return;
  2557. }
  2558. // Convert target properties to variables in an isolated makefile
  2559. // scope to configure the file. If properties are set they will
  2560. // override user make variables. If not the configuration will fall
  2561. // back to the directory-level values set by the user.
  2562. cmMakefile* mf = this->Makefile;
  2563. cmMakefile::ScopePushPop varScope(mf);
  2564. mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName.c_str());
  2565. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE");
  2566. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
  2567. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
  2568. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
  2569. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2570. }