cmLocalGenerator.cxx 116 KB

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