cmLocalGenerator.cxx 97 KB

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