cmLocalGenerator.cxx 116 KB

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