cmLocalGenerator.cxx 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmLocalGenerator.h"
  14. #include "cmComputeLinkInformation.h"
  15. #include "cmGeneratedFileStream.h"
  16. #include "cmGlobalGenerator.h"
  17. #include "cmInstallGenerator.h"
  18. #include "cmInstallFilesGenerator.h"
  19. #include "cmInstallScriptGenerator.h"
  20. #include "cmInstallTargetGenerator.h"
  21. #include "cmMakefile.h"
  22. #include "cmSourceFile.h"
  23. #include "cmTest.h"
  24. #include "cmake.h"
  25. #if defined(CMAKE_BUILD_WITH_CMAKE)
  26. # define CM_LG_ENCODE_OBJECT_NAMES
  27. # include <cmsys/MD5.h>
  28. #endif
  29. #include <cmsys/System.h>
  30. #include <ctype.h> // for isalpha
  31. #include <assert.h>
  32. cmLocalGenerator::cmLocalGenerator()
  33. {
  34. this->Makefile = new cmMakefile;
  35. this->Makefile->SetLocalGenerator(this);
  36. this->Parent = 0;
  37. this->WindowsShell = false;
  38. this->WindowsVSIDE = false;
  39. this->WatcomWMake = false;
  40. this->MinGWMake = false;
  41. this->NMake = false;
  42. this->MSYSShell = false;
  43. this->LinkScriptShell = false;
  44. this->IgnoreLibPrefix = false;
  45. this->UseRelativePaths = false;
  46. this->Configured = false;
  47. this->EmitUniversalBinaryFlags = true;
  48. this->IsMakefileGenerator = false;
  49. this->RelativePathsConfigured = false;
  50. this->PathConversionsSetup = false;
  51. this->BackwardsCompatibility = 0;
  52. this->BackwardsCompatibilityFinal = false;
  53. }
  54. cmLocalGenerator::~cmLocalGenerator()
  55. {
  56. delete this->Makefile;
  57. }
  58. void cmLocalGenerator::Configure()
  59. {
  60. cmLocalGenerator* previousLg =
  61. this->GetGlobalGenerator()->GetCurrentLocalGenerator();
  62. this->GetGlobalGenerator()->SetCurrentLocalGenerator(this);
  63. // make sure the CMakeFiles dir is there
  64. std::string filesDir = this->Makefile->GetStartOutputDirectory();
  65. filesDir += cmake::GetCMakeFilesDirectory();
  66. cmSystemTools::MakeDirectory(filesDir.c_str());
  67. // find & read the list file
  68. std::string currentStart = this->Makefile->GetStartDirectory();
  69. currentStart += "/CMakeLists.txt";
  70. this->Makefile->ReadListFile(currentStart.c_str());
  71. // at the end of the ReadListFile handle any old style subdirs
  72. // first get all the subdirectories
  73. std::vector<cmLocalGenerator *> subdirs = this->GetChildren();
  74. // for each subdir recurse
  75. std::vector<cmLocalGenerator *>::iterator sdi = subdirs.begin();
  76. for (; sdi != subdirs.end(); ++sdi)
  77. {
  78. if (!(*sdi)->Configured)
  79. {
  80. this->Makefile->ConfigureSubDirectory(*sdi);
  81. }
  82. }
  83. // Check whether relative paths should be used for optionally
  84. // relative paths.
  85. this->UseRelativePaths = this->Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");
  86. this->Configured = true;
  87. this->GetGlobalGenerator()->SetCurrentLocalGenerator(previousLg);
  88. }
  89. void cmLocalGenerator::SetupPathConversions()
  90. {
  91. // Setup the current output directory components for use by
  92. // Convert
  93. std::string outdir;
  94. outdir =
  95. cmSystemTools::CollapseFullPath(this->Makefile->GetHomeDirectory());
  96. cmSystemTools::SplitPath(outdir.c_str(), this->HomeDirectoryComponents);
  97. outdir =
  98. cmSystemTools::CollapseFullPath(this->Makefile->GetStartDirectory());
  99. cmSystemTools::SplitPath(outdir.c_str(), this->StartDirectoryComponents);
  100. outdir = cmSystemTools::CollapseFullPath
  101. (this->Makefile->GetHomeOutputDirectory());
  102. cmSystemTools::SplitPath(outdir.c_str(),
  103. this->HomeOutputDirectoryComponents);
  104. outdir = cmSystemTools::CollapseFullPath
  105. (this->Makefile->GetStartOutputDirectory());
  106. cmSystemTools::SplitPath(outdir.c_str(),
  107. this->StartOutputDirectoryComponents);
  108. }
  109. void cmLocalGenerator::SetGlobalGenerator(cmGlobalGenerator *gg)
  110. {
  111. this->GlobalGenerator = gg;
  112. // setup the home directories
  113. this->Makefile->GetProperties().SetCMakeInstance(gg->GetCMakeInstance());
  114. this->Makefile->SetHomeDirectory(
  115. gg->GetCMakeInstance()->GetHomeDirectory());
  116. this->Makefile->SetHomeOutputDirectory(
  117. gg->GetCMakeInstance()->GetHomeOutputDirectory());
  118. }
  119. void cmLocalGenerator::ConfigureFinalPass()
  120. {
  121. this->Makefile->ConfigureFinalPass();
  122. }
  123. void cmLocalGenerator::TraceDependencies()
  124. {
  125. // Generate the rule files for each target.
  126. cmTargets& targets = this->Makefile->GetTargets();
  127. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  128. {
  129. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  130. // so don't build a projectfile for it
  131. if (strncmp(t->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0)
  132. {
  133. const char* projectFilename = 0;
  134. if (this->IsMakefileGenerator == false) // only use of this variable
  135. {
  136. projectFilename = t->second.GetName();
  137. }
  138. t->second.TraceDependencies(projectFilename);
  139. }
  140. }
  141. }
  142. void cmLocalGenerator::GenerateTestFiles()
  143. {
  144. if ( !this->Makefile->IsOn("CMAKE_TESTING_ENABLED") )
  145. {
  146. return;
  147. }
  148. std::string file = this->Makefile->GetStartOutputDirectory();
  149. file += "/";
  150. file += "CTestTestfile.cmake";
  151. cmGeneratedFileStream fout(file.c_str());
  152. fout.SetCopyIfDifferent(true);
  153. fout << "# CMake generated Testfile for " << std::endl
  154. << "# Source directory: "
  155. << this->Makefile->GetStartDirectory() << std::endl
  156. << "# Build directory: "
  157. << this->Makefile->GetStartOutputDirectory() << std::endl
  158. << "# " << std::endl
  159. << "# This file replicates the SUBDIRS() and ADD_TEST() commands "
  160. << "from the source" << std::endl
  161. << "# tree CMakeLists.txt file, skipping any SUBDIRS() or "
  162. << "ADD_TEST() commands" << std::endl
  163. << "# that are excluded by CMake control structures, i.e. IF() "
  164. << "commands." << std::endl;
  165. const char* testIncludeFile =
  166. this->Makefile->GetProperty("TEST_INCLUDE_FILE");
  167. if ( testIncludeFile )
  168. {
  169. fout << "INCLUDE(\"" << testIncludeFile << "\")" << std::endl;
  170. }
  171. const std::vector<cmTest*> *tests = this->Makefile->GetTests();
  172. std::vector<cmTest*>::const_iterator it;
  173. for ( it = tests->begin(); it != tests->end(); ++ it )
  174. {
  175. cmTest* test = *it;
  176. fout << "ADD_TEST(";
  177. fout << test->GetName() << " \"" << test->GetCommand() << "\"";
  178. std::vector<cmStdString>::const_iterator argit;
  179. for (argit = test->GetArguments().begin();
  180. argit != test->GetArguments().end(); ++argit)
  181. {
  182. // Just double-quote all arguments so they are re-parsed
  183. // correctly by the test system.
  184. fout << " \"";
  185. for(std::string::const_iterator c = argit->begin();
  186. c != argit->end(); ++c)
  187. {
  188. // Escape quotes within arguments. We should escape
  189. // backslashes too but we cannot because it makes the result
  190. // inconsistent with previous behavior of this command.
  191. if((*c == '"'))
  192. {
  193. fout << '\\';
  194. }
  195. fout << *c;
  196. }
  197. fout << "\"";
  198. }
  199. fout << ")" << std::endl;
  200. cmPropertyMap::const_iterator pit;
  201. cmPropertyMap* mpit = &test->GetProperties();
  202. if ( mpit->size() )
  203. {
  204. fout << "SET_TESTS_PROPERTIES(" << test->GetName() << " PROPERTIES ";
  205. for ( pit = mpit->begin(); pit != mpit->end(); ++ pit )
  206. {
  207. fout << " " << pit->first.c_str() << " \"";
  208. const char* value = pit->second.GetValue();
  209. for ( ; *value; ++ value )
  210. {
  211. switch ( *value )
  212. {
  213. case '\\':
  214. case '"':
  215. case ' ':
  216. case '#':
  217. case '(':
  218. case ')':
  219. case '$':
  220. case '^':
  221. fout << "\\" << *value;
  222. break;
  223. case '\t':
  224. fout << "\\t";
  225. break;
  226. case '\n':
  227. fout << "\\n";
  228. break;
  229. case '\r':
  230. fout << "\\r";
  231. break;
  232. default:
  233. fout << *value;
  234. }
  235. }
  236. fout << "\"";
  237. }
  238. fout << ")" << std::endl;
  239. }
  240. }
  241. if ( this->Children.size())
  242. {
  243. size_t i;
  244. for(i = 0; i < this->Children.size(); ++i)
  245. {
  246. fout << "SUBDIRS(";
  247. std::string outP =
  248. this->Children[i]->GetMakefile()->GetStartOutputDirectory();
  249. fout << this->Convert(outP.c_str(),START_OUTPUT);
  250. fout << ")" << std::endl;
  251. }
  252. }
  253. }
  254. //----------------------------------------------------------------------------
  255. void cmLocalGenerator::GenerateInstallRules()
  256. {
  257. // Compute the install prefix.
  258. const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
  259. #if defined(_WIN32) && !defined(__CYGWIN__)
  260. std::string prefix_win32;
  261. if(!prefix)
  262. {
  263. if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32))
  264. {
  265. prefix_win32 = "C:";
  266. }
  267. const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
  268. if(project_name && project_name[0])
  269. {
  270. prefix_win32 += "/Program Files/";
  271. prefix_win32 += project_name;
  272. }
  273. else
  274. {
  275. prefix_win32 += "/InstalledCMakeProject";
  276. }
  277. prefix = prefix_win32.c_str();
  278. }
  279. #else
  280. if (!prefix)
  281. {
  282. prefix = "/usr/local";
  283. }
  284. #endif
  285. // Compute the set of configurations.
  286. std::vector<std::string> configurationTypes;
  287. if(const char* types =
  288. this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  289. {
  290. cmSystemTools::ExpandListArgument(types, configurationTypes);
  291. }
  292. const char* config = 0;
  293. if(configurationTypes.empty())
  294. {
  295. config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  296. }
  297. // Choose a default install configuration.
  298. const char* default_config = config;
  299. const char* default_order[] = {"RELEASE", "MINSIZEREL",
  300. "RELWITHDEBINFO", "DEBUG", 0};
  301. for(const char** c = default_order; *c && !default_config; ++c)
  302. {
  303. for(std::vector<std::string>::iterator i = configurationTypes.begin();
  304. i != configurationTypes.end(); ++i)
  305. {
  306. if(cmSystemTools::UpperCase(*i) == *c)
  307. {
  308. default_config = i->c_str();
  309. }
  310. }
  311. }
  312. if(!default_config && !configurationTypes.empty())
  313. {
  314. default_config = configurationTypes[0].c_str();
  315. }
  316. if(!default_config)
  317. {
  318. default_config = "Release";
  319. }
  320. // Create the install script file.
  321. std::string file = this->Makefile->GetStartOutputDirectory();
  322. std::string homedir = this->Makefile->GetHomeOutputDirectory();
  323. std::string currdir = this->Makefile->GetCurrentOutputDirectory();
  324. cmSystemTools::ConvertToUnixSlashes(file);
  325. cmSystemTools::ConvertToUnixSlashes(homedir);
  326. cmSystemTools::ConvertToUnixSlashes(currdir);
  327. int toplevel_install = 0;
  328. if ( currdir == homedir )
  329. {
  330. toplevel_install = 1;
  331. }
  332. file += "/cmake_install.cmake";
  333. cmGeneratedFileStream fout(file.c_str());
  334. fout.SetCopyIfDifferent(true);
  335. // Write the header.
  336. fout << "# Install script for directory: "
  337. << this->Makefile->GetCurrentDirectory() << std::endl << std::endl;
  338. fout << "# Set the install prefix" << std::endl
  339. << "IF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  340. << " SET(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
  341. << "ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  342. << "STRING(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
  343. << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
  344. << std::endl;
  345. // Write support code for generating per-configuration install rules.
  346. fout <<
  347. "# Set the install configuration name.\n"
  348. "IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  349. " IF(BUILD_TYPE)\n"
  350. " STRING(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
  351. " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
  352. " ELSE(BUILD_TYPE)\n"
  353. " SET(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
  354. " ENDIF(BUILD_TYPE)\n"
  355. " MESSAGE(STATUS \"Install configuration: "
  356. "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
  357. "ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  358. "\n";
  359. // Write support code for dealing with component-specific installs.
  360. fout <<
  361. "# Set the component getting installed.\n"
  362. "IF(NOT CMAKE_INSTALL_COMPONENT)\n"
  363. " IF(COMPONENT)\n"
  364. " MESSAGE(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
  365. " SET(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
  366. " ELSE(COMPONENT)\n"
  367. " SET(CMAKE_INSTALL_COMPONENT)\n"
  368. " ENDIF(COMPONENT)\n"
  369. "ENDIF(NOT CMAKE_INSTALL_COMPONENT)\n"
  370. "\n";
  371. // Copy user-specified install options to the install code.
  372. if(const char* so_no_exe =
  373. this->Makefile->GetDefinition("CMAKE_INSTALL_SO_NO_EXE"))
  374. {
  375. fout <<
  376. "# Install shared libraries without execute permission?\n"
  377. "IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
  378. " SET(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe << "\")\n"
  379. "ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
  380. "\n";
  381. }
  382. // Ask each install generator to write its code.
  383. std::vector<cmInstallGenerator*> const& installers =
  384. this->Makefile->GetInstallGenerators();
  385. for(std::vector<cmInstallGenerator*>::const_iterator
  386. gi = installers.begin();
  387. gi != installers.end(); ++gi)
  388. {
  389. (*gi)->Generate(fout, config, configurationTypes);
  390. }
  391. // Write rules from old-style specification stored in targets.
  392. this->GenerateTargetInstallRules(fout, config, configurationTypes);
  393. // Include install scripts from subdirectories.
  394. if(!this->Children.empty())
  395. {
  396. fout << "IF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
  397. fout << " # Include the install script for each subdirectory.\n";
  398. for(std::vector<cmLocalGenerator*>::const_iterator
  399. ci = this->Children.begin(); ci != this->Children.end(); ++ci)
  400. {
  401. if(!(*ci)->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  402. {
  403. std::string odir = (*ci)->GetMakefile()->GetStartOutputDirectory();
  404. cmSystemTools::ConvertToUnixSlashes(odir);
  405. fout << " INCLUDE(\"" << odir.c_str()
  406. << "/cmake_install.cmake\")" << std::endl;
  407. }
  408. }
  409. fout << "\n";
  410. fout << "ENDIF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n\n";
  411. }
  412. // Record the install manifest.
  413. if ( toplevel_install )
  414. {
  415. fout <<
  416. "IF(CMAKE_INSTALL_COMPONENT)\n"
  417. " SET(CMAKE_INSTALL_MANIFEST \"install_manifest_"
  418. "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
  419. "ELSE(CMAKE_INSTALL_COMPONENT)\n"
  420. " SET(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
  421. "ENDIF(CMAKE_INSTALL_COMPONENT)\n\n";
  422. fout
  423. << "FILE(WRITE \""
  424. << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
  425. << "\"\")" << std::endl;
  426. fout
  427. << "FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES})" << std::endl
  428. << " FILE(APPEND \""
  429. << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
  430. << "\"${file}\\n\")" << std::endl
  431. << "ENDFOREACH(file)" << std::endl;
  432. }
  433. }
  434. //----------------------------------------------------------------------------
  435. void cmLocalGenerator::GenerateTargetManifest()
  436. {
  437. // Collect the set of configuration types.
  438. std::vector<std::string> configNames;
  439. if(const char* configurationTypes =
  440. this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  441. {
  442. cmSystemTools::ExpandListArgument(configurationTypes, configNames);
  443. }
  444. else if(const char* buildType =
  445. this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
  446. {
  447. if(*buildType)
  448. {
  449. configNames.push_back(buildType);
  450. }
  451. }
  452. // Add our targets to the manifest for each configuration.
  453. cmTargets& targets = this->Makefile->GetTargets();
  454. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  455. {
  456. cmTarget& target = t->second;
  457. if(configNames.empty())
  458. {
  459. target.GenerateTargetManifest(0);
  460. }
  461. else
  462. {
  463. for(std::vector<std::string>::iterator ci = configNames.begin();
  464. ci != configNames.end(); ++ci)
  465. {
  466. const char* config = ci->c_str();
  467. target.GenerateTargetManifest(config);
  468. }
  469. }
  470. }
  471. }
  472. void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
  473. const char* lang,
  474. cmSourceFile& source,
  475. cmTarget& )
  476. {
  477. std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname));
  478. objectDir = this->Convert(objectDir.c_str(),START_OUTPUT,SHELL);
  479. std::string objectFile = this->Convert(ofname,START_OUTPUT,SHELL);
  480. std::string sourceFile =
  481. this->Convert(source.GetFullPath().c_str(),START_OUTPUT,SHELL,true);
  482. std::string varString = "CMAKE_";
  483. varString += lang;
  484. varString += "_COMPILE_OBJECT";
  485. std::vector<std::string> rules;
  486. rules.push_back(this->Makefile->GetRequiredDefinition(varString.c_str()));
  487. varString = "CMAKE_";
  488. varString += lang;
  489. varString += "_FLAGS";
  490. std::string flags;
  491. flags += this->Makefile->GetSafeDefinition(varString.c_str());
  492. flags += " ";
  493. flags += this->GetIncludeFlags(lang);
  494. // Construct the command lines.
  495. cmCustomCommandLines commandLines;
  496. std::vector<std::string> commands;
  497. cmSystemTools::ExpandList(rules, commands);
  498. cmLocalGenerator::RuleVariables vars;
  499. vars.Language = lang;
  500. vars.Source = sourceFile.c_str();
  501. vars.Object = objectFile.c_str();
  502. vars.ObjectDir = objectDir.c_str();
  503. vars.Flags = flags.c_str();
  504. for(std::vector<std::string>::iterator i = commands.begin();
  505. i != commands.end(); ++i)
  506. {
  507. // Expand the full command line string.
  508. this->ExpandRuleVariables(*i, vars);
  509. // Parse the string to get the custom command line.
  510. cmCustomCommandLine commandLine;
  511. std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
  512. for(std::vector<cmStdString>::iterator a = cmd.begin();
  513. a != cmd.end(); ++a)
  514. {
  515. commandLine.push_back(*a);
  516. }
  517. // Store this command line.
  518. commandLines.push_back(commandLine);
  519. }
  520. // Check for extra object-file dependencies.
  521. std::vector<std::string> depends;
  522. const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
  523. if(additionalDeps)
  524. {
  525. cmSystemTools::ExpandListArgument(additionalDeps, depends);
  526. }
  527. // Generate a meaningful comment for the command.
  528. std::string comment = "Building ";
  529. comment += lang;
  530. comment += " object ";
  531. comment += this->Convert(ofname, START_OUTPUT);
  532. // Add the custom command to build the object file.
  533. this->Makefile->AddCustomCommandToOutput(
  534. ofname,
  535. depends,
  536. source.GetFullPath().c_str(),
  537. commandLines,
  538. comment.c_str(),
  539. this->Makefile->GetStartOutputDirectory()
  540. );
  541. }
  542. void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
  543. {
  544. cmStdString objs;
  545. std::vector<std::string> objVector;
  546. // Add all the sources outputs to the depends of the target
  547. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  548. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  549. i != classes.end(); ++i)
  550. {
  551. cmSourceFile* sf = *i;
  552. if(!sf->GetCustomCommand() &&
  553. !sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  554. !sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  555. {
  556. std::string::size_type dir_len = 0;
  557. dir_len += strlen(this->Makefile->GetCurrentOutputDirectory());
  558. dir_len += 1;
  559. std::string obj = this->GetObjectFileNameWithoutTarget(*sf, dir_len);
  560. if(!obj.empty())
  561. {
  562. std::string ofname = this->Makefile->GetCurrentOutputDirectory();
  563. ofname += "/";
  564. ofname += obj;
  565. objVector.push_back(ofname);
  566. this->AddCustomCommandToCreateObject(ofname.c_str(),
  567. llang, *(*i), target);
  568. objs += this->Convert(ofname.c_str(),START_OUTPUT,MAKEFILE);
  569. objs += " ";
  570. }
  571. }
  572. }
  573. std::string createRule = "CMAKE_";
  574. createRule += llang;
  575. createRule += target.GetCreateRuleVariable();
  576. std::string targetName = target.GetFullName();
  577. // Executable :
  578. // Shared Library:
  579. // Static Library:
  580. // Shared Module:
  581. std::string linkLibs; // should be set
  582. std::string flags; // should be set
  583. std::string linkFlags; // should be set
  584. this->GetTargetFlags(linkLibs, flags, linkFlags, target);
  585. cmLocalGenerator::RuleVariables vars;
  586. vars.Language = llang;
  587. vars.Objects = objs.c_str();
  588. vars.ObjectDir = ".";
  589. vars.Target = targetName.c_str();
  590. vars.LinkLibraries = linkLibs.c_str();
  591. vars.Flags = flags.c_str();
  592. vars.LinkFlags = linkFlags.c_str();
  593. std::string langFlags;
  594. this->AddLanguageFlags(langFlags, llang, 0);
  595. vars.LanguageCompileFlags = langFlags.c_str();
  596. cmCustomCommandLines commandLines;
  597. std::vector<std::string> rules;
  598. rules.push_back(this->Makefile->GetRequiredDefinition(createRule.c_str()));
  599. std::vector<std::string> commands;
  600. cmSystemTools::ExpandList(rules, commands);
  601. for(std::vector<std::string>::iterator i = commands.begin();
  602. i != commands.end(); ++i)
  603. {
  604. // Expand the full command line string.
  605. this->ExpandRuleVariables(*i, vars);
  606. // Parse the string to get the custom command line.
  607. cmCustomCommandLine commandLine;
  608. std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
  609. for(std::vector<cmStdString>::iterator a = cmd.begin();
  610. a != cmd.end(); ++a)
  611. {
  612. commandLine.push_back(*a);
  613. }
  614. // Store this command line.
  615. commandLines.push_back(commandLine);
  616. }
  617. std::string targetFullPath = target.GetFullPath();
  618. // Generate a meaningful comment for the command.
  619. std::string comment = "Linking ";
  620. comment += llang;
  621. comment += " target ";
  622. comment += this->Convert(targetFullPath.c_str(), START_OUTPUT);
  623. this->Makefile->AddCustomCommandToOutput(
  624. targetFullPath.c_str(),
  625. objVector,
  626. 0,
  627. commandLines,
  628. comment.c_str(),
  629. this->Makefile->GetStartOutputDirectory()
  630. );
  631. target.AddSourceFile
  632. (this->Makefile->GetSource(targetFullPath.c_str()));
  633. }
  634. void cmLocalGenerator
  635. ::CreateCustomTargetsAndCommands(std::set<cmStdString> const& lang)
  636. {
  637. cmTargets &tgts = this->Makefile->GetTargets();
  638. for(cmTargets::iterator l = tgts.begin();
  639. l != tgts.end(); l++)
  640. {
  641. cmTarget& target = l->second;
  642. switch(target.GetType())
  643. {
  644. case cmTarget::STATIC_LIBRARY:
  645. case cmTarget::SHARED_LIBRARY:
  646. case cmTarget::MODULE_LIBRARY:
  647. case cmTarget::EXECUTABLE:
  648. {
  649. const char* llang =
  650. target.GetLinkerLanguage(this->GetGlobalGenerator());
  651. if(!llang)
  652. {
  653. cmSystemTools::Error
  654. ("CMake can not determine linker language for target:",
  655. target.GetName());
  656. return;
  657. }
  658. // if the language is not in the set lang then create custom
  659. // commands to build the target
  660. if(lang.count(llang) == 0)
  661. {
  662. this->AddBuildTargetRule(llang, target);
  663. }
  664. }
  665. break;
  666. case cmTarget::UTILITY:
  667. case cmTarget::GLOBAL_TARGET:
  668. case cmTarget::INSTALL_FILES:
  669. case cmTarget::INSTALL_PROGRAMS:
  670. case cmTarget::INSTALL_DIRECTORY:
  671. break;
  672. }
  673. }
  674. }
  675. // List of variables that are replaced when
  676. // rules are expanced. These variables are
  677. // replaced in the form <var> with GetSafeDefinition(var).
  678. // ${LANG} is replaced in the variable first with all enabled
  679. // languages.
  680. static const char* ruleReplaceVars[] =
  681. {
  682. "CMAKE_${LANG}_COMPILER",
  683. "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
  684. "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
  685. "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
  686. "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
  687. "CMAKE_${LANG}_LINK_FLAGS",
  688. "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
  689. "CMAKE_${LANG}_ARCHIVE",
  690. "CMAKE_AR",
  691. "CMAKE_CURRENT_SOURCE_DIR",
  692. "CMAKE_CURRENT_BINARY_DIR",
  693. "CMAKE_RANLIB",
  694. "CMAKE_LINKER",
  695. 0
  696. };
  697. std::string
  698. cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
  699. const RuleVariables& replaceValues)
  700. {
  701. if(replaceValues.LinkFlags)
  702. {
  703. if(variable == "LINK_FLAGS")
  704. {
  705. return replaceValues.LinkFlags;
  706. }
  707. }
  708. if(replaceValues.Flags)
  709. {
  710. if(variable == "FLAGS")
  711. {
  712. return replaceValues.Flags;
  713. }
  714. }
  715. if(replaceValues.Source)
  716. {
  717. if(variable == "SOURCE")
  718. {
  719. return replaceValues.Source;
  720. }
  721. }
  722. if(replaceValues.PreprocessedSource)
  723. {
  724. if(variable == "PREPROCESSED_SOURCE")
  725. {
  726. return replaceValues.PreprocessedSource;
  727. }
  728. }
  729. if(replaceValues.AssemblySource)
  730. {
  731. if(variable == "ASSEMBLY_SOURCE")
  732. {
  733. return replaceValues.AssemblySource;
  734. }
  735. }
  736. if(replaceValues.Object)
  737. {
  738. if(variable == "OBJECT")
  739. {
  740. return replaceValues.Object;
  741. }
  742. }
  743. if(replaceValues.ObjectDir)
  744. {
  745. if(variable == "OBJECT_DIR")
  746. {
  747. return replaceValues.ObjectDir;
  748. }
  749. }
  750. if(replaceValues.Objects)
  751. {
  752. if(variable == "OBJECTS")
  753. {
  754. return replaceValues.Objects;
  755. }
  756. }
  757. if(replaceValues.ObjectsQuoted)
  758. {
  759. if(variable == "OBJECTS_QUOTED")
  760. {
  761. return replaceValues.ObjectsQuoted;
  762. }
  763. }
  764. if(replaceValues.Defines && variable == "DEFINES")
  765. {
  766. return replaceValues.Defines;
  767. }
  768. if(replaceValues.TargetPDB )
  769. {
  770. if(variable == "TARGET_PDB")
  771. {
  772. return replaceValues.TargetPDB;
  773. }
  774. }
  775. if(replaceValues.Target)
  776. {
  777. if(variable == "TARGET_QUOTED")
  778. {
  779. std::string targetQuoted = replaceValues.Target;
  780. if(targetQuoted.size() && targetQuoted[0] != '\"')
  781. {
  782. targetQuoted = '\"';
  783. targetQuoted += replaceValues.Target;
  784. targetQuoted += '\"';
  785. }
  786. return targetQuoted;
  787. }
  788. if(replaceValues.LanguageCompileFlags)
  789. {
  790. if(variable == "LANGUAGE_COMPILE_FLAGS")
  791. {
  792. return replaceValues.LanguageCompileFlags;
  793. }
  794. }
  795. if(replaceValues.Target)
  796. {
  797. if(variable == "TARGET")
  798. {
  799. return replaceValues.Target;
  800. }
  801. }
  802. if(variable == "TARGET_IMPLIB")
  803. {
  804. return this->TargetImplib;
  805. }
  806. if(variable == "TARGET_VERSION_MAJOR")
  807. {
  808. if(replaceValues.TargetVersionMajor)
  809. {
  810. return replaceValues.TargetVersionMajor;
  811. }
  812. else
  813. {
  814. return "0";
  815. }
  816. }
  817. if(variable == "TARGET_VERSION_MINOR")
  818. {
  819. if(replaceValues.TargetVersionMinor)
  820. {
  821. return replaceValues.TargetVersionMinor;
  822. }
  823. else
  824. {
  825. return "0";
  826. }
  827. }
  828. if(replaceValues.Target)
  829. {
  830. if(variable == "TARGET_BASE")
  831. {
  832. // Strip the last extension off the target name.
  833. std::string targetBase = replaceValues.Target;
  834. std::string::size_type pos = targetBase.rfind(".");
  835. if(pos != targetBase.npos)
  836. {
  837. return targetBase.substr(0, pos);
  838. }
  839. else
  840. {
  841. return targetBase;
  842. }
  843. }
  844. }
  845. }
  846. if(replaceValues.TargetSOName)
  847. {
  848. if(variable == "TARGET_SONAME")
  849. {
  850. if(replaceValues.Language)
  851. {
  852. std::string name = "CMAKE_SHARED_LIBRARY_SONAME_";
  853. name += replaceValues.Language;
  854. name += "_FLAG";
  855. if(this->Makefile->GetDefinition(name.c_str()))
  856. {
  857. return replaceValues.TargetSOName;
  858. }
  859. }
  860. return "";
  861. }
  862. }
  863. if(replaceValues.TargetInstallNameDir)
  864. {
  865. if(variable == "TARGET_INSTALLNAME_DIR")
  866. {
  867. return replaceValues.TargetInstallNameDir;
  868. }
  869. }
  870. if(replaceValues.LinkLibraries)
  871. {
  872. if(variable == "LINK_LIBRARIES")
  873. {
  874. return replaceValues.LinkLibraries;
  875. }
  876. }
  877. std::vector<std::string> enabledLanguages;
  878. this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
  879. // loop over language specific replace variables
  880. int pos = 0;
  881. while(ruleReplaceVars[pos])
  882. {
  883. for(std::vector<std::string>::iterator i = enabledLanguages.begin();
  884. i != enabledLanguages.end(); ++i)
  885. {
  886. const char* lang = i->c_str();
  887. std::string actualReplace = ruleReplaceVars[pos];
  888. // If this is the compiler then look for the extra variable
  889. // _COMPILER_ARG1 which must be the first argument to the compiler
  890. const char* compilerArg1 = 0;
  891. if(actualReplace == "CMAKE_${LANG}_COMPILER")
  892. {
  893. std::string arg1 = actualReplace + "_ARG1";
  894. cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
  895. compilerArg1 = this->Makefile->GetDefinition(arg1.c_str());
  896. }
  897. if(actualReplace.find("${LANG}") != actualReplace.npos)
  898. {
  899. cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
  900. }
  901. if(actualReplace == variable)
  902. {
  903. std::string replace =
  904. this->Makefile->GetSafeDefinition(variable.c_str());
  905. // if the variable is not a FLAG then treat it like a path
  906. if(variable.find("_FLAG") == variable.npos)
  907. {
  908. std::string ret = this->ConvertToOutputForExisting(replace.c_str());
  909. // if there is a required first argument to the compiler add it
  910. // to the compiler string
  911. if(compilerArg1)
  912. {
  913. ret += " ";
  914. ret += compilerArg1;
  915. }
  916. return ret;
  917. }
  918. return replace;
  919. }
  920. }
  921. pos++;
  922. }
  923. return variable;
  924. }
  925. void
  926. cmLocalGenerator::ExpandRuleVariables(std::string& s,
  927. const RuleVariables& replaceValues)
  928. {
  929. std::vector<std::string> enabledLanguages;
  930. this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
  931. std::string::size_type start = s.find('<');
  932. // no variables to expand
  933. if(start == s.npos)
  934. {
  935. return;
  936. }
  937. std::string::size_type pos = 0;
  938. std::string expandedInput;
  939. while(start != s.npos && start < s.size()-2)
  940. {
  941. std::string::size_type end = s.find('>', start);
  942. // if we find a < with no > we are done
  943. if(end == s.npos)
  944. {
  945. return;
  946. }
  947. char c = s[start+1];
  948. // if the next char after the < is not A-Za-z then
  949. // skip it and try to find the next < in the string
  950. if(!isalpha(c))
  951. {
  952. start = s.find('<', start+1);
  953. }
  954. else
  955. {
  956. // extract the var
  957. std::string var = s.substr(start+1, end - start-1);
  958. std::string replace = this->ExpandRuleVariable(var,
  959. replaceValues);
  960. expandedInput += s.substr(pos, start-pos);
  961. expandedInput += replace;
  962. // move to next one
  963. start = s.find('<', start+var.size()+2);
  964. pos = end+1;
  965. }
  966. }
  967. // add the rest of the input
  968. expandedInput += s.substr(pos, s.size()-pos);
  969. s = expandedInput;
  970. }
  971. std::string
  972. cmLocalGenerator::ConvertToOutputForExisting(const char* p)
  973. {
  974. std::string ret = p;
  975. if(this->WindowsShell && ret.find(' ') != ret.npos
  976. && cmSystemTools::FileExists(p))
  977. {
  978. if(cmSystemTools::GetShortPath(p, ret))
  979. {
  980. return this->Convert(ret.c_str(), NONE, SHELL, true);
  981. }
  982. }
  983. return this->Convert(p, START_OUTPUT, SHELL, true);
  984. }
  985. const char* cmLocalGenerator::GetIncludeFlags(const char* lang)
  986. {
  987. if(!lang)
  988. {
  989. return "";
  990. }
  991. if(this->LanguageToIncludeFlags.count(lang))
  992. {
  993. return this->LanguageToIncludeFlags[lang].c_str();
  994. }
  995. cmOStringStream includeFlags;
  996. std::vector<std::string> includes;
  997. this->GetIncludeDirectories(includes);
  998. std::vector<std::string>::iterator i;
  999. std::string flagVar = "CMAKE_INCLUDE_FLAG_";
  1000. flagVar += lang;
  1001. const char* includeFlag =
  1002. this->Makefile->GetSafeDefinition(flagVar.c_str());
  1003. flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
  1004. flagVar += lang;
  1005. const char* sep = this->Makefile->GetDefinition(flagVar.c_str());
  1006. bool quotePaths = false;
  1007. if(this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
  1008. {
  1009. quotePaths = true;
  1010. }
  1011. bool repeatFlag = true;
  1012. // should the include flag be repeated like ie. -IA -IB
  1013. if(!sep)
  1014. {
  1015. sep = " ";
  1016. }
  1017. else
  1018. {
  1019. // if there is a separator then the flag is not repeated but is only
  1020. // given once i.e. -classpath a:b:c
  1021. repeatFlag = false;
  1022. }
  1023. // Support special system include flag if it is available and the
  1024. // normal flag is repeated for each directory.
  1025. std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
  1026. sysFlagVar += lang;
  1027. const char* sysIncludeFlag = 0;
  1028. if(repeatFlag)
  1029. {
  1030. sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar.c_str());
  1031. }
  1032. bool flagUsed = false;
  1033. std::set<cmStdString> emitted;
  1034. #ifdef __APPLE__
  1035. emitted.insert("/System/Library/Frameworks");
  1036. #endif
  1037. for(i = includes.begin(); i != includes.end(); ++i)
  1038. {
  1039. #ifdef __APPLE__
  1040. if(cmSystemTools::IsPathToFramework(i->c_str()))
  1041. {
  1042. std::string frameworkDir = *i;
  1043. frameworkDir += "/../";
  1044. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1045. if(emitted.insert(frameworkDir).second)
  1046. {
  1047. includeFlags
  1048. << "-F"
  1049. << this->ConvertToOutputForExisting(frameworkDir.c_str()) << " ";
  1050. }
  1051. continue;
  1052. }
  1053. #endif
  1054. std::string include = *i;
  1055. if(!flagUsed || repeatFlag)
  1056. {
  1057. if(sysIncludeFlag &&
  1058. this->Makefile->IsSystemIncludeDirectory(i->c_str()))
  1059. {
  1060. includeFlags << sysIncludeFlag;
  1061. }
  1062. else
  1063. {
  1064. includeFlags << includeFlag;
  1065. }
  1066. flagUsed = true;
  1067. }
  1068. std::string includePath = this->ConvertToOutputForExisting(i->c_str());
  1069. if(quotePaths && includePath.size() && includePath[0] != '\"')
  1070. {
  1071. includeFlags << "\"";
  1072. }
  1073. includeFlags << includePath;
  1074. if(quotePaths && includePath.size() && includePath[0] != '\"')
  1075. {
  1076. includeFlags << "\"";
  1077. }
  1078. includeFlags << sep;
  1079. }
  1080. std::string flags = includeFlags.str();
  1081. // remove trailing separators
  1082. if((sep[0] != ' ') && flags[flags.size()-1] == sep[0])
  1083. {
  1084. flags[flags.size()-1] = ' ';
  1085. }
  1086. std::string defineFlags = this->Makefile->GetDefineFlags();
  1087. flags += defineFlags;
  1088. this->LanguageToIncludeFlags[lang] = flags;
  1089. // Use this temorary variable for the return value to work-around a
  1090. // bogus GCC 2.95 warning.
  1091. const char* ret = this->LanguageToIncludeFlags[lang].c_str();
  1092. return ret;
  1093. }
  1094. //----------------------------------------------------------------------------
  1095. void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
  1096. bool filter_system_dirs)
  1097. {
  1098. // Need to decide whether to automatically include the source and
  1099. // binary directories at the beginning of the include path.
  1100. bool includeSourceDir = false;
  1101. bool includeBinaryDir = false;
  1102. // When automatic include directories are requested for a build then
  1103. // include the source and binary directories at the beginning of the
  1104. // include path to approximate include file behavior for an
  1105. // in-source build. This does not account for the case of a source
  1106. // file in a subdirectory of the current source directory but we
  1107. // cannot fix this because not all native build tools support
  1108. // per-source-file include paths.
  1109. if(this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
  1110. {
  1111. includeSourceDir = true;
  1112. includeBinaryDir = true;
  1113. }
  1114. // CMake versions below 2.0 would add the source tree to the -I path
  1115. // automatically. Preserve compatibility.
  1116. const char* versionValue =
  1117. this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  1118. int major = 0;
  1119. int minor = 0;
  1120. if(versionValue && sscanf(versionValue, "%d.%d", &major, &minor) != 2)
  1121. {
  1122. versionValue = 0;
  1123. }
  1124. if(versionValue && major < 2)
  1125. {
  1126. includeSourceDir = true;
  1127. }
  1128. // Hack for VTK 4.0 - 4.4 which depend on the old behavior but do
  1129. // not set the backwards compatibility level automatically.
  1130. const char* vtkSourceDir =
  1131. this->Makefile->GetDefinition("VTK_SOURCE_DIR");
  1132. if(vtkSourceDir)
  1133. {
  1134. const char* vtk_major =
  1135. this->Makefile->GetDefinition("VTK_MAJOR_VERSION");
  1136. const char* vtk_minor =
  1137. this->Makefile->GetDefinition("VTK_MINOR_VERSION");
  1138. vtk_major = vtk_major? vtk_major : "4";
  1139. vtk_minor = vtk_minor? vtk_minor : "4";
  1140. int vmajor = 0;
  1141. int vminor = 0;
  1142. if(sscanf(vtk_major, "%d", &vmajor) &&
  1143. sscanf(vtk_minor, "%d", &vminor) && vmajor == 4 && vminor <= 4)
  1144. {
  1145. includeSourceDir = true;
  1146. }
  1147. }
  1148. // Do not repeat an include path.
  1149. std::set<cmStdString> emitted;
  1150. // Store the automatic include paths.
  1151. if(includeBinaryDir)
  1152. {
  1153. dirs.push_back(this->Makefile->GetStartOutputDirectory());
  1154. emitted.insert(this->Makefile->GetStartOutputDirectory());
  1155. }
  1156. if(includeSourceDir)
  1157. {
  1158. if(emitted.find(this->Makefile->GetStartDirectory()) == emitted.end())
  1159. {
  1160. dirs.push_back(this->Makefile->GetStartDirectory());
  1161. emitted.insert(this->Makefile->GetStartDirectory());
  1162. }
  1163. }
  1164. if(filter_system_dirs)
  1165. {
  1166. // Do not explicitly add the standard include path "/usr/include".
  1167. // This can cause problems with certain standard library
  1168. // implementations because the wrong headers may be found first.
  1169. emitted.insert("/usr/include");
  1170. if(const char* implicitIncludes = this->Makefile->GetDefinition
  1171. ("CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES"))
  1172. {
  1173. std::vector<std::string> implicitIncludeVec;
  1174. cmSystemTools::ExpandListArgument(implicitIncludes, implicitIncludeVec);
  1175. for(unsigned int k = 0; k < implicitIncludeVec.size(); ++k)
  1176. {
  1177. emitted.insert(implicitIncludeVec[k]);
  1178. }
  1179. }
  1180. }
  1181. // Get the project-specified include directories.
  1182. std::vector<std::string>& includes =
  1183. this->Makefile->GetIncludeDirectories();
  1184. // Support putting all the in-project include directories first if
  1185. // it is requested by the project.
  1186. if(this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
  1187. {
  1188. const char* topSourceDir = this->Makefile->GetHomeDirectory();
  1189. const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory();
  1190. for(std::vector<std::string>::iterator i = includes.begin();
  1191. i != includes.end(); ++i)
  1192. {
  1193. // Emit this directory only if it is a subdirectory of the
  1194. // top-level source or binary tree.
  1195. if(cmSystemTools::ComparePath(i->c_str(), topSourceDir) ||
  1196. cmSystemTools::ComparePath(i->c_str(), topBinaryDir) ||
  1197. cmSystemTools::IsSubDirectory(i->c_str(), topSourceDir) ||
  1198. cmSystemTools::IsSubDirectory(i->c_str(), topBinaryDir))
  1199. {
  1200. if(emitted.insert(*i).second)
  1201. {
  1202. dirs.push_back(*i);
  1203. }
  1204. }
  1205. }
  1206. }
  1207. // Construct the final ordered include directory list.
  1208. for(std::vector<std::string>::iterator i = includes.begin();
  1209. i != includes.end(); ++i)
  1210. {
  1211. if(emitted.insert(*i).second)
  1212. {
  1213. dirs.push_back(*i);
  1214. }
  1215. }
  1216. }
  1217. void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
  1218. std::string& flags,
  1219. std::string& linkFlags,
  1220. cmTarget& target)
  1221. {
  1222. std::string buildType =
  1223. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1224. buildType = cmSystemTools::UpperCase(buildType);
  1225. const char* libraryLinkVariable =
  1226. "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
  1227. switch(target.GetType())
  1228. {
  1229. case cmTarget::STATIC_LIBRARY:
  1230. {
  1231. const char* targetLinkFlags =
  1232. target.GetProperty("STATIC_LIBRARY_FLAGS");
  1233. if(targetLinkFlags)
  1234. {
  1235. linkFlags += targetLinkFlags;
  1236. linkFlags += " ";
  1237. }
  1238. }
  1239. break;
  1240. case cmTarget::MODULE_LIBRARY:
  1241. libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
  1242. case cmTarget::SHARED_LIBRARY:
  1243. {
  1244. linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
  1245. linkFlags += " ";
  1246. if(buildType.size())
  1247. {
  1248. std::string build = libraryLinkVariable;
  1249. build += "_";
  1250. build += buildType;
  1251. linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
  1252. linkFlags += " ";
  1253. }
  1254. if(this->Makefile->IsOn("WIN32") &&
  1255. !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
  1256. {
  1257. const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
  1258. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1259. i != sources.end(); ++i)
  1260. {
  1261. cmSourceFile* sf = *i;
  1262. if(sf->GetExtension() == "def")
  1263. {
  1264. linkFlags +=
  1265. this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1266. linkFlags += this->Convert(sf->GetFullPath().c_str(),
  1267. START_OUTPUT, SHELL);
  1268. linkFlags += " ";
  1269. }
  1270. }
  1271. }
  1272. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1273. if(targetLinkFlags)
  1274. {
  1275. linkFlags += targetLinkFlags;
  1276. linkFlags += " ";
  1277. std::string configLinkFlags = targetLinkFlags;
  1278. configLinkFlags += buildType;
  1279. targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
  1280. if(targetLinkFlags)
  1281. {
  1282. linkFlags += targetLinkFlags;
  1283. linkFlags += " ";
  1284. }
  1285. }
  1286. cmOStringStream linklibsStr;
  1287. this->OutputLinkLibraries(linklibsStr, target, false);
  1288. linkLibs = linklibsStr.str();
  1289. }
  1290. break;
  1291. case cmTarget::EXECUTABLE:
  1292. {
  1293. linkFlags +=
  1294. this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1295. linkFlags += " ";
  1296. if(buildType.size())
  1297. {
  1298. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1299. build += buildType;
  1300. linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
  1301. linkFlags += " ";
  1302. }
  1303. const char* linkLanguage =
  1304. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1305. if(!linkLanguage)
  1306. {
  1307. cmSystemTools::Error
  1308. ("CMake can not determine linker language for target:",
  1309. target.GetName());
  1310. return;
  1311. }
  1312. std::string langVar = "CMAKE_";
  1313. langVar += linkLanguage;
  1314. std::string flagsVar = langVar + "_FLAGS";
  1315. std::string sharedFlagsVar = "CMAKE_SHARED_LIBRARY_";
  1316. sharedFlagsVar += linkLanguage;
  1317. sharedFlagsVar += "_FLAGS";
  1318. flags += this->Makefile->GetSafeDefinition(flagsVar.c_str());
  1319. flags += " ";
  1320. flags += this->Makefile->GetSafeDefinition(sharedFlagsVar.c_str());
  1321. flags += " ";
  1322. cmOStringStream linklibs;
  1323. this->OutputLinkLibraries(linklibs, target, false);
  1324. linkLibs = linklibs.str();
  1325. if(cmSystemTools::IsOn
  1326. (this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1327. {
  1328. std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_")
  1329. + linkLanguage + std::string("_FLAGS");
  1330. linkFlags += this->Makefile->GetSafeDefinition(sFlagVar.c_str());
  1331. linkFlags += " ";
  1332. }
  1333. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  1334. {
  1335. linkFlags +=
  1336. this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1337. linkFlags += " ";
  1338. }
  1339. else
  1340. {
  1341. linkFlags +=
  1342. this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1343. linkFlags += " ";
  1344. }
  1345. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1346. if(targetLinkFlags)
  1347. {
  1348. linkFlags += targetLinkFlags;
  1349. linkFlags += " ";
  1350. std::string configLinkFlags = targetLinkFlags;
  1351. configLinkFlags += buildType;
  1352. targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
  1353. if(targetLinkFlags)
  1354. {
  1355. linkFlags += targetLinkFlags;
  1356. linkFlags += " ";
  1357. }
  1358. }
  1359. }
  1360. break;
  1361. case cmTarget::UTILITY:
  1362. case cmTarget::GLOBAL_TARGET:
  1363. case cmTarget::INSTALL_FILES:
  1364. case cmTarget::INSTALL_PROGRAMS:
  1365. case cmTarget::INSTALL_DIRECTORY:
  1366. break;
  1367. }
  1368. }
  1369. std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib)
  1370. {
  1371. #if defined(_WIN32) && !defined(__CYGWIN__)
  1372. // Work-ardound command line parsing limitations in MSVC 6.0 and
  1373. // Watcom.
  1374. if(this->Makefile->IsOn("MSVC60") || this->Makefile->IsOn("WATCOM"))
  1375. {
  1376. // Search for the last space.
  1377. std::string::size_type pos = lib.rfind(' ');
  1378. if(pos != lib.npos)
  1379. {
  1380. // Find the slash after the last space, if any.
  1381. pos = lib.find('/', pos);
  1382. // Convert the portion of the path with a space to a short path.
  1383. std::string sp;
  1384. if(cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp))
  1385. {
  1386. // Append the rest of the path with no space.
  1387. sp += lib.substr(pos);
  1388. // Convert to an output path.
  1389. return this->Convert(sp.c_str(), NONE, SHELL);
  1390. }
  1391. }
  1392. }
  1393. #endif
  1394. // Normal behavior.
  1395. return this->Convert(lib.c_str(), START_OUTPUT, SHELL);
  1396. }
  1397. /**
  1398. * Output the linking rules on a command line. For executables,
  1399. * targetLibrary should be a NULL pointer. For libraries, it should point
  1400. * to the name of the library. This will not link a library against itself.
  1401. */
  1402. void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout,
  1403. cmTarget& tgt,
  1404. bool relink)
  1405. {
  1406. const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  1407. cmComputeLinkInformation* pcli = tgt.GetLinkInformation(config);
  1408. if(!pcli)
  1409. {
  1410. return;
  1411. }
  1412. cmComputeLinkInformation& cli = *pcli;
  1413. // Collect library linking flags command line options.
  1414. std::string linkLibs;
  1415. const char* linkLanguage = cli.GetLinkLanguage();
  1416. std::string libPathFlag =
  1417. this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
  1418. std::string libPathTerminator =
  1419. this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
  1420. // Flags to link an executable to shared libraries.
  1421. std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
  1422. linkFlagsVar += linkLanguage;
  1423. linkFlagsVar += "_FLAGS";
  1424. if( tgt.GetType() == cmTarget::EXECUTABLE )
  1425. {
  1426. linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar.c_str());
  1427. linkLibs += " ";
  1428. }
  1429. // Append the framework search path flags.
  1430. std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
  1431. for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
  1432. fdi != fwDirs.end(); ++fdi)
  1433. {
  1434. linkLibs += "-F";
  1435. linkLibs += this->Convert(fdi->c_str(), NONE, SHELL, false);
  1436. linkLibs += " ";
  1437. }
  1438. // Append the library search path flags.
  1439. std::vector<std::string> const& libDirs = cli.GetDirectories();
  1440. for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
  1441. libDir != libDirs.end(); ++libDir)
  1442. {
  1443. std::string libpath = this->ConvertToOutputForExisting(libDir->c_str());
  1444. linkLibs += libPathFlag;
  1445. linkLibs += libpath;
  1446. linkLibs += libPathTerminator;
  1447. linkLibs += " ";
  1448. }
  1449. // Append the link items.
  1450. typedef cmComputeLinkInformation::ItemVector ItemVector;
  1451. ItemVector const& items = cli.GetItems();
  1452. for(ItemVector::const_iterator li = items.begin(); li != items.end(); ++li)
  1453. {
  1454. if(li->IsPath)
  1455. {
  1456. linkLibs += this->ConvertToLinkReference(li->Value);
  1457. }
  1458. else
  1459. {
  1460. linkLibs += li->Value;
  1461. }
  1462. linkLibs += " ";
  1463. }
  1464. // Write the library flags to the build rule.
  1465. fout << linkLibs;
  1466. // Get the RPATH entries.
  1467. std::vector<std::string> runtimeDirs;
  1468. cli.GetRPath(runtimeDirs, relink);
  1469. // Check what kind of rpath flags to use.
  1470. if(cli.GetRuntimeSep().empty())
  1471. {
  1472. // Each rpath entry gets its own option ("-R a -R b -R c")
  1473. std::string rpath;
  1474. for(std::vector<std::string>::iterator ri = runtimeDirs.begin();
  1475. ri != runtimeDirs.end(); ++ri)
  1476. {
  1477. rpath += cli.GetRuntimeFlag();
  1478. rpath += this->Convert(ri->c_str(), FULL, SHELL, false);
  1479. rpath += " ";
  1480. }
  1481. fout << rpath;
  1482. }
  1483. else
  1484. {
  1485. // All rpath entries are combined ("-Wl,-rpath,a:b:c").
  1486. std::string rpath = cli.GetRPathString(relink);
  1487. // If not relinking, make sure the rpath string is long enough to
  1488. // support a subsequent chrpath on installation.
  1489. if(!relink)
  1490. {
  1491. std::string::size_type minLength = cli.GetChrpathString().size();
  1492. while(rpath.size() < minLength)
  1493. {
  1494. rpath += cli.GetRuntimeSep();
  1495. }
  1496. }
  1497. // Store the rpath option in the stream.
  1498. if(!rpath.empty())
  1499. {
  1500. fout << cli.GetRuntimeFlag();
  1501. fout << this->EscapeForShell(rpath.c_str(), true);
  1502. fout << " ";
  1503. }
  1504. }
  1505. // Add the linker runtime search path if any.
  1506. std::string rpath_link = cli.GetRPathLinkString();
  1507. if(!cli.GetRPathLinkFlag().empty() && !rpath_link.empty())
  1508. {
  1509. fout << cli.GetRPathLinkFlag();
  1510. fout << this->EscapeForShell(rpath_link.c_str(), true);
  1511. fout << " ";
  1512. }
  1513. // Add standard libraries for this language.
  1514. std::string standardLibsVar = "CMAKE_";
  1515. standardLibsVar += cli.GetLinkLanguage();
  1516. standardLibsVar += "_STANDARD_LIBRARIES";
  1517. if(const char* stdLibs =
  1518. this->Makefile->GetDefinition(standardLibsVar.c_str()))
  1519. {
  1520. fout << stdLibs << " ";
  1521. }
  1522. }
  1523. //----------------------------------------------------------------------------
  1524. void cmLocalGenerator::AddLanguageFlags(std::string& flags,
  1525. const char* lang,
  1526. const char* config)
  1527. {
  1528. // Add language-specific flags.
  1529. std::string flagsVar = "CMAKE_";
  1530. flagsVar += lang;
  1531. flagsVar += "_FLAGS";
  1532. if(this->EmitUniversalBinaryFlags)
  1533. {
  1534. const char* osxArch =
  1535. this->Makefile->GetDefinition("CMAKE_OSX_ARCHITECTURES");
  1536. const char* sysroot =
  1537. this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
  1538. if(osxArch && sysroot && lang && lang[0] =='C')
  1539. {
  1540. std::vector<std::string> archs;
  1541. cmSystemTools::ExpandListArgument(std::string(osxArch),
  1542. archs);
  1543. bool addArchFlag = true;
  1544. if(archs.size() == 1)
  1545. {
  1546. const char* archOrig =
  1547. this->Makefile->GetSafeDefinition("CMAKE_OSX_ARCHITECTURES_DEFAULT");
  1548. if(archs[0] == archOrig)
  1549. {
  1550. addArchFlag = false;
  1551. }
  1552. }
  1553. // if there is more than one arch add the -arch and
  1554. // -isysroot flags, or if there is one arch flag, but
  1555. // it is not the default -arch flag for the system, then
  1556. // add it. Otherwize do not add -arch and -isysroot
  1557. if(addArchFlag)
  1558. {
  1559. for( std::vector<std::string>::iterator i = archs.begin();
  1560. i != archs.end(); ++i)
  1561. {
  1562. flags += " -arch ";
  1563. flags += *i;
  1564. }
  1565. flags += " -isysroot ";
  1566. flags += sysroot;
  1567. }
  1568. }
  1569. }
  1570. this->AddConfigVariableFlags(flags, flagsVar.c_str(), config);
  1571. }
  1572. //----------------------------------------------------------------------------
  1573. std::string cmLocalGenerator::GetRealDependency(const char* inName,
  1574. const char* config)
  1575. {
  1576. // Older CMake code may specify the dependency using the target
  1577. // output file rather than the target name. Such code would have
  1578. // been written before there was support for target properties that
  1579. // modify the name so stripping down to just the file name should
  1580. // produce the target name in this case.
  1581. std::string name = cmSystemTools::GetFilenameName(inName);
  1582. if(cmSystemTools::GetFilenameLastExtension(name) == ".exe")
  1583. {
  1584. name = cmSystemTools::GetFilenameWithoutLastExtension(name);
  1585. }
  1586. // Look for a CMake target with the given name.
  1587. if(cmTarget* target = this->Makefile->FindTargetToUse(name.c_str()))
  1588. {
  1589. // make sure it is not just a coincidence that the target name
  1590. // found is part of the inName
  1591. if(cmSystemTools::FileIsFullPath(inName))
  1592. {
  1593. std::string tLocation = target->GetLocation(config);
  1594. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1595. std::string depLocation = cmSystemTools::GetFilenamePath(
  1596. std::string(inName));
  1597. depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
  1598. tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
  1599. if(depLocation != tLocation)
  1600. {
  1601. // it is a full path to a depend that has the same name
  1602. // as a target but is in a different location so do not use
  1603. // the target as the depend
  1604. return inName;
  1605. }
  1606. }
  1607. switch (target->GetType())
  1608. {
  1609. case cmTarget::EXECUTABLE:
  1610. case cmTarget::STATIC_LIBRARY:
  1611. case cmTarget::SHARED_LIBRARY:
  1612. case cmTarget::MODULE_LIBRARY:
  1613. {
  1614. // Get the location of the target's output file and depend on it.
  1615. if(const char* location = target->GetLocation(config))
  1616. {
  1617. return location;
  1618. }
  1619. }
  1620. break;
  1621. case cmTarget::UTILITY:
  1622. case cmTarget::GLOBAL_TARGET:
  1623. // Depending on a utility target may not work but just trust
  1624. // the user to have given a valid name.
  1625. return inName;
  1626. case cmTarget::INSTALL_FILES:
  1627. case cmTarget::INSTALL_PROGRAMS:
  1628. case cmTarget::INSTALL_DIRECTORY:
  1629. break;
  1630. }
  1631. }
  1632. // The name was not that of a CMake target. It must name a file.
  1633. if(cmSystemTools::FileIsFullPath(inName))
  1634. {
  1635. // This is a full path. Return it as given.
  1636. return inName;
  1637. }
  1638. // Treat the name as relative to the source directory in which it
  1639. // was given.
  1640. name = this->Makefile->GetCurrentDirectory();
  1641. name += "/";
  1642. name += inName;
  1643. return name;
  1644. }
  1645. //----------------------------------------------------------------------------
  1646. std::string cmLocalGenerator::GetRealLocation(const char* inName,
  1647. const char* config)
  1648. {
  1649. std::string outName=inName;
  1650. // Look for a CMake target with the given name, which is an executable
  1651. // and which can be run
  1652. cmTarget* target = this->Makefile->FindTargetToUse(inName);
  1653. if ((target != 0)
  1654. && (target->GetType() == cmTarget::EXECUTABLE)
  1655. && ((this->Makefile->IsOn("CMAKE_CROSSCOMPILING") == false)
  1656. || (target->IsImported() == true)))
  1657. {
  1658. outName = target->GetLocation( config );
  1659. }
  1660. return outName;
  1661. }
  1662. //----------------------------------------------------------------------------
  1663. void cmLocalGenerator::AddSharedFlags(std::string& flags,
  1664. const char* lang,
  1665. bool shared)
  1666. {
  1667. std::string flagsVar;
  1668. // Add flags for dealing with shared libraries for this language.
  1669. if(shared)
  1670. {
  1671. flagsVar = "CMAKE_SHARED_LIBRARY_";
  1672. flagsVar += lang;
  1673. flagsVar += "_FLAGS";
  1674. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1675. }
  1676. // Add flags specific to shared builds.
  1677. if(cmSystemTools::IsOn(this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1678. {
  1679. flagsVar = "CMAKE_SHARED_BUILD_";
  1680. flagsVar += lang;
  1681. flagsVar += "_FLAGS";
  1682. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1683. }
  1684. }
  1685. //----------------------------------------------------------------------------
  1686. void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
  1687. const char* var,
  1688. const char* config)
  1689. {
  1690. // Add the flags from the variable itself.
  1691. std::string flagsVar = var;
  1692. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1693. // Add the flags from the build-type specific variable.
  1694. if(config && *config)
  1695. {
  1696. flagsVar += "_";
  1697. flagsVar += cmSystemTools::UpperCase(config);
  1698. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1699. }
  1700. }
  1701. //----------------------------------------------------------------------------
  1702. void cmLocalGenerator::AppendFlags(std::string& flags,
  1703. const char* newFlags)
  1704. {
  1705. if(newFlags && *newFlags)
  1706. {
  1707. std::string newf = newFlags;
  1708. if(flags.size())
  1709. {
  1710. flags += " ";
  1711. }
  1712. flags += newFlags;
  1713. }
  1714. }
  1715. //----------------------------------------------------------------------------
  1716. void cmLocalGenerator::AppendDefines(std::string& defines,
  1717. const char* defines_list,
  1718. const char* lang)
  1719. {
  1720. // Short-circuit if there are no definitions.
  1721. if(!defines_list)
  1722. {
  1723. return;
  1724. }
  1725. // Expand the list of definitions.
  1726. std::vector<std::string> defines_vec;
  1727. cmSystemTools::ExpandListArgument(defines_list, defines_vec);
  1728. // Short-circuit if there are no definitions.
  1729. if(defines_vec.empty())
  1730. {
  1731. return;
  1732. }
  1733. // Lookup the define flag for the current language.
  1734. std::string dflag = "-D";
  1735. if(lang)
  1736. {
  1737. std::string defineFlagVar = "CMAKE_";
  1738. defineFlagVar += lang;
  1739. defineFlagVar += "_DEFINE_FLAG";
  1740. const char* df = this->Makefile->GetDefinition(defineFlagVar.c_str());
  1741. if(df && *df)
  1742. {
  1743. dflag = df;
  1744. }
  1745. }
  1746. // Add each definition to the command line with appropriate escapes.
  1747. const char* dsep = defines.empty()? "" : " ";
  1748. for(std::vector<std::string>::const_iterator di = defines_vec.begin();
  1749. di != defines_vec.end(); ++di)
  1750. {
  1751. // Skip unsupported definitions.
  1752. if(!this->CheckDefinition(*di))
  1753. {
  1754. continue;
  1755. }
  1756. // Separate from previous definitions.
  1757. defines += dsep;
  1758. dsep = " ";
  1759. // Append the definition with proper escaping.
  1760. defines += dflag;
  1761. if(this->WatcomWMake)
  1762. {
  1763. // The Watcom compiler does its own command line parsing instead
  1764. // of using the windows shell rules. Definitions are one of
  1765. // -DNAME
  1766. // -DNAME=<cpp-token>
  1767. // -DNAME="c-string with spaces and other characters(?@#$)"
  1768. //
  1769. // Watcom will properly parse each of these cases from the
  1770. // command line without any escapes. However we still have to
  1771. // get the '$' and '#' characters through WMake as '$$' and
  1772. // '$#'.
  1773. for(const char* c = di->c_str(); *c; ++c)
  1774. {
  1775. if(*c == '$' || *c == '#')
  1776. {
  1777. defines += '$';
  1778. }
  1779. defines += *c;
  1780. }
  1781. }
  1782. else
  1783. {
  1784. // Make the definition appear properly on the command line.
  1785. defines += this->EscapeForShell(di->c_str(), true);
  1786. }
  1787. }
  1788. }
  1789. //----------------------------------------------------------------------------
  1790. std::string
  1791. cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,
  1792. const char* default_comment)
  1793. {
  1794. // Check for a comment provided with the command.
  1795. if(cc.GetComment())
  1796. {
  1797. return cc.GetComment();
  1798. }
  1799. // Construct a reasonable default comment if possible.
  1800. if(!cc.GetOutputs().empty())
  1801. {
  1802. std::string comment;
  1803. comment = "Generating ";
  1804. const char* sep = "";
  1805. for(std::vector<std::string>::const_iterator o = cc.GetOutputs().begin();
  1806. o != cc.GetOutputs().end(); ++o)
  1807. {
  1808. comment += sep;
  1809. comment += this->Convert(o->c_str(), cmLocalGenerator::START_OUTPUT);
  1810. sep = ", ";
  1811. }
  1812. return comment;
  1813. }
  1814. // Otherwise use the provided default.
  1815. return default_comment;
  1816. }
  1817. //----------------------------------------------------------------------------
  1818. std::string
  1819. cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(const char* remote)
  1820. {
  1821. return this->Convert(remote, START_OUTPUT, SHELL, true);
  1822. }
  1823. //----------------------------------------------------------------------------
  1824. std::string cmLocalGenerator::Convert(const char* source,
  1825. RelativeRoot relative,
  1826. OutputFormat output,
  1827. bool optional)
  1828. {
  1829. // Make sure the relative path conversion components are set.
  1830. if(!this->PathConversionsSetup)
  1831. {
  1832. this->SetupPathConversions();
  1833. this->PathConversionsSetup = true;
  1834. }
  1835. // Convert the path to a relative path.
  1836. std::string result = source;
  1837. if (!optional || this->UseRelativePaths)
  1838. {
  1839. switch (relative)
  1840. {
  1841. case HOME:
  1842. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1843. result = this->ConvertToRelativePath(this->HomeDirectoryComponents,
  1844. result.c_str());
  1845. break;
  1846. case START:
  1847. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1848. result = this->ConvertToRelativePath(this->StartDirectoryComponents,
  1849. result.c_str());
  1850. break;
  1851. case HOME_OUTPUT:
  1852. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1853. result =
  1854. this->ConvertToRelativePath(this->HomeOutputDirectoryComponents,
  1855. result.c_str());
  1856. break;
  1857. case START_OUTPUT:
  1858. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1859. result =
  1860. this->ConvertToRelativePath(this->StartOutputDirectoryComponents,
  1861. result.c_str());
  1862. break;
  1863. case FULL:
  1864. result = cmSystemTools::CollapseFullPath(result.c_str());
  1865. break;
  1866. case NONE:
  1867. break;
  1868. }
  1869. }
  1870. // Now convert it to an output path.
  1871. if (output == MAKEFILE)
  1872. {
  1873. result = cmSystemTools::ConvertToOutputPath(result.c_str());
  1874. }
  1875. else if( output == SHELL)
  1876. {
  1877. // For the MSYS shell convert drive letters to posix paths, so
  1878. // that c:/some/path becomes /c/some/path. This is needed to
  1879. // avoid problems with the shell path translation.
  1880. if(this->MSYSShell && !this->LinkScriptShell)
  1881. {
  1882. if(result.size() > 2 && result[1] == ':')
  1883. {
  1884. result[1] = result[0];
  1885. result[0] = '/';
  1886. }
  1887. }
  1888. if(this->WindowsShell)
  1889. {
  1890. std::string::size_type pos = 0;
  1891. while((pos = result.find('/', pos)) != std::string::npos)
  1892. {
  1893. result[pos] = '\\';
  1894. pos++;
  1895. }
  1896. }
  1897. result = this->EscapeForShell(result.c_str(), true, false);
  1898. }
  1899. return result;
  1900. }
  1901. //----------------------------------------------------------------------------
  1902. std::string cmLocalGenerator::FindRelativePathTopSource()
  1903. {
  1904. // Relative path conversion within a single tree managed by CMake is
  1905. // safe. We can use our parent relative path top if and only if
  1906. // this is a subdirectory of that top.
  1907. if(cmLocalGenerator* parent = this->GetParent())
  1908. {
  1909. std::string parentTop = parent->FindRelativePathTopSource();
  1910. if(cmSystemTools::IsSubDirectory(
  1911. this->Makefile->GetStartDirectory(), parentTop.c_str()))
  1912. {
  1913. return parentTop;
  1914. }
  1915. }
  1916. // Otherwise this directory itself is the new top.
  1917. return this->Makefile->GetStartDirectory();
  1918. }
  1919. //----------------------------------------------------------------------------
  1920. std::string cmLocalGenerator::FindRelativePathTopBinary()
  1921. {
  1922. // Relative path conversion within a single tree managed by CMake is
  1923. // safe. We can use our parent relative path top if and only if
  1924. // this is a subdirectory of that top.
  1925. if(cmLocalGenerator* parent = this->GetParent())
  1926. {
  1927. std::string parentTop = parent->FindRelativePathTopBinary();
  1928. if(cmSystemTools::IsSubDirectory(
  1929. this->Makefile->GetStartOutputDirectory(), parentTop.c_str()))
  1930. {
  1931. return parentTop;
  1932. }
  1933. }
  1934. // Otherwise this directory itself is the new top.
  1935. return this->Makefile->GetStartOutputDirectory();
  1936. }
  1937. //----------------------------------------------------------------------------
  1938. void cmLocalGenerator::ConfigureRelativePaths()
  1939. {
  1940. // Relative path conversion inside the source tree is not used to
  1941. // construct relative paths passed to build tools so it is safe to
  1942. // even when the source is a network path.
  1943. std::string source = this->FindRelativePathTopSource();
  1944. this->RelativePathTopSource = source;
  1945. // The current working directory on Windows cannot be a network
  1946. // path. Therefore relative paths cannot work when the binary tree
  1947. // is a network path.
  1948. std::string binary = this->FindRelativePathTopBinary();
  1949. if(binary.size() < 2 || binary.substr(0, 2) != "//")
  1950. {
  1951. this->RelativePathTopBinary = binary;
  1952. }
  1953. else
  1954. {
  1955. this->RelativePathTopBinary = "";
  1956. }
  1957. }
  1958. //----------------------------------------------------------------------------
  1959. static bool cmLocalGeneratorNotAbove(const char* a, const char* b)
  1960. {
  1961. return (cmSystemTools::ComparePath(a, b) ||
  1962. cmSystemTools::IsSubDirectory(a, b));
  1963. }
  1964. //----------------------------------------------------------------------------
  1965. std::string
  1966. cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
  1967. const char* in_remote)
  1968. {
  1969. // The path should never be quoted.
  1970. assert(in_remote[0] != '\"');
  1971. // The local path should never have a trailing slash.
  1972. assert(local.size() > 0 && !(local[local.size()-1] == ""));
  1973. // If the path is already relative then just return the path.
  1974. if(!cmSystemTools::FileIsFullPath(in_remote))
  1975. {
  1976. return in_remote;
  1977. }
  1978. // Make sure relative path conversion is configured.
  1979. if(!this->RelativePathsConfigured)
  1980. {
  1981. this->ConfigureRelativePaths();
  1982. this->RelativePathsConfigured = true;
  1983. }
  1984. // Skip conversion if the path and local are not both in the source
  1985. // or both in the binary tree.
  1986. std::string local_path = cmSystemTools::JoinPath(local);
  1987. if(!((cmLocalGeneratorNotAbove(local_path.c_str(),
  1988. this->RelativePathTopBinary.c_str()) &&
  1989. cmLocalGeneratorNotAbove(in_remote,
  1990. this->RelativePathTopBinary.c_str())) ||
  1991. (cmLocalGeneratorNotAbove(local_path.c_str(),
  1992. this->RelativePathTopSource.c_str()) &&
  1993. cmLocalGeneratorNotAbove(in_remote,
  1994. this->RelativePathTopSource.c_str()))))
  1995. {
  1996. return in_remote;
  1997. }
  1998. // Identify the longest shared path component between the remote
  1999. // path and the local path.
  2000. std::vector<std::string> remote;
  2001. cmSystemTools::SplitPath(in_remote, remote);
  2002. unsigned int common=0;
  2003. while(common < remote.size() &&
  2004. common < local.size() &&
  2005. cmSystemTools::ComparePath(remote[common].c_str(),
  2006. local[common].c_str()))
  2007. {
  2008. ++common;
  2009. }
  2010. // If no part of the path is in common then return the full path.
  2011. if(common == 0)
  2012. {
  2013. return in_remote;
  2014. }
  2015. // If the entire path is in common then just return a ".".
  2016. if(common == remote.size() &&
  2017. common == local.size())
  2018. {
  2019. return ".";
  2020. }
  2021. // If the entire path is in common except for a trailing slash then
  2022. // just return a "./".
  2023. if(common+1 == remote.size() &&
  2024. remote[common].size() == 0 &&
  2025. common == local.size())
  2026. {
  2027. return "./";
  2028. }
  2029. // Construct the relative path.
  2030. std::string relative;
  2031. // First add enough ../ to get up to the level of the shared portion
  2032. // of the path. Leave off the trailing slash. Note that the last
  2033. // component of local will never be empty because local should never
  2034. // have a trailing slash.
  2035. for(unsigned int i=common; i < local.size(); ++i)
  2036. {
  2037. relative += "..";
  2038. if(i < local.size()-1)
  2039. {
  2040. relative += "/";
  2041. }
  2042. }
  2043. // Now add the portion of the destination path that is not included
  2044. // in the shared portion of the path. Add a slash the first time
  2045. // only if there was already something in the path. If there was a
  2046. // trailing slash in the input then the last iteration of the loop
  2047. // will add a slash followed by an empty string which will preserve
  2048. // the trailing slash in the output.
  2049. for(unsigned int i=common; i < remote.size(); ++i)
  2050. {
  2051. if(relative.size() > 0)
  2052. {
  2053. relative += "/";
  2054. }
  2055. relative += remote[i];
  2056. }
  2057. // Finally return the path.
  2058. return relative;
  2059. }
  2060. //----------------------------------------------------------------------------
  2061. void
  2062. cmLocalGenerator
  2063. ::GenerateTargetInstallRules(
  2064. std::ostream& os, const char* config,
  2065. std::vector<std::string> const& configurationTypes)
  2066. {
  2067. // Convert the old-style install specification from each target to
  2068. // an install generator and run it.
  2069. cmTargets& tgts = this->Makefile->GetTargets();
  2070. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  2071. {
  2072. // Include the user-specified pre-install script for this target.
  2073. if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
  2074. {
  2075. cmInstallScriptGenerator g(preinstall, false, 0);
  2076. g.Generate(os, config, configurationTypes);
  2077. }
  2078. // Install this target if a destination is given.
  2079. if(l->second.GetInstallPath() != "")
  2080. {
  2081. // Compute the full install destination. Note that converting
  2082. // to unix slashes also removes any trailing slash.
  2083. // We also skip over the leading slash given by the user.
  2084. std::string destination = l->second.GetInstallPath().substr(1);
  2085. cmSystemTools::ConvertToUnixSlashes(destination);
  2086. // Generate the proper install generator for this target type.
  2087. switch(l->second.GetType())
  2088. {
  2089. case cmTarget::EXECUTABLE:
  2090. case cmTarget::STATIC_LIBRARY:
  2091. case cmTarget::MODULE_LIBRARY:
  2092. {
  2093. // Use a target install generator.
  2094. cmInstallTargetGenerator g(l->second, destination.c_str(), false);
  2095. g.Generate(os, config, configurationTypes);
  2096. }
  2097. break;
  2098. case cmTarget::SHARED_LIBRARY:
  2099. {
  2100. #if defined(_WIN32) || defined(__CYGWIN__)
  2101. // Special code to handle DLL. Install the import library
  2102. // to the normal destination and the DLL to the runtime
  2103. // destination.
  2104. cmInstallTargetGenerator g1(l->second, destination.c_str(), true);
  2105. g1.Generate(os, config, configurationTypes);
  2106. // We also skip over the leading slash given by the user.
  2107. destination = l->second.GetRuntimeInstallPath().substr(1);
  2108. cmSystemTools::ConvertToUnixSlashes(destination);
  2109. cmInstallTargetGenerator g2(l->second, destination.c_str(), false);
  2110. g2.Generate(os, config, configurationTypes);
  2111. #else
  2112. // Use a target install generator.
  2113. cmInstallTargetGenerator g(l->second, destination.c_str(), false);
  2114. g.Generate(os, config, configurationTypes);
  2115. #endif
  2116. }
  2117. break;
  2118. default:
  2119. break;
  2120. }
  2121. }
  2122. // Include the user-specified post-install script for this target.
  2123. if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
  2124. {
  2125. cmInstallScriptGenerator g(postinstall, false, 0);
  2126. g.Generate(os, config, configurationTypes);
  2127. }
  2128. }
  2129. }
  2130. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2131. static std::string cmLocalGeneratorMD5(const char* input)
  2132. {
  2133. char md5out[32];
  2134. cmsysMD5* md5 = cmsysMD5_New();
  2135. cmsysMD5_Initialize(md5);
  2136. cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
  2137. cmsysMD5_FinalizeHex(md5, md5out);
  2138. cmsysMD5_Delete(md5);
  2139. return std::string(md5out, 32);
  2140. }
  2141. static bool
  2142. cmLocalGeneratorShortenObjectName(std::string& objName,
  2143. std::string::size_type max_len)
  2144. {
  2145. // Replace the beginning of the path portion of the object name with
  2146. // its own md5 sum.
  2147. std::string::size_type pos = objName.find('/', objName.size()-max_len+32);
  2148. if(pos != objName.npos)
  2149. {
  2150. std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
  2151. md5name += objName.substr(pos);
  2152. objName = md5name;
  2153. // The object name is now short enough.
  2154. return true;
  2155. }
  2156. else
  2157. {
  2158. // The object name could not be shortened enough.
  2159. return false;
  2160. }
  2161. }
  2162. static bool cmLocalGeneratorCheckObjectName(std::string& objName,
  2163. std::string::size_type dir_len)
  2164. {
  2165. // Choose a maximum file name length.
  2166. #if defined(_WIN32) || defined(__CYGWIN__)
  2167. std::string::size_type const max_total_len = 250;
  2168. #else
  2169. std::string::size_type const max_total_len = 1000;
  2170. #endif
  2171. // Enforce the maximum file name length if possible.
  2172. std::string::size_type max_obj_len = max_total_len;
  2173. if(dir_len < max_total_len)
  2174. {
  2175. max_obj_len = max_total_len - dir_len;
  2176. if(objName.size() > max_obj_len)
  2177. {
  2178. // The current object file name is too long. Try to shorten it.
  2179. return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
  2180. }
  2181. else
  2182. {
  2183. // The object file name is short enough.
  2184. return true;
  2185. }
  2186. }
  2187. else
  2188. {
  2189. // The build directory in which the object will be stored is
  2190. // already too deep.
  2191. return false;
  2192. }
  2193. }
  2194. #endif
  2195. //----------------------------------------------------------------------------
  2196. std::string&
  2197. cmLocalGenerator
  2198. ::CreateSafeUniqueObjectFileName(const char* sin,
  2199. std::string::size_type dir_len)
  2200. {
  2201. // Look for an existing mapped name for this object file.
  2202. std::map<cmStdString,cmStdString>::iterator it =
  2203. this->UniqueObjectNamesMap.find(sin);
  2204. // If no entry exists create one.
  2205. if(it == this->UniqueObjectNamesMap.end())
  2206. {
  2207. // Start with the original name.
  2208. std::string ssin = sin;
  2209. // Avoid full paths by removing leading slashes.
  2210. std::string::size_type pos = 0;
  2211. for(;pos < ssin.size() && ssin[pos] == '/'; ++pos);
  2212. ssin = ssin.substr(pos);
  2213. // Avoid full paths by removing colons.
  2214. cmSystemTools::ReplaceString(ssin, ":", "_");
  2215. // Avoid relative paths that go up the tree.
  2216. cmSystemTools::ReplaceString(ssin, "../", "__/");
  2217. // Avoid spaces.
  2218. cmSystemTools::ReplaceString(ssin, " ", "_");
  2219. // Mangle the name if necessary.
  2220. if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
  2221. {
  2222. bool done;
  2223. int cc = 0;
  2224. char rpstr[100];
  2225. sprintf(rpstr, "_p_");
  2226. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2227. std::string sssin = sin;
  2228. do
  2229. {
  2230. done = true;
  2231. for ( it = this->UniqueObjectNamesMap.begin();
  2232. it != this->UniqueObjectNamesMap.end();
  2233. ++ it )
  2234. {
  2235. if ( it->second == ssin )
  2236. {
  2237. done = false;
  2238. }
  2239. }
  2240. if ( done )
  2241. {
  2242. break;
  2243. }
  2244. sssin = ssin;
  2245. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2246. sprintf(rpstr, "_p%d_", cc++);
  2247. }
  2248. while ( !done );
  2249. }
  2250. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2251. cmLocalGeneratorCheckObjectName(ssin, dir_len);
  2252. #else
  2253. (void)dir_len;
  2254. #endif
  2255. // Insert the newly mapped object file name.
  2256. std::map<cmStdString, cmStdString>::value_type e(sin, ssin);
  2257. it = this->UniqueObjectNamesMap.insert(e).first;
  2258. }
  2259. // Return the map entry.
  2260. return it->second;
  2261. }
  2262. //----------------------------------------------------------------------------
  2263. std::string
  2264. cmLocalGenerator
  2265. ::GetObjectFileNameWithoutTarget(const cmSourceFile& source,
  2266. std::string::size_type dir_len,
  2267. bool* hasSourceExtension)
  2268. {
  2269. // Construct the object file name using the full path to the source
  2270. // file which is its only unique identification.
  2271. const char* fullPath = source.GetFullPath().c_str();
  2272. // Try referencing the source relative to the source tree.
  2273. std::string relFromSource = this->Convert(fullPath, START);
  2274. assert(!relFromSource.empty());
  2275. bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
  2276. bool subSource = relSource && relFromSource[0] != '.';
  2277. // Try referencing the source relative to the binary tree.
  2278. std::string relFromBinary = this->Convert(fullPath, START_OUTPUT);
  2279. assert(!relFromBinary.empty());
  2280. bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
  2281. bool subBinary = relBinary && relFromBinary[0] != '.';
  2282. // Select a nice-looking reference to the source file to construct
  2283. // the object file name.
  2284. std::string objectName;
  2285. if((relSource && !relBinary) || (subSource && !subBinary))
  2286. {
  2287. objectName = relFromSource;
  2288. }
  2289. else if((relBinary && !relSource) || (subBinary && !subSource))
  2290. {
  2291. objectName = relFromBinary;
  2292. }
  2293. else if(relFromBinary.length() < relFromSource.length())
  2294. {
  2295. objectName = relFromBinary;
  2296. }
  2297. else
  2298. {
  2299. objectName = relFromSource;
  2300. }
  2301. // if it is still a full path check for the try compile case
  2302. // try compile never have in source sources, and should not
  2303. // have conflicting source file names in the same target
  2304. if(cmSystemTools::FileIsFullPath(objectName.c_str()))
  2305. {
  2306. if(this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
  2307. {
  2308. objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
  2309. }
  2310. }
  2311. // Replace the original source file extension with the object file
  2312. // extension.
  2313. bool keptSourceExtension = true;
  2314. if(!source.GetPropertyAsBool("KEEP_EXTENSION"))
  2315. {
  2316. // Decide whether this language wants to replace the source
  2317. // extension with the object extension. For CMake 2.4
  2318. // compatibility do this by default.
  2319. bool replaceExt = this->NeedBackwardsCompatibility(2, 4);
  2320. if(!replaceExt)
  2321. {
  2322. std::string repVar = "CMAKE_";
  2323. repVar += source.GetLanguage();
  2324. repVar += "_OUTPUT_EXTENSION_REPLACE";
  2325. replaceExt = this->Makefile->IsOn(repVar.c_str());
  2326. }
  2327. // Remove the source extension if it is to be replaced.
  2328. if(replaceExt)
  2329. {
  2330. keptSourceExtension = false;
  2331. std::string::size_type dot_pos = objectName.rfind(".");
  2332. if(dot_pos != std::string::npos)
  2333. {
  2334. objectName = objectName.substr(0, dot_pos);
  2335. }
  2336. }
  2337. // Store the new extension.
  2338. objectName +=
  2339. this->GlobalGenerator->GetLanguageOutputExtension(source);
  2340. }
  2341. if(hasSourceExtension)
  2342. {
  2343. *hasSourceExtension = keptSourceExtension;
  2344. }
  2345. // Convert to a safe name.
  2346. return this->CreateSafeUniqueObjectFileName(objectName.c_str(), dir_len);
  2347. }
  2348. //----------------------------------------------------------------------------
  2349. const char*
  2350. cmLocalGenerator
  2351. ::GetSourceFileLanguage(const cmSourceFile& source)
  2352. {
  2353. return source.GetLanguage();
  2354. }
  2355. //----------------------------------------------------------------------------
  2356. std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
  2357. {
  2358. std::string result;
  2359. bool forceOn = cmSystemTools::GetForceUnixPaths();
  2360. if(forceOn && this->WindowsShell)
  2361. {
  2362. cmSystemTools::SetForceUnixPaths(false);
  2363. }
  2364. result = cmSystemTools::EscapeSpaces(str);
  2365. if(forceOn && this->WindowsShell)
  2366. {
  2367. cmSystemTools::SetForceUnixPaths(true);
  2368. }
  2369. return result;
  2370. }
  2371. //----------------------------------------------------------------------------
  2372. std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
  2373. bool forEcho)
  2374. {
  2375. // Compute the flags for the target shell environment.
  2376. int flags = 0;
  2377. if(this->WindowsVSIDE)
  2378. {
  2379. flags |= cmsysSystem_Shell_Flag_VSIDE;
  2380. }
  2381. else
  2382. {
  2383. flags |= cmsysSystem_Shell_Flag_Make;
  2384. }
  2385. if(makeVars)
  2386. {
  2387. flags |= cmsysSystem_Shell_Flag_AllowMakeVariables;
  2388. }
  2389. if(forEcho)
  2390. {
  2391. flags |= cmsysSystem_Shell_Flag_EchoWindows;
  2392. }
  2393. if(this->WatcomWMake)
  2394. {
  2395. flags |= cmsysSystem_Shell_Flag_WatcomWMake;
  2396. }
  2397. if(this->MinGWMake)
  2398. {
  2399. flags |= cmsysSystem_Shell_Flag_MinGWMake;
  2400. }
  2401. if(this->NMake)
  2402. {
  2403. flags |= cmsysSystem_Shell_Flag_NMake;
  2404. }
  2405. // Compute the buffer size needed.
  2406. int size = (this->WindowsShell ?
  2407. cmsysSystem_Shell_GetArgumentSizeForWindows(str, flags) :
  2408. cmsysSystem_Shell_GetArgumentSizeForUnix(str, flags));
  2409. // Compute the shell argument itself.
  2410. std::vector<char> arg(size);
  2411. if(this->WindowsShell)
  2412. {
  2413. cmsysSystem_Shell_GetArgumentForWindows(str, &arg[0], flags);
  2414. }
  2415. else
  2416. {
  2417. cmsysSystem_Shell_GetArgumentForUnix(str, &arg[0], flags);
  2418. }
  2419. return std::string(&arg[0]);
  2420. }
  2421. //----------------------------------------------------------------------------
  2422. std::string cmLocalGenerator::EscapeForCMake(const char* str)
  2423. {
  2424. // Always double-quote the argument to take care of most escapes.
  2425. std::string result = "\"";
  2426. for(const char* c = str; *c; ++c)
  2427. {
  2428. if(*c == '"')
  2429. {
  2430. // Escape the double quote to avoid ending the argument.
  2431. result += "\\\"";
  2432. }
  2433. else if(*c == '$')
  2434. {
  2435. // Escape the dollar to avoid expanding variables.
  2436. result += "\\$";
  2437. }
  2438. else if(*c == '\\')
  2439. {
  2440. // Escape the backslash to avoid other escapes.
  2441. result += "\\\\";
  2442. }
  2443. else
  2444. {
  2445. // Other characters will be parsed correctly.
  2446. result += *c;
  2447. }
  2448. }
  2449. result += "\"";
  2450. return result;
  2451. }
  2452. //----------------------------------------------------------------------------
  2453. std::string
  2454. cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
  2455. {
  2456. cmSystemTools::Error("GetTargetDirectory"
  2457. " called on cmLocalGenerator");
  2458. return "";
  2459. }
  2460. //----------------------------------------------------------------------------
  2461. void
  2462. cmLocalGenerator::GetTargetObjectFileDirectories(cmTarget* ,
  2463. std::vector<std::string>&
  2464. )
  2465. {
  2466. cmSystemTools::Error("GetTargetObjectFileDirectories"
  2467. " called on cmLocalGenerator");
  2468. }
  2469. //----------------------------------------------------------------------------
  2470. unsigned int cmLocalGenerator::GetBackwardsCompatibility()
  2471. {
  2472. // The computed version may change until the project is fully
  2473. // configured.
  2474. if(!this->BackwardsCompatibilityFinal)
  2475. {
  2476. unsigned int major = 0;
  2477. unsigned int minor = 0;
  2478. unsigned int patch = 0;
  2479. if(const char* value
  2480. = this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"))
  2481. {
  2482. switch(sscanf(value, "%u.%u.%u", &major, &minor, &patch))
  2483. {
  2484. case 2: patch = 0; break;
  2485. case 1: minor = 0; patch = 0; break;
  2486. default: break;
  2487. }
  2488. }
  2489. this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
  2490. this->BackwardsCompatibilityFinal = this->Configured;
  2491. }
  2492. return this->BackwardsCompatibility;
  2493. }
  2494. //----------------------------------------------------------------------------
  2495. bool cmLocalGenerator::NeedBackwardsCompatibility(unsigned int major,
  2496. unsigned int minor,
  2497. unsigned int patch)
  2498. {
  2499. // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
  2500. // equal to or lower than the given version.
  2501. unsigned int actual_compat = this->GetBackwardsCompatibility();
  2502. return (actual_compat &&
  2503. actual_compat <= CMake_VERSION_ENCODE(major, minor, patch));
  2504. }
  2505. //----------------------------------------------------------------------------
  2506. bool cmLocalGenerator::CheckDefinition(std::string const& define) const
  2507. {
  2508. // Many compilers do not support -DNAME(arg)=sdf so we disable it.
  2509. bool function_style = false;
  2510. for(const char* c = define.c_str(); *c && *c != '='; ++c)
  2511. {
  2512. if(*c == '(')
  2513. {
  2514. function_style = true;
  2515. break;
  2516. }
  2517. }
  2518. if(function_style)
  2519. {
  2520. cmOStringStream e;
  2521. e << "WARNING: Function-style preprocessor definitions may not be "
  2522. << "passed on the compiler command line because many compilers "
  2523. << "do not support it.\n"
  2524. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2525. << "Consider defining the macro in a (configured) header file.\n";
  2526. cmSystemTools::Message(e.str().c_str());
  2527. return false;
  2528. }
  2529. // Many compilers do not support # in the value so we disable it.
  2530. if(define.find_first_of("#") != define.npos)
  2531. {
  2532. cmOStringStream e;
  2533. e << "WARNING: Peprocessor definitions containing '#' may not be "
  2534. << "passed on the compiler command line because many compilers "
  2535. << "do not support it.\n"
  2536. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2537. << "Consider defining the macro in a (configured) header file.\n";
  2538. cmSystemTools::Message(e.str().c_str());
  2539. return false;
  2540. }
  2541. // Assume it is supported.
  2542. return true;
  2543. }
  2544. //----------------------------------------------------------------------------
  2545. static std::string cmLGInfoProp(cmTarget* target, const char* prop)
  2546. {
  2547. if(const char* val = target->GetProperty(prop))
  2548. {
  2549. return val;
  2550. }
  2551. else
  2552. {
  2553. // For compatibility check for a variable.
  2554. return target->GetMakefile()->GetSafeDefinition(prop);
  2555. }
  2556. }
  2557. //----------------------------------------------------------------------------
  2558. void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
  2559. const char* targetName,
  2560. const char* fname)
  2561. {
  2562. std::string info_EXECUTABLE_NAME = targetName;
  2563. // Lookup the properties.
  2564. std::string info_INFO_STRING =
  2565. cmLGInfoProp(target, "MACOSX_BUNDLE_INFO_STRING");
  2566. std::string info_ICON_FILE =
  2567. cmLGInfoProp(target, "MACOSX_BUNDLE_ICON_FILE");
  2568. std::string info_GUI_IDENTIFIER =
  2569. cmLGInfoProp(target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
  2570. std::string info_LONG_VERSION_STRING =
  2571. cmLGInfoProp(target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
  2572. std::string info_BUNDLE_NAME =
  2573. cmLGInfoProp(target, "MACOSX_BUNDLE_BUNDLE_NAME");
  2574. std::string info_SHORT_VERSION_STRING =
  2575. cmLGInfoProp(target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
  2576. std::string info_BUNDLE_VERSION =
  2577. cmLGInfoProp(target, "MACOSX_BUNDLE_BUNDLE_VERSION");
  2578. std::string info_COPYRIGHT =
  2579. cmLGInfoProp(target, "MACOSX_BUNDLE_COPYRIGHT");
  2580. // Generate the file.
  2581. cmGeneratedFileStream fout(fname);
  2582. fout.SetCopyIfDifferent(true);
  2583. fout <<
  2584. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  2585. "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"\n"
  2586. " \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
  2587. "<plist version=\"1.0\">\n"
  2588. "<dict>\n"
  2589. "\t<key>CFBundleDevelopmentRegion</key>\n"
  2590. "\t<string>English</string>\n"
  2591. "\t<key>CFBundleExecutable</key>\n"
  2592. "\t<string>" << info_EXECUTABLE_NAME << "</string>\n"
  2593. "\t<key>CFBundleGetInfoString</key>\n"
  2594. "\t<string>" << info_INFO_STRING << "</string>\n"
  2595. "\t<key>CFBundleIconFile</key>\n"
  2596. "\t<string>" << info_ICON_FILE << "</string>\n"
  2597. "\t<key>CFBundleIdentifier</key>\n"
  2598. "\t<string>" << info_GUI_IDENTIFIER << "</string>\n"
  2599. "\t<key>CFBundleInfoDictionaryVersion</key>\n"
  2600. "\t<string>6.0</string>\n"
  2601. "\t<key>CFBundleLongVersionString</key>\n"
  2602. "\t<string>" << info_LONG_VERSION_STRING << "</string>\n"
  2603. "\t<key>CFBundleName</key>\n"
  2604. "\t<string>" << info_BUNDLE_NAME << "</string>\n"
  2605. "\t<key>CFBundlePackageType</key>\n"
  2606. "\t<string>APPL</string>\n"
  2607. "\t<key>CFBundleShortVersionString</key>\n"
  2608. "\t<string>" << info_SHORT_VERSION_STRING << "</string>\n"
  2609. "\t<key>CFBundleSignature</key>\n"
  2610. "\t<string>????" /* break string to avoid trigraph */ "</string>\n"
  2611. "\t<key>CFBundleVersion</key>\n"
  2612. "\t<string>" << info_BUNDLE_VERSION << "</string>\n"
  2613. "\t<key>CSResourcesFileMapped</key>\n"
  2614. "\t<true/>\n"
  2615. "\t<key>LSRequiresCarbon</key>\n"
  2616. "\t<true/>\n"
  2617. "\t<key>NSHumanReadableCopyright</key>\n"
  2618. "\t<string>" << info_COPYRIGHT << "</string>\n"
  2619. "</dict>\n"
  2620. "</plist>\n"
  2621. ;
  2622. }