cmLocalGenerator.cxx 117 KB

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