cmLocalGenerator.cxx 94 KB

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