cmLocalGenerator.cxx 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmLocalGenerator.h"
  11. #include "cmComputeLinkInformation.h"
  12. #include "cmGeneratedFileStream.h"
  13. #include "cmGlobalGenerator.h"
  14. #include "cmInstallGenerator.h"
  15. #include "cmInstallFilesGenerator.h"
  16. #include "cmInstallScriptGenerator.h"
  17. #include "cmInstallTargetGenerator.h"
  18. #include "cmMakefile.h"
  19. #include "cmSourceFile.h"
  20. #include "cmTest.h"
  21. #include "cmTestGenerator.h"
  22. #include "cmVersion.h"
  23. #include "cmake.h"
  24. #if defined(CMAKE_BUILD_WITH_CMAKE)
  25. # define CM_LG_ENCODE_OBJECT_NAMES
  26. # include <cmsys/MD5.h>
  27. #endif
  28. #include <cmsys/System.h>
  29. #include <ctype.h> // for isalpha
  30. #include <assert.h>
  31. #if defined(__HAIKU__)
  32. #include <StorageKit.h>
  33. #endif
  34. cmLocalGenerator::cmLocalGenerator()
  35. {
  36. this->Makefile = 0; // moved to after set on global
  37. this->Parent = 0;
  38. this->WindowsShell = false;
  39. this->WindowsVSIDE = false;
  40. this->WatcomWMake = false;
  41. this->MinGWMake = false;
  42. this->NMake = false;
  43. this->MSYSShell = false;
  44. this->LinkScriptShell = false;
  45. this->IgnoreLibPrefix = false;
  46. this->UseRelativePaths = false;
  47. this->Configured = false;
  48. this->EmitUniversalBinaryFlags = true;
  49. this->IsMakefileGenerator = false;
  50. this->RelativePathsConfigured = false;
  51. this->PathConversionsSetup = false;
  52. this->BackwardsCompatibility = 0;
  53. this->BackwardsCompatibilityFinal = false;
  54. }
  55. cmLocalGenerator::~cmLocalGenerator()
  56. {
  57. delete this->Makefile;
  58. }
  59. //----------------------------------------------------------------------------
  60. class cmLocalGeneratorCurrent
  61. {
  62. cmGlobalGenerator* GG;
  63. cmLocalGenerator* LG;
  64. public:
  65. cmLocalGeneratorCurrent(cmLocalGenerator* lg)
  66. {
  67. this->GG = lg->GetGlobalGenerator();
  68. this->LG = this->GG->GetCurrentLocalGenerator();
  69. this->GG->SetCurrentLocalGenerator(lg);
  70. }
  71. ~cmLocalGeneratorCurrent()
  72. {
  73. this->GG->SetCurrentLocalGenerator(this->LG);
  74. }
  75. };
  76. //----------------------------------------------------------------------------
  77. void cmLocalGenerator::Configure()
  78. {
  79. // Manage the global generator's current local generator.
  80. cmLocalGeneratorCurrent clg(this);
  81. static_cast<void>(clg);
  82. // make sure the CMakeFiles dir is there
  83. std::string filesDir = this->Makefile->GetStartOutputDirectory();
  84. filesDir += cmake::GetCMakeFilesDirectory();
  85. cmSystemTools::MakeDirectory(filesDir.c_str());
  86. // find & read the list file
  87. this->ReadInputFile();
  88. // at the end of the ReadListFile handle any old style subdirs
  89. // first get all the subdirectories
  90. std::vector<cmLocalGenerator *> subdirs = this->GetChildren();
  91. // for each subdir recurse
  92. std::vector<cmLocalGenerator *>::iterator sdi = subdirs.begin();
  93. for (; sdi != subdirs.end(); ++sdi)
  94. {
  95. if (!(*sdi)->Configured)
  96. {
  97. this->Makefile->ConfigureSubDirectory(*sdi);
  98. }
  99. }
  100. // Check whether relative paths should be used for optionally
  101. // relative paths.
  102. this->UseRelativePaths = this->Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");
  103. this->ComputeObjectMaxPath();
  104. this->Configured = true;
  105. }
  106. //----------------------------------------------------------------------------
  107. void cmLocalGenerator::ComputeObjectMaxPath()
  108. {
  109. // Choose a maximum object file name length.
  110. #if defined(_WIN32) || defined(__CYGWIN__)
  111. this->ObjectPathMax = 250;
  112. #else
  113. this->ObjectPathMax = 1000;
  114. #endif
  115. const char* plen = this->Makefile->GetDefinition("CMAKE_OBJECT_PATH_MAX");
  116. if(plen && *plen)
  117. {
  118. unsigned int pmax;
  119. if(sscanf(plen, "%u", &pmax) == 1)
  120. {
  121. if(pmax >= 128)
  122. {
  123. this->ObjectPathMax = pmax;
  124. }
  125. else
  126. {
  127. cmOStringStream w;
  128. w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
  129. << ", which is less than the minimum of 128. "
  130. << "The value will be ignored.";
  131. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  132. }
  133. }
  134. else
  135. {
  136. cmOStringStream w;
  137. w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
  138. << "\", which fails to parse as a positive integer. "
  139. << "The value will be ignored.";
  140. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  141. }
  142. }
  143. this->ObjectMaxPathViolations.clear();
  144. }
  145. //----------------------------------------------------------------------------
  146. void cmLocalGenerator::ReadInputFile()
  147. {
  148. // Look for the CMakeLists.txt file.
  149. std::string currentStart = this->Makefile->GetStartDirectory();
  150. currentStart += "/CMakeLists.txt";
  151. if(cmSystemTools::FileExists(currentStart.c_str(), true))
  152. {
  153. this->Makefile->ReadListFile(currentStart.c_str());
  154. return;
  155. }
  156. if(!this->Parent)
  157. {
  158. return;
  159. }
  160. // The file is missing. Check policy CMP0014.
  161. cmMakefile* mf = this->Parent->GetMakefile();
  162. cmOStringStream e;
  163. e << "The source directory\n"
  164. << " " << this->Makefile->GetStartDirectory() << "\n"
  165. << "does not contain a CMakeLists.txt file.";
  166. switch (mf->GetPolicyStatus(cmPolicies::CMP0014))
  167. {
  168. case cmPolicies::WARN:
  169. // Print the warning.
  170. e << "\n"
  171. << "CMake does not support this case but it used "
  172. << "to work accidentally and is being allowed for "
  173. << "compatibility."
  174. << "\n"
  175. << mf->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0014);
  176. mf->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  177. case cmPolicies::OLD:
  178. // OLD behavior does not warn.
  179. return;
  180. case cmPolicies::REQUIRED_IF_USED:
  181. case cmPolicies::REQUIRED_ALWAYS:
  182. e << "\n"
  183. << mf->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0014);
  184. case cmPolicies::NEW:
  185. // NEW behavior prints the error.
  186. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  187. break;
  188. }
  189. }
  190. void cmLocalGenerator::SetupPathConversions()
  191. {
  192. // Setup the current output directory components for use by
  193. // Convert
  194. std::string outdir;
  195. outdir =
  196. cmSystemTools::CollapseFullPath(this->Makefile->GetHomeDirectory());
  197. cmSystemTools::SplitPath(outdir.c_str(), this->HomeDirectoryComponents);
  198. outdir =
  199. cmSystemTools::CollapseFullPath(this->Makefile->GetStartDirectory());
  200. cmSystemTools::SplitPath(outdir.c_str(), this->StartDirectoryComponents);
  201. outdir = cmSystemTools::CollapseFullPath
  202. (this->Makefile->GetHomeOutputDirectory());
  203. cmSystemTools::SplitPath(outdir.c_str(),
  204. this->HomeOutputDirectoryComponents);
  205. outdir = cmSystemTools::CollapseFullPath
  206. (this->Makefile->GetStartOutputDirectory());
  207. cmSystemTools::SplitPath(outdir.c_str(),
  208. this->StartOutputDirectoryComponents);
  209. }
  210. void cmLocalGenerator::SetGlobalGenerator(cmGlobalGenerator *gg)
  211. {
  212. this->GlobalGenerator = gg;
  213. this->Makefile = new cmMakefile;
  214. this->Makefile->SetLocalGenerator(this);
  215. // setup the home directories
  216. this->Makefile->GetProperties().SetCMakeInstance(gg->GetCMakeInstance());
  217. this->Makefile->SetHomeDirectory(
  218. gg->GetCMakeInstance()->GetHomeDirectory());
  219. this->Makefile->SetHomeOutputDirectory(
  220. gg->GetCMakeInstance()->GetHomeOutputDirectory());
  221. }
  222. void cmLocalGenerator::ConfigureFinalPass()
  223. {
  224. this->Makefile->ConfigureFinalPass();
  225. }
  226. void cmLocalGenerator::TraceDependencies()
  227. {
  228. // Generate the rule files for each target.
  229. cmTargets& targets = this->Makefile->GetTargets();
  230. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  231. {
  232. const char* projectFilename = 0;
  233. if (this->IsMakefileGenerator == false) // only use of this variable
  234. {
  235. projectFilename = t->second.GetName();
  236. }
  237. t->second.TraceDependencies(projectFilename);
  238. }
  239. }
  240. void cmLocalGenerator::GenerateTestFiles()
  241. {
  242. if ( !this->Makefile->IsOn("CMAKE_TESTING_ENABLED") )
  243. {
  244. return;
  245. }
  246. // Compute the set of configurations.
  247. std::vector<std::string> configurationTypes;
  248. const char* config =
  249. this->Makefile->GetConfigurations(configurationTypes, false);
  250. std::string file = this->Makefile->GetStartOutputDirectory();
  251. file += "/";
  252. file += "CTestTestfile.cmake";
  253. cmGeneratedFileStream fout(file.c_str());
  254. fout.SetCopyIfDifferent(true);
  255. fout << "# CMake generated Testfile for " << std::endl
  256. << "# Source directory: "
  257. << this->Makefile->GetStartDirectory() << std::endl
  258. << "# Build directory: "
  259. << this->Makefile->GetStartOutputDirectory() << std::endl
  260. << "# " << std::endl
  261. << "# This file includes the relevent testing commands "
  262. << "required for " << std::endl
  263. << "# testing this directory and lists subdirectories to "
  264. << "be tested as well." << std::endl;
  265. const char* testIncludeFile =
  266. this->Makefile->GetProperty("TEST_INCLUDE_FILE");
  267. if ( testIncludeFile )
  268. {
  269. fout << "INCLUDE(\"" << testIncludeFile << "\")" << std::endl;
  270. }
  271. // Ask each test generator to write its code.
  272. std::vector<cmTestGenerator*> const&
  273. testers = this->Makefile->GetTestGenerators();
  274. for(std::vector<cmTestGenerator*>::const_iterator gi = testers.begin();
  275. gi != testers.end(); ++gi)
  276. {
  277. (*gi)->Generate(fout, config, configurationTypes);
  278. }
  279. if ( this->Children.size())
  280. {
  281. size_t i;
  282. for(i = 0; i < this->Children.size(); ++i)
  283. {
  284. fout << "SUBDIRS(";
  285. std::string outP =
  286. this->Children[i]->GetMakefile()->GetStartOutputDirectory();
  287. fout << this->Convert(outP.c_str(),START_OUTPUT);
  288. fout << ")" << std::endl;
  289. }
  290. }
  291. }
  292. //----------------------------------------------------------------------------
  293. void cmLocalGenerator::GenerateInstallRules()
  294. {
  295. // Compute the install prefix.
  296. const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
  297. #if defined(_WIN32) && !defined(__CYGWIN__)
  298. std::string prefix_win32;
  299. if(!prefix)
  300. {
  301. if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32))
  302. {
  303. prefix_win32 = "C:";
  304. }
  305. const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
  306. if(project_name && project_name[0])
  307. {
  308. prefix_win32 += "/Program Files/";
  309. prefix_win32 += project_name;
  310. }
  311. else
  312. {
  313. prefix_win32 += "/InstalledCMakeProject";
  314. }
  315. prefix = prefix_win32.c_str();
  316. }
  317. #elif defined(__HAIKU__)
  318. if (!prefix)
  319. {
  320. BPath dir;
  321. if (find_directory(B_COMMON_DIRECTORY, &dir) == B_OK)
  322. {
  323. prefix = dir.Path();
  324. }
  325. else
  326. {
  327. prefix = "/boot/common";
  328. }
  329. }
  330. #else
  331. if (!prefix)
  332. {
  333. prefix = "/usr/local";
  334. }
  335. #endif
  336. // Compute the set of configurations.
  337. std::vector<std::string> configurationTypes;
  338. const char* config =
  339. this->Makefile->GetConfigurations(configurationTypes, false);
  340. // Choose a default install configuration.
  341. const char* default_config = config;
  342. const char* default_order[] = {"RELEASE", "MINSIZEREL",
  343. "RELWITHDEBINFO", "DEBUG", 0};
  344. for(const char** c = default_order; *c && !default_config; ++c)
  345. {
  346. for(std::vector<std::string>::iterator i = configurationTypes.begin();
  347. i != configurationTypes.end(); ++i)
  348. {
  349. if(cmSystemTools::UpperCase(*i) == *c)
  350. {
  351. default_config = i->c_str();
  352. }
  353. }
  354. }
  355. if(!default_config && !configurationTypes.empty())
  356. {
  357. default_config = configurationTypes[0].c_str();
  358. }
  359. if(!default_config)
  360. {
  361. default_config = "Release";
  362. }
  363. // Create the install script file.
  364. std::string file = this->Makefile->GetStartOutputDirectory();
  365. std::string homedir = this->Makefile->GetHomeOutputDirectory();
  366. std::string currdir = this->Makefile->GetCurrentOutputDirectory();
  367. cmSystemTools::ConvertToUnixSlashes(file);
  368. cmSystemTools::ConvertToUnixSlashes(homedir);
  369. cmSystemTools::ConvertToUnixSlashes(currdir);
  370. int toplevel_install = 0;
  371. if ( currdir == homedir )
  372. {
  373. toplevel_install = 1;
  374. }
  375. file += "/cmake_install.cmake";
  376. cmGeneratedFileStream fout(file.c_str());
  377. fout.SetCopyIfDifferent(true);
  378. // Write the header.
  379. fout << "# Install script for directory: "
  380. << this->Makefile->GetCurrentDirectory() << std::endl << std::endl;
  381. fout << "# Set the install prefix" << std::endl
  382. << "IF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  383. << " SET(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
  384. << "ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  385. << "STRING(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
  386. << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
  387. << std::endl;
  388. // Write support code for generating per-configuration install rules.
  389. fout <<
  390. "# Set the install configuration name.\n"
  391. "IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  392. " IF(BUILD_TYPE)\n"
  393. " STRING(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
  394. " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
  395. " ELSE(BUILD_TYPE)\n"
  396. " SET(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
  397. " ENDIF(BUILD_TYPE)\n"
  398. " MESSAGE(STATUS \"Install configuration: "
  399. "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
  400. "ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  401. "\n";
  402. // Write support code for dealing with component-specific installs.
  403. fout <<
  404. "# Set the component getting installed.\n"
  405. "IF(NOT CMAKE_INSTALL_COMPONENT)\n"
  406. " IF(COMPONENT)\n"
  407. " MESSAGE(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
  408. " SET(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
  409. " ELSE(COMPONENT)\n"
  410. " SET(CMAKE_INSTALL_COMPONENT)\n"
  411. " ENDIF(COMPONENT)\n"
  412. "ENDIF(NOT CMAKE_INSTALL_COMPONENT)\n"
  413. "\n";
  414. // Copy user-specified install options to the install code.
  415. if(const char* so_no_exe =
  416. this->Makefile->GetDefinition("CMAKE_INSTALL_SO_NO_EXE"))
  417. {
  418. fout <<
  419. "# Install shared libraries without execute permission?\n"
  420. "IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
  421. " SET(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe << "\")\n"
  422. "ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
  423. "\n";
  424. }
  425. // Ask each install generator to write its code.
  426. std::vector<cmInstallGenerator*> const& installers =
  427. this->Makefile->GetInstallGenerators();
  428. for(std::vector<cmInstallGenerator*>::const_iterator
  429. gi = installers.begin();
  430. gi != installers.end(); ++gi)
  431. {
  432. (*gi)->Generate(fout, config, configurationTypes);
  433. }
  434. // Write rules from old-style specification stored in targets.
  435. this->GenerateTargetInstallRules(fout, config, configurationTypes);
  436. // Include install scripts from subdirectories.
  437. if(!this->Children.empty())
  438. {
  439. fout << "IF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
  440. fout << " # Include the install script for each subdirectory.\n";
  441. for(std::vector<cmLocalGenerator*>::const_iterator
  442. ci = this->Children.begin(); ci != this->Children.end(); ++ci)
  443. {
  444. if(!(*ci)->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  445. {
  446. std::string odir = (*ci)->GetMakefile()->GetStartOutputDirectory();
  447. cmSystemTools::ConvertToUnixSlashes(odir);
  448. fout << " INCLUDE(\"" << odir.c_str()
  449. << "/cmake_install.cmake\")" << std::endl;
  450. }
  451. }
  452. fout << "\n";
  453. fout << "ENDIF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n\n";
  454. }
  455. // Record the install manifest.
  456. if ( toplevel_install )
  457. {
  458. fout <<
  459. "IF(CMAKE_INSTALL_COMPONENT)\n"
  460. " SET(CMAKE_INSTALL_MANIFEST \"install_manifest_"
  461. "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
  462. "ELSE(CMAKE_INSTALL_COMPONENT)\n"
  463. " SET(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
  464. "ENDIF(CMAKE_INSTALL_COMPONENT)\n\n";
  465. fout
  466. << "FILE(WRITE \""
  467. << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
  468. << "\"\")" << std::endl;
  469. fout
  470. << "FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES})" << std::endl
  471. << " FILE(APPEND \""
  472. << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
  473. << "\"${file}\\n\")" << std::endl
  474. << "ENDFOREACH(file)" << std::endl;
  475. }
  476. }
  477. //----------------------------------------------------------------------------
  478. void cmLocalGenerator::GenerateTargetManifest()
  479. {
  480. // Collect the set of configuration types.
  481. std::vector<std::string> configNames;
  482. this->Makefile->GetConfigurations(configNames);
  483. // Add our targets to the manifest for each configuration.
  484. cmTargets& targets = this->Makefile->GetTargets();
  485. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  486. {
  487. cmTarget& target = t->second;
  488. if(configNames.empty())
  489. {
  490. target.GenerateTargetManifest(0);
  491. }
  492. else
  493. {
  494. for(std::vector<std::string>::iterator ci = configNames.begin();
  495. ci != configNames.end(); ++ci)
  496. {
  497. const char* config = ci->c_str();
  498. target.GenerateTargetManifest(config);
  499. }
  500. }
  501. }
  502. }
  503. void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
  504. const char* lang,
  505. cmSourceFile& source,
  506. cmTarget& target)
  507. {
  508. std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname));
  509. objectDir = this->Convert(objectDir.c_str(),START_OUTPUT,SHELL);
  510. std::string objectFile = this->Convert(ofname,START_OUTPUT,SHELL);
  511. std::string sourceFile =
  512. this->Convert(source.GetFullPath().c_str(),START_OUTPUT,SHELL,true);
  513. std::string varString = "CMAKE_";
  514. varString += lang;
  515. varString += "_COMPILE_OBJECT";
  516. std::vector<std::string> rules;
  517. rules.push_back(this->Makefile->GetRequiredDefinition(varString.c_str()));
  518. varString = "CMAKE_";
  519. varString += lang;
  520. varString += "_FLAGS";
  521. std::string flags;
  522. flags += this->Makefile->GetSafeDefinition(varString.c_str());
  523. flags += " ";
  524. {
  525. std::vector<std::string> includes;
  526. this->GetIncludeDirectories(includes, &target, lang);
  527. flags += this->GetIncludeFlags(includes, lang);
  528. }
  529. flags += this->Makefile->GetDefineFlags();
  530. // Construct the command lines.
  531. cmCustomCommandLines commandLines;
  532. std::vector<std::string> commands;
  533. cmSystemTools::ExpandList(rules, commands);
  534. cmLocalGenerator::RuleVariables vars;
  535. vars.Language = lang;
  536. vars.Source = sourceFile.c_str();
  537. vars.Object = objectFile.c_str();
  538. vars.ObjectDir = objectDir.c_str();
  539. vars.Flags = flags.c_str();
  540. for(std::vector<std::string>::iterator i = commands.begin();
  541. i != commands.end(); ++i)
  542. {
  543. // Expand the full command line string.
  544. this->ExpandRuleVariables(*i, vars);
  545. // Parse the string to get the custom command line.
  546. cmCustomCommandLine commandLine;
  547. std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
  548. for(std::vector<cmStdString>::iterator a = cmd.begin();
  549. a != cmd.end(); ++a)
  550. {
  551. commandLine.push_back(*a);
  552. }
  553. // Store this command line.
  554. commandLines.push_back(commandLine);
  555. }
  556. // Check for extra object-file dependencies.
  557. std::vector<std::string> depends;
  558. const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
  559. if(additionalDeps)
  560. {
  561. cmSystemTools::ExpandListArgument(additionalDeps, depends);
  562. }
  563. // Generate a meaningful comment for the command.
  564. std::string comment = "Building ";
  565. comment += lang;
  566. comment += " object ";
  567. comment += this->Convert(ofname, START_OUTPUT);
  568. // Add the custom command to build the object file.
  569. this->Makefile->AddCustomCommandToOutput(
  570. ofname,
  571. depends,
  572. source.GetFullPath().c_str(),
  573. commandLines,
  574. comment.c_str(),
  575. this->Makefile->GetStartOutputDirectory()
  576. );
  577. }
  578. void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
  579. {
  580. cmStdString objs;
  581. std::vector<std::string> objVector;
  582. // Add all the sources outputs to the depends of the target
  583. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  584. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  585. i != classes.end(); ++i)
  586. {
  587. cmSourceFile* sf = *i;
  588. if(!sf->GetCustomCommand() &&
  589. !sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  590. !sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  591. {
  592. std::string dir_max;
  593. dir_max += this->Makefile->GetCurrentOutputDirectory();
  594. dir_max += "/";
  595. std::string obj = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
  596. if(!obj.empty())
  597. {
  598. std::string ofname = this->Makefile->GetCurrentOutputDirectory();
  599. ofname += "/";
  600. ofname += obj;
  601. objVector.push_back(ofname);
  602. this->AddCustomCommandToCreateObject(ofname.c_str(),
  603. llang, *(*i), target);
  604. objs += this->Convert(ofname.c_str(),START_OUTPUT,MAKEFILE);
  605. objs += " ";
  606. }
  607. }
  608. }
  609. std::string createRule = "CMAKE_";
  610. createRule += llang;
  611. createRule += target.GetCreateRuleVariable();
  612. std::string targetName = target.GetFullName();
  613. // Executable :
  614. // Shared Library:
  615. // Static Library:
  616. // Shared Module:
  617. std::string linkLibs; // should be set
  618. std::string flags; // should be set
  619. std::string linkFlags; // should be set
  620. this->GetTargetFlags(linkLibs, flags, linkFlags, target);
  621. cmLocalGenerator::RuleVariables vars;
  622. vars.Language = llang;
  623. vars.Objects = objs.c_str();
  624. vars.ObjectDir = ".";
  625. vars.Target = targetName.c_str();
  626. vars.LinkLibraries = linkLibs.c_str();
  627. vars.Flags = flags.c_str();
  628. vars.LinkFlags = linkFlags.c_str();
  629. std::string langFlags;
  630. this->AddLanguageFlags(langFlags, llang, 0);
  631. this->AddArchitectureFlags(langFlags, &target, llang, 0);
  632. vars.LanguageCompileFlags = langFlags.c_str();
  633. cmCustomCommandLines commandLines;
  634. std::vector<std::string> rules;
  635. rules.push_back(this->Makefile->GetRequiredDefinition(createRule.c_str()));
  636. std::vector<std::string> commands;
  637. cmSystemTools::ExpandList(rules, commands);
  638. for(std::vector<std::string>::iterator i = commands.begin();
  639. i != commands.end(); ++i)
  640. {
  641. // Expand the full command line string.
  642. this->ExpandRuleVariables(*i, vars);
  643. // Parse the string to get the custom command line.
  644. cmCustomCommandLine commandLine;
  645. std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
  646. for(std::vector<cmStdString>::iterator a = cmd.begin();
  647. a != cmd.end(); ++a)
  648. {
  649. commandLine.push_back(*a);
  650. }
  651. // Store this command line.
  652. commandLines.push_back(commandLine);
  653. }
  654. std::string targetFullPath = target.GetFullPath();
  655. // Generate a meaningful comment for the command.
  656. std::string comment = "Linking ";
  657. comment += llang;
  658. comment += " target ";
  659. comment += this->Convert(targetFullPath.c_str(), START_OUTPUT);
  660. this->Makefile->AddCustomCommandToOutput(
  661. targetFullPath.c_str(),
  662. objVector,
  663. 0,
  664. commandLines,
  665. comment.c_str(),
  666. this->Makefile->GetStartOutputDirectory()
  667. );
  668. target.AddSourceFile
  669. (this->Makefile->GetSource(targetFullPath.c_str()));
  670. }
  671. void cmLocalGenerator
  672. ::CreateCustomTargetsAndCommands(std::set<cmStdString> const& lang)
  673. {
  674. cmTargets &tgts = this->Makefile->GetTargets();
  675. for(cmTargets::iterator l = tgts.begin();
  676. l != tgts.end(); l++)
  677. {
  678. cmTarget& target = l->second;
  679. switch(target.GetType())
  680. {
  681. case cmTarget::STATIC_LIBRARY:
  682. case cmTarget::SHARED_LIBRARY:
  683. case cmTarget::MODULE_LIBRARY:
  684. case cmTarget::EXECUTABLE:
  685. {
  686. const char* llang = target.GetLinkerLanguage();
  687. if(!llang)
  688. {
  689. cmSystemTools::Error
  690. ("CMake can not determine linker language for target:",
  691. target.GetName());
  692. return;
  693. }
  694. // if the language is not in the set lang then create custom
  695. // commands to build the target
  696. if(lang.count(llang) == 0)
  697. {
  698. this->AddBuildTargetRule(llang, target);
  699. }
  700. }
  701. break;
  702. default:
  703. break;
  704. }
  705. }
  706. }
  707. // List of variables that are replaced when
  708. // rules are expanced. These variables are
  709. // replaced in the form <var> with GetSafeDefinition(var).
  710. // ${LANG} is replaced in the variable first with all enabled
  711. // languages.
  712. static const char* ruleReplaceVars[] =
  713. {
  714. "CMAKE_${LANG}_COMPILER",
  715. "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
  716. "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
  717. "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
  718. "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
  719. "CMAKE_${LANG}_LINK_FLAGS",
  720. "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
  721. "CMAKE_${LANG}_ARCHIVE",
  722. "CMAKE_AR",
  723. "CMAKE_CURRENT_SOURCE_DIR",
  724. "CMAKE_CURRENT_BINARY_DIR",
  725. "CMAKE_RANLIB",
  726. "CMAKE_LINKER",
  727. 0
  728. };
  729. std::string
  730. cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
  731. const RuleVariables& replaceValues)
  732. {
  733. if(replaceValues.LinkFlags)
  734. {
  735. if(variable == "LINK_FLAGS")
  736. {
  737. return replaceValues.LinkFlags;
  738. }
  739. }
  740. if(replaceValues.Flags)
  741. {
  742. if(variable == "FLAGS")
  743. {
  744. return replaceValues.Flags;
  745. }
  746. }
  747. if(replaceValues.Source)
  748. {
  749. if(variable == "SOURCE")
  750. {
  751. return replaceValues.Source;
  752. }
  753. }
  754. if(replaceValues.PreprocessedSource)
  755. {
  756. if(variable == "PREPROCESSED_SOURCE")
  757. {
  758. return replaceValues.PreprocessedSource;
  759. }
  760. }
  761. if(replaceValues.AssemblySource)
  762. {
  763. if(variable == "ASSEMBLY_SOURCE")
  764. {
  765. return replaceValues.AssemblySource;
  766. }
  767. }
  768. if(replaceValues.Object)
  769. {
  770. if(variable == "OBJECT")
  771. {
  772. return replaceValues.Object;
  773. }
  774. }
  775. if(replaceValues.ObjectDir)
  776. {
  777. if(variable == "OBJECT_DIR")
  778. {
  779. return replaceValues.ObjectDir;
  780. }
  781. }
  782. if(replaceValues.Objects)
  783. {
  784. if(variable == "OBJECTS")
  785. {
  786. return replaceValues.Objects;
  787. }
  788. }
  789. if(replaceValues.ObjectsQuoted)
  790. {
  791. if(variable == "OBJECTS_QUOTED")
  792. {
  793. return replaceValues.ObjectsQuoted;
  794. }
  795. }
  796. if(replaceValues.Defines && variable == "DEFINES")
  797. {
  798. return replaceValues.Defines;
  799. }
  800. if(replaceValues.TargetPDB )
  801. {
  802. if(variable == "TARGET_PDB")
  803. {
  804. return replaceValues.TargetPDB;
  805. }
  806. }
  807. if(replaceValues.DependencyFile )
  808. {
  809. if(variable == "DEP_FILE")
  810. {
  811. return replaceValues.DependencyFile;
  812. }
  813. }
  814. if(replaceValues.Target)
  815. {
  816. if(variable == "TARGET_QUOTED")
  817. {
  818. std::string targetQuoted = replaceValues.Target;
  819. if(targetQuoted.size() && targetQuoted[0] != '\"')
  820. {
  821. targetQuoted = '\"';
  822. targetQuoted += replaceValues.Target;
  823. targetQuoted += '\"';
  824. }
  825. return targetQuoted;
  826. }
  827. if(variable == "TARGET_UNQUOTED")
  828. {
  829. std::string unquoted = replaceValues.Target;
  830. std::string::size_type sz = unquoted.size();
  831. if(sz > 2 && unquoted[0] == '\"' && unquoted[sz-1] == '\"')
  832. {
  833. unquoted = unquoted.substr(1, sz-2);
  834. }
  835. return unquoted;
  836. }
  837. if(replaceValues.LanguageCompileFlags)
  838. {
  839. if(variable == "LANGUAGE_COMPILE_FLAGS")
  840. {
  841. return replaceValues.LanguageCompileFlags;
  842. }
  843. }
  844. if(replaceValues.Target)
  845. {
  846. if(variable == "TARGET")
  847. {
  848. return replaceValues.Target;
  849. }
  850. }
  851. if(variable == "TARGET_IMPLIB")
  852. {
  853. return this->TargetImplib;
  854. }
  855. if(variable == "TARGET_VERSION_MAJOR")
  856. {
  857. if(replaceValues.TargetVersionMajor)
  858. {
  859. return replaceValues.TargetVersionMajor;
  860. }
  861. else
  862. {
  863. return "0";
  864. }
  865. }
  866. if(variable == "TARGET_VERSION_MINOR")
  867. {
  868. if(replaceValues.TargetVersionMinor)
  869. {
  870. return replaceValues.TargetVersionMinor;
  871. }
  872. else
  873. {
  874. return "0";
  875. }
  876. }
  877. if(replaceValues.Target)
  878. {
  879. if(variable == "TARGET_BASE")
  880. {
  881. // Strip the last extension off the target name.
  882. std::string targetBase = replaceValues.Target;
  883. std::string::size_type pos = targetBase.rfind(".");
  884. if(pos != targetBase.npos)
  885. {
  886. return targetBase.substr(0, pos);
  887. }
  888. else
  889. {
  890. return targetBase;
  891. }
  892. }
  893. }
  894. }
  895. if(variable == "TARGET_SONAME" || variable == "SONAME_FLAG" ||
  896. variable == "TARGET_INSTALLNAME_DIR")
  897. {
  898. // All these variables depend on TargetSOName
  899. if(replaceValues.TargetSOName)
  900. {
  901. if(variable == "TARGET_SONAME")
  902. {
  903. return replaceValues.TargetSOName;
  904. }
  905. if(variable == "SONAME_FLAG" && replaceValues.SONameFlag)
  906. {
  907. return replaceValues.SONameFlag;
  908. }
  909. if(replaceValues.TargetInstallNameDir &&
  910. variable == "TARGET_INSTALLNAME_DIR")
  911. {
  912. return replaceValues.TargetInstallNameDir;
  913. }
  914. }
  915. return "";
  916. }
  917. if(replaceValues.LinkLibraries)
  918. {
  919. if(variable == "LINK_LIBRARIES")
  920. {
  921. return replaceValues.LinkLibraries;
  922. }
  923. }
  924. if(replaceValues.Language)
  925. {
  926. if(variable == "LANGUAGE")
  927. {
  928. return replaceValues.Language;
  929. }
  930. }
  931. if(replaceValues.CMTarget)
  932. {
  933. if(variable == "TARGET_NAME")
  934. {
  935. return replaceValues.CMTarget->GetName();
  936. }
  937. if(variable == "TARGET_TYPE")
  938. {
  939. return cmTarget::GetTargetTypeName(replaceValues.CMTarget->GetType());
  940. }
  941. }
  942. if(replaceValues.Output)
  943. {
  944. if(variable == "OUTPUT")
  945. {
  946. return replaceValues.Output;
  947. }
  948. }
  949. if(variable == "CMAKE_COMMAND")
  950. {
  951. const char* cmcommand =
  952. this->GetMakefile()->GetDefinition("CMAKE_COMMAND");
  953. return this->Convert(cmcommand, FULL, SHELL);
  954. }
  955. std::vector<std::string> enabledLanguages;
  956. this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
  957. // loop over language specific replace variables
  958. int pos = 0;
  959. while(ruleReplaceVars[pos])
  960. {
  961. for(std::vector<std::string>::iterator i = enabledLanguages.begin();
  962. i != enabledLanguages.end(); ++i)
  963. {
  964. const char* lang = i->c_str();
  965. std::string actualReplace = ruleReplaceVars[pos];
  966. // If this is the compiler then look for the extra variable
  967. // _COMPILER_ARG1 which must be the first argument to the compiler
  968. const char* compilerArg1 = 0;
  969. if(actualReplace == "CMAKE_${LANG}_COMPILER")
  970. {
  971. std::string arg1 = actualReplace + "_ARG1";
  972. cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
  973. compilerArg1 = this->Makefile->GetDefinition(arg1.c_str());
  974. }
  975. if(actualReplace.find("${LANG}") != actualReplace.npos)
  976. {
  977. cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
  978. }
  979. if(actualReplace == variable)
  980. {
  981. std::string replace =
  982. this->Makefile->GetSafeDefinition(variable.c_str());
  983. // if the variable is not a FLAG then treat it like a path
  984. if(variable.find("_FLAG") == variable.npos)
  985. {
  986. std::string ret = this->ConvertToOutputForExisting(replace.c_str());
  987. // if there is a required first argument to the compiler add it
  988. // to the compiler string
  989. if(compilerArg1)
  990. {
  991. ret += " ";
  992. ret += compilerArg1;
  993. }
  994. return ret;
  995. }
  996. return replace;
  997. }
  998. }
  999. pos++;
  1000. }
  1001. return variable;
  1002. }
  1003. void
  1004. cmLocalGenerator::ExpandRuleVariables(std::string& s,
  1005. const RuleVariables& replaceValues)
  1006. {
  1007. std::vector<std::string> enabledLanguages;
  1008. this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
  1009. this->InsertRuleLauncher(s, replaceValues.CMTarget,
  1010. replaceValues.RuleLauncher);
  1011. std::string::size_type start = s.find('<');
  1012. // no variables to expand
  1013. if(start == s.npos)
  1014. {
  1015. return;
  1016. }
  1017. std::string::size_type pos = 0;
  1018. std::string expandedInput;
  1019. while(start != s.npos && start < s.size()-2)
  1020. {
  1021. std::string::size_type end = s.find('>', start);
  1022. // if we find a < with no > we are done
  1023. if(end == s.npos)
  1024. {
  1025. return;
  1026. }
  1027. char c = s[start+1];
  1028. // if the next char after the < is not A-Za-z then
  1029. // skip it and try to find the next < in the string
  1030. if(!isalpha(c))
  1031. {
  1032. start = s.find('<', start+1);
  1033. }
  1034. else
  1035. {
  1036. // extract the var
  1037. std::string var = s.substr(start+1, end - start-1);
  1038. std::string replace = this->ExpandRuleVariable(var,
  1039. replaceValues);
  1040. expandedInput += s.substr(pos, start-pos);
  1041. expandedInput += replace;
  1042. // move to next one
  1043. start = s.find('<', start+var.size()+2);
  1044. pos = end+1;
  1045. }
  1046. }
  1047. // add the rest of the input
  1048. expandedInput += s.substr(pos, s.size()-pos);
  1049. s = expandedInput;
  1050. }
  1051. //----------------------------------------------------------------------------
  1052. const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target,
  1053. const char* prop)
  1054. {
  1055. if(target)
  1056. {
  1057. return target->GetProperty(prop);
  1058. }
  1059. else
  1060. {
  1061. return this->Makefile->GetProperty(prop);
  1062. }
  1063. }
  1064. //----------------------------------------------------------------------------
  1065. void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target,
  1066. const char* prop)
  1067. {
  1068. if(const char* val = this->GetRuleLauncher(target, prop))
  1069. {
  1070. cmOStringStream wrapped;
  1071. wrapped << val << " " << s;
  1072. s = wrapped.str();
  1073. }
  1074. }
  1075. //----------------------------------------------------------------------------
  1076. std::string
  1077. cmLocalGenerator::ConvertToOutputForExistingCommon(const char* remote,
  1078. std::string const& result)
  1079. {
  1080. // If this is a windows shell, the result has a space, and the path
  1081. // already exists, we can use a short-path to reference it without a
  1082. // space.
  1083. if(this->WindowsShell && result.find(' ') != result.npos &&
  1084. cmSystemTools::FileExists(remote))
  1085. {
  1086. std::string tmp;
  1087. if(cmSystemTools::GetShortPath(remote, tmp))
  1088. {
  1089. return this->Convert(tmp.c_str(), NONE, SHELL, true);
  1090. }
  1091. }
  1092. // Otherwise, leave it unchanged.
  1093. return result;
  1094. }
  1095. //----------------------------------------------------------------------------
  1096. std::string
  1097. cmLocalGenerator::ConvertToOutputForExisting(const char* remote,
  1098. RelativeRoot local)
  1099. {
  1100. // Perform standard conversion.
  1101. std::string result = this->Convert(remote, local, SHELL, true);
  1102. // Consider short-path.
  1103. return this->ConvertToOutputForExistingCommon(remote, result);
  1104. }
  1105. //----------------------------------------------------------------------------
  1106. std::string
  1107. cmLocalGenerator::ConvertToOutputForExisting(RelativeRoot remote,
  1108. const char* local)
  1109. {
  1110. // Perform standard conversion.
  1111. std::string result = this->Convert(remote, local, SHELL, true);
  1112. // Consider short-path.
  1113. const char* remotePath = this->GetRelativeRootPath(remote);
  1114. return this->ConvertToOutputForExistingCommon(remotePath, result);
  1115. }
  1116. //----------------------------------------------------------------------------
  1117. std::string
  1118. cmLocalGenerator::ConvertToIncludeReference(std::string const& path)
  1119. {
  1120. return this->ConvertToOutputForExisting(path.c_str());
  1121. }
  1122. //----------------------------------------------------------------------------
  1123. std::string cmLocalGenerator::GetIncludeFlags(
  1124. const std::vector<std::string> &includes,
  1125. const char* lang, bool forResponseFile)
  1126. {
  1127. if(!lang)
  1128. {
  1129. return "";
  1130. }
  1131. cmOStringStream includeFlags;
  1132. std::string flagVar = "CMAKE_INCLUDE_FLAG_";
  1133. flagVar += lang;
  1134. const char* includeFlag =
  1135. this->Makefile->GetSafeDefinition(flagVar.c_str());
  1136. flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
  1137. flagVar += lang;
  1138. const char* sep = this->Makefile->GetDefinition(flagVar.c_str());
  1139. bool quotePaths = false;
  1140. if(this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
  1141. {
  1142. quotePaths = true;
  1143. }
  1144. bool repeatFlag = true;
  1145. // should the include flag be repeated like ie. -IA -IB
  1146. if(!sep)
  1147. {
  1148. sep = " ";
  1149. }
  1150. else
  1151. {
  1152. // if there is a separator then the flag is not repeated but is only
  1153. // given once i.e. -classpath a:b:c
  1154. repeatFlag = false;
  1155. }
  1156. // Support special system include flag if it is available and the
  1157. // normal flag is repeated for each directory.
  1158. std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
  1159. sysFlagVar += lang;
  1160. const char* sysIncludeFlag = 0;
  1161. if(repeatFlag)
  1162. {
  1163. sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar.c_str());
  1164. }
  1165. bool flagUsed = false;
  1166. std::set<cmStdString> emitted;
  1167. #ifdef __APPLE__
  1168. emitted.insert("/System/Library/Frameworks");
  1169. #endif
  1170. std::vector<std::string>::const_iterator i;
  1171. for(i = includes.begin(); i != includes.end(); ++i)
  1172. {
  1173. if(this->Makefile->IsOn("APPLE")
  1174. && cmSystemTools::IsPathToFramework(i->c_str()))
  1175. {
  1176. std::string frameworkDir = *i;
  1177. frameworkDir += "/../";
  1178. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1179. if(emitted.insert(frameworkDir).second)
  1180. {
  1181. OutputFormat format = forResponseFile? RESPONSE : SHELL;
  1182. includeFlags
  1183. << "-F" << this->Convert(frameworkDir.c_str(),
  1184. START_OUTPUT, format, true)
  1185. << " ";
  1186. }
  1187. continue;
  1188. }
  1189. std::string include = *i;
  1190. if(!flagUsed || repeatFlag)
  1191. {
  1192. if(sysIncludeFlag &&
  1193. this->Makefile->IsSystemIncludeDirectory(i->c_str()))
  1194. {
  1195. includeFlags << sysIncludeFlag;
  1196. }
  1197. else
  1198. {
  1199. includeFlags << includeFlag;
  1200. }
  1201. flagUsed = true;
  1202. }
  1203. std::string includePath;
  1204. if(forResponseFile)
  1205. {
  1206. includePath = this->Convert(i->c_str(), START_OUTPUT,
  1207. RESPONSE, true);
  1208. }
  1209. else
  1210. {
  1211. includePath = this->ConvertToIncludeReference(*i);
  1212. }
  1213. if(quotePaths && includePath.size() && includePath[0] != '\"')
  1214. {
  1215. includeFlags << "\"";
  1216. }
  1217. includeFlags << includePath;
  1218. if(quotePaths && includePath.size() && includePath[0] != '\"')
  1219. {
  1220. includeFlags << "\"";
  1221. }
  1222. includeFlags << sep;
  1223. }
  1224. std::string flags = includeFlags.str();
  1225. // remove trailing separators
  1226. if((sep[0] != ' ') && flags.size()>0 && flags[flags.size()-1] == sep[0])
  1227. {
  1228. flags[flags.size()-1] = ' ';
  1229. }
  1230. return flags;
  1231. }
  1232. //----------------------------------------------------------------------------
  1233. void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
  1234. cmTarget* target,
  1235. const char* lang)
  1236. {
  1237. // Need to decide whether to automatically include the source and
  1238. // binary directories at the beginning of the include path.
  1239. bool includeSourceDir = false;
  1240. bool includeBinaryDir = false;
  1241. // When automatic include directories are requested for a build then
  1242. // include the source and binary directories at the beginning of the
  1243. // include path to approximate include file behavior for an
  1244. // in-source build. This does not account for the case of a source
  1245. // file in a subdirectory of the current source directory but we
  1246. // cannot fix this because not all native build tools support
  1247. // per-source-file include paths.
  1248. if(this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
  1249. {
  1250. includeSourceDir = true;
  1251. includeBinaryDir = true;
  1252. }
  1253. // CMake versions below 2.0 would add the source tree to the -I path
  1254. // automatically. Preserve compatibility.
  1255. if(this->NeedBackwardsCompatibility(1,9))
  1256. {
  1257. includeSourceDir = true;
  1258. }
  1259. // Hack for VTK 4.0 - 4.4 which depend on the old behavior but do
  1260. // not set the backwards compatibility level automatically.
  1261. const char* vtkSourceDir =
  1262. this->Makefile->GetDefinition("VTK_SOURCE_DIR");
  1263. if(vtkSourceDir)
  1264. {
  1265. const char* vtk_major =
  1266. this->Makefile->GetDefinition("VTK_MAJOR_VERSION");
  1267. const char* vtk_minor =
  1268. this->Makefile->GetDefinition("VTK_MINOR_VERSION");
  1269. vtk_major = vtk_major? vtk_major : "4";
  1270. vtk_minor = vtk_minor? vtk_minor : "4";
  1271. int vmajor = 0;
  1272. int vminor = 0;
  1273. if(sscanf(vtk_major, "%d", &vmajor) &&
  1274. sscanf(vtk_minor, "%d", &vminor) && vmajor == 4 && vminor <= 4)
  1275. {
  1276. includeSourceDir = true;
  1277. }
  1278. }
  1279. // Do not repeat an include path.
  1280. std::set<cmStdString> emitted;
  1281. // Store the automatic include paths.
  1282. if(includeBinaryDir)
  1283. {
  1284. if(emitted.find(
  1285. this->Makefile->GetStartOutputDirectory()) == emitted.end())
  1286. {
  1287. dirs.push_back(this->Makefile->GetStartOutputDirectory());
  1288. emitted.insert(this->Makefile->GetStartOutputDirectory());
  1289. }
  1290. }
  1291. if(includeSourceDir)
  1292. {
  1293. if(emitted.find(this->Makefile->GetStartDirectory()) == emitted.end())
  1294. {
  1295. dirs.push_back(this->Makefile->GetStartDirectory());
  1296. emitted.insert(this->Makefile->GetStartDirectory());
  1297. }
  1298. }
  1299. // Load implicit include directories for this language.
  1300. std::string impDirVar = "CMAKE_";
  1301. impDirVar += lang;
  1302. impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES";
  1303. if(const char* value = this->Makefile->GetDefinition(impDirVar.c_str()))
  1304. {
  1305. std::vector<std::string> impDirVec;
  1306. cmSystemTools::ExpandListArgument(value, impDirVec);
  1307. for(std::vector<std::string>::const_iterator i = impDirVec.begin();
  1308. i != impDirVec.end(); ++i)
  1309. {
  1310. emitted.insert(*i);
  1311. }
  1312. }
  1313. // Get the target-specific include directories.
  1314. std::vector<std::string> includes;
  1315. if(target)
  1316. {
  1317. includes = target->GetIncludeDirectories();
  1318. }
  1319. // Support putting all the in-project include directories first if
  1320. // it is requested by the project.
  1321. if(this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
  1322. {
  1323. const char* topSourceDir = this->Makefile->GetHomeDirectory();
  1324. const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory();
  1325. for(std::vector<std::string>::const_iterator i = includes.begin();
  1326. i != includes.end(); ++i)
  1327. {
  1328. // Emit this directory only if it is a subdirectory of the
  1329. // top-level source or binary tree.
  1330. if(cmSystemTools::ComparePath(i->c_str(), topSourceDir) ||
  1331. cmSystemTools::ComparePath(i->c_str(), topBinaryDir) ||
  1332. cmSystemTools::IsSubDirectory(i->c_str(), topSourceDir) ||
  1333. cmSystemTools::IsSubDirectory(i->c_str(), topBinaryDir))
  1334. {
  1335. if(emitted.insert(*i).second)
  1336. {
  1337. dirs.push_back(*i);
  1338. }
  1339. }
  1340. }
  1341. }
  1342. // Construct the final ordered include directory list.
  1343. for(std::vector<std::string>::const_iterator i = includes.begin();
  1344. i != includes.end(); ++i)
  1345. {
  1346. if(emitted.insert(*i).second)
  1347. {
  1348. dirs.push_back(*i);
  1349. }
  1350. }
  1351. }
  1352. void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
  1353. std::string& flags,
  1354. std::string& linkFlags,
  1355. cmTarget& target)
  1356. {
  1357. std::string buildType =
  1358. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1359. buildType = cmSystemTools::UpperCase(buildType);
  1360. const char* libraryLinkVariable =
  1361. "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
  1362. switch(target.GetType())
  1363. {
  1364. case cmTarget::STATIC_LIBRARY:
  1365. {
  1366. const char* targetLinkFlags =
  1367. target.GetProperty("STATIC_LIBRARY_FLAGS");
  1368. if(targetLinkFlags)
  1369. {
  1370. linkFlags += targetLinkFlags;
  1371. linkFlags += " ";
  1372. }
  1373. if(!buildType.empty())
  1374. {
  1375. std::string build = "STATIC_LIBRARY_FLAGS_";
  1376. build += buildType;
  1377. targetLinkFlags = target.GetProperty(build.c_str());
  1378. if(targetLinkFlags)
  1379. {
  1380. linkFlags += targetLinkFlags;
  1381. linkFlags += " ";
  1382. }
  1383. }
  1384. }
  1385. break;
  1386. case cmTarget::MODULE_LIBRARY:
  1387. libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
  1388. case cmTarget::SHARED_LIBRARY:
  1389. {
  1390. linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
  1391. linkFlags += " ";
  1392. if(!buildType.empty())
  1393. {
  1394. std::string build = libraryLinkVariable;
  1395. build += "_";
  1396. build += buildType;
  1397. linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
  1398. linkFlags += " ";
  1399. }
  1400. if(this->Makefile->IsOn("WIN32") &&
  1401. !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
  1402. {
  1403. const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
  1404. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1405. i != sources.end(); ++i)
  1406. {
  1407. cmSourceFile* sf = *i;
  1408. if(sf->GetExtension() == "def")
  1409. {
  1410. linkFlags +=
  1411. this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1412. linkFlags += this->Convert(sf->GetFullPath().c_str(),
  1413. FULL, SHELL);
  1414. linkFlags += " ";
  1415. }
  1416. }
  1417. }
  1418. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1419. if(targetLinkFlags)
  1420. {
  1421. linkFlags += targetLinkFlags;
  1422. linkFlags += " ";
  1423. }
  1424. if(!buildType.empty())
  1425. {
  1426. std::string configLinkFlags = "LINK_FLAGS_";
  1427. configLinkFlags += buildType;
  1428. targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
  1429. if(targetLinkFlags)
  1430. {
  1431. linkFlags += targetLinkFlags;
  1432. linkFlags += " ";
  1433. }
  1434. }
  1435. cmOStringStream linklibsStr;
  1436. this->OutputLinkLibraries(linklibsStr, target, false);
  1437. linkLibs = linklibsStr.str();
  1438. }
  1439. break;
  1440. case cmTarget::EXECUTABLE:
  1441. {
  1442. linkFlags +=
  1443. this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1444. linkFlags += " ";
  1445. if(!buildType.empty())
  1446. {
  1447. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1448. build += buildType;
  1449. linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
  1450. linkFlags += " ";
  1451. }
  1452. const char* linkLanguage = target.GetLinkerLanguage();
  1453. if(!linkLanguage)
  1454. {
  1455. cmSystemTools::Error
  1456. ("CMake can not determine linker language for target:",
  1457. target.GetName());
  1458. return;
  1459. }
  1460. this->AddLanguageFlags(flags, linkLanguage, buildType.c_str());
  1461. std::string sharedFlagsVar = "CMAKE_SHARED_LIBRARY_";
  1462. sharedFlagsVar += linkLanguage;
  1463. sharedFlagsVar += "_FLAGS";
  1464. flags += " ";
  1465. flags += this->Makefile->GetSafeDefinition(sharedFlagsVar.c_str());
  1466. flags += " ";
  1467. cmOStringStream linklibs;
  1468. this->OutputLinkLibraries(linklibs, target, false);
  1469. linkLibs = linklibs.str();
  1470. if(cmSystemTools::IsOn
  1471. (this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1472. {
  1473. std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_")
  1474. + linkLanguage + std::string("_FLAGS");
  1475. linkFlags += this->Makefile->GetSafeDefinition(sFlagVar.c_str());
  1476. linkFlags += " ";
  1477. }
  1478. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  1479. {
  1480. linkFlags +=
  1481. this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1482. linkFlags += " ";
  1483. }
  1484. else
  1485. {
  1486. linkFlags +=
  1487. this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1488. linkFlags += " ";
  1489. }
  1490. if (target.IsExecutableWithExports())
  1491. {
  1492. std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
  1493. exportFlagVar += linkLanguage;
  1494. exportFlagVar += "_FLAG";
  1495. linkFlags +=
  1496. this->Makefile->GetSafeDefinition(exportFlagVar.c_str());
  1497. linkFlags += " ";
  1498. }
  1499. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1500. if(targetLinkFlags)
  1501. {
  1502. linkFlags += targetLinkFlags;
  1503. linkFlags += " ";
  1504. }
  1505. if(!buildType.empty())
  1506. {
  1507. std::string configLinkFlags = "LINK_FLAGS_";
  1508. configLinkFlags += buildType;
  1509. targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
  1510. if(targetLinkFlags)
  1511. {
  1512. linkFlags += targetLinkFlags;
  1513. linkFlags += " ";
  1514. }
  1515. }
  1516. }
  1517. break;
  1518. default:
  1519. break;
  1520. }
  1521. }
  1522. std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib)
  1523. {
  1524. #if defined(_WIN32) && !defined(__CYGWIN__)
  1525. // Work-ardound command line parsing limitations in MSVC 6.0 and
  1526. // Watcom.
  1527. if(this->Makefile->IsOn("MSVC60") || this->Makefile->IsOn("WATCOM"))
  1528. {
  1529. // Search for the last space.
  1530. std::string::size_type pos = lib.rfind(' ');
  1531. if(pos != lib.npos)
  1532. {
  1533. // Find the slash after the last space, if any.
  1534. pos = lib.find('/', pos);
  1535. // Convert the portion of the path with a space to a short path.
  1536. std::string sp;
  1537. if(cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp))
  1538. {
  1539. // Append the rest of the path with no space.
  1540. sp += lib.substr(pos);
  1541. // Convert to an output path.
  1542. return this->Convert(sp.c_str(), NONE, SHELL);
  1543. }
  1544. }
  1545. }
  1546. #endif
  1547. // Normal behavior.
  1548. return this->Convert(lib.c_str(), START_OUTPUT, SHELL);
  1549. }
  1550. /**
  1551. * Output the linking rules on a command line. For executables,
  1552. * targetLibrary should be a NULL pointer. For libraries, it should point
  1553. * to the name of the library. This will not link a library against itself.
  1554. */
  1555. void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout,
  1556. cmTarget& tgt,
  1557. bool relink)
  1558. {
  1559. const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  1560. cmComputeLinkInformation* pcli = tgt.GetLinkInformation(config);
  1561. if(!pcli)
  1562. {
  1563. return;
  1564. }
  1565. cmComputeLinkInformation& cli = *pcli;
  1566. // Collect library linking flags command line options.
  1567. std::string linkLibs;
  1568. const char* linkLanguage = cli.GetLinkLanguage();
  1569. std::string libPathFlag =
  1570. this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
  1571. std::string libPathTerminator =
  1572. this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
  1573. // Flags to link an executable to shared libraries.
  1574. std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
  1575. linkFlagsVar += linkLanguage;
  1576. linkFlagsVar += "_FLAGS";
  1577. if( tgt.GetType() == cmTarget::EXECUTABLE )
  1578. {
  1579. linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar.c_str());
  1580. linkLibs += " ";
  1581. }
  1582. // Append the framework search path flags.
  1583. std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
  1584. for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
  1585. fdi != fwDirs.end(); ++fdi)
  1586. {
  1587. linkLibs += "-F";
  1588. linkLibs += this->Convert(fdi->c_str(), NONE, SHELL, false);
  1589. linkLibs += " ";
  1590. }
  1591. // Append the library search path flags.
  1592. std::vector<std::string> const& libDirs = cli.GetDirectories();
  1593. for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
  1594. libDir != libDirs.end(); ++libDir)
  1595. {
  1596. std::string libpath = this->ConvertToOutputForExisting(libDir->c_str());
  1597. linkLibs += libPathFlag;
  1598. linkLibs += libpath;
  1599. linkLibs += libPathTerminator;
  1600. linkLibs += " ";
  1601. }
  1602. // Append the link items.
  1603. typedef cmComputeLinkInformation::ItemVector ItemVector;
  1604. ItemVector const& items = cli.GetItems();
  1605. for(ItemVector::const_iterator li = items.begin(); li != items.end(); ++li)
  1606. {
  1607. if(li->IsPath)
  1608. {
  1609. linkLibs += this->ConvertToLinkReference(li->Value);
  1610. }
  1611. else
  1612. {
  1613. linkLibs += li->Value;
  1614. }
  1615. linkLibs += " ";
  1616. }
  1617. // Write the library flags to the build rule.
  1618. fout << linkLibs;
  1619. // Get the RPATH entries.
  1620. std::vector<std::string> runtimeDirs;
  1621. cli.GetRPath(runtimeDirs, relink);
  1622. // Check what kind of rpath flags to use.
  1623. if(cli.GetRuntimeSep().empty())
  1624. {
  1625. // Each rpath entry gets its own option ("-R a -R b -R c")
  1626. std::string rpath;
  1627. for(std::vector<std::string>::iterator ri = runtimeDirs.begin();
  1628. ri != runtimeDirs.end(); ++ri)
  1629. {
  1630. rpath += cli.GetRuntimeFlag();
  1631. rpath += this->Convert(ri->c_str(), NONE, SHELL, false);
  1632. rpath += " ";
  1633. }
  1634. fout << rpath;
  1635. }
  1636. else
  1637. {
  1638. // All rpath entries are combined ("-Wl,-rpath,a:b:c").
  1639. std::string rpath = cli.GetRPathString(relink);
  1640. // Store the rpath option in the stream.
  1641. if(!rpath.empty())
  1642. {
  1643. fout << cli.GetRuntimeFlag();
  1644. fout << this->EscapeForShell(rpath.c_str(), true);
  1645. fout << " ";
  1646. }
  1647. }
  1648. // Add the linker runtime search path if any.
  1649. std::string rpath_link = cli.GetRPathLinkString();
  1650. if(!cli.GetRPathLinkFlag().empty() && !rpath_link.empty())
  1651. {
  1652. fout << cli.GetRPathLinkFlag();
  1653. fout << this->EscapeForShell(rpath_link.c_str(), true);
  1654. fout << " ";
  1655. }
  1656. // Add standard libraries for this language.
  1657. std::string standardLibsVar = "CMAKE_";
  1658. standardLibsVar += cli.GetLinkLanguage();
  1659. standardLibsVar += "_STANDARD_LIBRARIES";
  1660. if(const char* stdLibs =
  1661. this->Makefile->GetDefinition(standardLibsVar.c_str()))
  1662. {
  1663. fout << stdLibs << " ";
  1664. }
  1665. }
  1666. //----------------------------------------------------------------------------
  1667. void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
  1668. cmTarget* target,
  1669. const char *lang,
  1670. const char* config)
  1671. {
  1672. // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone):
  1673. if(!this->Makefile->IsOn("APPLE"))
  1674. {
  1675. return;
  1676. }
  1677. if(this->EmitUniversalBinaryFlags)
  1678. {
  1679. std::vector<std::string> archs;
  1680. target->GetAppleArchs(config, archs);
  1681. const char* sysroot =
  1682. this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
  1683. const char* sysrootDefault =
  1684. this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT_DEFAULT");
  1685. const char* deploymentTarget =
  1686. this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
  1687. std::string isysrootVar = std::string("CMAKE_") + lang + "_HAS_ISYSROOT";
  1688. bool hasIsysroot = this->Makefile->IsOn(isysrootVar.c_str());
  1689. std::string deploymentTargetFlagVar =
  1690. std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG";
  1691. const char* deploymentTargetFlag =
  1692. this->Makefile->GetDefinition(deploymentTargetFlagVar.c_str());
  1693. bool flagsUsed = false;
  1694. if(!archs.empty() && sysroot && lang && (lang[0] =='C' || lang[0] == 'F'))
  1695. {
  1696. // if there is more than one arch add the -arch and
  1697. // -isysroot flags, or if there is one arch flag, but
  1698. // it is not the default -arch flag for the system, then
  1699. // add it. Otherwize do not add -arch and -isysroot
  1700. if(archs[0] != "")
  1701. {
  1702. for( std::vector<std::string>::iterator i = archs.begin();
  1703. i != archs.end(); ++i)
  1704. {
  1705. flags += " -arch ";
  1706. flags += *i;
  1707. }
  1708. if(hasIsysroot)
  1709. {
  1710. flags += " -isysroot ";
  1711. flags += sysroot;
  1712. }
  1713. flagsUsed = true;
  1714. }
  1715. }
  1716. if(!flagsUsed && sysroot && sysrootDefault &&
  1717. strcmp(sysroot, sysrootDefault) != 0 && hasIsysroot)
  1718. {
  1719. flags += " -isysroot ";
  1720. flags += sysroot;
  1721. }
  1722. if (deploymentTargetFlag && *deploymentTargetFlag &&
  1723. deploymentTarget && *deploymentTarget)
  1724. {
  1725. flags += " ";
  1726. flags += deploymentTargetFlag;
  1727. flags += deploymentTarget;
  1728. }
  1729. }
  1730. }
  1731. //----------------------------------------------------------------------------
  1732. void cmLocalGenerator::AddLanguageFlags(std::string& flags,
  1733. const char* lang,
  1734. const char* config)
  1735. {
  1736. // Add language-specific flags.
  1737. std::string flagsVar = "CMAKE_";
  1738. flagsVar += lang;
  1739. flagsVar += "_FLAGS";
  1740. this->AddConfigVariableFlags(flags, flagsVar.c_str(), config);
  1741. }
  1742. //----------------------------------------------------------------------------
  1743. bool cmLocalGenerator::GetRealDependency(const char* inName,
  1744. const char* config,
  1745. std::string& dep)
  1746. {
  1747. // Older CMake code may specify the dependency using the target
  1748. // output file rather than the target name. Such code would have
  1749. // been written before there was support for target properties that
  1750. // modify the name so stripping down to just the file name should
  1751. // produce the target name in this case.
  1752. std::string name = cmSystemTools::GetFilenameName(inName);
  1753. if(cmSystemTools::GetFilenameLastExtension(name) == ".exe")
  1754. {
  1755. name = cmSystemTools::GetFilenameWithoutLastExtension(name);
  1756. }
  1757. // Look for a CMake target with the given name.
  1758. if(cmTarget* target = this->Makefile->FindTargetToUse(name.c_str()))
  1759. {
  1760. // make sure it is not just a coincidence that the target name
  1761. // found is part of the inName
  1762. if(cmSystemTools::FileIsFullPath(inName))
  1763. {
  1764. std::string tLocation;
  1765. if(target->GetType() >= cmTarget::EXECUTABLE &&
  1766. target->GetType() <= cmTarget::MODULE_LIBRARY)
  1767. {
  1768. tLocation = target->GetLocation(config);
  1769. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1770. tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
  1771. }
  1772. std::string depLocation = cmSystemTools::GetFilenamePath(
  1773. std::string(inName));
  1774. depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
  1775. if(depLocation != tLocation)
  1776. {
  1777. // it is a full path to a depend that has the same name
  1778. // as a target but is in a different location so do not use
  1779. // the target as the depend
  1780. dep = inName;
  1781. return true;
  1782. }
  1783. }
  1784. switch (target->GetType())
  1785. {
  1786. case cmTarget::EXECUTABLE:
  1787. case cmTarget::STATIC_LIBRARY:
  1788. case cmTarget::SHARED_LIBRARY:
  1789. case cmTarget::MODULE_LIBRARY:
  1790. case cmTarget::UNKNOWN_LIBRARY:
  1791. dep = target->GetLocation(config);
  1792. return true;
  1793. case cmTarget::OBJECT_LIBRARY:
  1794. // An object library has no single file on which to depend.
  1795. // This was listed to get the target-level dependency.
  1796. return false;
  1797. case cmTarget::UTILITY:
  1798. case cmTarget::GLOBAL_TARGET:
  1799. // A utility target has no file on which to depend. This was listed
  1800. // only to get the target-level dependency.
  1801. return false;
  1802. }
  1803. }
  1804. // The name was not that of a CMake target. It must name a file.
  1805. if(cmSystemTools::FileIsFullPath(inName))
  1806. {
  1807. // This is a full path. Return it as given.
  1808. dep = inName;
  1809. return true;
  1810. }
  1811. // Check for a source file in this directory that matches the
  1812. // dependency.
  1813. if(cmSourceFile* sf = this->Makefile->GetSource(inName))
  1814. {
  1815. dep = sf->GetFullPath();
  1816. return true;
  1817. }
  1818. // Treat the name as relative to the source directory in which it
  1819. // was given.
  1820. dep = this->Makefile->GetCurrentDirectory();
  1821. dep += "/";
  1822. dep += inName;
  1823. return true;
  1824. }
  1825. //----------------------------------------------------------------------------
  1826. void cmLocalGenerator::AddSharedFlags(std::string& flags,
  1827. const char* lang,
  1828. bool shared)
  1829. {
  1830. std::string flagsVar;
  1831. // Add flags for dealing with shared libraries for this language.
  1832. if(shared)
  1833. {
  1834. flagsVar = "CMAKE_SHARED_LIBRARY_";
  1835. flagsVar += lang;
  1836. flagsVar += "_FLAGS";
  1837. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1838. }
  1839. }
  1840. //----------------------------------------------------------------------------
  1841. void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
  1842. const char* var,
  1843. const char* config)
  1844. {
  1845. // Add the flags from the variable itself.
  1846. std::string flagsVar = var;
  1847. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1848. // Add the flags from the build-type specific variable.
  1849. if(config && *config)
  1850. {
  1851. flagsVar += "_";
  1852. flagsVar += cmSystemTools::UpperCase(config);
  1853. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1854. }
  1855. }
  1856. //----------------------------------------------------------------------------
  1857. void cmLocalGenerator::AppendFlags(std::string& flags,
  1858. const char* newFlags)
  1859. {
  1860. if(newFlags && *newFlags)
  1861. {
  1862. std::string newf = newFlags;
  1863. if(flags.size())
  1864. {
  1865. flags += " ";
  1866. }
  1867. flags += newFlags;
  1868. }
  1869. }
  1870. //----------------------------------------------------------------------------
  1871. void cmLocalGenerator::AppendDefines(std::string& defines,
  1872. const char* defines_list,
  1873. const char* lang)
  1874. {
  1875. // Short-circuit if there are no definitions.
  1876. if(!defines_list)
  1877. {
  1878. return;
  1879. }
  1880. // Expand the list of definitions.
  1881. std::vector<std::string> defines_vec;
  1882. cmSystemTools::ExpandListArgument(defines_list, defines_vec);
  1883. // Short-circuit if there are no definitions.
  1884. if(defines_vec.empty())
  1885. {
  1886. return;
  1887. }
  1888. // Lookup the define flag for the current language.
  1889. std::string dflag = "-D";
  1890. if(lang)
  1891. {
  1892. std::string defineFlagVar = "CMAKE_";
  1893. defineFlagVar += lang;
  1894. defineFlagVar += "_DEFINE_FLAG";
  1895. const char* df = this->Makefile->GetDefinition(defineFlagVar.c_str());
  1896. if(df && *df)
  1897. {
  1898. dflag = df;
  1899. }
  1900. }
  1901. // Add each definition to the command line with appropriate escapes.
  1902. const char* dsep = defines.empty()? "" : " ";
  1903. for(std::vector<std::string>::const_iterator di = defines_vec.begin();
  1904. di != defines_vec.end(); ++di)
  1905. {
  1906. // Skip unsupported definitions.
  1907. if(!this->CheckDefinition(*di))
  1908. {
  1909. continue;
  1910. }
  1911. // Separate from previous definitions.
  1912. defines += dsep;
  1913. dsep = " ";
  1914. // Append the definition with proper escaping.
  1915. defines += dflag;
  1916. if(this->WatcomWMake)
  1917. {
  1918. // The Watcom compiler does its own command line parsing instead
  1919. // of using the windows shell rules. Definitions are one of
  1920. // -DNAME
  1921. // -DNAME=<cpp-token>
  1922. // -DNAME="c-string with spaces and other characters(?@#$)"
  1923. //
  1924. // Watcom will properly parse each of these cases from the
  1925. // command line without any escapes. However we still have to
  1926. // get the '$' and '#' characters through WMake as '$$' and
  1927. // '$#'.
  1928. for(const char* c = di->c_str(); *c; ++c)
  1929. {
  1930. if(*c == '$' || *c == '#')
  1931. {
  1932. defines += '$';
  1933. }
  1934. defines += *c;
  1935. }
  1936. }
  1937. else
  1938. {
  1939. // Make the definition appear properly on the command line. Use
  1940. // -DNAME="value" instead of -D"NAME=value" to help VS6 parser.
  1941. std::string::size_type eq = di->find("=");
  1942. defines += di->substr(0, eq);
  1943. if(eq != di->npos)
  1944. {
  1945. defines += "=";
  1946. defines += this->EscapeForShell(di->c_str() + eq + 1, true);
  1947. }
  1948. }
  1949. }
  1950. }
  1951. //----------------------------------------------------------------------------
  1952. void cmLocalGenerator::AppendFeatureOptions(
  1953. std::string& flags, const char* lang, const char* feature)
  1954. {
  1955. std::string optVar = "CMAKE_";
  1956. optVar += lang;
  1957. optVar += "_COMPILE_OPTIONS_";
  1958. optVar += feature;
  1959. if(const char* optionList = this->Makefile->GetDefinition(optVar.c_str()))
  1960. {
  1961. std::vector<std::string> options;
  1962. cmSystemTools::ExpandListArgument(optionList, options);
  1963. for(std::vector<std::string>::const_iterator oi = options.begin();
  1964. oi != options.end(); ++oi)
  1965. {
  1966. this->AppendFlags(flags, this->EscapeForShell(oi->c_str()).c_str());
  1967. }
  1968. }
  1969. }
  1970. //----------------------------------------------------------------------------
  1971. std::string
  1972. cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,
  1973. const char* default_comment)
  1974. {
  1975. // Check for a comment provided with the command.
  1976. if(cc.GetComment())
  1977. {
  1978. return cc.GetComment();
  1979. }
  1980. // Construct a reasonable default comment if possible.
  1981. if(!cc.GetOutputs().empty())
  1982. {
  1983. std::string comment;
  1984. comment = "Generating ";
  1985. const char* sep = "";
  1986. for(std::vector<std::string>::const_iterator o = cc.GetOutputs().begin();
  1987. o != cc.GetOutputs().end(); ++o)
  1988. {
  1989. comment += sep;
  1990. comment += this->Convert(o->c_str(), cmLocalGenerator::START_OUTPUT);
  1991. sep = ", ";
  1992. }
  1993. return comment;
  1994. }
  1995. // Otherwise use the provided default.
  1996. return default_comment;
  1997. }
  1998. //----------------------------------------------------------------------------
  1999. std::string
  2000. cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(const char* remote)
  2001. {
  2002. return this->Convert(remote, START_OUTPUT, SHELL, true);
  2003. }
  2004. //----------------------------------------------------------------------------
  2005. const char* cmLocalGenerator::GetRelativeRootPath(RelativeRoot relroot)
  2006. {
  2007. switch (relroot)
  2008. {
  2009. case HOME: return this->Makefile->GetHomeDirectory();
  2010. case START: return this->Makefile->GetStartDirectory();
  2011. case HOME_OUTPUT: return this->Makefile->GetHomeOutputDirectory();
  2012. case START_OUTPUT: return this->Makefile->GetStartOutputDirectory();
  2013. default: break;
  2014. }
  2015. return 0;
  2016. }
  2017. //----------------------------------------------------------------------------
  2018. std::string cmLocalGenerator::Convert(const char* source,
  2019. RelativeRoot relative,
  2020. OutputFormat output,
  2021. bool optional)
  2022. {
  2023. // Make sure the relative path conversion components are set.
  2024. if(!this->PathConversionsSetup)
  2025. {
  2026. this->SetupPathConversions();
  2027. this->PathConversionsSetup = true;
  2028. }
  2029. // Convert the path to a relative path.
  2030. std::string result = source;
  2031. if (!optional || this->UseRelativePaths)
  2032. {
  2033. switch (relative)
  2034. {
  2035. case HOME:
  2036. //result = cmSystemTools::CollapseFullPath(result.c_str());
  2037. result = this->ConvertToRelativePath(this->HomeDirectoryComponents,
  2038. result.c_str());
  2039. break;
  2040. case START:
  2041. //result = cmSystemTools::CollapseFullPath(result.c_str());
  2042. result = this->ConvertToRelativePath(this->StartDirectoryComponents,
  2043. result.c_str());
  2044. break;
  2045. case HOME_OUTPUT:
  2046. //result = cmSystemTools::CollapseFullPath(result.c_str());
  2047. result =
  2048. this->ConvertToRelativePath(this->HomeOutputDirectoryComponents,
  2049. result.c_str());
  2050. break;
  2051. case START_OUTPUT:
  2052. //result = cmSystemTools::CollapseFullPath(result.c_str());
  2053. result =
  2054. this->ConvertToRelativePath(this->StartOutputDirectoryComponents,
  2055. result.c_str());
  2056. break;
  2057. case FULL:
  2058. result = cmSystemTools::CollapseFullPath(result.c_str());
  2059. break;
  2060. case NONE:
  2061. break;
  2062. }
  2063. }
  2064. return this->ConvertToOutputFormat(result.c_str(), output);
  2065. }
  2066. //----------------------------------------------------------------------------
  2067. std::string cmLocalGenerator::ConvertToOutputFormat(const char* source,
  2068. OutputFormat output)
  2069. {
  2070. std::string result = source;
  2071. // Convert it to an output path.
  2072. if (output == MAKEFILE)
  2073. {
  2074. result = cmSystemTools::ConvertToOutputPath(result.c_str());
  2075. }
  2076. else if( output == SHELL)
  2077. {
  2078. // For the MSYS shell convert drive letters to posix paths, so
  2079. // that c:/some/path becomes /c/some/path. This is needed to
  2080. // avoid problems with the shell path translation.
  2081. if(this->MSYSShell && !this->LinkScriptShell)
  2082. {
  2083. if(result.size() > 2 && result[1] == ':')
  2084. {
  2085. result[1] = result[0];
  2086. result[0] = '/';
  2087. }
  2088. }
  2089. if(this->WindowsShell)
  2090. {
  2091. std::string::size_type pos = 0;
  2092. while((pos = result.find('/', pos)) != std::string::npos)
  2093. {
  2094. result[pos] = '\\';
  2095. pos++;
  2096. }
  2097. }
  2098. result = this->EscapeForShell(result.c_str(), true, false);
  2099. }
  2100. else if(output == RESPONSE)
  2101. {
  2102. result = this->EscapeForShell(result.c_str(), false, false);
  2103. }
  2104. return result;
  2105. }
  2106. //----------------------------------------------------------------------------
  2107. std::string cmLocalGenerator::Convert(RelativeRoot remote,
  2108. const char* local,
  2109. OutputFormat output,
  2110. bool optional)
  2111. {
  2112. const char* remotePath = this->GetRelativeRootPath(remote);
  2113. // The relative root must have a path (i.e. not FULL or NONE)
  2114. assert(remotePath != 0);
  2115. if(local && (!optional || this->UseRelativePaths))
  2116. {
  2117. std::vector<std::string> components;
  2118. cmSystemTools::SplitPath(local, components);
  2119. std::string result = this->ConvertToRelativePath(components, remotePath);
  2120. return this->ConvertToOutputFormat(result.c_str(), output);
  2121. }
  2122. else
  2123. {
  2124. return this->ConvertToOutputFormat(remotePath, output);
  2125. }
  2126. }
  2127. //----------------------------------------------------------------------------
  2128. std::string cmLocalGenerator::FindRelativePathTopSource()
  2129. {
  2130. // Relative path conversion within a single tree managed by CMake is
  2131. // safe. We can use our parent relative path top if and only if
  2132. // this is a subdirectory of that top.
  2133. if(cmLocalGenerator* parent = this->GetParent())
  2134. {
  2135. std::string parentTop = parent->FindRelativePathTopSource();
  2136. if(cmSystemTools::IsSubDirectory(
  2137. this->Makefile->GetStartDirectory(), parentTop.c_str()))
  2138. {
  2139. return parentTop;
  2140. }
  2141. }
  2142. // Otherwise this directory itself is the new top.
  2143. return this->Makefile->GetStartDirectory();
  2144. }
  2145. //----------------------------------------------------------------------------
  2146. std::string cmLocalGenerator::FindRelativePathTopBinary()
  2147. {
  2148. // Relative path conversion within a single tree managed by CMake is
  2149. // safe. We can use our parent relative path top if and only if
  2150. // this is a subdirectory of that top.
  2151. if(cmLocalGenerator* parent = this->GetParent())
  2152. {
  2153. std::string parentTop = parent->FindRelativePathTopBinary();
  2154. if(cmSystemTools::IsSubDirectory(
  2155. this->Makefile->GetStartOutputDirectory(), parentTop.c_str()))
  2156. {
  2157. return parentTop;
  2158. }
  2159. }
  2160. // Otherwise this directory itself is the new top.
  2161. return this->Makefile->GetStartOutputDirectory();
  2162. }
  2163. //----------------------------------------------------------------------------
  2164. void cmLocalGenerator::ConfigureRelativePaths()
  2165. {
  2166. // Relative path conversion inside the source tree is not used to
  2167. // construct relative paths passed to build tools so it is safe to
  2168. // even when the source is a network path.
  2169. std::string source = this->FindRelativePathTopSource();
  2170. this->RelativePathTopSource = source;
  2171. // The current working directory on Windows cannot be a network
  2172. // path. Therefore relative paths cannot work when the binary tree
  2173. // is a network path.
  2174. std::string binary = this->FindRelativePathTopBinary();
  2175. if(binary.size() < 2 || binary.substr(0, 2) != "//")
  2176. {
  2177. this->RelativePathTopBinary = binary;
  2178. }
  2179. else
  2180. {
  2181. this->RelativePathTopBinary = "";
  2182. }
  2183. }
  2184. //----------------------------------------------------------------------------
  2185. static bool cmLocalGeneratorNotAbove(const char* a, const char* b)
  2186. {
  2187. return (cmSystemTools::ComparePath(a, b) ||
  2188. cmSystemTools::IsSubDirectory(a, b));
  2189. }
  2190. //----------------------------------------------------------------------------
  2191. std::string
  2192. cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
  2193. const char* in_remote, bool force)
  2194. {
  2195. // The path should never be quoted.
  2196. assert(in_remote[0] != '\"');
  2197. // The local path should never have a trailing slash.
  2198. assert(local.size() > 0 && !(local[local.size()-1] == ""));
  2199. // If the path is already relative then just return the path.
  2200. if(!cmSystemTools::FileIsFullPath(in_remote))
  2201. {
  2202. return in_remote;
  2203. }
  2204. // Make sure relative path conversion is configured.
  2205. if(!this->RelativePathsConfigured)
  2206. {
  2207. this->ConfigureRelativePaths();
  2208. this->RelativePathsConfigured = true;
  2209. }
  2210. if(!force)
  2211. {
  2212. // Skip conversion if the path and local are not both in the source
  2213. // or both in the binary tree.
  2214. std::string local_path = cmSystemTools::JoinPath(local);
  2215. if(!((cmLocalGeneratorNotAbove(local_path.c_str(),
  2216. this->RelativePathTopBinary.c_str()) &&
  2217. cmLocalGeneratorNotAbove(in_remote,
  2218. this->RelativePathTopBinary.c_str())) ||
  2219. (cmLocalGeneratorNotAbove(local_path.c_str(),
  2220. this->RelativePathTopSource.c_str()) &&
  2221. cmLocalGeneratorNotAbove(in_remote,
  2222. this->RelativePathTopSource.c_str()))))
  2223. {
  2224. return in_remote;
  2225. }
  2226. }
  2227. // Identify the longest shared path component between the remote
  2228. // path and the local path.
  2229. std::vector<std::string> remote;
  2230. cmSystemTools::SplitPath(in_remote, remote);
  2231. unsigned int common=0;
  2232. while(common < remote.size() &&
  2233. common < local.size() &&
  2234. cmSystemTools::ComparePath(remote[common].c_str(),
  2235. local[common].c_str()))
  2236. {
  2237. ++common;
  2238. }
  2239. // If no part of the path is in common then return the full path.
  2240. if(common == 0)
  2241. {
  2242. return in_remote;
  2243. }
  2244. // If the entire path is in common then just return a ".".
  2245. if(common == remote.size() &&
  2246. common == local.size())
  2247. {
  2248. return ".";
  2249. }
  2250. // If the entire path is in common except for a trailing slash then
  2251. // just return a "./".
  2252. if(common+1 == remote.size() &&
  2253. remote[common].size() == 0 &&
  2254. common == local.size())
  2255. {
  2256. return "./";
  2257. }
  2258. // Construct the relative path.
  2259. std::string relative;
  2260. // First add enough ../ to get up to the level of the shared portion
  2261. // of the path. Leave off the trailing slash. Note that the last
  2262. // component of local will never be empty because local should never
  2263. // have a trailing slash.
  2264. for(unsigned int i=common; i < local.size(); ++i)
  2265. {
  2266. relative += "..";
  2267. if(i < local.size()-1)
  2268. {
  2269. relative += "/";
  2270. }
  2271. }
  2272. // Now add the portion of the destination path that is not included
  2273. // in the shared portion of the path. Add a slash the first time
  2274. // only if there was already something in the path. If there was a
  2275. // trailing slash in the input then the last iteration of the loop
  2276. // will add a slash followed by an empty string which will preserve
  2277. // the trailing slash in the output.
  2278. for(unsigned int i=common; i < remote.size(); ++i)
  2279. {
  2280. if(relative.size() > 0)
  2281. {
  2282. relative += "/";
  2283. }
  2284. relative += remote[i];
  2285. }
  2286. // Finally return the path.
  2287. return relative;
  2288. }
  2289. //----------------------------------------------------------------------------
  2290. void
  2291. cmLocalGenerator
  2292. ::GenerateTargetInstallRules(
  2293. std::ostream& os, const char* config,
  2294. std::vector<std::string> const& configurationTypes)
  2295. {
  2296. // Convert the old-style install specification from each target to
  2297. // an install generator and run it.
  2298. cmTargets& tgts = this->Makefile->GetTargets();
  2299. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  2300. {
  2301. // Include the user-specified pre-install script for this target.
  2302. if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
  2303. {
  2304. cmInstallScriptGenerator g(preinstall, false, 0);
  2305. g.Generate(os, config, configurationTypes);
  2306. }
  2307. // Install this target if a destination is given.
  2308. if(l->second.GetInstallPath() != "")
  2309. {
  2310. // Compute the full install destination. Note that converting
  2311. // to unix slashes also removes any trailing slash.
  2312. // We also skip over the leading slash given by the user.
  2313. std::string destination = l->second.GetInstallPath().substr(1);
  2314. cmSystemTools::ConvertToUnixSlashes(destination);
  2315. if(destination.empty())
  2316. {
  2317. destination = ".";
  2318. }
  2319. // Generate the proper install generator for this target type.
  2320. switch(l->second.GetType())
  2321. {
  2322. case cmTarget::EXECUTABLE:
  2323. case cmTarget::STATIC_LIBRARY:
  2324. case cmTarget::MODULE_LIBRARY:
  2325. {
  2326. // Use a target install generator.
  2327. cmInstallTargetGenerator g(l->second, destination.c_str(), false);
  2328. g.Generate(os, config, configurationTypes);
  2329. }
  2330. break;
  2331. case cmTarget::SHARED_LIBRARY:
  2332. {
  2333. #if defined(_WIN32) || defined(__CYGWIN__)
  2334. // Special code to handle DLL. Install the import library
  2335. // to the normal destination and the DLL to the runtime
  2336. // destination.
  2337. cmInstallTargetGenerator g1(l->second, destination.c_str(), true);
  2338. g1.Generate(os, config, configurationTypes);
  2339. // We also skip over the leading slash given by the user.
  2340. destination = l->second.GetRuntimeInstallPath().substr(1);
  2341. cmSystemTools::ConvertToUnixSlashes(destination);
  2342. cmInstallTargetGenerator g2(l->second, destination.c_str(), false);
  2343. g2.Generate(os, config, configurationTypes);
  2344. #else
  2345. // Use a target install generator.
  2346. cmInstallTargetGenerator g(l->second, destination.c_str(), false);
  2347. g.Generate(os, config, configurationTypes);
  2348. #endif
  2349. }
  2350. break;
  2351. default:
  2352. break;
  2353. }
  2354. }
  2355. // Include the user-specified post-install script for this target.
  2356. if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
  2357. {
  2358. cmInstallScriptGenerator g(postinstall, false, 0);
  2359. g.Generate(os, config, configurationTypes);
  2360. }
  2361. }
  2362. }
  2363. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2364. static std::string cmLocalGeneratorMD5(const char* input)
  2365. {
  2366. char md5out[32];
  2367. cmsysMD5* md5 = cmsysMD5_New();
  2368. cmsysMD5_Initialize(md5);
  2369. cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
  2370. cmsysMD5_FinalizeHex(md5, md5out);
  2371. cmsysMD5_Delete(md5);
  2372. return std::string(md5out, 32);
  2373. }
  2374. static bool
  2375. cmLocalGeneratorShortenObjectName(std::string& objName,
  2376. std::string::size_type max_len)
  2377. {
  2378. // Replace the beginning of the path portion of the object name with
  2379. // its own md5 sum.
  2380. std::string::size_type pos = objName.find('/', objName.size()-max_len+32);
  2381. if(pos != objName.npos)
  2382. {
  2383. std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
  2384. md5name += objName.substr(pos);
  2385. objName = md5name;
  2386. // The object name is now short enough.
  2387. return true;
  2388. }
  2389. else
  2390. {
  2391. // The object name could not be shortened enough.
  2392. return false;
  2393. }
  2394. }
  2395. static
  2396. bool cmLocalGeneratorCheckObjectName(std::string& objName,
  2397. std::string::size_type dir_len,
  2398. std::string::size_type max_total_len)
  2399. {
  2400. // Enforce the maximum file name length if possible.
  2401. std::string::size_type max_obj_len = max_total_len;
  2402. if(dir_len < max_total_len)
  2403. {
  2404. max_obj_len = max_total_len - dir_len;
  2405. if(objName.size() > max_obj_len)
  2406. {
  2407. // The current object file name is too long. Try to shorten it.
  2408. return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
  2409. }
  2410. else
  2411. {
  2412. // The object file name is short enough.
  2413. return true;
  2414. }
  2415. }
  2416. else
  2417. {
  2418. // The build directory in which the object will be stored is
  2419. // already too deep.
  2420. return false;
  2421. }
  2422. }
  2423. #endif
  2424. //----------------------------------------------------------------------------
  2425. std::string&
  2426. cmLocalGenerator
  2427. ::CreateSafeUniqueObjectFileName(const char* sin,
  2428. std::string const& dir_max)
  2429. {
  2430. // Look for an existing mapped name for this object file.
  2431. std::map<cmStdString,cmStdString>::iterator it =
  2432. this->UniqueObjectNamesMap.find(sin);
  2433. // If no entry exists create one.
  2434. if(it == this->UniqueObjectNamesMap.end())
  2435. {
  2436. // Start with the original name.
  2437. std::string ssin = sin;
  2438. // Avoid full paths by removing leading slashes.
  2439. std::string::size_type pos = 0;
  2440. for(;pos < ssin.size() && ssin[pos] == '/'; ++pos)
  2441. {
  2442. }
  2443. ssin = ssin.substr(pos);
  2444. // Avoid full paths by removing colons.
  2445. cmSystemTools::ReplaceString(ssin, ":", "_");
  2446. // Avoid relative paths that go up the tree.
  2447. cmSystemTools::ReplaceString(ssin, "../", "__/");
  2448. // Avoid spaces.
  2449. cmSystemTools::ReplaceString(ssin, " ", "_");
  2450. // Mangle the name if necessary.
  2451. if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
  2452. {
  2453. bool done;
  2454. int cc = 0;
  2455. char rpstr[100];
  2456. sprintf(rpstr, "_p_");
  2457. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2458. std::string sssin = sin;
  2459. do
  2460. {
  2461. done = true;
  2462. for ( it = this->UniqueObjectNamesMap.begin();
  2463. it != this->UniqueObjectNamesMap.end();
  2464. ++ it )
  2465. {
  2466. if ( it->second == ssin )
  2467. {
  2468. done = false;
  2469. }
  2470. }
  2471. if ( done )
  2472. {
  2473. break;
  2474. }
  2475. sssin = ssin;
  2476. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2477. sprintf(rpstr, "_p%d_", cc++);
  2478. }
  2479. while ( !done );
  2480. }
  2481. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2482. if(!cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
  2483. this->ObjectPathMax))
  2484. {
  2485. // Warn if this is the first time the path has been seen.
  2486. if(this->ObjectMaxPathViolations.insert(dir_max).second)
  2487. {
  2488. cmOStringStream m;
  2489. m << "The object file directory\n"
  2490. << " " << dir_max << "\n"
  2491. << "has " << dir_max.size() << " characters. "
  2492. << "The maximum full path to an object file is "
  2493. << this->ObjectPathMax << " characters "
  2494. << "(see CMAKE_OBJECT_PATH_MAX). "
  2495. << "Object file\n"
  2496. << " " << ssin << "\n"
  2497. << "cannot be safely placed under this directory. "
  2498. << "The build may not work correctly.";
  2499. this->Makefile->IssueMessage(cmake::WARNING, m.str());
  2500. }
  2501. }
  2502. #else
  2503. (void)dir_max;
  2504. #endif
  2505. // Insert the newly mapped object file name.
  2506. std::map<cmStdString, cmStdString>::value_type e(sin, ssin);
  2507. it = this->UniqueObjectNamesMap.insert(e).first;
  2508. }
  2509. // Return the map entry.
  2510. return it->second;
  2511. }
  2512. //----------------------------------------------------------------------------
  2513. std::string
  2514. cmLocalGenerator
  2515. ::GetObjectFileNameWithoutTarget(const cmSourceFile& source,
  2516. std::string const& dir_max,
  2517. bool* hasSourceExtension)
  2518. {
  2519. // Construct the object file name using the full path to the source
  2520. // file which is its only unique identification.
  2521. const char* fullPath = source.GetFullPath().c_str();
  2522. // Try referencing the source relative to the source tree.
  2523. std::string relFromSource = this->Convert(fullPath, START);
  2524. assert(!relFromSource.empty());
  2525. bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
  2526. bool subSource = relSource && relFromSource[0] != '.';
  2527. // Try referencing the source relative to the binary tree.
  2528. std::string relFromBinary = this->Convert(fullPath, START_OUTPUT);
  2529. assert(!relFromBinary.empty());
  2530. bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
  2531. bool subBinary = relBinary && relFromBinary[0] != '.';
  2532. // Select a nice-looking reference to the source file to construct
  2533. // the object file name.
  2534. std::string objectName;
  2535. if((relSource && !relBinary) || (subSource && !subBinary))
  2536. {
  2537. objectName = relFromSource;
  2538. }
  2539. else if((relBinary && !relSource) || (subBinary && !subSource))
  2540. {
  2541. objectName = relFromBinary;
  2542. }
  2543. else if(relFromBinary.length() < relFromSource.length())
  2544. {
  2545. objectName = relFromBinary;
  2546. }
  2547. else
  2548. {
  2549. objectName = relFromSource;
  2550. }
  2551. // if it is still a full path check for the try compile case
  2552. // try compile never have in source sources, and should not
  2553. // have conflicting source file names in the same target
  2554. if(cmSystemTools::FileIsFullPath(objectName.c_str()))
  2555. {
  2556. if(this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
  2557. {
  2558. objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
  2559. }
  2560. }
  2561. // Replace the original source file extension with the object file
  2562. // extension.
  2563. bool keptSourceExtension = true;
  2564. if(!source.GetPropertyAsBool("KEEP_EXTENSION"))
  2565. {
  2566. // Decide whether this language wants to replace the source
  2567. // extension with the object extension. For CMake 2.4
  2568. // compatibility do this by default.
  2569. bool replaceExt = this->NeedBackwardsCompatibility(2, 4);
  2570. if(!replaceExt)
  2571. {
  2572. std::string repVar = "CMAKE_";
  2573. repVar += source.GetLanguage();
  2574. repVar += "_OUTPUT_EXTENSION_REPLACE";
  2575. replaceExt = this->Makefile->IsOn(repVar.c_str());
  2576. }
  2577. // Remove the source extension if it is to be replaced.
  2578. if(replaceExt)
  2579. {
  2580. keptSourceExtension = false;
  2581. std::string::size_type dot_pos = objectName.rfind(".");
  2582. if(dot_pos != std::string::npos)
  2583. {
  2584. objectName = objectName.substr(0, dot_pos);
  2585. }
  2586. }
  2587. // Store the new extension.
  2588. objectName +=
  2589. this->GlobalGenerator->GetLanguageOutputExtension(source);
  2590. }
  2591. if(hasSourceExtension)
  2592. {
  2593. *hasSourceExtension = keptSourceExtension;
  2594. }
  2595. // Convert to a safe name.
  2596. return this->CreateSafeUniqueObjectFileName(objectName.c_str(), dir_max);
  2597. }
  2598. //----------------------------------------------------------------------------
  2599. const char*
  2600. cmLocalGenerator
  2601. ::GetSourceFileLanguage(const cmSourceFile& source)
  2602. {
  2603. return source.GetLanguage();
  2604. }
  2605. //----------------------------------------------------------------------------
  2606. std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
  2607. {
  2608. std::string result;
  2609. #if defined(_WIN32) && !defined(__CYGWIN__)
  2610. // if there are spaces
  2611. std::string temp = str;
  2612. if (temp.find(" ") != std::string::npos &&
  2613. temp.find("\"")==std::string::npos)
  2614. {
  2615. result = "\"";
  2616. result += str;
  2617. result += "\"";
  2618. return result;
  2619. }
  2620. return str;
  2621. #else
  2622. for(const char* ch = str; *ch != '\0'; ++ch)
  2623. {
  2624. if(*ch == ' ')
  2625. {
  2626. result += '\\';
  2627. }
  2628. result += *ch;
  2629. }
  2630. return result;
  2631. #endif
  2632. }
  2633. //----------------------------------------------------------------------------
  2634. static bool cmLocalGeneratorIsShellOperator(const char* str)
  2635. {
  2636. if(strcmp(str, "<") == 0 ||
  2637. strcmp(str, ">") == 0 ||
  2638. strcmp(str, "<<") == 0 ||
  2639. strcmp(str, ">>") == 0 ||
  2640. strcmp(str, "|") == 0 ||
  2641. strcmp(str, "||") == 0 ||
  2642. strcmp(str, "&&") == 0 ||
  2643. strcmp(str, "&>") == 0 ||
  2644. strcmp(str, "1>") == 0 ||
  2645. strcmp(str, "2>") == 0 ||
  2646. strcmp(str, "2>&1") == 0 ||
  2647. strcmp(str, "1>&2") == 0)
  2648. {
  2649. return true;
  2650. }
  2651. return false;
  2652. }
  2653. //----------------------------------------------------------------------------
  2654. std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
  2655. bool forEcho)
  2656. {
  2657. // Do not escape shell operators.
  2658. if(cmLocalGeneratorIsShellOperator(str))
  2659. {
  2660. return str;
  2661. }
  2662. // Compute the flags for the target shell environment.
  2663. int flags = 0;
  2664. if(this->WindowsVSIDE)
  2665. {
  2666. flags |= cmsysSystem_Shell_Flag_VSIDE;
  2667. }
  2668. else if(!this->LinkScriptShell)
  2669. {
  2670. flags |= cmsysSystem_Shell_Flag_Make;
  2671. }
  2672. if(makeVars)
  2673. {
  2674. flags |= cmsysSystem_Shell_Flag_AllowMakeVariables;
  2675. }
  2676. if(forEcho)
  2677. {
  2678. flags |= cmsysSystem_Shell_Flag_EchoWindows;
  2679. }
  2680. if(this->WatcomWMake)
  2681. {
  2682. flags |= cmsysSystem_Shell_Flag_WatcomWMake;
  2683. }
  2684. if(this->MinGWMake)
  2685. {
  2686. flags |= cmsysSystem_Shell_Flag_MinGWMake;
  2687. }
  2688. if(this->NMake)
  2689. {
  2690. flags |= cmsysSystem_Shell_Flag_NMake;
  2691. }
  2692. // Compute the buffer size needed.
  2693. int size = (this->WindowsShell ?
  2694. cmsysSystem_Shell_GetArgumentSizeForWindows(str, flags) :
  2695. cmsysSystem_Shell_GetArgumentSizeForUnix(str, flags));
  2696. // Compute the shell argument itself.
  2697. std::vector<char> arg(size);
  2698. if(this->WindowsShell)
  2699. {
  2700. cmsysSystem_Shell_GetArgumentForWindows(str, &arg[0], flags);
  2701. }
  2702. else
  2703. {
  2704. cmsysSystem_Shell_GetArgumentForUnix(str, &arg[0], flags);
  2705. }
  2706. return std::string(&arg[0]);
  2707. }
  2708. //----------------------------------------------------------------------------
  2709. std::string cmLocalGenerator::EscapeForCMake(const char* str)
  2710. {
  2711. // Always double-quote the argument to take care of most escapes.
  2712. std::string result = "\"";
  2713. for(const char* c = str; *c; ++c)
  2714. {
  2715. if(*c == '"')
  2716. {
  2717. // Escape the double quote to avoid ending the argument.
  2718. result += "\\\"";
  2719. }
  2720. else if(*c == '$')
  2721. {
  2722. // Escape the dollar to avoid expanding variables.
  2723. result += "\\$";
  2724. }
  2725. else if(*c == '\\')
  2726. {
  2727. // Escape the backslash to avoid other escapes.
  2728. result += "\\\\";
  2729. }
  2730. else
  2731. {
  2732. // Other characters will be parsed correctly.
  2733. result += *c;
  2734. }
  2735. }
  2736. result += "\"";
  2737. return result;
  2738. }
  2739. //----------------------------------------------------------------------------
  2740. cmLocalGenerator::FortranFormat
  2741. cmLocalGenerator::GetFortranFormat(const char* value)
  2742. {
  2743. FortranFormat format = FortranFormatNone;
  2744. if(value && *value)
  2745. {
  2746. std::vector<std::string> fmt;
  2747. cmSystemTools::ExpandListArgument(value, fmt);
  2748. for(std::vector<std::string>::iterator fi = fmt.begin();
  2749. fi != fmt.end(); ++fi)
  2750. {
  2751. if(*fi == "FIXED")
  2752. {
  2753. format = FortranFormatFixed;
  2754. }
  2755. if(*fi == "FREE")
  2756. {
  2757. format = FortranFormatFree;
  2758. }
  2759. }
  2760. }
  2761. return format;
  2762. }
  2763. //----------------------------------------------------------------------------
  2764. std::string
  2765. cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
  2766. {
  2767. cmSystemTools::Error("GetTargetDirectory"
  2768. " called on cmLocalGenerator");
  2769. return "";
  2770. }
  2771. //----------------------------------------------------------------------------
  2772. unsigned int cmLocalGenerator::GetBackwardsCompatibility()
  2773. {
  2774. // The computed version may change until the project is fully
  2775. // configured.
  2776. if(!this->BackwardsCompatibilityFinal)
  2777. {
  2778. unsigned int major = 0;
  2779. unsigned int minor = 0;
  2780. unsigned int patch = 0;
  2781. if(const char* value
  2782. = this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"))
  2783. {
  2784. switch(sscanf(value, "%u.%u.%u", &major, &minor, &patch))
  2785. {
  2786. case 2: patch = 0; break;
  2787. case 1: minor = 0; patch = 0; break;
  2788. default: break;
  2789. }
  2790. }
  2791. this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
  2792. this->BackwardsCompatibilityFinal = this->Configured;
  2793. }
  2794. return this->BackwardsCompatibility;
  2795. }
  2796. //----------------------------------------------------------------------------
  2797. bool cmLocalGenerator::NeedBackwardsCompatibility(unsigned int major,
  2798. unsigned int minor,
  2799. unsigned int patch)
  2800. {
  2801. // Check the policy to decide whether to pay attention to this
  2802. // variable.
  2803. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0001))
  2804. {
  2805. case cmPolicies::WARN:
  2806. // WARN is just OLD without warning because user code does not
  2807. // always affect whether this check is done.
  2808. case cmPolicies::OLD:
  2809. // Old behavior is to check the variable.
  2810. break;
  2811. case cmPolicies::NEW:
  2812. // New behavior is to ignore the variable.
  2813. return false;
  2814. case cmPolicies::REQUIRED_IF_USED:
  2815. case cmPolicies::REQUIRED_ALWAYS:
  2816. // This will never be the case because the only way to require
  2817. // the setting is to require the user to specify version policy
  2818. // 2.6 or higher. Once we add that requirement then this whole
  2819. // method can be removed anyway.
  2820. return false;
  2821. }
  2822. // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
  2823. // equal to or lower than the given version.
  2824. unsigned int actual_compat = this->GetBackwardsCompatibility();
  2825. return (actual_compat &&
  2826. actual_compat <= CMake_VERSION_ENCODE(major, minor, patch));
  2827. }
  2828. //----------------------------------------------------------------------------
  2829. bool cmLocalGenerator::CheckDefinition(std::string const& define) const
  2830. {
  2831. // Many compilers do not support -DNAME(arg)=sdf so we disable it.
  2832. bool function_style = false;
  2833. for(const char* c = define.c_str(); *c && *c != '='; ++c)
  2834. {
  2835. if(*c == '(')
  2836. {
  2837. function_style = true;
  2838. break;
  2839. }
  2840. }
  2841. if(function_style)
  2842. {
  2843. cmOStringStream e;
  2844. e << "WARNING: Function-style preprocessor definitions may not be "
  2845. << "passed on the compiler command line because many compilers "
  2846. << "do not support it.\n"
  2847. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2848. << "Consider defining the macro in a (configured) header file.\n";
  2849. cmSystemTools::Message(e.str().c_str());
  2850. return false;
  2851. }
  2852. // Many compilers do not support # in the value so we disable it.
  2853. if(define.find_first_of("#") != define.npos)
  2854. {
  2855. cmOStringStream e;
  2856. e << "WARNING: Preprocessor definitions containing '#' may not be "
  2857. << "passed on the compiler command line because many compilers "
  2858. << "do not support it.\n"
  2859. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2860. << "Consider defining the macro in a (configured) header file.\n";
  2861. cmSystemTools::Message(e.str().c_str());
  2862. return false;
  2863. }
  2864. // Assume it is supported.
  2865. return true;
  2866. }
  2867. //----------------------------------------------------------------------------
  2868. static void cmLGInfoProp(cmMakefile* mf, cmTarget* target, const char* prop)
  2869. {
  2870. if(const char* val = target->GetProperty(prop))
  2871. {
  2872. mf->AddDefinition(prop, val);
  2873. }
  2874. }
  2875. //----------------------------------------------------------------------------
  2876. void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
  2877. const char* targetName,
  2878. const char* fname)
  2879. {
  2880. // Find the Info.plist template.
  2881. const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
  2882. std::string inFile = (in && *in)? in : "MacOSXBundleInfo.plist.in";
  2883. if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
  2884. {
  2885. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2886. if(!inMod.empty())
  2887. {
  2888. inFile = inMod;
  2889. }
  2890. }
  2891. if(!cmSystemTools::FileExists(inFile.c_str(), true))
  2892. {
  2893. cmOStringStream e;
  2894. e << "Target " << target->GetName() << " Info.plist template \""
  2895. << inFile << "\" could not be found.";
  2896. cmSystemTools::Error(e.str().c_str());
  2897. return;
  2898. }
  2899. // Convert target properties to variables in an isolated makefile
  2900. // scope to configure the file. If properties are set they will
  2901. // override user make variables. If not the configuration will fall
  2902. // back to the directory-level values set by the user.
  2903. cmMakefile* mf = this->Makefile;
  2904. mf->PushScope();
  2905. mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName);
  2906. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING");
  2907. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE");
  2908. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
  2909. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
  2910. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_NAME");
  2911. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
  2912. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
  2913. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
  2914. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2915. mf->PopScope();
  2916. }
  2917. //----------------------------------------------------------------------------
  2918. void cmLocalGenerator::GenerateFrameworkInfoPList(cmTarget* target,
  2919. const char* targetName,
  2920. const char* fname)
  2921. {
  2922. // Find the Info.plist template.
  2923. const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
  2924. std::string inFile = (in && *in)? in : "MacOSXFrameworkInfo.plist.in";
  2925. if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
  2926. {
  2927. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2928. if(!inMod.empty())
  2929. {
  2930. inFile = inMod;
  2931. }
  2932. }
  2933. if(!cmSystemTools::FileExists(inFile.c_str(), true))
  2934. {
  2935. cmOStringStream e;
  2936. e << "Target " << target->GetName() << " Info.plist template \""
  2937. << inFile << "\" could not be found.";
  2938. cmSystemTools::Error(e.str().c_str());
  2939. return;
  2940. }
  2941. // Convert target properties to variables in an isolated makefile
  2942. // scope to configure the file. If properties are set they will
  2943. // override user make variables. If not the configuration will fall
  2944. // back to the directory-level values set by the user.
  2945. cmMakefile* mf = this->Makefile;
  2946. mf->PushScope();
  2947. mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName);
  2948. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE");
  2949. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
  2950. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
  2951. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
  2952. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2953. mf->PopScope();
  2954. }