cmLocalGenerator.cxx 97 KB

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