cmLocalGenerator.cxx 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409
  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 "cmGeneratedFileStream.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmInstallGenerator.h"
  17. #include "cmInstallFilesGenerator.h"
  18. #include "cmInstallScriptGenerator.h"
  19. #include "cmInstallTargetGenerator.h"
  20. #include "cmMakefile.h"
  21. #include "cmOrderLinkDirectories.h"
  22. #include "cmSourceFile.h"
  23. #include "cmTest.h"
  24. #include "cmake.h"
  25. #include <cmsys/System.h>
  26. #include <ctype.h> // for isalpha
  27. cmLocalGenerator::cmLocalGenerator()
  28. {
  29. this->Makefile = new cmMakefile;
  30. this->Makefile->SetLocalGenerator(this);
  31. this->ExcludeFromAll = false;
  32. this->Parent = 0;
  33. this->WindowsShell = false;
  34. this->WindowsVSIDE = false;
  35. this->WatcomWMake = false;
  36. this->MSYSShell = false;
  37. this->IgnoreLibPrefix = false;
  38. this->UseRelativePaths = false;
  39. this->Configured = false;
  40. this->EmitUniversalBinaryFlags = true;
  41. }
  42. cmLocalGenerator::~cmLocalGenerator()
  43. {
  44. delete this->Makefile;
  45. }
  46. void cmLocalGenerator::Configure()
  47. {
  48. // make sure the CMakeFiles dir is there
  49. std::string filesDir = this->Makefile->GetStartOutputDirectory();
  50. filesDir += cmake::GetCMakeFilesDirectory();
  51. cmSystemTools::MakeDirectory(filesDir.c_str());
  52. // find & read the list file
  53. std::string currentStart = this->Makefile->GetStartDirectory();
  54. currentStart += "/CMakeLists.txt";
  55. this->Makefile->ReadListFile(currentStart.c_str());
  56. // at the end of the ReadListFile handle any old style subdirs
  57. // first get all the subdirectories
  58. std::vector<cmLocalGenerator *> subdirs = this->GetChildren();
  59. // for each subdir recurse
  60. std::vector<cmLocalGenerator *>::iterator sdi = subdirs.begin();
  61. for (; sdi != subdirs.end(); ++sdi)
  62. {
  63. if (!(*sdi)->Configured)
  64. {
  65. this->Makefile->ConfigureSubDirectory(*sdi);
  66. }
  67. }
  68. this->SetupPathConversions();
  69. // Check whether relative paths should be used for optionally
  70. // relative paths.
  71. this->UseRelativePaths = this->Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");
  72. this->Configured = true;
  73. }
  74. void cmLocalGenerator::SetupPathConversions()
  75. {
  76. // Setup the current output directory components for use by
  77. // Convert
  78. std::string outdir;
  79. outdir =
  80. cmSystemTools::CollapseFullPath(this->Makefile->GetHomeDirectory());
  81. cmSystemTools::SplitPath(outdir.c_str(), this->HomeDirectoryComponents);
  82. outdir =
  83. cmSystemTools::CollapseFullPath(this->Makefile->GetStartDirectory());
  84. cmSystemTools::SplitPath(outdir.c_str(), this->StartDirectoryComponents);
  85. outdir = cmSystemTools::CollapseFullPath
  86. (this->Makefile->GetHomeOutputDirectory());
  87. cmSystemTools::SplitPath(outdir.c_str(),
  88. this->HomeOutputDirectoryComponents);
  89. outdir = cmSystemTools::CollapseFullPath
  90. (this->Makefile->GetStartOutputDirectory());
  91. cmSystemTools::SplitPath(outdir.c_str(),
  92. this->StartOutputDirectoryComponents);
  93. }
  94. void cmLocalGenerator::SetGlobalGenerator(cmGlobalGenerator *gg)
  95. {
  96. this->GlobalGenerator = gg;
  97. // setup the home directories
  98. this->Makefile->GetProperties().SetCMakeInstance(gg->GetCMakeInstance());
  99. this->Makefile->SetHomeDirectory(
  100. gg->GetCMakeInstance()->GetHomeDirectory());
  101. this->Makefile->SetHomeOutputDirectory(
  102. gg->GetCMakeInstance()->GetHomeOutputDirectory());
  103. }
  104. void cmLocalGenerator::ConfigureFinalPass()
  105. {
  106. this->Makefile->ConfigureFinalPass();
  107. }
  108. void cmLocalGenerator::GenerateTestFiles()
  109. {
  110. if ( !this->Makefile->IsOn("CMAKE_TESTING_ENABLED") )
  111. {
  112. return;
  113. }
  114. std::string file = this->Makefile->GetStartOutputDirectory();
  115. file += "/";
  116. if ( this->Makefile->IsSet("CTEST_NEW_FORMAT") )
  117. {
  118. file += "CTestTestfile.cmake";
  119. }
  120. else
  121. {
  122. file += "DartTestfile.txt";
  123. }
  124. cmGeneratedFileStream fout(file.c_str());
  125. fout.SetCopyIfDifferent(true);
  126. fout << "# CMake generated Testfile for " << std::endl
  127. << "# Source directory: "
  128. << this->Makefile->GetStartDirectory() << std::endl
  129. << "# Build directory: "
  130. << this->Makefile->GetStartOutputDirectory() << std::endl
  131. << "# " << std::endl
  132. << "# This file replicates the SUBDIRS() and ADD_TEST() commands "
  133. << "from the source" << std::endl
  134. << "# tree CMakeLists.txt file, skipping any SUBDIRS() or "
  135. << "ADD_TEST() commands" << std::endl
  136. << "# that are excluded by CMake control structures, i.e. IF() "
  137. << "commands." << std::endl
  138. << "#" << std::endl
  139. << "# The next line is critical for Dart to work" << std::endl
  140. << "# Duh :-)" << std::endl << std::endl;
  141. const char* testIncludeFile =
  142. this->Makefile->GetProperty("TEST_INCLUDE_FILE");
  143. if ( testIncludeFile )
  144. {
  145. fout << "INCLUDE(\"" << testIncludeFile << "\")" << std::endl;
  146. }
  147. const std::vector<cmTest*> *tests = this->Makefile->GetTests();
  148. std::vector<cmTest*>::const_iterator it;
  149. for ( it = tests->begin(); it != tests->end(); ++ it )
  150. {
  151. cmTest* test = *it;
  152. fout << "ADD_TEST(";
  153. fout << test->GetName() << " \"" << test->GetCommand() << "\"";
  154. std::vector<cmStdString>::const_iterator argit;
  155. for (argit = test->GetArguments().begin();
  156. argit != test->GetArguments().end(); ++argit)
  157. {
  158. // Just double-quote all arguments so they are re-parsed
  159. // correctly by the test system.
  160. fout << " \"";
  161. for(std::string::const_iterator c = argit->begin();
  162. c != argit->end(); ++c)
  163. {
  164. // Escape quotes within arguments. We should escape
  165. // backslashes too but we cannot because it makes the result
  166. // inconsistent with previous behavior of this command.
  167. if((*c == '"'))
  168. {
  169. fout << '\\';
  170. }
  171. fout << *c;
  172. }
  173. fout << "\"";
  174. }
  175. fout << ")" << std::endl;
  176. cmPropertyMap::const_iterator pit;
  177. cmPropertyMap* mpit = &test->GetProperties();
  178. if ( mpit->size() )
  179. {
  180. fout << "SET_TESTS_PROPERTIES(" << test->GetName() << " PROPERTIES ";
  181. for ( pit = mpit->begin(); pit != mpit->end(); ++ pit )
  182. {
  183. fout << " " << pit->first.c_str() << " \"";
  184. const char* value = pit->second.GetValue();
  185. for ( ; *value; ++ value )
  186. {
  187. switch ( *value )
  188. {
  189. case '\\':
  190. case '"':
  191. case ' ':
  192. case '#':
  193. case '(':
  194. case ')':
  195. case '$':
  196. case '^':
  197. fout << "\\" << *value;
  198. break;
  199. case '\t':
  200. fout << "\\t";
  201. break;
  202. case '\n':
  203. fout << "\\n";
  204. break;
  205. case '\r':
  206. fout << "\\r";
  207. break;
  208. default:
  209. fout << *value;
  210. }
  211. }
  212. fout << "\"";
  213. }
  214. fout << ")" << std::endl;
  215. }
  216. }
  217. if ( this->Children.size())
  218. {
  219. fout << "SUBDIRS(";
  220. size_t i;
  221. std::string outDir = this->Makefile->GetStartOutputDirectory();
  222. outDir += "/";
  223. for(i = 0; i < this->Children.size(); ++i)
  224. {
  225. std::string binP =
  226. this->Children[i]->GetMakefile()->GetStartOutputDirectory();
  227. cmSystemTools::ReplaceString(binP, outDir.c_str(), "");
  228. if ( i > 0 )
  229. {
  230. fout << " ";
  231. }
  232. fout << binP.c_str();
  233. }
  234. fout << ")" << std::endl << std::endl;;
  235. }
  236. }
  237. //----------------------------------------------------------------------------
  238. void cmLocalGenerator::GenerateInstallRules()
  239. {
  240. // Compute the install prefix.
  241. const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
  242. #if defined(_WIN32) && !defined(__CYGWIN__)
  243. std::string prefix_win32;
  244. if(!prefix)
  245. {
  246. if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32))
  247. {
  248. prefix_win32 = "C:";
  249. }
  250. const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
  251. if(project_name && project_name[0])
  252. {
  253. prefix_win32 += "/Program Files/";
  254. prefix_win32 += project_name;
  255. }
  256. else
  257. {
  258. prefix_win32 += "/InstalledCMakeProject";
  259. }
  260. prefix = prefix_win32.c_str();
  261. }
  262. #else
  263. if (!prefix)
  264. {
  265. prefix = "/usr/local";
  266. }
  267. #endif
  268. // Compute the set of configurations.
  269. std::vector<std::string> configurationTypes;
  270. if(const char* types =
  271. this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  272. {
  273. cmSystemTools::ExpandListArgument(types, configurationTypes);
  274. }
  275. const char* config = 0;
  276. if(configurationTypes.empty())
  277. {
  278. config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  279. }
  280. // Choose a default install configuration.
  281. const char* default_config = config;
  282. const char* default_order[] = {"RELEASE", "MINSIZEREL",
  283. "RELWITHDEBINFO", "DEBUG", 0};
  284. for(const char** c = default_order; *c && !default_config; ++c)
  285. {
  286. for(std::vector<std::string>::iterator i = configurationTypes.begin();
  287. i != configurationTypes.end(); ++i)
  288. {
  289. if(cmSystemTools::UpperCase(*i) == *c)
  290. {
  291. default_config = i->c_str();
  292. }
  293. }
  294. }
  295. if(!default_config && !configurationTypes.empty())
  296. {
  297. default_config = configurationTypes[0].c_str();
  298. }
  299. if(!default_config)
  300. {
  301. default_config = "Release";
  302. }
  303. // Create the install script file.
  304. std::string file = this->Makefile->GetStartOutputDirectory();
  305. std::string homedir = this->Makefile->GetHomeOutputDirectory();
  306. std::string currdir = this->Makefile->GetCurrentOutputDirectory();
  307. cmSystemTools::ConvertToUnixSlashes(file);
  308. cmSystemTools::ConvertToUnixSlashes(homedir);
  309. cmSystemTools::ConvertToUnixSlashes(currdir);
  310. int toplevel_install = 0;
  311. if ( currdir == homedir )
  312. {
  313. toplevel_install = 1;
  314. }
  315. file += "/cmake_install.cmake";
  316. cmGeneratedFileStream fout(file.c_str());
  317. fout.SetCopyIfDifferent(true);
  318. // Write the header.
  319. fout << "# Install script for directory: "
  320. << this->Makefile->GetCurrentDirectory() << std::endl << std::endl;
  321. fout << "# Set the install prefix" << std::endl
  322. << "IF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  323. << " SET(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
  324. << "ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  325. << "STRING(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
  326. << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
  327. << std::endl;
  328. // Write support code for generating per-configuration install rules.
  329. fout <<
  330. "# Set the install configuration name.\n"
  331. "IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  332. " IF(BUILD_TYPE)\n"
  333. " STRING(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
  334. " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
  335. " ELSE(BUILD_TYPE)\n"
  336. " SET(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
  337. " ENDIF(BUILD_TYPE)\n"
  338. " MESSAGE(STATUS \"Install configuration: "
  339. "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
  340. "ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  341. "\n";
  342. // Write support code for dealing with component-specific installs.
  343. fout <<
  344. "# Set the component getting installed.\n"
  345. "IF(NOT CMAKE_INSTALL_COMPONENT)\n"
  346. " IF(COMPONENT)\n"
  347. " MESSAGE(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
  348. " SET(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
  349. " ELSE(COMPONENT)\n"
  350. " SET(CMAKE_INSTALL_COMPONENT)\n"
  351. " ENDIF(COMPONENT)\n"
  352. "ENDIF(NOT CMAKE_INSTALL_COMPONENT)\n"
  353. "\n";
  354. // Ask each install generator to write its code.
  355. std::vector<cmInstallGenerator*> const& installers =
  356. this->Makefile->GetInstallGenerators();
  357. for(std::vector<cmInstallGenerator*>::const_iterator
  358. gi = installers.begin();
  359. gi != installers.end(); ++gi)
  360. {
  361. (*gi)->Generate(fout, config, configurationTypes);
  362. }
  363. // Write rules from old-style specification stored in targets.
  364. this->GenerateTargetInstallRules(fout, config, configurationTypes);
  365. // Include install scripts from subdirectories.
  366. if(!this->Children.empty())
  367. {
  368. fout << "IF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
  369. fout << " # Include the install script for each subdirectory.\n";
  370. for(std::vector<cmLocalGenerator*>::const_iterator
  371. ci = this->Children.begin(); ci != this->Children.end(); ++ci)
  372. {
  373. if(!(*ci)->GetExcludeAll())
  374. {
  375. std::string odir = (*ci)->GetMakefile()->GetStartOutputDirectory();
  376. cmSystemTools::ConvertToUnixSlashes(odir);
  377. fout << " INCLUDE(\"" << odir.c_str()
  378. << "/cmake_install.cmake\")" << std::endl;
  379. }
  380. }
  381. fout << "\n";
  382. fout << "ENDIF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
  383. }
  384. // Record the install manifest.
  385. if ( toplevel_install )
  386. {
  387. fout <<
  388. "IF(CMAKE_INSTALL_COMPONENT)\n"
  389. " SET(CMAKE_INSTALL_MANIFEST \"install_manifest_"
  390. "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
  391. "ELSE(CMAKE_INSTALL_COMPONENT)\n"
  392. " SET(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
  393. "ENDIF(CMAKE_INSTALL_COMPONENT)\n";
  394. fout
  395. << "FILE(WRITE \""
  396. << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
  397. << "\"\")" << std::endl;
  398. fout
  399. << "FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES})" << std::endl
  400. << " FILE(APPEND \""
  401. << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
  402. << "\"${file}\\n\")" << std::endl
  403. << "ENDFOREACH(file)" << std::endl;
  404. }
  405. }
  406. //----------------------------------------------------------------------------
  407. void cmLocalGenerator::GenerateTargetManifest(cmTargetManifest& manifest)
  408. {
  409. // Collect the set of configuration types.
  410. std::vector<std::string> configNames;
  411. if(const char* configurationTypes =
  412. this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  413. {
  414. cmSystemTools::ExpandListArgument(configurationTypes, configNames);
  415. }
  416. else if(const char* buildType =
  417. this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
  418. {
  419. if(*buildType)
  420. {
  421. configNames.push_back(buildType);
  422. }
  423. }
  424. // Add our targets to the manifest for each configuration.
  425. cmTargets& targets = this->Makefile->GetTargets();
  426. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  427. {
  428. cmTarget& target = t->second;
  429. cmTarget::TargetType type = target.GetType();
  430. if(type == cmTarget::STATIC_LIBRARY ||
  431. type == cmTarget::SHARED_LIBRARY ||
  432. type == cmTarget::MODULE_LIBRARY ||
  433. type == cmTarget::EXECUTABLE)
  434. {
  435. if(configNames.empty())
  436. {
  437. manifest[""].insert(target.GetFullPath(0, false));
  438. if(type == cmTarget::SHARED_LIBRARY &&
  439. this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  440. {
  441. manifest[""].insert(target.GetFullPath(0, true));
  442. }
  443. }
  444. else
  445. {
  446. for(std::vector<std::string>::iterator ci = configNames.begin();
  447. ci != configNames.end(); ++ci)
  448. {
  449. const char* config = ci->c_str();
  450. manifest[config].insert(target.GetFullPath(config, false));
  451. if(type == cmTarget::SHARED_LIBRARY &&
  452. this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  453. {
  454. manifest[config].insert(target.GetFullPath(config, true));
  455. }
  456. }
  457. }
  458. }
  459. }
  460. }
  461. void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
  462. const char* lang,
  463. cmSourceFile& source,
  464. cmTarget& )
  465. {
  466. std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname));
  467. objectDir = this->Convert(objectDir.c_str(),START_OUTPUT,SHELL);
  468. std::string objectFile = this->Convert(ofname,START_OUTPUT,SHELL);
  469. std::string sourceFile =
  470. this->Convert(source.GetFullPath().c_str(),START_OUTPUT,SHELL,true);
  471. std::string varString = "CMAKE_";
  472. varString += lang;
  473. varString += "_COMPILE_OBJECT";
  474. std::vector<std::string> rules;
  475. rules.push_back(this->Makefile->GetRequiredDefinition(varString.c_str()));
  476. varString = "CMAKE_";
  477. varString += lang;
  478. varString += "_FLAGS";
  479. std::string flags;
  480. flags += this->Makefile->GetSafeDefinition(varString.c_str());
  481. flags += " ";
  482. flags += this->GetIncludeFlags(lang);
  483. // Construct the command lines.
  484. cmCustomCommandLines commandLines;
  485. std::vector<std::string> commands;
  486. cmSystemTools::ExpandList(rules, commands);
  487. cmLocalGenerator::RuleVariables vars;
  488. vars.Language = lang;
  489. vars.Source = sourceFile.c_str();
  490. vars.Object = objectFile.c_str();
  491. vars.ObjectDir = objectDir.c_str();
  492. vars.Flags = flags.c_str();
  493. for(std::vector<std::string>::iterator i = commands.begin();
  494. i != commands.end(); ++i)
  495. {
  496. // Expand the full command line string.
  497. this->ExpandRuleVariables(*i, vars);
  498. // Parse the string to get the custom command line.
  499. cmCustomCommandLine commandLine;
  500. std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
  501. for(std::vector<cmStdString>::iterator a = cmd.begin();
  502. a != cmd.end(); ++a)
  503. {
  504. commandLine.push_back(*a);
  505. }
  506. // Store this command line.
  507. commandLines.push_back(commandLine);
  508. }
  509. // Check for extra object-file dependencies.
  510. std::vector<std::string> depends;
  511. const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
  512. if(additionalDeps)
  513. {
  514. cmSystemTools::ExpandListArgument(additionalDeps, depends);
  515. }
  516. // Generate a meaningful comment for the command.
  517. std::string comment = "Building ";
  518. comment += lang;
  519. comment += " object ";
  520. comment += this->Convert(ofname, START_OUTPUT);
  521. // Add the custom command to build the object file.
  522. this->Makefile->AddCustomCommandToOutput(
  523. ofname,
  524. depends,
  525. source.GetFullPath().c_str(),
  526. commandLines,
  527. comment.c_str(),
  528. this->Makefile->GetStartOutputDirectory()
  529. );
  530. }
  531. void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
  532. {
  533. cmStdString objs;
  534. std::vector<std::string> objVector;
  535. // Add all the sources outputs to the depends of the target
  536. std::vector<cmSourceFile*>& classes = target.GetSourceFiles();
  537. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  538. i != classes.end(); ++i)
  539. {
  540. if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  541. !(*i)->GetCustomCommand())
  542. {
  543. std::string outExt =
  544. this->GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  545. (*i)->GetSourceExtension().c_str());
  546. if(outExt.size() && !(*i)->GetPropertyAsBool("EXTERNAL_OBJECT") )
  547. {
  548. std::string ofname = this->Makefile->GetCurrentOutputDirectory();
  549. ofname += "/";
  550. ofname += (*i)->GetSourceName() + outExt;
  551. objVector.push_back(ofname);
  552. this->AddCustomCommandToCreateObject(ofname.c_str(),
  553. llang, *(*i), target);
  554. objs += this->Convert(ofname.c_str(),START_OUTPUT,MAKEFILE);
  555. objs += " ";
  556. }
  557. }
  558. }
  559. std::string createRule = "CMAKE_";
  560. createRule += llang;
  561. createRule += target.GetCreateRuleVariable();
  562. std::string targetName = target.GetFullName();
  563. // Executable :
  564. // Shared Library:
  565. // Static Library:
  566. // Shared Module:
  567. std::string linkLibs; // should be set
  568. std::string flags; // should be set
  569. std::string linkFlags; // should be set
  570. this->GetTargetFlags(linkLibs, flags, linkFlags, target);
  571. cmLocalGenerator::RuleVariables vars;
  572. vars.Language = llang;
  573. vars.Objects = objs.c_str();
  574. vars.ObjectDir = ".";
  575. vars.Target = targetName.c_str();
  576. vars.LinkLibraries = linkLibs.c_str();
  577. vars.Flags = flags.c_str();
  578. vars.LinkFlags = linkFlags.c_str();
  579. std::string langFlags;
  580. this->AddLanguageFlags(langFlags, llang, 0);
  581. vars.LanguageCompileFlags = langFlags.c_str();
  582. cmCustomCommandLines commandLines;
  583. std::vector<std::string> rules;
  584. rules.push_back(this->Makefile->GetRequiredDefinition(createRule.c_str()));
  585. std::vector<std::string> commands;
  586. cmSystemTools::ExpandList(rules, commands);
  587. for(std::vector<std::string>::iterator i = commands.begin();
  588. i != commands.end(); ++i)
  589. {
  590. // Expand the full command line string.
  591. this->ExpandRuleVariables(*i, vars);
  592. // Parse the string to get the custom command line.
  593. cmCustomCommandLine commandLine;
  594. std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
  595. for(std::vector<cmStdString>::iterator a = cmd.begin();
  596. a != cmd.end(); ++a)
  597. {
  598. commandLine.push_back(*a);
  599. }
  600. // Store this command line.
  601. commandLines.push_back(commandLine);
  602. }
  603. std::string targetFullPath = target.GetFullPath();
  604. // Generate a meaningful comment for the command.
  605. std::string comment = "Linking ";
  606. comment += llang;
  607. comment += " target ";
  608. comment += this->Convert(targetFullPath.c_str(), START_OUTPUT);
  609. this->Makefile->AddCustomCommandToOutput(
  610. targetFullPath.c_str(),
  611. objVector,
  612. 0,
  613. commandLines,
  614. comment.c_str(),
  615. this->Makefile->GetStartOutputDirectory()
  616. );
  617. target.GetSourceFiles().push_back
  618. (this->Makefile->GetSource(targetFullPath.c_str()));
  619. }
  620. void cmLocalGenerator
  621. ::CreateCustomTargetsAndCommands(std::set<cmStdString> const& lang)
  622. {
  623. cmTargets &tgts = this->Makefile->GetTargets();
  624. for(cmTargets::iterator l = tgts.begin();
  625. l != tgts.end(); l++)
  626. {
  627. cmTarget& target = l->second;
  628. switch(target.GetType())
  629. {
  630. case cmTarget::STATIC_LIBRARY:
  631. case cmTarget::SHARED_LIBRARY:
  632. case cmTarget::MODULE_LIBRARY:
  633. case cmTarget::EXECUTABLE:
  634. {
  635. const char* llang =
  636. target.GetLinkerLanguage(this->GetGlobalGenerator());
  637. if(!llang)
  638. {
  639. cmSystemTools::Error
  640. ("CMake can not determine linker language for target:",
  641. target.GetName());
  642. return;
  643. }
  644. // if the language is not in the set lang then create custom
  645. // commands to build the target
  646. if(lang.count(llang) == 0)
  647. {
  648. this->AddBuildTargetRule(llang, target);
  649. }
  650. }
  651. break;
  652. case cmTarget::UTILITY:
  653. case cmTarget::GLOBAL_TARGET:
  654. case cmTarget::INSTALL_FILES:
  655. case cmTarget::INSTALL_PROGRAMS:
  656. case cmTarget::INSTALL_DIRECTORY:
  657. break;
  658. }
  659. }
  660. }
  661. // List of variables that are replaced when
  662. // rules are expanced. These variables are
  663. // replaced in the form <var> with GetSafeDefinition(var).
  664. // ${LANG} is replaced in the variable first with all enabled
  665. // languages.
  666. static const char* ruleReplaceVars[] =
  667. {
  668. "CMAKE_${LANG}_COMPILER",
  669. "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
  670. "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
  671. "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
  672. "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
  673. "CMAKE_${LANG}_LINK_FLAGS",
  674. "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
  675. "CMAKE_${LANG}_ARCHIVE",
  676. "CMAKE_AR",
  677. "CMAKE_CURRENT_SOURCE_DIR",
  678. "CMAKE_CURRENT_BINARY_DIR",
  679. "CMAKE_RANLIB",
  680. 0
  681. };
  682. std::string
  683. cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
  684. const RuleVariables& replaceValues)
  685. {
  686. if(replaceValues.LinkFlags)
  687. {
  688. if(variable == "LINK_FLAGS")
  689. {
  690. return replaceValues.LinkFlags;
  691. }
  692. }
  693. if(replaceValues.Flags)
  694. {
  695. if(variable == "FLAGS")
  696. {
  697. return replaceValues.Flags;
  698. }
  699. }
  700. if(replaceValues.Source)
  701. {
  702. if(variable == "SOURCE")
  703. {
  704. return replaceValues.Source;
  705. }
  706. }
  707. if(replaceValues.PreprocessedSource)
  708. {
  709. if(variable == "PREPROCESSED_SOURCE")
  710. {
  711. return replaceValues.PreprocessedSource;
  712. }
  713. }
  714. if(replaceValues.AssemblySource)
  715. {
  716. if(variable == "ASSEMBLY_SOURCE")
  717. {
  718. return replaceValues.AssemblySource;
  719. }
  720. }
  721. if(replaceValues.Object)
  722. {
  723. if(variable == "OBJECT")
  724. {
  725. return replaceValues.Object;
  726. }
  727. }
  728. if(replaceValues.ObjectDir)
  729. {
  730. if(variable == "OBJECT_DIR")
  731. {
  732. return replaceValues.ObjectDir;
  733. }
  734. }
  735. if(replaceValues.Objects)
  736. {
  737. if(variable == "OBJECTS")
  738. {
  739. return replaceValues.Objects;
  740. }
  741. }
  742. if(replaceValues.ObjectsQuoted)
  743. {
  744. if(variable == "OBJECTS_QUOTED")
  745. {
  746. return replaceValues.ObjectsQuoted;
  747. }
  748. }
  749. if(replaceValues.TargetPDB )
  750. {
  751. if(variable == "TARGET_PDB")
  752. {
  753. return replaceValues.TargetPDB;
  754. }
  755. }
  756. if(replaceValues.Target)
  757. {
  758. if(variable == "TARGET_QUOTED")
  759. {
  760. std::string targetQuoted = replaceValues.Target;
  761. if(targetQuoted.size() && targetQuoted[0] != '\"')
  762. {
  763. targetQuoted = '\"';
  764. targetQuoted += replaceValues.Target;
  765. targetQuoted += '\"';
  766. }
  767. return targetQuoted;
  768. }
  769. if(replaceValues.LanguageCompileFlags)
  770. {
  771. if(variable == "LANGUAGE_COMPILE_FLAGS")
  772. {
  773. return replaceValues.LanguageCompileFlags;
  774. }
  775. }
  776. if(replaceValues.Target)
  777. {
  778. if(variable == "TARGET")
  779. {
  780. return replaceValues.Target;
  781. }
  782. }
  783. if(variable == "TARGET_IMPLIB")
  784. {
  785. return this->TargetImplib;
  786. }
  787. if(variable == "TARGET_VERSION_MAJOR")
  788. {
  789. if(replaceValues.TargetVersionMajor)
  790. {
  791. return replaceValues.TargetVersionMajor;
  792. }
  793. else
  794. {
  795. return "0";
  796. }
  797. }
  798. if(variable == "TARGET_VERSION_MINOR")
  799. {
  800. if(replaceValues.TargetVersionMinor)
  801. {
  802. return replaceValues.TargetVersionMinor;
  803. }
  804. else
  805. {
  806. return "0";
  807. }
  808. }
  809. if(replaceValues.Target)
  810. {
  811. if(variable == "TARGET_BASE")
  812. {
  813. // Strip the last extension off the target name.
  814. std::string targetBase = replaceValues.Target;
  815. std::string::size_type pos = targetBase.rfind(".");
  816. if(pos != targetBase.npos)
  817. {
  818. return targetBase.substr(0, pos);
  819. }
  820. else
  821. {
  822. return targetBase;
  823. }
  824. }
  825. }
  826. }
  827. if(replaceValues.TargetSOName)
  828. {
  829. if(variable == "TARGET_SONAME")
  830. {
  831. if(replaceValues.Language)
  832. {
  833. std::string name = "CMAKE_SHARED_LIBRARY_SONAME_";
  834. name += replaceValues.Language;
  835. name += "_FLAG";
  836. if(this->Makefile->GetDefinition(name.c_str()))
  837. {
  838. return replaceValues.TargetSOName;
  839. }
  840. }
  841. return "";
  842. }
  843. }
  844. if(replaceValues.TargetInstallNameDir)
  845. {
  846. if(variable == "TARGET_INSTALLNAME_DIR")
  847. {
  848. return replaceValues.TargetInstallNameDir;
  849. }
  850. }
  851. if(replaceValues.LinkLibraries)
  852. {
  853. if(variable == "LINK_LIBRARIES")
  854. {
  855. return replaceValues.LinkLibraries;
  856. }
  857. }
  858. std::vector<std::string> enabledLanguages;
  859. this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
  860. // loop over language specific replace variables
  861. int pos = 0;
  862. while(ruleReplaceVars[pos])
  863. {
  864. for(std::vector<std::string>::iterator i = enabledLanguages.begin();
  865. i != enabledLanguages.end(); ++i)
  866. {
  867. const char* lang = i->c_str();
  868. std::string actualReplace = ruleReplaceVars[pos];
  869. // If this is the compiler then look for the extra variable
  870. // _COMPILER_ARG1 which must be the first argument to the compiler
  871. const char* compilerArg1 = 0;
  872. if(actualReplace == "CMAKE_${LANG}_COMPILER")
  873. {
  874. std::string arg1 = actualReplace + "_ARG1";
  875. cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
  876. compilerArg1 = this->Makefile->GetDefinition(arg1.c_str());
  877. }
  878. if(actualReplace.find("${LANG}") != actualReplace.npos)
  879. {
  880. cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
  881. }
  882. if(actualReplace == variable)
  883. {
  884. std::string replace =
  885. this->Makefile->GetSafeDefinition(variable.c_str());
  886. // if the variable is not a FLAG then treat it like a path
  887. if(variable.find("_FLAG") == variable.npos)
  888. {
  889. std::string ret = this->ConvertToOutputForExisting(replace.c_str());
  890. // if there is a required first argument to the compiler add it
  891. // to the compiler string
  892. if(compilerArg1)
  893. {
  894. ret += " ";
  895. ret += compilerArg1;
  896. }
  897. return ret;
  898. }
  899. return replace;
  900. }
  901. }
  902. pos++;
  903. }
  904. return variable;
  905. }
  906. void
  907. cmLocalGenerator::ExpandRuleVariables(std::string& s,
  908. const RuleVariables& replaceValues)
  909. {
  910. std::vector<std::string> enabledLanguages;
  911. this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
  912. std::string::size_type start = s.find('<');
  913. // no variables to expand
  914. if(start == s.npos)
  915. {
  916. return;
  917. }
  918. std::string::size_type pos = 0;
  919. std::string expandedInput;
  920. while(start != s.npos && start < s.size()-2)
  921. {
  922. std::string::size_type end = s.find('>', start);
  923. // if we find a < with no > we are done
  924. if(end == s.npos)
  925. {
  926. return;
  927. }
  928. char c = s[start+1];
  929. // if the next char after the < is not A-Za-z then
  930. // skip it and try to find the next < in the string
  931. if(!isalpha(c))
  932. {
  933. start = s.find('<', start+1);
  934. }
  935. else
  936. {
  937. // extract the var
  938. std::string var = s.substr(start+1, end - start-1);
  939. std::string replace = this->ExpandRuleVariable(var,
  940. replaceValues);
  941. expandedInput += s.substr(pos, start-pos);
  942. expandedInput += replace;
  943. // move to next one
  944. start = s.find('<', start+var.size()+2);
  945. pos = end+1;
  946. }
  947. }
  948. // add the rest of the input
  949. expandedInput += s.substr(pos, s.size()-pos);
  950. s = expandedInput;
  951. }
  952. std::string
  953. cmLocalGenerator::ConvertToOutputForExisting(const char* p)
  954. {
  955. std::string ret = p;
  956. if(this->WindowsShell && ret.find(' ') != ret.npos
  957. && cmSystemTools::FileExists(p))
  958. {
  959. if(cmSystemTools::GetShortPath(p, ret))
  960. {
  961. return this->Convert(ret.c_str(), NONE, SHELL, true);
  962. }
  963. }
  964. return this->Convert(p, START_OUTPUT, SHELL, true);
  965. }
  966. const char* cmLocalGenerator::GetIncludeFlags(const char* lang)
  967. {
  968. if(!lang)
  969. {
  970. return "";
  971. }
  972. if(this->LanguageToIncludeFlags.count(lang))
  973. {
  974. return this->LanguageToIncludeFlags[lang].c_str();
  975. }
  976. cmOStringStream includeFlags;
  977. std::vector<std::string> includes;
  978. this->GetIncludeDirectories(includes);
  979. std::vector<std::string>::iterator i;
  980. std::string flagVar = "CMAKE_INCLUDE_FLAG_";
  981. flagVar += lang;
  982. const char* includeFlag =
  983. this->Makefile->GetSafeDefinition(flagVar.c_str());
  984. flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
  985. flagVar += lang;
  986. const char* sep = this->Makefile->GetDefinition(flagVar.c_str());
  987. bool quotePaths = false;
  988. if(this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
  989. {
  990. quotePaths = true;
  991. }
  992. bool repeatFlag = true;
  993. // should the include flag be repeated like ie. -IA -IB
  994. if(!sep)
  995. {
  996. sep = " ";
  997. }
  998. else
  999. {
  1000. // if there is a separator then the flag is not repeated but is only
  1001. // given once i.e. -classpath a:b:c
  1002. repeatFlag = false;
  1003. }
  1004. // Support special system include flag if it is available and the
  1005. // normal flag is repeated for each directory.
  1006. std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
  1007. sysFlagVar += lang;
  1008. const char* sysIncludeFlag = 0;
  1009. if(repeatFlag)
  1010. {
  1011. sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar.c_str());
  1012. }
  1013. bool flagUsed = false;
  1014. std::set<cmStdString> emitted;
  1015. for(i = includes.begin(); i != includes.end(); ++i)
  1016. {
  1017. #ifdef __APPLE__
  1018. if(cmSystemTools::IsPathToFramework(i->c_str()))
  1019. {
  1020. std::string frameworkDir = *i;
  1021. frameworkDir += "/../";
  1022. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1023. if(emitted.insert(frameworkDir).second)
  1024. {
  1025. includeFlags
  1026. << "-F"
  1027. << this->ConvertToOutputForExisting(frameworkDir.c_str()) << " ";
  1028. }
  1029. continue;
  1030. }
  1031. #endif
  1032. std::string include = *i;
  1033. if(!flagUsed || repeatFlag)
  1034. {
  1035. if(sysIncludeFlag &&
  1036. this->Makefile->IsSystemIncludeDirectory(i->c_str()))
  1037. {
  1038. includeFlags << sysIncludeFlag;
  1039. }
  1040. else
  1041. {
  1042. includeFlags << includeFlag;
  1043. }
  1044. flagUsed = true;
  1045. }
  1046. std::string includePath = this->ConvertToOutputForExisting(i->c_str());
  1047. if(quotePaths && includePath.size() && includePath[0] != '\"')
  1048. {
  1049. includeFlags << "\"";
  1050. }
  1051. includeFlags << includePath;
  1052. if(quotePaths && includePath.size() && includePath[0] != '\"')
  1053. {
  1054. includeFlags << "\"";
  1055. }
  1056. includeFlags << sep;
  1057. }
  1058. std::string flags = includeFlags.str();
  1059. // remove trailing separators
  1060. if((sep[0] != ' ') && flags[flags.size()-1] == sep[0])
  1061. {
  1062. flags[flags.size()-1] = ' ';
  1063. }
  1064. flags += this->Makefile->GetDefineFlags();
  1065. this->LanguageToIncludeFlags[lang] = flags;
  1066. // Use this temorary variable for the return value to work-around a
  1067. // bogus GCC 2.95 warning.
  1068. const char* ret = this->LanguageToIncludeFlags[lang].c_str();
  1069. return ret;
  1070. }
  1071. //----------------------------------------------------------------------------
  1072. void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
  1073. bool filter_system_dirs)
  1074. {
  1075. // Need to decide whether to automatically include the source and
  1076. // binary directories at the beginning of the include path.
  1077. bool includeSourceDir = false;
  1078. bool includeBinaryDir = false;
  1079. // When automatic include directories are requested for a build then
  1080. // include the source and binary directories at the beginning of the
  1081. // include path to approximate include file behavior for an
  1082. // in-source build. This does not account for the case of a source
  1083. // file in a subdirectory of the current source directory but we
  1084. // cannot fix this because not all native build tools support
  1085. // per-source-file include paths.
  1086. if(this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
  1087. {
  1088. includeSourceDir = true;
  1089. includeBinaryDir = true;
  1090. }
  1091. // CMake versions below 2.0 would add the source tree to the -I path
  1092. // automatically. Preserve compatibility.
  1093. const char* versionValue =
  1094. this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  1095. int major = 0;
  1096. int minor = 0;
  1097. if(versionValue && sscanf(versionValue, "%d.%d", &major, &minor) != 2)
  1098. {
  1099. versionValue = 0;
  1100. }
  1101. if(versionValue && major < 2)
  1102. {
  1103. includeSourceDir = true;
  1104. }
  1105. // Hack for VTK 4.0 - 4.4 which depend on the old behavior but do
  1106. // not set the backwards compatibility level automatically.
  1107. const char* vtkSourceDir =
  1108. this->Makefile->GetDefinition("VTK_SOURCE_DIR");
  1109. if(vtkSourceDir)
  1110. {
  1111. const char* vtk_major =
  1112. this->Makefile->GetDefinition("VTK_MAJOR_VERSION");
  1113. const char* vtk_minor =
  1114. this->Makefile->GetDefinition("VTK_MINOR_VERSION");
  1115. vtk_major = vtk_major? vtk_major : "4";
  1116. vtk_minor = vtk_minor? vtk_minor : "4";
  1117. int vmajor = 0;
  1118. int vminor = 0;
  1119. if(sscanf(vtk_major, "%d", &vmajor) &&
  1120. sscanf(vtk_minor, "%d", &vminor) && vmajor == 4 && vminor <= 4)
  1121. {
  1122. includeSourceDir = true;
  1123. }
  1124. }
  1125. // Do not repeat an include path.
  1126. std::set<cmStdString> emitted;
  1127. // Store the automatic include paths.
  1128. if(includeBinaryDir)
  1129. {
  1130. dirs.push_back(this->Makefile->GetStartOutputDirectory());
  1131. emitted.insert(this->Makefile->GetStartOutputDirectory());
  1132. }
  1133. if(includeSourceDir)
  1134. {
  1135. if(emitted.find(this->Makefile->GetStartDirectory()) == emitted.end())
  1136. {
  1137. dirs.push_back(this->Makefile->GetStartDirectory());
  1138. emitted.insert(this->Makefile->GetStartDirectory());
  1139. }
  1140. }
  1141. if(filter_system_dirs)
  1142. {
  1143. // Do not explicitly add the standard include path "/usr/include".
  1144. // This can cause problems with certain standard library
  1145. // implementations because the wrong headers may be found first.
  1146. emitted.insert("/usr/include");
  1147. if(const char* implicitIncludes = this->Makefile->GetDefinition
  1148. ("CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES"))
  1149. {
  1150. std::vector<std::string> implicitIncludeVec;
  1151. cmSystemTools::ExpandListArgument(implicitIncludes, implicitIncludeVec);
  1152. for(unsigned int k = 0; k < implicitIncludeVec.size(); ++k)
  1153. {
  1154. emitted.insert(implicitIncludeVec[k]);
  1155. }
  1156. }
  1157. }
  1158. // Get the project-specified include directories.
  1159. std::vector<std::string>& includes =
  1160. this->Makefile->GetIncludeDirectories();
  1161. // Support putting all the in-project include directories first if
  1162. // it is requested by the project.
  1163. if(this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
  1164. {
  1165. const char* topSourceDir = this->Makefile->GetHomeDirectory();
  1166. const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory();
  1167. for(std::vector<std::string>::iterator i = includes.begin();
  1168. i != includes.end(); ++i)
  1169. {
  1170. // Emit this directory only if it is a subdirectory of the
  1171. // top-level source or binary tree.
  1172. if(cmSystemTools::ComparePath(i->c_str(), topSourceDir) ||
  1173. cmSystemTools::ComparePath(i->c_str(), topBinaryDir) ||
  1174. cmSystemTools::IsSubDirectory(i->c_str(), topSourceDir) ||
  1175. cmSystemTools::IsSubDirectory(i->c_str(), topBinaryDir))
  1176. {
  1177. if(emitted.insert(*i).second)
  1178. {
  1179. dirs.push_back(*i);
  1180. }
  1181. }
  1182. }
  1183. }
  1184. // Construct the final ordered include directory list.
  1185. for(std::vector<std::string>::iterator i = includes.begin();
  1186. i != includes.end(); ++i)
  1187. {
  1188. if(emitted.insert(*i).second)
  1189. {
  1190. dirs.push_back(*i);
  1191. }
  1192. }
  1193. }
  1194. void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
  1195. std::string& flags,
  1196. std::string& linkFlags,
  1197. cmTarget& target)
  1198. {
  1199. std::string buildType =
  1200. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1201. buildType = cmSystemTools::UpperCase(buildType);
  1202. const char* libraryLinkVariable =
  1203. "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
  1204. switch(target.GetType())
  1205. {
  1206. case cmTarget::STATIC_LIBRARY:
  1207. {
  1208. const char* targetLinkFlags =
  1209. target.GetProperty("STATIC_LIBRARY_FLAGS");
  1210. if(targetLinkFlags)
  1211. {
  1212. linkFlags += targetLinkFlags;
  1213. linkFlags += " ";
  1214. }
  1215. }
  1216. break;
  1217. case cmTarget::MODULE_LIBRARY:
  1218. libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
  1219. case cmTarget::SHARED_LIBRARY:
  1220. {
  1221. linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
  1222. linkFlags += " ";
  1223. if(buildType.size())
  1224. {
  1225. std::string build = libraryLinkVariable;
  1226. build += "_";
  1227. build += buildType;
  1228. linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
  1229. linkFlags += " ";
  1230. }
  1231. if(this->Makefile->IsOn("WIN32") &&
  1232. !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
  1233. {
  1234. const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
  1235. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1236. i != sources.end(); ++i)
  1237. {
  1238. if((*i)->GetSourceExtension() == "def")
  1239. {
  1240. linkFlags +=
  1241. this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1242. linkFlags += this->Convert((*i)->GetFullPath().c_str(),
  1243. START_OUTPUT,MAKEFILE);
  1244. linkFlags += " ";
  1245. }
  1246. }
  1247. }
  1248. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1249. if(targetLinkFlags)
  1250. {
  1251. linkFlags += targetLinkFlags;
  1252. linkFlags += " ";
  1253. std::string configLinkFlags = targetLinkFlags;
  1254. configLinkFlags += buildType;
  1255. targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
  1256. if(targetLinkFlags)
  1257. {
  1258. linkFlags += targetLinkFlags;
  1259. linkFlags += " ";
  1260. }
  1261. }
  1262. cmOStringStream linklibsStr;
  1263. this->OutputLinkLibraries(linklibsStr, target, false);
  1264. linkLibs = linklibsStr.str();
  1265. }
  1266. break;
  1267. case cmTarget::EXECUTABLE:
  1268. {
  1269. linkFlags +=
  1270. this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1271. linkFlags += " ";
  1272. if(buildType.size())
  1273. {
  1274. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1275. build += buildType;
  1276. linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
  1277. linkFlags += " ";
  1278. }
  1279. const char* linkLanguage =
  1280. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1281. if(!linkLanguage)
  1282. {
  1283. cmSystemTools::Error
  1284. ("CMake can not determine linker language for target:",
  1285. target.GetName());
  1286. return;
  1287. }
  1288. std::string langVar = "CMAKE_";
  1289. langVar += linkLanguage;
  1290. std::string flagsVar = langVar + "_FLAGS";
  1291. std::string sharedFlagsVar = "CMAKE_SHARED_LIBRARY_";
  1292. sharedFlagsVar += linkLanguage;
  1293. sharedFlagsVar += "_FLAGS";
  1294. flags += this->Makefile->GetSafeDefinition(flagsVar.c_str());
  1295. flags += " ";
  1296. flags += this->Makefile->GetSafeDefinition(sharedFlagsVar.c_str());
  1297. flags += " ";
  1298. cmOStringStream linklibs;
  1299. this->OutputLinkLibraries(linklibs, target, false);
  1300. linkLibs = linklibs.str();
  1301. if(cmSystemTools::IsOn
  1302. (this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1303. {
  1304. std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_")
  1305. + linkLanguage + std::string("_FLAGS");
  1306. linkFlags += this->Makefile->GetSafeDefinition(sFlagVar.c_str());
  1307. linkFlags += " ";
  1308. }
  1309. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  1310. {
  1311. linkFlags +=
  1312. this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1313. linkFlags += " ";
  1314. }
  1315. else
  1316. {
  1317. linkFlags +=
  1318. this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1319. linkFlags += " ";
  1320. }
  1321. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1322. if(targetLinkFlags)
  1323. {
  1324. linkFlags += targetLinkFlags;
  1325. linkFlags += " ";
  1326. std::string configLinkFlags = targetLinkFlags;
  1327. configLinkFlags += buildType;
  1328. targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
  1329. if(targetLinkFlags)
  1330. {
  1331. linkFlags += targetLinkFlags;
  1332. linkFlags += " ";
  1333. }
  1334. }
  1335. }
  1336. break;
  1337. case cmTarget::UTILITY:
  1338. case cmTarget::GLOBAL_TARGET:
  1339. case cmTarget::INSTALL_FILES:
  1340. case cmTarget::INSTALL_PROGRAMS:
  1341. case cmTarget::INSTALL_DIRECTORY:
  1342. break;
  1343. }
  1344. }
  1345. /**
  1346. * Output the linking rules on a command line. For executables,
  1347. * targetLibrary should be a NULL pointer. For libraries, it should point
  1348. * to the name of the library. This will not link a library against itself.
  1349. */
  1350. void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout,
  1351. cmTarget& tgt,
  1352. bool relink)
  1353. {
  1354. // Try to emit each search path once
  1355. std::set<cmStdString> emitted;
  1356. // Embed runtime search paths if possible and if required.
  1357. bool outputRuntime = true;
  1358. std::string runtimeFlag;
  1359. std::string runtimeSep;
  1360. const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  1361. const char* linkLanguage =
  1362. tgt.GetLinkerLanguage(this->GetGlobalGenerator());
  1363. if(!linkLanguage)
  1364. {
  1365. cmSystemTools::
  1366. Error("CMake can not determine linker language for target:",
  1367. tgt.GetName());
  1368. return;
  1369. }
  1370. std::string runTimeFlagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1371. runTimeFlagVar += linkLanguage;
  1372. runTimeFlagVar += "_FLAG";
  1373. std::string runTimeFlagSepVar = runTimeFlagVar + "_SEP";
  1374. runtimeFlag = this->Makefile->GetSafeDefinition(runTimeFlagVar.c_str());
  1375. runtimeSep = this->Makefile->GetSafeDefinition(runTimeFlagSepVar.c_str());
  1376. // concatenate all paths or no?
  1377. bool runtimeConcatenate = ( runtimeSep!="" );
  1378. if(runtimeFlag == "" || this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  1379. {
  1380. outputRuntime = false;
  1381. }
  1382. // Some search paths should never be emitted
  1383. emitted.insert("");
  1384. emitted.insert("/usr/lib");
  1385. std::string libPathFlag =
  1386. this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
  1387. std::string libLinkFlag =
  1388. this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FLAG");
  1389. // collect all the flags needed for linking libraries
  1390. std::string linkLibs;
  1391. // Flags to link an executable to shared libraries.
  1392. std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
  1393. linkFlagsVar += linkLanguage;
  1394. linkFlagsVar += "_FLAGS";
  1395. if( tgt.GetType() == cmTarget::EXECUTABLE )
  1396. {
  1397. linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar.c_str());
  1398. linkLibs += " ";
  1399. }
  1400. // Compute the link library and directory information.
  1401. std::vector<cmStdString> libNames;
  1402. std::vector<cmStdString> libDirs;
  1403. this->ComputeLinkInformation(tgt, config, libNames, libDirs);
  1404. // Select whether to generate an rpath for the install tree or the
  1405. // build tree.
  1406. bool linking_for_install =
  1407. relink || tgt.GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  1408. bool use_install_rpath =
  1409. outputRuntime && tgt.HaveInstallTreeRPATH() && linking_for_install;
  1410. bool use_build_rpath =
  1411. outputRuntime && tgt.HaveBuildTreeRPATH() && !linking_for_install;
  1412. bool use_link_rpath =
  1413. outputRuntime && linking_for_install &&
  1414. tgt.GetPropertyAsBool("INSTALL_RPATH_USE_LINK_PATH");
  1415. // Construct the RPATH.
  1416. std::vector<std::string> runtimeDirs;
  1417. if(use_install_rpath)
  1418. {
  1419. const char* install_rpath = tgt.GetProperty("INSTALL_RPATH");
  1420. cmSystemTools::ExpandListArgument(install_rpath, runtimeDirs);
  1421. for(unsigned int i=0; i < runtimeDirs.size(); ++i)
  1422. {
  1423. runtimeDirs[i] =
  1424. this->Convert(runtimeDirs[i].c_str(), FULL, SHELL, false);
  1425. }
  1426. }
  1427. // Append the library search path flags.
  1428. for(std::vector<cmStdString>::const_iterator libDir = libDirs.begin();
  1429. libDir != libDirs.end(); ++libDir)
  1430. {
  1431. std::string libpath = this->ConvertToOutputForExisting(libDir->c_str());
  1432. if(emitted.insert(libpath).second)
  1433. {
  1434. std::string fullLibPath;
  1435. if(!this->WindowsShell && this->UseRelativePaths)
  1436. {
  1437. fullLibPath = "\"`cd ";
  1438. }
  1439. fullLibPath += libpath;
  1440. if(!this->WindowsShell && this->UseRelativePaths)
  1441. {
  1442. fullLibPath += ";pwd`\"";
  1443. }
  1444. std::string::size_type pos = libDir->find(libPathFlag.c_str());
  1445. if((pos == std::string::npos || pos > 0)
  1446. && libDir->find("${") == std::string::npos)
  1447. {
  1448. linkLibs += libPathFlag;
  1449. linkLibs += fullLibPath;
  1450. linkLibs += " ";
  1451. // Put this directory in the rpath if using build-tree rpath
  1452. // support or if using the link path as an rpath.
  1453. if(use_build_rpath)
  1454. {
  1455. runtimeDirs.push_back(fullLibPath);
  1456. }
  1457. else if(use_link_rpath)
  1458. {
  1459. // Do not add any path inside the source or build tree.
  1460. const char* topSourceDir = this->Makefile->GetHomeDirectory();
  1461. const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory();
  1462. if(!cmSystemTools::ComparePath(libDir->c_str(), topSourceDir) &&
  1463. !cmSystemTools::ComparePath(libDir->c_str(), topBinaryDir) &&
  1464. !cmSystemTools::IsSubDirectory(libDir->c_str(), topSourceDir) &&
  1465. !cmSystemTools::IsSubDirectory(libDir->c_str(), topBinaryDir))
  1466. {
  1467. runtimeDirs.push_back(fullLibPath);
  1468. }
  1469. }
  1470. }
  1471. }
  1472. }
  1473. // Append the link libraries.
  1474. for(std::vector<cmStdString>::iterator lib = libNames.begin();
  1475. lib != libNames.end(); ++lib)
  1476. {
  1477. linkLibs += *lib;
  1478. linkLibs += " ";
  1479. }
  1480. fout << linkLibs;
  1481. if(!runtimeDirs.empty())
  1482. {
  1483. // For the runtime search directories, do a "-Wl,-rpath,a:b:c" or
  1484. // a "-R a -R b -R c" type link line
  1485. fout << runtimeFlag;
  1486. std::vector<std::string>::iterator itr = runtimeDirs.begin();
  1487. fout << *itr;
  1488. ++itr;
  1489. for( ; itr != runtimeDirs.end(); ++itr )
  1490. {
  1491. if(runtimeConcatenate)
  1492. {
  1493. #ifdef __QNX__
  1494. fout << runtimeSep << this->Convert(itr->c_str(), NONE, SHELL, false);
  1495. #else
  1496. fout << runtimeSep << *itr;
  1497. #endif
  1498. }
  1499. else
  1500. {
  1501. fout << " " << runtimeFlag << *itr;
  1502. }
  1503. }
  1504. fout << " ";
  1505. }
  1506. // Add standard libraries for this language.
  1507. std::string standardLibsVar = "CMAKE_";
  1508. standardLibsVar += linkLanguage;
  1509. standardLibsVar += "_STANDARD_LIBRARIES";
  1510. if(const char* stdLibs =
  1511. this->Makefile->GetDefinition(standardLibsVar.c_str()))
  1512. {
  1513. fout << stdLibs << " ";
  1514. }
  1515. }
  1516. //----------------------------------------------------------------------------
  1517. void cmLocalGenerator
  1518. ::ComputeLinkInformation(cmTarget& target,
  1519. const char* config,
  1520. std::vector<cmStdString>& outLibs,
  1521. std::vector<cmStdString>& outDirs,
  1522. std::vector<cmStdString>* fullPathLibs)
  1523. {
  1524. // Compute which library configuration to link.
  1525. cmTarget::LinkLibraryType linkType = cmTarget::OPTIMIZED;
  1526. if(config && cmSystemTools::UpperCase(config) == "DEBUG")
  1527. {
  1528. linkType = cmTarget::DEBUG;
  1529. }
  1530. // Get the list of libraries against which this target wants to link.
  1531. std::vector<std::string> linkLibraries;
  1532. const cmTarget::LinkLibraryVectorType& inLibs = target.GetLinkLibraries();
  1533. for(cmTarget::LinkLibraryVectorType::const_iterator j = inLibs.begin();
  1534. j != inLibs.end(); ++j)
  1535. {
  1536. // For backwards compatibility variables may have been expanded
  1537. // inside library names. Clean up the resulting name.
  1538. std::string lib = j->first;
  1539. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  1540. if(pos != lib.npos)
  1541. {
  1542. lib = lib.substr(pos, lib.npos);
  1543. }
  1544. pos = lib.find_last_not_of(" \t\r\n");
  1545. if(pos != lib.npos)
  1546. {
  1547. lib = lib.substr(0, pos+1);
  1548. }
  1549. if(lib.empty())
  1550. {
  1551. continue;
  1552. }
  1553. // Link to a library if it is not the same target and is meant for
  1554. // this configuration type.
  1555. if((target.GetType() == cmTarget::EXECUTABLE ||
  1556. lib != target.GetName()) &&
  1557. (j->second == cmTarget::GENERAL || j->second == linkType))
  1558. {
  1559. // Compute the proper name to use to link this library.
  1560. cmTarget* tgt = this->GlobalGenerator->FindTarget(0, lib.c_str());
  1561. if(tgt && (tgt->GetType() == cmTarget::STATIC_LIBRARY ||
  1562. tgt->GetType() == cmTarget::SHARED_LIBRARY ||
  1563. tgt->GetType() == cmTarget::MODULE_LIBRARY))
  1564. {
  1565. // This is a CMake target. Ask the target for its real name.
  1566. // Pass the full path to the target file but purposely leave
  1567. // off the per-configuration subdirectory. The link directory
  1568. // ordering knows how to deal with this.
  1569. std::string linkItem = tgt->GetDirectory(0);
  1570. linkItem += "/";
  1571. linkItem += tgt->GetFullName(config);
  1572. linkLibraries.push_back(linkItem);
  1573. // For full path, use the true location.
  1574. if(fullPathLibs)
  1575. {
  1576. fullPathLibs->push_back(tgt->GetFullPath(config));
  1577. }
  1578. }
  1579. else
  1580. {
  1581. // This is not a CMake target. Use the name given.
  1582. linkLibraries.push_back(lib);
  1583. // Add to the list of full paths if this library is one.
  1584. if(fullPathLibs &&
  1585. cmSystemTools::FileIsFullPath(lib.c_str()) &&
  1586. !cmSystemTools::FileIsDirectory(lib.c_str()))
  1587. {
  1588. fullPathLibs->push_back(lib);
  1589. }
  1590. }
  1591. }
  1592. }
  1593. // Get the list of directories the target wants to search for libraries.
  1594. const std::vector<std::string>&
  1595. linkDirectories = target.GetLinkDirectories();
  1596. // Lookup link type selection flags.
  1597. const char* static_link_type_flag = 0;
  1598. const char* shared_link_type_flag = 0;
  1599. const char* target_type_str = 0;
  1600. switch(target.GetType())
  1601. {
  1602. case cmTarget::EXECUTABLE: target_type_str = "EXE"; break;
  1603. case cmTarget::SHARED_LIBRARY: target_type_str = "SHARED_LIBRARY"; break;
  1604. case cmTarget::MODULE_LIBRARY: target_type_str = "SHARED_MODULE"; break;
  1605. default: break;
  1606. }
  1607. if(target_type_str)
  1608. {
  1609. // Get the language used for linking.
  1610. const char* linkLanguage =
  1611. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1612. if(!linkLanguage)
  1613. {
  1614. cmSystemTools::
  1615. Error("CMake can not determine linker language for target:",
  1616. target.GetName());
  1617. return;
  1618. }
  1619. std::string static_link_type_flag_var = "CMAKE_";
  1620. static_link_type_flag_var += target_type_str;
  1621. static_link_type_flag_var += "_LINK_STATIC_";
  1622. static_link_type_flag_var += linkLanguage;
  1623. static_link_type_flag_var += "_FLAGS";
  1624. static_link_type_flag =
  1625. this->Makefile->GetDefinition(static_link_type_flag_var.c_str());
  1626. std::string shared_link_type_flag_var = "CMAKE_";
  1627. shared_link_type_flag_var += target_type_str;
  1628. shared_link_type_flag_var += "_LINK_DYNAMIC_";
  1629. shared_link_type_flag_var += linkLanguage;
  1630. shared_link_type_flag_var += "_FLAGS";
  1631. shared_link_type_flag =
  1632. this->Makefile->GetDefinition(shared_link_type_flag_var.c_str());
  1633. }
  1634. // Compute the link directory order needed to link the libraries.
  1635. cmOrderLinkDirectories orderLibs;
  1636. orderLibs.SetLinkTypeInformation(cmOrderLinkDirectories::LinkShared,
  1637. static_link_type_flag,
  1638. shared_link_type_flag);
  1639. orderLibs.AddLinkPrefix(
  1640. this->Makefile->GetDefinition("CMAKE_STATIC_LIBRARY_PREFIX"));
  1641. orderLibs.AddLinkPrefix(
  1642. this->Makefile->GetDefinition("CMAKE_SHARED_LIBRARY_PREFIX"));
  1643. // Import library names should be matched and treated as shared
  1644. // libraries for the purposes of linking.
  1645. orderLibs.AddLinkExtension(
  1646. this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"),
  1647. cmOrderLinkDirectories::LinkShared);
  1648. orderLibs.AddLinkExtension(
  1649. this->Makefile->GetDefinition("CMAKE_STATIC_LIBRARY_SUFFIX"),
  1650. cmOrderLinkDirectories::LinkStatic);
  1651. orderLibs.AddLinkExtension(
  1652. this->Makefile->GetDefinition("CMAKE_SHARED_LIBRARY_SUFFIX"),
  1653. cmOrderLinkDirectories::LinkShared);
  1654. orderLibs.AddLinkExtension(
  1655. this->Makefile->GetDefinition("CMAKE_LINK_LIBRARY_SUFFIX"));
  1656. if(const char* linkSuffixes =
  1657. this->Makefile->GetDefinition("CMAKE_EXTRA_LINK_EXTENSIONS"))
  1658. {
  1659. std::vector<std::string> linkSuffixVec;
  1660. cmSystemTools::ExpandListArgument(linkSuffixes, linkSuffixVec);
  1661. for(std::vector<std::string>::iterator i = linkSuffixVec.begin();
  1662. i != linkSuffixVec.end(); ++i)
  1663. {
  1664. orderLibs.AddLinkExtension(i->c_str());
  1665. }
  1666. }
  1667. std::string configSubdir;
  1668. cmGlobalGenerator* gg = this->GetGlobalGenerator();
  1669. gg->AppendDirectoryForConfig("", config, "", configSubdir);
  1670. orderLibs.SetLinkInformation(target.GetName(),
  1671. linkLibraries,
  1672. linkDirectories,
  1673. gg->GetTargetManifest(),
  1674. configSubdir.c_str());
  1675. orderLibs.DetermineLibraryPathOrder();
  1676. std::vector<cmStdString> orderedLibs;
  1677. orderLibs.GetLinkerInformation(outDirs, orderedLibs);
  1678. // Make sure libraries are linked with the proper syntax.
  1679. std::string libLinkFlag =
  1680. this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FLAG");
  1681. std::string libLinkSuffix =
  1682. this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_SUFFIX");
  1683. for(std::vector<cmStdString>::iterator l = orderedLibs.begin();
  1684. l != orderedLibs.end(); ++l)
  1685. {
  1686. std::string lib = *l;
  1687. if(lib[0] == '-' || lib[0] == '$' || lib[0] == '`')
  1688. {
  1689. // The library is linked with special syntax by the user.
  1690. outLibs.push_back(lib);
  1691. }
  1692. else
  1693. {
  1694. // Generate the proper link syntax.
  1695. lib = libLinkFlag;
  1696. lib += *l;
  1697. lib += libLinkSuffix;
  1698. outLibs.push_back(lib);
  1699. }
  1700. }
  1701. }
  1702. //----------------------------------------------------------------------------
  1703. void cmLocalGenerator::AddLanguageFlags(std::string& flags,
  1704. const char* lang,
  1705. const char* config)
  1706. {
  1707. // Add language-specific flags.
  1708. std::string flagsVar = "CMAKE_";
  1709. flagsVar += lang;
  1710. flagsVar += "_FLAGS";
  1711. if(this->EmitUniversalBinaryFlags)
  1712. {
  1713. const char* osxArch =
  1714. this->Makefile->GetDefinition("CMAKE_OSX_ARCHITECTURES");
  1715. const char* sysroot =
  1716. this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
  1717. if(osxArch && sysroot && lang && lang[0] =='C')
  1718. {
  1719. std::vector<std::string> archs;
  1720. cmSystemTools::ExpandListArgument(std::string(osxArch),
  1721. archs);
  1722. if(archs.size() > 1)
  1723. {
  1724. for( std::vector<std::string>::iterator i = archs.begin();
  1725. i != archs.end(); ++i)
  1726. {
  1727. flags += " -arch ";
  1728. flags += *i;
  1729. }
  1730. flags += " -isysroot ";
  1731. flags += sysroot;
  1732. }
  1733. }
  1734. }
  1735. this->AddConfigVariableFlags(flags, flagsVar.c_str(), config);
  1736. }
  1737. //----------------------------------------------------------------------------
  1738. std::string cmLocalGenerator::GetRealDependency(const char* inName,
  1739. const char* config)
  1740. {
  1741. // Older CMake code may specify the dependency using the target
  1742. // output file rather than the target name. Such code would have
  1743. // been written before there was support for target properties that
  1744. // modify the name so stripping down to just the file name should
  1745. // produce the target name in this case.
  1746. std::string name = cmSystemTools::GetFilenameName(inName);
  1747. if(cmSystemTools::GetFilenameLastExtension(name) == ".exe")
  1748. {
  1749. name = cmSystemTools::GetFilenameWithoutLastExtension(name);
  1750. }
  1751. // Look for a CMake target with the given name.
  1752. if(cmTarget* target = this->GlobalGenerator->FindTarget(0, name.c_str()))
  1753. {
  1754. // make sure it is not just a coincidence that the target name
  1755. // found is part of the inName
  1756. if(cmSystemTools::FileIsFullPath(inName))
  1757. {
  1758. std::string tLocation = target->GetLocation(config);
  1759. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1760. std::string depLocation = cmSystemTools::GetFilenamePath(
  1761. std::string(inName));
  1762. depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
  1763. tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
  1764. if(depLocation != tLocation)
  1765. {
  1766. // it is a full path to a depend that has the same name
  1767. // as a target but is in a different location so do not use
  1768. // the target as the depend
  1769. return inName;
  1770. }
  1771. }
  1772. switch (target->GetType())
  1773. {
  1774. case cmTarget::EXECUTABLE:
  1775. case cmTarget::STATIC_LIBRARY:
  1776. case cmTarget::SHARED_LIBRARY:
  1777. case cmTarget::MODULE_LIBRARY:
  1778. {
  1779. // Get the location of the target's output file and depend on it.
  1780. if(const char* location = target->GetLocation(config))
  1781. {
  1782. return location;
  1783. }
  1784. }
  1785. break;
  1786. case cmTarget::UTILITY:
  1787. case cmTarget::GLOBAL_TARGET:
  1788. // Depending on a utility target may not work but just trust
  1789. // the user to have given a valid name.
  1790. return inName;
  1791. case cmTarget::INSTALL_FILES:
  1792. case cmTarget::INSTALL_PROGRAMS:
  1793. case cmTarget::INSTALL_DIRECTORY:
  1794. break;
  1795. }
  1796. }
  1797. // The name was not that of a CMake target. It must name a file.
  1798. if(cmSystemTools::FileIsFullPath(inName))
  1799. {
  1800. // This is a full path. Return it as given.
  1801. return inName;
  1802. }
  1803. // Treat the name as relative to the source directory in which it
  1804. // was given.
  1805. name = this->Makefile->GetCurrentDirectory();
  1806. name += "/";
  1807. name += inName;
  1808. return name;
  1809. }
  1810. //----------------------------------------------------------------------------
  1811. void cmLocalGenerator::AddSharedFlags(std::string& flags,
  1812. const char* lang,
  1813. bool shared)
  1814. {
  1815. std::string flagsVar;
  1816. // Add flags for dealing with shared libraries for this language.
  1817. if(shared)
  1818. {
  1819. flagsVar = "CMAKE_SHARED_LIBRARY_";
  1820. flagsVar += lang;
  1821. flagsVar += "_FLAGS";
  1822. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1823. }
  1824. // Add flags specific to shared builds.
  1825. if(cmSystemTools::IsOn(this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1826. {
  1827. flagsVar = "CMAKE_SHARED_BUILD_";
  1828. flagsVar += lang;
  1829. flagsVar += "_FLAGS";
  1830. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1831. }
  1832. }
  1833. //----------------------------------------------------------------------------
  1834. void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
  1835. const char* var,
  1836. const char* config)
  1837. {
  1838. // Add the flags from the variable itself.
  1839. std::string flagsVar = var;
  1840. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1841. // Add the flags from the build-type specific variable.
  1842. if(config && *config)
  1843. {
  1844. flagsVar += "_";
  1845. flagsVar += cmSystemTools::UpperCase(config);
  1846. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1847. }
  1848. }
  1849. //----------------------------------------------------------------------------
  1850. void cmLocalGenerator::AppendFlags(std::string& flags,
  1851. const char* newFlags)
  1852. {
  1853. if(newFlags && *newFlags)
  1854. {
  1855. if(flags.size())
  1856. {
  1857. flags += " ";
  1858. }
  1859. flags += newFlags;
  1860. }
  1861. }
  1862. //----------------------------------------------------------------------------
  1863. std::string
  1864. cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,
  1865. const char* default_comment)
  1866. {
  1867. // Check for a comment provided with the command.
  1868. if(cc.GetComment())
  1869. {
  1870. return cc.GetComment();
  1871. }
  1872. // Construct a reasonable default comment if possible.
  1873. if(!cc.GetOutputs().empty())
  1874. {
  1875. std::string comment;
  1876. comment = "Generating ";
  1877. const char* sep = "";
  1878. for(std::vector<std::string>::const_iterator o = cc.GetOutputs().begin();
  1879. o != cc.GetOutputs().end(); ++o)
  1880. {
  1881. comment += sep;
  1882. comment += this->Convert(o->c_str(), cmLocalGenerator::START_OUTPUT);
  1883. sep = ", ";
  1884. }
  1885. return comment;
  1886. }
  1887. // Otherwise use the provided default.
  1888. return default_comment;
  1889. }
  1890. //----------------------------------------------------------------------------
  1891. std::string
  1892. cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(const char* remote)
  1893. {
  1894. return this->Convert(remote, START_OUTPUT, SHELL, true);
  1895. }
  1896. //----------------------------------------------------------------------------
  1897. std::string cmLocalGenerator::Convert(const char* source,
  1898. RelativeRoot relative,
  1899. OutputFormat output,
  1900. bool optional)
  1901. {
  1902. // Convert the path to a relative path.
  1903. std::string result = source;
  1904. if (!optional || this->UseRelativePaths)
  1905. {
  1906. switch (relative)
  1907. {
  1908. case HOME:
  1909. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1910. result = this->GlobalGenerator->
  1911. ConvertToRelativePath(this->HomeDirectoryComponents,
  1912. result.c_str());
  1913. break;
  1914. case START:
  1915. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1916. result = this->GlobalGenerator->
  1917. ConvertToRelativePath(this->StartDirectoryComponents,
  1918. result.c_str());
  1919. break;
  1920. case HOME_OUTPUT:
  1921. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1922. result = this->GlobalGenerator->
  1923. ConvertToRelativePath(this->HomeOutputDirectoryComponents,
  1924. result.c_str());
  1925. break;
  1926. case START_OUTPUT:
  1927. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1928. result = this->GlobalGenerator->
  1929. ConvertToRelativePath(this->StartOutputDirectoryComponents,
  1930. result.c_str());
  1931. break;
  1932. case FULL:
  1933. result = cmSystemTools::CollapseFullPath(result.c_str());
  1934. break;
  1935. case NONE:
  1936. break;
  1937. }
  1938. }
  1939. // Now convert it to an output path.
  1940. if (output == MAKEFILE)
  1941. {
  1942. result = cmSystemTools::ConvertToOutputPath(result.c_str());
  1943. }
  1944. if( output == SHELL)
  1945. {
  1946. // For the MSYS shell convert drive letters to posix paths, so
  1947. // that c:/some/path becomes /c/some/path. This is needed to
  1948. // avoid problems with the shell path translation.
  1949. if(this->MSYSShell)
  1950. {
  1951. if(result.size() > 2 && result[1] == ':')
  1952. {
  1953. result[1] = result[0];
  1954. result[0] = '/';
  1955. }
  1956. }
  1957. if(this->WindowsShell)
  1958. {
  1959. std::string::size_type pos = 0;
  1960. while((pos = result.find('/', pos)) != std::string::npos)
  1961. {
  1962. result[pos] = '\\';
  1963. pos++;
  1964. }
  1965. }
  1966. result = this->EscapeForShell(result.c_str(), true, false);
  1967. }
  1968. return result;
  1969. }
  1970. //----------------------------------------------------------------------------
  1971. void
  1972. cmLocalGenerator
  1973. ::GenerateTargetInstallRules(
  1974. std::ostream& os, const char* config,
  1975. std::vector<std::string> const& configurationTypes)
  1976. {
  1977. // Convert the old-style install specification from each target to
  1978. // an install generator and run it.
  1979. cmTargets& tgts = this->Makefile->GetTargets();
  1980. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  1981. {
  1982. // Include the user-specified pre-install script for this target.
  1983. if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
  1984. {
  1985. cmInstallScriptGenerator g(preinstall);
  1986. g.Generate(os, config, configurationTypes);
  1987. }
  1988. // Install this target if a destination is given.
  1989. if(l->second.GetInstallPath() != "")
  1990. {
  1991. // Compute the full install destination. Note that converting
  1992. // to unix slashes also removes any trailing slash.
  1993. std::string destination = "${CMAKE_INSTALL_PREFIX}";
  1994. destination += l->second.GetInstallPath();
  1995. cmSystemTools::ConvertToUnixSlashes(destination);
  1996. // Generate the proper install generator for this target type.
  1997. switch(l->second.GetType())
  1998. {
  1999. case cmTarget::EXECUTABLE:
  2000. case cmTarget::STATIC_LIBRARY:
  2001. case cmTarget::MODULE_LIBRARY:
  2002. {
  2003. // Use a target install generator.
  2004. cmInstallTargetGenerator g(l->second, destination.c_str(), false);
  2005. g.Generate(os, config, configurationTypes);
  2006. }
  2007. break;
  2008. case cmTarget::SHARED_LIBRARY:
  2009. {
  2010. #if defined(_WIN32) || defined(__CYGWIN__)
  2011. // Special code to handle DLL. Install the import library
  2012. // to the normal destination and the DLL to the runtime
  2013. // destination.
  2014. cmInstallTargetGenerator g1(l->second, destination.c_str(), true);
  2015. g1.Generate(os, config, configurationTypes);
  2016. destination = "${CMAKE_INSTALL_PREFIX}";
  2017. destination += l->second.GetRuntimeInstallPath();
  2018. cmSystemTools::ConvertToUnixSlashes(destination);
  2019. cmInstallTargetGenerator g2(l->second, destination.c_str(), false);
  2020. g2.Generate(os, config, configurationTypes);
  2021. #else
  2022. // Use a target install generator.
  2023. cmInstallTargetGenerator g(l->second, destination.c_str(), false);
  2024. g.Generate(os, config, configurationTypes);
  2025. #endif
  2026. }
  2027. break;
  2028. case cmTarget::INSTALL_FILES:
  2029. {
  2030. // Use a file install generator.
  2031. const char* no_permissions = "";
  2032. const char* no_rename = "";
  2033. const char* no_component = "";
  2034. std::vector<std::string> no_configurations;
  2035. cmInstallFilesGenerator g(l->second.GetSourceLists(),
  2036. destination.c_str(), false,
  2037. no_permissions, no_configurations,
  2038. no_component, no_rename);
  2039. g.Generate(os, config, configurationTypes);
  2040. }
  2041. break;
  2042. case cmTarget::INSTALL_PROGRAMS:
  2043. {
  2044. // Use a file install generator.
  2045. const char* no_permissions = "";
  2046. const char* no_rename = "";
  2047. const char* no_component = "";
  2048. std::vector<std::string> no_configurations;
  2049. cmInstallFilesGenerator g(l->second.GetSourceLists(),
  2050. destination.c_str(), true,
  2051. no_permissions, no_configurations,
  2052. no_component, no_rename);
  2053. g.Generate(os, config, configurationTypes);
  2054. }
  2055. break;
  2056. case cmTarget::UTILITY:
  2057. default:
  2058. break;
  2059. }
  2060. }
  2061. // Include the user-specified post-install script for this target.
  2062. if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
  2063. {
  2064. cmInstallScriptGenerator g(postinstall);
  2065. g.Generate(os, config, configurationTypes);
  2066. }
  2067. }
  2068. }
  2069. //----------------------------------------------------------------------------
  2070. std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName(const char* sin)
  2071. {
  2072. // Look for an existing mapped name for this object file.
  2073. std::map<cmStdString,cmStdString>::iterator it =
  2074. this->UniqueObjectNamesMap.find(sin);
  2075. // If no entry exists create one.
  2076. if(it == this->UniqueObjectNamesMap.end())
  2077. {
  2078. // Start with the original name.
  2079. std::string ssin = sin;
  2080. // Avoid full paths by removing leading slashes.
  2081. std::string::size_type pos = 0;
  2082. for(;pos < ssin.size() && ssin[pos] == '/'; ++pos);
  2083. ssin = ssin.substr(pos);
  2084. // Avoid full paths by removing colons.
  2085. cmSystemTools::ReplaceString(ssin, ":", "_");
  2086. // Avoid relative paths that go up the tree.
  2087. cmSystemTools::ReplaceString(ssin, "../", "__/");
  2088. // Avoid spaces.
  2089. cmSystemTools::ReplaceString(ssin, " ", "_");
  2090. // Mangle the name if necessary.
  2091. if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
  2092. {
  2093. bool done;
  2094. int cc = 0;
  2095. char rpstr[100];
  2096. sprintf(rpstr, "_p_");
  2097. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2098. std::string sssin = sin;
  2099. do
  2100. {
  2101. done = true;
  2102. for ( it = this->UniqueObjectNamesMap.begin();
  2103. it != this->UniqueObjectNamesMap.end();
  2104. ++ it )
  2105. {
  2106. if ( it->second == ssin )
  2107. {
  2108. done = false;
  2109. }
  2110. }
  2111. if ( done )
  2112. {
  2113. break;
  2114. }
  2115. sssin = ssin;
  2116. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2117. sprintf(rpstr, "_p%d_", cc++);
  2118. }
  2119. while ( !done );
  2120. }
  2121. // Insert the newly mapped object file name.
  2122. std::map<cmStdString, cmStdString>::value_type e(sin, ssin);
  2123. it = this->UniqueObjectNamesMap.insert(e).first;
  2124. }
  2125. // Return the map entry.
  2126. return it->second;
  2127. }
  2128. //----------------------------------------------------------------------------
  2129. std::string
  2130. cmLocalGenerator::GetObjectFileNameWithoutTarget(const cmSourceFile& source)
  2131. {
  2132. // If the source file is located below the current binary directory
  2133. // then use that relative path for the object file name.
  2134. std::string objectName = this->Convert(source.GetFullPath().c_str(),
  2135. START_OUTPUT);
  2136. if(cmSystemTools::FileIsFullPath(objectName.c_str()) ||
  2137. objectName.empty() || objectName[0] == '.')
  2138. {
  2139. // If the source file is located below the current source
  2140. // directory then use that relative path for the object file name.
  2141. // Otherwise just use the relative path from the current binary
  2142. // directory.
  2143. std::string relFromSource = this->Convert(source.GetFullPath().c_str(),
  2144. START);
  2145. if(!cmSystemTools::FileIsFullPath(relFromSource.c_str()) &&
  2146. !relFromSource.empty() && relFromSource[0] != '.')
  2147. {
  2148. objectName = relFromSource;
  2149. }
  2150. }
  2151. // if it is still a full path check for the try compile case
  2152. // try compile never have in source sources, and should not
  2153. // have conflicting source file names in the same target
  2154. if(cmSystemTools::FileIsFullPath(objectName.c_str()))
  2155. {
  2156. if(this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
  2157. {
  2158. objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
  2159. }
  2160. }
  2161. // Replace the original source file extension with the object file
  2162. // extension.
  2163. std::string::size_type dot_pos = objectName.rfind(".");
  2164. if(dot_pos != std::string::npos)
  2165. {
  2166. objectName = objectName.substr(0, dot_pos);
  2167. }
  2168. if ( source.GetPropertyAsBool("KEEP_EXTENSION") )
  2169. {
  2170. if ( !source.GetSourceExtension().empty() )
  2171. {
  2172. objectName += "." + source.GetSourceExtension();
  2173. }
  2174. }
  2175. else
  2176. {
  2177. objectName +=
  2178. this->GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  2179. source.GetSourceExtension().c_str());
  2180. }
  2181. // Convert to a safe name.
  2182. return this->CreateSafeUniqueObjectFileName(objectName.c_str());
  2183. }
  2184. //----------------------------------------------------------------------------
  2185. const char*
  2186. cmLocalGenerator
  2187. ::GetSourceFileLanguage(const cmSourceFile& source)
  2188. {
  2189. // Check for an explicitly assigned language.
  2190. if(const char* lang = source.GetProperty("LANGUAGE"))
  2191. {
  2192. return lang;
  2193. }
  2194. // Infer the language from the source file extension.
  2195. return (this->GlobalGenerator
  2196. ->GetLanguageFromExtension(source.GetSourceExtension().c_str()));
  2197. }
  2198. //----------------------------------------------------------------------------
  2199. std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
  2200. {
  2201. std::string result;
  2202. bool forceOn = cmSystemTools::GetForceUnixPaths();
  2203. if(forceOn && this->WindowsShell)
  2204. {
  2205. cmSystemTools::SetForceUnixPaths(false);
  2206. }
  2207. result = cmSystemTools::EscapeSpaces(str);
  2208. if(forceOn && this->WindowsShell)
  2209. {
  2210. cmSystemTools::SetForceUnixPaths(true);
  2211. }
  2212. return result;
  2213. }
  2214. //----------------------------------------------------------------------------
  2215. std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
  2216. bool forEcho)
  2217. {
  2218. // Compute the flags for the target shell environment.
  2219. int flags = 0;
  2220. if(this->WindowsVSIDE)
  2221. {
  2222. flags |= cmsysSystem_Shell_Flag_VSIDE;
  2223. }
  2224. else
  2225. {
  2226. flags |= cmsysSystem_Shell_Flag_Make;
  2227. }
  2228. if(makeVars)
  2229. {
  2230. flags |= cmsysSystem_Shell_Flag_AllowMakeVariables;
  2231. }
  2232. if(forEcho)
  2233. {
  2234. flags |= cmsysSystem_Shell_Flag_EchoWindows;
  2235. }
  2236. if(this->WatcomWMake)
  2237. {
  2238. flags |= cmsysSystem_Shell_Flag_WatcomWMake;
  2239. }
  2240. // Compute the buffer size needed.
  2241. int size = (this->WindowsShell ?
  2242. cmsysSystem_Shell_GetArgumentSizeForWindows(str, flags) :
  2243. cmsysSystem_Shell_GetArgumentSizeForUnix(str, flags));
  2244. // Compute the shell argument itself.
  2245. std::vector<char> arg(size);
  2246. if(this->WindowsShell)
  2247. {
  2248. cmsysSystem_Shell_GetArgumentForWindows(str, &arg[0], flags);
  2249. }
  2250. else
  2251. {
  2252. cmsysSystem_Shell_GetArgumentForUnix(str, &arg[0], flags);
  2253. }
  2254. return std::string(&arg[0]);
  2255. }
  2256. void
  2257. cmLocalGenerator::GetTargetObjectFileDirectories(cmTarget* ,
  2258. std::vector<std::string>&
  2259. )
  2260. {
  2261. cmSystemTools::Error("GetTargetObjectFileDirectories"
  2262. " called on cmLocalGenerator");
  2263. }
  2264. std::string cmLocalGenerator::GetSourceObjectName(cmSourceFile& sf)
  2265. {
  2266. return sf.GetSourceName();
  2267. }