cmLocalGenerator.cxx 97 KB

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