cmLocalGenerator.cxx 94 KB

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