cmLocalGenerator.cxx 98 KB

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