cmLocalGenerator.cxx 95 KB

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