cmLocalGenerator.cxx 94 KB

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