cmLocalGenerator.cxx 116 KB

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