cmLocalGenerator.cxx 116 KB

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