cmLocalGenerator.cxx 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836
  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 <ctype.h> // for isalpha
  26. cmLocalGenerator::cmLocalGenerator()
  27. {
  28. this->Makefile = new cmMakefile;
  29. this->Makefile->SetLocalGenerator(this);
  30. this->ExcludeFromAll = false;
  31. this->Parent = 0;
  32. this->WindowsShell = false;
  33. this->IgnoreLibPrefix = false;
  34. this->UseRelativePaths = false;
  35. this->Configured = false;
  36. this->EmitUniversalBinaryFlags = true;
  37. }
  38. cmLocalGenerator::~cmLocalGenerator()
  39. {
  40. delete this->Makefile;
  41. }
  42. void cmLocalGenerator::Configure()
  43. {
  44. // make sure the CMakeFiles dir is there
  45. std::string filesDir = this->Makefile->GetStartOutputDirectory();
  46. filesDir += "/CMakeFiles";
  47. cmSystemTools::MakeDirectory(filesDir.c_str());
  48. // find & read the list file
  49. std::string currentStart = this->Makefile->GetStartDirectory();
  50. currentStart += "/CMakeLists.txt";
  51. this->Makefile->ReadListFile(currentStart.c_str());
  52. // at the end of the ReadListFile handle any old style subdirs
  53. // first get all the subdirectories
  54. std::vector<cmLocalGenerator *> subdirs = this->GetChildren();
  55. // for each subdir recurse
  56. std::vector<cmLocalGenerator *>::iterator sdi = subdirs.begin();
  57. for (; sdi != subdirs.end(); ++sdi)
  58. {
  59. if (!(*sdi)->Configured)
  60. {
  61. this->Makefile->ConfigureSubDirectory(*sdi);
  62. }
  63. }
  64. this->SetupPathConversions();
  65. // Check whether relative paths should be used for optionally
  66. // relative paths.
  67. this->UseRelativePaths = this->Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");
  68. this->Configured = true;
  69. }
  70. void cmLocalGenerator::SetupPathConversions()
  71. {
  72. // Setup the current output directory components for use by
  73. // Convert
  74. std::string outdir;
  75. outdir =
  76. cmSystemTools::CollapseFullPath(this->Makefile->GetHomeDirectory());
  77. cmSystemTools::SplitPath(outdir.c_str(), this->HomeDirectoryComponents);
  78. outdir =
  79. cmSystemTools::CollapseFullPath(this->Makefile->GetStartDirectory());
  80. cmSystemTools::SplitPath(outdir.c_str(), this->StartDirectoryComponents);
  81. outdir =
  82. cmSystemTools::CollapseFullPath(this->Makefile->GetHomeOutputDirectory());
  83. cmSystemTools::SplitPath(outdir.c_str(), this->HomeOutputDirectoryComponents);
  84. outdir =
  85. cmSystemTools::CollapseFullPath(this->Makefile->GetStartOutputDirectory());
  86. cmSystemTools::SplitPath(outdir.c_str(), this->StartOutputDirectoryComponents);
  87. }
  88. void cmLocalGenerator::SetGlobalGenerator(cmGlobalGenerator *gg)
  89. {
  90. this->GlobalGenerator = gg;
  91. // setup the home directories
  92. this->Makefile->SetHomeDirectory(
  93. gg->GetCMakeInstance()->GetHomeDirectory());
  94. this->Makefile->SetHomeOutputDirectory(
  95. gg->GetCMakeInstance()->GetHomeOutputDirectory());
  96. }
  97. void cmLocalGenerator::ConfigureFinalPass()
  98. {
  99. this->Makefile->ConfigureFinalPass();
  100. }
  101. void cmLocalGenerator::GenerateTestFiles()
  102. {
  103. if ( !this->Makefile->IsOn("CMAKE_TESTING_ENABLED") )
  104. {
  105. return;
  106. }
  107. std::string file = this->Makefile->GetStartOutputDirectory();
  108. file += "/";
  109. if ( this->Makefile->IsSet("CTEST_NEW_FORMAT") )
  110. {
  111. file += "CTestTestfile.cmake";
  112. }
  113. else
  114. {
  115. file += "DartTestfile.txt";
  116. }
  117. cmGeneratedFileStream fout(file.c_str());
  118. fout.SetCopyIfDifferent(true);
  119. fout << "# CMake generated Testfile for " << std::endl
  120. << "# Source directory: " << this->Makefile->GetStartDirectory() << std::endl
  121. << "# Build directory: " << this->Makefile->GetStartOutputDirectory() << std::endl
  122. << "# " << std::endl
  123. << "# This file replicates the SUBDIRS() and ADD_TEST() commands from the source" << std::endl
  124. << "# tree CMakeLists.txt file, skipping any SUBDIRS() or ADD_TEST() commands" << std::endl
  125. << "# that are excluded by CMake control structures, i.e. IF() commands." << std::endl
  126. << "#" << std::endl
  127. << "# The next line is critical for Dart to work" << std::endl
  128. << "# Duh :-)" << std::endl << std::endl;
  129. const char* testIncludeFile = this->Makefile->GetProperty("TEST_INCLUDE_FILE");
  130. if ( testIncludeFile )
  131. {
  132. fout << "INCLUDE(\"" << testIncludeFile << "\")" << std::endl;
  133. }
  134. const std::vector<cmTest*> *tests = this->Makefile->GetTests();
  135. std::vector<cmTest*>::const_iterator it;
  136. for ( it = tests->begin(); it != tests->end(); ++ it )
  137. {
  138. cmTest* test = *it;
  139. fout << "ADD_TEST(";
  140. fout << test->GetName() << " \"" << test->GetCommand() << "\"";
  141. std::vector<cmStdString>::const_iterator argit;
  142. for (argit = test->GetArguments().begin();
  143. argit != test->GetArguments().end(); ++argit)
  144. {
  145. // Just double-quote all arguments so they are re-parsed
  146. // correctly by the test system.
  147. fout << " \"";
  148. for(std::string::const_iterator c = argit->begin(); c != argit->end(); ++c)
  149. {
  150. // Escape quotes within arguments. We should escape
  151. // backslashes too but we cannot because it makes the result
  152. // inconsistent with previous behavior of this command.
  153. if((*c == '"'))
  154. {
  155. fout << '\\';
  156. }
  157. fout << *c;
  158. }
  159. fout << "\"";
  160. }
  161. fout << ")" << std::endl;
  162. std::map<cmStdString,cmStdString>::const_iterator pit;
  163. const std::map<cmStdString,cmStdString>* mpit = &test->GetProperties();
  164. if ( mpit->size() )
  165. {
  166. fout << "SET_TESTS_PROPERTIES(" << test->GetName() << " PROPERTIES ";
  167. for ( pit = mpit->begin(); pit != mpit->end(); ++ pit )
  168. {
  169. fout << " " << pit->first.c_str() << " \"";
  170. const char* value = pit->second.c_str();
  171. for ( ; *value; ++ value )
  172. {
  173. switch ( *value )
  174. {
  175. case '\\':
  176. case '"':
  177. case ' ':
  178. case '#':
  179. case '(':
  180. case ')':
  181. case '$':
  182. case '^':
  183. fout << "\\" << *value;
  184. break;
  185. case '\t':
  186. fout << "\\t";
  187. break;
  188. case '\n':
  189. fout << "\\n";
  190. break;
  191. case '\r':
  192. fout << "\\r";
  193. break;
  194. default:
  195. fout << *value;
  196. }
  197. }
  198. fout << "\"";
  199. }
  200. fout << ")" << std::endl;
  201. }
  202. }
  203. if ( this->Children.size())
  204. {
  205. fout << "SUBDIRS(";
  206. size_t i;
  207. std::string outDir = this->Makefile->GetStartOutputDirectory();
  208. outDir += "/";
  209. for(i = 0; i < this->Children.size(); ++i)
  210. {
  211. std::string binP = this->Children[i]->GetMakefile()->GetStartOutputDirectory();
  212. cmSystemTools::ReplaceString(binP, outDir.c_str(), "");
  213. if ( i > 0 )
  214. {
  215. fout << " ";
  216. }
  217. fout << binP.c_str();
  218. }
  219. fout << ")" << std::endl << std::endl;;
  220. }
  221. }
  222. //----------------------------------------------------------------------------
  223. void cmLocalGenerator::GenerateInstallRules()
  224. {
  225. // Compute the install prefix.
  226. const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
  227. #if defined(_WIN32) && !defined(__CYGWIN__)
  228. std::string prefix_win32;
  229. if(!prefix)
  230. {
  231. if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32))
  232. {
  233. prefix_win32 = "C:";
  234. }
  235. const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
  236. if(project_name && project_name[0])
  237. {
  238. prefix_win32 += "/Program Files/";
  239. prefix_win32 += project_name;
  240. }
  241. else
  242. {
  243. prefix_win32 += "/InstalledCMakeProject";
  244. }
  245. prefix = prefix_win32.c_str();
  246. }
  247. #else
  248. if (!prefix)
  249. {
  250. prefix = "/usr/local";
  251. }
  252. #endif
  253. // Compute the set of configurations.
  254. std::vector<std::string> configurationTypes;
  255. if(const char* types = this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  256. {
  257. cmSystemTools::ExpandListArgument(types, configurationTypes);
  258. }
  259. const char* config = 0;
  260. if(configurationTypes.empty())
  261. {
  262. config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  263. }
  264. // Create the install script file.
  265. std::string file = this->Makefile->GetStartOutputDirectory();
  266. std::string homedir = this->Makefile->GetHomeOutputDirectory();
  267. std::string currdir = this->Makefile->GetCurrentOutputDirectory();
  268. cmSystemTools::ConvertToUnixSlashes(file);
  269. cmSystemTools::ConvertToUnixSlashes(homedir);
  270. cmSystemTools::ConvertToUnixSlashes(currdir);
  271. int toplevel_install = 0;
  272. if ( currdir == homedir )
  273. {
  274. toplevel_install = 1;
  275. }
  276. file += "/cmake_install.cmake";
  277. cmGeneratedFileStream fout(file.c_str());
  278. fout.SetCopyIfDifferent(true);
  279. // Write the header.
  280. fout << "# Install script for directory: "
  281. << this->Makefile->GetCurrentDirectory() << std::endl << std::endl;
  282. fout << "# Set the install prefix" << std::endl
  283. << "IF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  284. << " SET(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
  285. << "ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  286. << "STRING(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\")" << std::endl
  287. << std::endl;
  288. // Write support code for generating per-configuration install rules.
  289. fout <<
  290. "# Set the install configuration name.\n"
  291. "IF(NOT CMAKE_INSTALL_CONFIG_NAME)\n"
  292. " IF(BUILD_TYPE)\n"
  293. " STRING(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
  294. " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
  295. " ELSE(BUILD_TYPE)\n"
  296. " SET(CMAKE_INSTALL_CONFIG_NAME Release)\n"
  297. " ENDIF(BUILD_TYPE)\n"
  298. " MESSAGE(STATUS \"Install configuration: \\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
  299. "ENDIF(NOT CMAKE_INSTALL_CONFIG_NAME)\n"
  300. "\n";
  301. // Write support code for dealing with component-specific installs.
  302. fout <<
  303. "# Set the component getting installed.\n"
  304. "IF(NOT CMAKE_INSTALL_COMPONENT)\n"
  305. " IF(COMPONENT)\n"
  306. " MESSAGE(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
  307. " SET(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
  308. " ELSE(COMPONENT)\n"
  309. " SET(CMAKE_INSTALL_COMPONENT)\n"
  310. " ENDIF(COMPONENT)\n"
  311. "ENDIF(NOT CMAKE_INSTALL_COMPONENT)\n"
  312. "\n";
  313. // Ask each install generator to write its code.
  314. std::vector<cmInstallGenerator*> const& installers =
  315. this->Makefile->GetInstallGenerators();
  316. for(std::vector<cmInstallGenerator*>::const_iterator gi = installers.begin();
  317. gi != installers.end(); ++gi)
  318. {
  319. (*gi)->Generate(fout, config, configurationTypes);
  320. }
  321. // Write rules from old-style specification stored in targets.
  322. this->GenerateTargetInstallRules(fout, config, configurationTypes);
  323. // Include install scripts from subdirectories.
  324. if ( this->Children.size())
  325. {
  326. std::vector<cmLocalGenerator*>::const_iterator i = this->Children.begin();
  327. for(; i != this->Children.end(); ++i)
  328. {
  329. std::string odir = (*i)->GetMakefile()->GetStartOutputDirectory();
  330. cmSystemTools::ConvertToUnixSlashes(odir);
  331. fout << "INCLUDE(\"" << odir.c_str()
  332. << "/cmake_install.cmake\")" << std::endl;
  333. }
  334. fout << std::endl;;
  335. }
  336. // Record the install manifest.
  337. if ( toplevel_install )
  338. {
  339. fout <<
  340. "IF(CMAKE_INSTALL_COMPONENT)\n"
  341. " SET(CMAKE_INSTALL_MANIFEST \"install_manifest_"
  342. "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
  343. "ELSE(CMAKE_INSTALL_COMPONENT)\n"
  344. " SET(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
  345. "ENDIF(CMAKE_INSTALL_COMPONENT)\n";
  346. fout
  347. << "FILE(WRITE \""
  348. << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
  349. << "\"\")" << std::endl;
  350. fout
  351. << "FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES})" << std::endl
  352. << " FILE(APPEND \""
  353. << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
  354. << "\"${file}\\n\")" << std::endl
  355. << "ENDFOREACH(file)" << std::endl;
  356. }
  357. }
  358. //----------------------------------------------------------------------------
  359. void cmLocalGenerator::GenerateTargetManifest(cmTargetManifest& manifest)
  360. {
  361. // Collect the set of configuration types.
  362. std::vector<std::string> configNames;
  363. if(const char* configurationTypes =
  364. this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  365. {
  366. cmSystemTools::ExpandListArgument(configurationTypes, configNames);
  367. }
  368. else if(const char* buildType =
  369. this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
  370. {
  371. if(*buildType)
  372. {
  373. configNames.push_back(buildType);
  374. }
  375. }
  376. // Add our targets to the manifest for each configuration.
  377. cmTargets& targets = this->Makefile->GetTargets();
  378. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  379. {
  380. cmTarget& target = t->second;
  381. cmTarget::TargetType type = target.GetType();
  382. if(type == cmTarget::STATIC_LIBRARY ||
  383. type == cmTarget::SHARED_LIBRARY ||
  384. type == cmTarget::MODULE_LIBRARY ||
  385. type == cmTarget::EXECUTABLE)
  386. {
  387. if(configNames.empty())
  388. {
  389. manifest[""].insert(target.GetFullPath(0, false));
  390. if(type == cmTarget::SHARED_LIBRARY &&
  391. this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  392. {
  393. manifest[""].insert(target.GetFullPath(0, true));
  394. }
  395. }
  396. else
  397. {
  398. for(std::vector<std::string>::iterator ci = configNames.begin();
  399. ci != configNames.end(); ++ci)
  400. {
  401. const char* config = ci->c_str();
  402. manifest[config].insert(target.GetFullPath(config, false));
  403. if(type == cmTarget::SHARED_LIBRARY &&
  404. this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  405. {
  406. manifest[config].insert(target.GetFullPath(config, true));
  407. }
  408. }
  409. }
  410. }
  411. }
  412. }
  413. void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
  414. const char* lang,
  415. cmSourceFile& source,
  416. cmTarget& )
  417. {
  418. std::string objectFile = this->Convert(ofname,START_OUTPUT,SHELL);
  419. std::string sourceFile =
  420. this->Convert(source.GetFullPath().c_str(),START_OUTPUT,SHELL,true);
  421. std::string varString = "CMAKE_";
  422. varString += lang;
  423. varString += "_COMPILE_OBJECT";
  424. std::vector<std::string> rules;
  425. rules.push_back(this->Makefile->GetRequiredDefinition(varString.c_str()));
  426. varString = "CMAKE_";
  427. varString += lang;
  428. varString += "_FLAGS";
  429. std::string flags;
  430. flags += this->Makefile->GetSafeDefinition(varString.c_str());
  431. flags += " ";
  432. flags += this->GetIncludeFlags(lang);
  433. std::vector<std::string> commands;
  434. cmSystemTools::ExpandList(rules, commands);
  435. cmLocalGenerator::RuleVariables vars;
  436. vars.Language = lang;
  437. vars.Source = sourceFile.c_str();
  438. vars.Object = objectFile.c_str();
  439. vars.Flags = flags.c_str();
  440. for(std::vector<std::string>::iterator i = commands.begin();
  441. i != commands.end(); ++i)
  442. {
  443. this->ExpandRuleVariables(*i, vars);
  444. }
  445. std::vector<std::string> sourceAndDeps;
  446. sourceAndDeps.push_back(sourceFile);
  447. if(commands.size() > 1)
  448. {
  449. cmSystemTools::Error("Currently custom rules can only have one command sorry ");
  450. }
  451. // Check for extra object-file dependencies.
  452. std::vector<std::string> depends;
  453. const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
  454. if(additionalDeps)
  455. {
  456. cmSystemTools::ExpandListArgument(additionalDeps, depends);
  457. for(std::vector<std::string>::iterator i = depends.begin();
  458. i != depends.end(); ++i)
  459. {
  460. sourceAndDeps.push_back(this->Convert(i->c_str(),START_OUTPUT,SHELL));
  461. }
  462. }
  463. #if 0
  464. std::string command;
  465. std::string args;
  466. cmSystemTools::SplitProgramFromArgs(commands[0].c_str(), command, args);
  467. std::vector<std::string> argsv;
  468. argsv.push_back(args);
  469. this->Makefile->AddCustomCommandToOutput(ofname,
  470. command.c_str(),
  471. argsv,
  472. source.GetFullPath().c_str(),
  473. sourceAndDeps,
  474. "build from source");
  475. #endif
  476. }
  477. void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
  478. {
  479. cmStdString objs;
  480. std::vector<std::string> objVector;
  481. // Add all the sources outputs to the depends of the target
  482. std::vector<cmSourceFile*>& classes = target.GetSourceFiles();
  483. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  484. i != classes.end(); ++i)
  485. {
  486. if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  487. !(*i)->GetCustomCommand())
  488. {
  489. std::string outExt =
  490. this->GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  491. (*i)->GetSourceExtension().c_str());
  492. if(outExt.size() && !(*i)->GetPropertyAsBool("EXTERNAL_OBJECT") )
  493. {
  494. std::string ofname = this->Makefile->GetCurrentOutputDirectory();
  495. ofname += "/";
  496. ofname += (*i)->GetSourceName() + outExt;
  497. objVector.push_back(ofname);
  498. this->AddCustomCommandToCreateObject(ofname.c_str(), llang, *(*i), target);
  499. objs += this->Convert(ofname.c_str(),START_OUTPUT,MAKEFILE);
  500. objs += " ";
  501. }
  502. }
  503. }
  504. std::string createRule = "CMAKE_";
  505. createRule += llang;
  506. createRule += target.GetCreateRuleVariable();
  507. std::string targetName = target.GetFullName();
  508. // Executable :
  509. // Shared Library:
  510. // Static Library:
  511. // Shared Module:
  512. std::string linkLibs; // should be set
  513. std::string flags; // should be set
  514. std::string linkFlags; // should be set
  515. this->GetTargetFlags(linkLibs, flags, linkFlags, target);
  516. std::string rule = this->Makefile->GetRequiredDefinition(createRule.c_str());
  517. cmLocalGenerator::RuleVariables vars;
  518. vars.Language = llang;
  519. vars.Objects = objs.c_str();
  520. vars.Target = targetName.c_str();
  521. vars.LinkLibraries = linkLibs.c_str();
  522. vars.Flags = flags.c_str();
  523. vars.LinkFlags = linkFlags.c_str();
  524. this->ExpandRuleVariables(rule, vars);
  525. }
  526. void cmLocalGenerator::CreateCustomTargetsAndCommands(std::set<cmStdString> const& lang)
  527. {
  528. cmTargets &tgts = this->Makefile->GetTargets();
  529. for(cmTargets::iterator l = tgts.begin();
  530. l != tgts.end(); l++)
  531. {
  532. cmTarget& target = l->second;
  533. switch(target.GetType())
  534. {
  535. case cmTarget::STATIC_LIBRARY:
  536. case cmTarget::SHARED_LIBRARY:
  537. case cmTarget::MODULE_LIBRARY:
  538. case cmTarget::EXECUTABLE:
  539. {
  540. const char* llang = target.GetLinkerLanguage(this->GetGlobalGenerator());
  541. if(!llang)
  542. {
  543. cmSystemTools::Error("CMake can not determine linker language for target:",
  544. target.GetName());
  545. return;
  546. }
  547. // if the language is not in the set lang then create custom
  548. // commands to build the target
  549. if(lang.count(llang) == 0)
  550. {
  551. this->AddBuildTargetRule(llang, target);
  552. }
  553. }
  554. break;
  555. case cmTarget::UTILITY:
  556. case cmTarget::GLOBAL_TARGET:
  557. case cmTarget::INSTALL_FILES:
  558. case cmTarget::INSTALL_PROGRAMS:
  559. case cmTarget::INSTALL_DIRECTORY:
  560. break;
  561. }
  562. }
  563. }
  564. // List of variables that are replaced when
  565. // rules are expanced. These variables are
  566. // replaced in the form <var> with GetSafeDefinition(var).
  567. // ${LANG} is replaced in the variable first with all enabled
  568. // languages.
  569. static const char* ruleReplaceVars[] =
  570. {
  571. "CMAKE_${LANG}_COMPILER",
  572. "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
  573. "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
  574. "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
  575. "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
  576. "CMAKE_${LANG}_LINK_FLAGS",
  577. "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
  578. "CMAKE_${LANG}_ARCHIVE",
  579. "CMAKE_AR",
  580. "CMAKE_CURRENT_SOURCE_DIR",
  581. "CMAKE_CURRENT_BINARY_DIR",
  582. "CMAKE_RANLIB",
  583. 0
  584. };
  585. std::string
  586. cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
  587. const RuleVariables& replaceValues)
  588. {
  589. if(replaceValues.LinkFlags)
  590. {
  591. if(variable == "LINK_FLAGS")
  592. {
  593. return replaceValues.LinkFlags;
  594. }
  595. }
  596. if(replaceValues.Flags)
  597. {
  598. if(variable == "FLAGS")
  599. {
  600. return replaceValues.Flags;
  601. }
  602. }
  603. if(replaceValues.Source)
  604. {
  605. if(variable == "SOURCE")
  606. {
  607. return replaceValues.Source;
  608. }
  609. }
  610. if(replaceValues.Object)
  611. {
  612. if(variable == "OBJECT")
  613. {
  614. return replaceValues.Object;
  615. }
  616. }
  617. if(replaceValues.Objects)
  618. {
  619. if(variable == "OBJECTS")
  620. {
  621. return replaceValues.Objects;
  622. }
  623. }
  624. if(replaceValues.ObjectsQuoted)
  625. {
  626. if(variable == "OBJECTS_QUOTED")
  627. {
  628. return replaceValues.ObjectsQuoted;
  629. }
  630. }
  631. if(replaceValues.Target)
  632. {
  633. if(variable == "TARGET_QUOTED")
  634. {
  635. std::string targetQuoted = replaceValues.Target;
  636. if(targetQuoted.size() && targetQuoted[0] != '\"')
  637. {
  638. targetQuoted = '\"';
  639. targetQuoted += replaceValues.Target;
  640. targetQuoted += '\"';
  641. return targetQuoted;
  642. }
  643. }
  644. if(variable == "LANGUAGE_COMPILE_FLAGS")
  645. {
  646. return replaceValues.LanguageCompileFlags;
  647. }
  648. if(variable == "TARGET")
  649. {
  650. return replaceValues.Target;
  651. }
  652. if(variable == "TARGET_IMPLIB")
  653. {
  654. return this->TargetImplib;
  655. }
  656. if(variable == "TARGET_BASE")
  657. {
  658. // Strip the last extension off the target name.
  659. std::string targetBase = replaceValues.Target;
  660. std::string::size_type pos = targetBase.rfind(".");
  661. if(pos != targetBase.npos)
  662. {
  663. return targetBase.substr(0, pos);
  664. }
  665. else
  666. {
  667. return targetBase;
  668. }
  669. }
  670. }
  671. if(replaceValues.TargetSOName)
  672. {
  673. if(variable == "TARGET_SONAME")
  674. {
  675. if(replaceValues.Language)
  676. {
  677. std::string name = "CMAKE_SHARED_LIBRARY_SONAME_";
  678. name += replaceValues.Language;
  679. name += "_FLAG";
  680. if(this->Makefile->GetDefinition(name.c_str()))
  681. {
  682. return replaceValues.TargetSOName;
  683. }
  684. }
  685. return "";
  686. }
  687. }
  688. if(replaceValues.TargetInstallNameDir)
  689. {
  690. if(variable == "TARGET_INSTALLNAME_DIR")
  691. {
  692. return replaceValues.TargetInstallNameDir;
  693. }
  694. }
  695. if(replaceValues.LinkLibraries)
  696. {
  697. if(variable == "LINK_LIBRARIES")
  698. {
  699. return replaceValues.LinkLibraries;
  700. }
  701. }
  702. std::vector<std::string> enabledLanguages;
  703. this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
  704. // loop over language specific replace variables
  705. int pos = 0;
  706. while(ruleReplaceVars[pos])
  707. {
  708. for(std::vector<std::string>::iterator i = enabledLanguages.begin();
  709. i != enabledLanguages.end(); ++i)
  710. {
  711. const char* lang = i->c_str();
  712. std::string actualReplace = ruleReplaceVars[pos];
  713. // If this is the compiler then look for the extra variable
  714. // _COMPILER_ARG1 which must be the first argument to the compiler
  715. const char* compilerArg1 = 0;
  716. if(actualReplace == "CMAKE_${LANG}_COMPILER")
  717. {
  718. std::string arg1 = actualReplace + "_ARG1";
  719. cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
  720. compilerArg1 = this->Makefile->GetDefinition(arg1.c_str());
  721. }
  722. if(actualReplace.find("${LANG}") != actualReplace.npos)
  723. {
  724. cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
  725. }
  726. if(actualReplace == variable)
  727. {
  728. std::string replace = this->Makefile->GetSafeDefinition(variable.c_str());
  729. // if the variable is not a FLAG then treat it like a path
  730. if(variable.find("_FLAG") == variable.npos)
  731. {
  732. std::string ret = this->ConvertToOutputForExisting(replace.c_str());
  733. // if there is a required first argument to the compiler add it to the compiler string
  734. if(compilerArg1)
  735. {
  736. ret += " ";
  737. ret += compilerArg1;
  738. }
  739. return ret;
  740. }
  741. return replace;
  742. }
  743. }
  744. pos++;
  745. }
  746. return variable;
  747. }
  748. void
  749. cmLocalGenerator::ExpandRuleVariables(std::string& s,
  750. const RuleVariables& replaceValues)
  751. {
  752. std::vector<std::string> enabledLanguages;
  753. this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
  754. std::string::size_type start = s.find('<');
  755. // no variables to expand
  756. if(start == s.npos)
  757. {
  758. return;
  759. }
  760. std::string::size_type pos = 0;
  761. std::string expandedInput;
  762. while(start != s.npos && start < s.size()-2)
  763. {
  764. std::string::size_type end = s.find('>', start);
  765. // if we find a < with no > we are done
  766. if(end == s.npos)
  767. {
  768. return;
  769. }
  770. char c = s[start+1];
  771. // if the next char after the < is not A-Za-z then
  772. // skip it and try to find the next < in the string
  773. if(!isalpha(c))
  774. {
  775. start = s.find('<', start+1);
  776. }
  777. else
  778. {
  779. // extract the var
  780. std::string var = s.substr(start+1, end - start-1);
  781. std::string replace = this->ExpandRuleVariable(var,
  782. replaceValues);
  783. expandedInput += s.substr(pos, start-pos);
  784. expandedInput += replace;
  785. // move to next one
  786. start = s.find('<', start+var.size()+2);
  787. pos = end+1;
  788. }
  789. }
  790. // add the rest of the input
  791. expandedInput += s.substr(pos, s.size()-pos);
  792. s = expandedInput;
  793. }
  794. std::string
  795. cmLocalGenerator::ConvertToOutputForExisting(const char* p)
  796. {
  797. std::string ret = this->Convert(p, START_OUTPUT, SHELL, true);
  798. // if there are spaces in the path, then get the short path version
  799. // if there is one
  800. if(ret.find(' ') != std::string::npos)
  801. {
  802. if(cmSystemTools::FileExists(p))
  803. {
  804. if(!cmSystemTools::GetShortPath(ret.c_str(), ret))
  805. {
  806. ret = this->Convert(p,START_OUTPUT,MAKEFILE,true);
  807. }
  808. }
  809. }
  810. return ret;
  811. }
  812. const char* cmLocalGenerator::GetIncludeFlags(const char* lang)
  813. {
  814. if(!lang)
  815. {
  816. return "";
  817. }
  818. if(this->LanguageToIncludeFlags.count(lang))
  819. {
  820. return this->LanguageToIncludeFlags[lang].c_str();
  821. }
  822. cmOStringStream includeFlags;
  823. std::vector<std::string> includes;
  824. this->GetIncludeDirectories(includes);
  825. std::vector<std::string>::iterator i;
  826. std::string flagVar = "CMAKE_INCLUDE_FLAG_";
  827. flagVar += lang;
  828. const char* includeFlag = this->Makefile->GetDefinition(flagVar.c_str());
  829. flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
  830. flagVar += lang;
  831. const char* sep = this->Makefile->GetDefinition(flagVar.c_str());
  832. bool quotePaths = false;
  833. if(this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
  834. {
  835. quotePaths = true;
  836. }
  837. bool repeatFlag = true; // should the include flag be repeated like ie. -IA -IB
  838. if(!sep)
  839. {
  840. sep = " ";
  841. }
  842. else
  843. {
  844. // if there is a separator then the flag is not repeated but is only given once
  845. // i.e. -classpath a:b:c
  846. repeatFlag = false;
  847. }
  848. bool flagUsed = false;
  849. std::set<cmStdString> emitted;
  850. for(i = includes.begin(); i != includes.end(); ++i)
  851. {
  852. #ifdef __APPLE__
  853. if(cmSystemTools::IsPathToFramework(i->c_str()))
  854. {
  855. std::string frameworkDir = *i;
  856. frameworkDir += "/../";
  857. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  858. if(emitted.insert(frameworkDir).second)
  859. {
  860. includeFlags << "-F" << this->ConvertToOutputForExisting(frameworkDir.c_str()) << " ";
  861. }
  862. continue;
  863. }
  864. #endif
  865. std::string include = *i;
  866. if(!flagUsed || repeatFlag)
  867. {
  868. includeFlags << includeFlag;
  869. flagUsed = true;
  870. }
  871. std::string includePath = this->ConvertToOutputForExisting(i->c_str());
  872. if(quotePaths && includePath.size() && includePath[0] != '\"')
  873. {
  874. includeFlags << "\"";
  875. }
  876. includeFlags << includePath;
  877. if(quotePaths && includePath.size() && includePath[0] != '\"')
  878. {
  879. includeFlags << "\"";
  880. }
  881. includeFlags << sep;
  882. }
  883. std::string flags = includeFlags.str();
  884. // remove trailing separators
  885. if((sep[0] != ' ') && flags[flags.size()-1] == sep[0])
  886. {
  887. flags[flags.size()-1] = ' ';
  888. }
  889. flags += this->Makefile->GetDefineFlags();
  890. this->LanguageToIncludeFlags[lang] = flags;
  891. // Use this temorary variable for the return value to work-around a
  892. // bogus GCC 2.95 warning.
  893. const char* ret = this->LanguageToIncludeFlags[lang].c_str();
  894. return ret;
  895. }
  896. //----------------------------------------------------------------------------
  897. void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs)
  898. {
  899. // Need to decide whether to automatically include the source and
  900. // binary directories at the beginning of the include path.
  901. bool includeSourceDir = false;
  902. bool includeBinaryDir = false;
  903. // When automatic include directories are requested for a build then
  904. // include the source and binary directories at the beginning of the
  905. // include path to approximate include file behavior for an
  906. // in-source build. This does not account for the case of a source
  907. // file in a subdirectory of the current source directory but we
  908. // cannot fix this because not all native build tools support
  909. // per-source-file include paths.
  910. if(this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
  911. {
  912. includeSourceDir = true;
  913. includeBinaryDir = true;
  914. }
  915. // CMake versions below 2.0 would add the source tree to the -I path
  916. // automatically. Preserve compatibility.
  917. const char* versionValue =
  918. this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  919. int major = 0;
  920. int minor = 0;
  921. if(versionValue && sscanf(versionValue, "%d.%d", &major, &minor) != 2)
  922. {
  923. versionValue = 0;
  924. }
  925. if(versionValue && major < 2)
  926. {
  927. includeSourceDir = true;
  928. }
  929. // Hack for VTK 4.0 - 4.4 which depend on the old behavior but do
  930. // not set the backwards compatibility level automatically.
  931. const char* vtkSourceDir =
  932. this->Makefile->GetDefinition("VTK_SOURCE_DIR");
  933. if(vtkSourceDir)
  934. {
  935. const char* vtk_major = this->Makefile->GetDefinition("VTK_MAJOR_VERSION");
  936. const char* vtk_minor = this->Makefile->GetDefinition("VTK_MINOR_VERSION");
  937. vtk_major = vtk_major? vtk_major : "4";
  938. vtk_minor = vtk_minor? vtk_minor : "4";
  939. int vmajor = 0;
  940. int vminor = 0;
  941. if(sscanf(vtk_major, "%d", &vmajor) && sscanf(vtk_minor, "%d", &vminor) &&
  942. vmajor == 4 && vminor <= 4)
  943. {
  944. includeSourceDir = true;
  945. }
  946. }
  947. // Do not repeat an include path.
  948. std::set<cmStdString> emitted;
  949. // Store the automatic include paths.
  950. if(includeBinaryDir)
  951. {
  952. dirs.push_back(this->Makefile->GetStartOutputDirectory());
  953. emitted.insert(this->Makefile->GetStartOutputDirectory());
  954. }
  955. if(includeSourceDir)
  956. {
  957. if(emitted.find(this->Makefile->GetStartDirectory()) == emitted.end())
  958. {
  959. dirs.push_back(this->Makefile->GetStartDirectory());
  960. emitted.insert(this->Makefile->GetStartDirectory());
  961. }
  962. }
  963. // Do not explicitly add the standard include path "/usr/include".
  964. // This can cause problems with certain standard library
  965. // implementations because the wrong headers may be found first.
  966. emitted.insert("/usr/include");
  967. if(const char* implicitIncludes =
  968. this->Makefile->GetDefinition("CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES"))
  969. {
  970. std::vector<std::string> implicitIncludeVec;
  971. cmSystemTools::ExpandListArgument(implicitIncludes, implicitIncludeVec);
  972. for(unsigned int k = 0; k < implicitIncludeVec.size(); ++k)
  973. {
  974. emitted.insert(implicitIncludeVec[k]);
  975. }
  976. }
  977. // Construct the ordered list.
  978. std::vector<std::string>& includes = this->Makefile->GetIncludeDirectories();
  979. for(std::vector<std::string>::iterator i = includes.begin();
  980. i != includes.end(); ++i)
  981. {
  982. if(emitted.find(*i) == emitted.end())
  983. {
  984. dirs.push_back(*i);
  985. emitted.insert(*i);
  986. }
  987. }
  988. }
  989. void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
  990. std::string& flags,
  991. std::string& linkFlags,
  992. cmTarget& target)
  993. {
  994. std::string buildType = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  995. buildType = cmSystemTools::UpperCase(buildType);
  996. const char* libraryLinkVariable = "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
  997. switch(target.GetType())
  998. {
  999. case cmTarget::STATIC_LIBRARY:
  1000. {
  1001. const char* targetLinkFlags = target.GetProperty("STATIC_LIBRARY_FLAGS");
  1002. if(targetLinkFlags)
  1003. {
  1004. linkFlags += targetLinkFlags;
  1005. linkFlags += " ";
  1006. }
  1007. }
  1008. break;
  1009. case cmTarget::MODULE_LIBRARY:
  1010. libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
  1011. case cmTarget::SHARED_LIBRARY:
  1012. {
  1013. linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
  1014. linkFlags += " ";
  1015. if(buildType.size())
  1016. {
  1017. std::string build = libraryLinkVariable;
  1018. build += "_";
  1019. build += buildType;
  1020. linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
  1021. linkFlags += " ";
  1022. }
  1023. if(this->Makefile->IsOn("WIN32") && !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
  1024. {
  1025. const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
  1026. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1027. i != sources.end(); ++i)
  1028. {
  1029. if((*i)->GetSourceExtension() == "def")
  1030. {
  1031. linkFlags += this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1032. linkFlags += this->Convert((*i)->GetFullPath().c_str(),START_OUTPUT,MAKEFILE);
  1033. linkFlags += " ";
  1034. }
  1035. }
  1036. }
  1037. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1038. if(targetLinkFlags)
  1039. {
  1040. linkFlags += targetLinkFlags;
  1041. linkFlags += " ";
  1042. std::string configLinkFlags = targetLinkFlags;
  1043. configLinkFlags += buildType;
  1044. targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
  1045. if(targetLinkFlags)
  1046. {
  1047. linkFlags += targetLinkFlags;
  1048. linkFlags += " ";
  1049. }
  1050. }
  1051. cmOStringStream linklibsStr;
  1052. this->OutputLinkLibraries(linklibsStr, target, false);
  1053. linkLibs = linklibsStr.str();
  1054. }
  1055. break;
  1056. case cmTarget::EXECUTABLE:
  1057. {
  1058. linkFlags += this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1059. linkFlags += " ";
  1060. if(buildType.size())
  1061. {
  1062. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1063. build += buildType;
  1064. linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
  1065. linkFlags += " ";
  1066. }
  1067. const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator());
  1068. if(!linkLanguage)
  1069. {
  1070. cmSystemTools::Error("CMake can not determine linker language for target:",
  1071. target.GetName());
  1072. return;
  1073. }
  1074. std::string langVar = "CMAKE_";
  1075. langVar += linkLanguage;
  1076. std::string flagsVar = langVar + "_FLAGS";
  1077. std::string sharedFlagsVar = "CMAKE_SHARED_LIBRARY_";
  1078. sharedFlagsVar += linkLanguage;
  1079. sharedFlagsVar += "_FLAGS";
  1080. flags += this->Makefile->GetSafeDefinition(flagsVar.c_str());
  1081. flags += " ";
  1082. flags += this->Makefile->GetSafeDefinition(sharedFlagsVar.c_str());
  1083. flags += " ";
  1084. cmOStringStream linklibs;
  1085. this->OutputLinkLibraries(linklibs, target, false);
  1086. linkLibs = linklibs.str();
  1087. if(cmSystemTools::IsOn(this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1088. {
  1089. std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_") + linkLanguage
  1090. + std::string("_FLAGS");
  1091. linkFlags += this->Makefile->GetSafeDefinition(sFlagVar.c_str());
  1092. linkFlags += " ";
  1093. }
  1094. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  1095. {
  1096. linkFlags += this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1097. linkFlags += " ";
  1098. }
  1099. else
  1100. {
  1101. linkFlags += this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1102. linkFlags += " ";
  1103. }
  1104. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1105. if(targetLinkFlags)
  1106. {
  1107. linkFlags += targetLinkFlags;
  1108. linkFlags += " ";
  1109. std::string configLinkFlags = targetLinkFlags;
  1110. configLinkFlags += buildType;
  1111. targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
  1112. if(targetLinkFlags)
  1113. {
  1114. linkFlags += targetLinkFlags;
  1115. linkFlags += " ";
  1116. }
  1117. }
  1118. }
  1119. break;
  1120. case cmTarget::UTILITY:
  1121. case cmTarget::GLOBAL_TARGET:
  1122. case cmTarget::INSTALL_FILES:
  1123. case cmTarget::INSTALL_PROGRAMS:
  1124. case cmTarget::INSTALL_DIRECTORY:
  1125. break;
  1126. }
  1127. }
  1128. /**
  1129. * Output the linking rules on a command line. For executables,
  1130. * targetLibrary should be a NULL pointer. For libraries, it should point
  1131. * to the name of the library. This will not link a library against itself.
  1132. */
  1133. void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout,
  1134. cmTarget& tgt,
  1135. bool relink)
  1136. {
  1137. // Try to emit each search path once
  1138. std::set<cmStdString> emitted;
  1139. // Embed runtime search paths if possible and if required.
  1140. bool outputRuntime = true;
  1141. std::string runtimeFlag;
  1142. std::string runtimeSep;
  1143. const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  1144. const char* linkLanguage = tgt.GetLinkerLanguage(this->GetGlobalGenerator());
  1145. if(!linkLanguage)
  1146. {
  1147. cmSystemTools::
  1148. Error("CMake can not determine linker language for target:",
  1149. tgt.GetName());
  1150. return;
  1151. }
  1152. std::string runTimeFlagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1153. runTimeFlagVar += linkLanguage;
  1154. runTimeFlagVar += "_FLAG";
  1155. std::string runTimeFlagSepVar = runTimeFlagVar + "_SEP";
  1156. runtimeFlag = this->Makefile->GetSafeDefinition(runTimeFlagVar.c_str());
  1157. runtimeSep = this->Makefile->GetSafeDefinition(runTimeFlagSepVar.c_str());
  1158. // concatenate all paths or no?
  1159. bool runtimeConcatenate = ( runtimeSep!="" );
  1160. if(runtimeFlag == "" || this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  1161. {
  1162. outputRuntime = false;
  1163. }
  1164. // Some search paths should never be emitted
  1165. emitted.insert("");
  1166. emitted.insert("/usr/lib");
  1167. std::string libPathFlag = this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
  1168. std::string libLinkFlag = this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FLAG");
  1169. // collect all the flags needed for linking libraries
  1170. std::string linkLibs;
  1171. // Flags to link an executable to shared libraries.
  1172. std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
  1173. linkFlagsVar += linkLanguage;
  1174. linkFlagsVar += "_FLAGS";
  1175. if( tgt.GetType() == cmTarget::EXECUTABLE )
  1176. {
  1177. linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar.c_str());
  1178. linkLibs += " ";
  1179. }
  1180. // Compute the link library and directory information.
  1181. std::vector<cmStdString> libNames;
  1182. std::vector<cmStdString> libDirs;
  1183. this->ComputeLinkInformation(tgt, config, libNames, libDirs);
  1184. // Select whether to generate an rpath for the install tree or the
  1185. // build tree.
  1186. bool linking_for_install =
  1187. relink || tgt.GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  1188. bool use_install_rpath =
  1189. outputRuntime && tgt.HaveInstallTreeRPATH() && linking_for_install;
  1190. bool use_build_rpath =
  1191. outputRuntime && tgt.HaveBuildTreeRPATH() && !linking_for_install;
  1192. // Construct the RPATH.
  1193. std::vector<std::string> runtimeDirs;
  1194. if(use_install_rpath)
  1195. {
  1196. const char* install_rpath = tgt.GetProperty("INSTALL_RPATH");
  1197. cmSystemTools::ExpandListArgument(install_rpath, runtimeDirs);
  1198. for(unsigned int i=0; i < runtimeDirs.size(); ++i)
  1199. {
  1200. runtimeDirs[i] =
  1201. this->Convert(runtimeDirs[i].c_str(), FULL, SHELL, false);
  1202. }
  1203. }
  1204. // Append the library search path flags.
  1205. for(std::vector<cmStdString>::const_iterator libDir = libDirs.begin();
  1206. libDir != libDirs.end(); ++libDir)
  1207. {
  1208. std::string libpath = this->ConvertToOutputForExisting(libDir->c_str());
  1209. if(emitted.insert(libpath).second)
  1210. {
  1211. std::string fullLibPath;
  1212. if(!this->WindowsShell && this->UseRelativePaths)
  1213. {
  1214. fullLibPath = "\"`cd ";
  1215. }
  1216. fullLibPath += libpath;
  1217. if(!this->WindowsShell && this->UseRelativePaths)
  1218. {
  1219. fullLibPath += ";pwd`\"";
  1220. }
  1221. std::string::size_type pos = libDir->find(libPathFlag.c_str());
  1222. if((pos == std::string::npos || pos > 0)
  1223. && libDir->find("${") == std::string::npos)
  1224. {
  1225. linkLibs += libPathFlag;
  1226. if(use_build_rpath)
  1227. {
  1228. runtimeDirs.push_back( fullLibPath );
  1229. }
  1230. }
  1231. linkLibs += fullLibPath;
  1232. linkLibs += " ";
  1233. }
  1234. }
  1235. // Append the link libraries.
  1236. for(std::vector<cmStdString>::iterator lib = libNames.begin();
  1237. lib != libNames.end(); ++lib)
  1238. {
  1239. linkLibs += *lib;
  1240. linkLibs += " ";
  1241. }
  1242. fout << linkLibs;
  1243. if(!runtimeDirs.empty())
  1244. {
  1245. // For the runtime search directories, do a "-Wl,-rpath,a:b:c" or
  1246. // a "-R a -R b -R c" type link line
  1247. fout << runtimeFlag;
  1248. std::vector<std::string>::iterator itr = runtimeDirs.begin();
  1249. fout << *itr;
  1250. ++itr;
  1251. for( ; itr != runtimeDirs.end(); ++itr )
  1252. {
  1253. if(runtimeConcatenate)
  1254. {
  1255. fout << runtimeSep << *itr;
  1256. }
  1257. else
  1258. {
  1259. fout << " " << runtimeFlag << *itr;
  1260. }
  1261. }
  1262. fout << " ";
  1263. }
  1264. if(this->Makefile->GetDefinition("CMAKE_STANDARD_LIBRARIES"))
  1265. {
  1266. fout << this->Makefile->GetDefinition("CMAKE_STANDARD_LIBRARIES") << " ";
  1267. }
  1268. }
  1269. //----------------------------------------------------------------------------
  1270. void
  1271. cmLocalGenerator::ComputeLinkInformation(cmTarget& target,
  1272. const char* config,
  1273. std::vector<cmStdString>& outLibs,
  1274. std::vector<cmStdString>& outDirs,
  1275. std::vector<cmStdString>* fullPathLibs)
  1276. {
  1277. // Compute which library configuration to link.
  1278. cmTarget::LinkLibraryType linkType = cmTarget::OPTIMIZED;
  1279. if(config && cmSystemTools::UpperCase(config) == "DEBUG")
  1280. {
  1281. linkType = cmTarget::DEBUG;
  1282. }
  1283. // Get the list of libraries against which this target wants to link.
  1284. std::vector<std::string> linkLibraries;
  1285. const cmTarget::LinkLibraryVectorType& inLibs = target.GetLinkLibraries();
  1286. for(cmTarget::LinkLibraryVectorType::const_iterator j = inLibs.begin();
  1287. j != inLibs.end(); ++j)
  1288. {
  1289. // For backwards compatibility variables may have been expanded
  1290. // inside library names. Clean up the resulting name.
  1291. std::string lib = j->first;
  1292. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  1293. if(pos != lib.npos)
  1294. {
  1295. lib = lib.substr(pos, lib.npos);
  1296. }
  1297. pos = lib.find_last_not_of(" \t\r\n");
  1298. if(pos != lib.npos)
  1299. {
  1300. lib = lib.substr(0, pos+1);
  1301. }
  1302. if(lib.empty())
  1303. {
  1304. continue;
  1305. }
  1306. // Link to a library if it is not the same target and is meant for
  1307. // this configuration type.
  1308. if((target.GetType() == cmTarget::EXECUTABLE ||
  1309. lib != target.GetName()) &&
  1310. (j->second == cmTarget::GENERAL || j->second == linkType))
  1311. {
  1312. // Compute the proper name to use to link this library.
  1313. cmTarget* tgt = this->GlobalGenerator->FindTarget(0, lib.c_str());
  1314. if(tgt)
  1315. {
  1316. // This is a CMake target. Ask the target for its real name.
  1317. std::string realLibrary = tgt->GetFullPath(config);
  1318. linkLibraries.push_back(realLibrary);
  1319. if(fullPathLibs)
  1320. {
  1321. fullPathLibs->push_back(realLibrary);
  1322. }
  1323. }
  1324. else
  1325. {
  1326. // This is not a CMake target. Use the name given.
  1327. linkLibraries.push_back(lib);
  1328. }
  1329. }
  1330. }
  1331. // Get the list of directories the target wants to search for libraries.
  1332. const std::vector<std::string>&
  1333. linkDirectories = target.GetLinkDirectories();
  1334. // Compute the link directory order needed to link the libraries.
  1335. cmOrderLinkDirectories orderLibs;
  1336. orderLibs.SetLinkPrefix(
  1337. this->Makefile->GetDefinition("CMAKE_STATIC_LIBRARY_PREFIX"));
  1338. orderLibs.AddLinkExtension(
  1339. this->Makefile->GetDefinition("CMAKE_STATIC_LIBRARY_SUFFIX"));
  1340. orderLibs.AddLinkExtension(
  1341. this->Makefile->GetDefinition("CMAKE_SHARED_LIBRARY_SUFFIX"));
  1342. orderLibs.AddLinkExtension(
  1343. this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"));
  1344. orderLibs.AddLinkExtension(
  1345. this->Makefile->GetDefinition("CMAKE_LINK_LIBRARY_SUFFIX"));
  1346. if(const char* linkSuffixes =
  1347. this->Makefile->GetDefinition("CMAKE_EXTRA_LINK_EXTENSIONS"))
  1348. {
  1349. std::vector<std::string> linkSuffixVec;
  1350. cmSystemTools::ExpandListArgument(linkSuffixes, linkSuffixVec);
  1351. for(std::vector<std::string>::iterator i = linkSuffixVec.begin();
  1352. i != linkSuffixVec.end(); ++i)
  1353. {
  1354. orderLibs.AddLinkExtension(i->c_str());
  1355. }
  1356. }
  1357. std::string configSubdir;
  1358. cmGlobalGenerator* gg = this->GetGlobalGenerator();
  1359. gg->AppendDirectoryForConfig("", config, "", configSubdir);
  1360. orderLibs.SetLinkInformation(target.GetName(),
  1361. linkLibraries,
  1362. linkDirectories,
  1363. gg->GetTargetManifest(),
  1364. configSubdir.c_str());
  1365. orderLibs.DetermineLibraryPathOrder();
  1366. std::vector<cmStdString> orderedLibs;
  1367. orderLibs.GetLinkerInformation(outDirs, orderedLibs);
  1368. if(fullPathLibs)
  1369. {
  1370. orderLibs.GetFullPathLibraries(*fullPathLibs);
  1371. }
  1372. // Make sure libraries are linked with the proper syntax.
  1373. std::string libLinkFlag =
  1374. this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FLAG");
  1375. std::string libLinkSuffix =
  1376. this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_SUFFIX");
  1377. for(std::vector<cmStdString>::iterator l = orderedLibs.begin();
  1378. l != orderedLibs.end(); ++l)
  1379. {
  1380. std::string lib = *l;
  1381. if(lib[0] == '-' || lib[0] == '$' || lib[0] == '`')
  1382. {
  1383. // The library is linked with special syntax by the user.
  1384. outLibs.push_back(lib);
  1385. }
  1386. else
  1387. {
  1388. // Generate the proper link syntax.
  1389. lib = libLinkFlag;
  1390. lib += *l;
  1391. lib += libLinkSuffix;
  1392. outLibs.push_back(lib);
  1393. }
  1394. }
  1395. }
  1396. //----------------------------------------------------------------------------
  1397. void cmLocalGenerator::AddLanguageFlags(std::string& flags,
  1398. const char* lang,
  1399. const char* config)
  1400. {
  1401. // Add language-specific flags.
  1402. std::string flagsVar = "CMAKE_";
  1403. flagsVar += lang;
  1404. flagsVar += "_FLAGS";
  1405. if(this->EmitUniversalBinaryFlags)
  1406. {
  1407. const char* osxArch =
  1408. this->Makefile->GetDefinition("CMAKE_OSX_ARCHITECTURES");
  1409. const char* sysroot =
  1410. this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
  1411. if(osxArch && sysroot && lang && lang[0] =='C')
  1412. {
  1413. std::vector<std::string> archs;
  1414. cmSystemTools::ExpandListArgument(std::string(osxArch),
  1415. archs);
  1416. if(archs.size() > 1)
  1417. {
  1418. for( std::vector<std::string>::iterator i = archs.begin();
  1419. i != archs.end(); ++i)
  1420. {
  1421. flags += " -arch ";
  1422. flags += *i;
  1423. }
  1424. flags += " -isysroot ";
  1425. flags += sysroot;
  1426. }
  1427. }
  1428. }
  1429. this->AddConfigVariableFlags(flags, flagsVar.c_str(), config);
  1430. }
  1431. //----------------------------------------------------------------------------
  1432. std::string cmLocalGenerator::GetRealDependency(const char* inName,
  1433. const char* config)
  1434. {
  1435. // Older CMake code may specify the dependency using the target
  1436. // output file rather than the target name. Such code would have
  1437. // been written before there was support for target properties that
  1438. // modify the name so stripping down to just the file name should
  1439. // produce the target name in this case.
  1440. std::string name = cmSystemTools::GetFilenameName(inName);
  1441. if(cmSystemTools::GetFilenameLastExtension(name) == ".exe")
  1442. {
  1443. name = cmSystemTools::GetFilenameWithoutLastExtension(name);
  1444. }
  1445. // Look for a CMake target with the given name.
  1446. if(cmTarget* target = this->GlobalGenerator->FindTarget(0, name.c_str()))
  1447. {
  1448. switch (target->GetType())
  1449. {
  1450. case cmTarget::EXECUTABLE:
  1451. case cmTarget::STATIC_LIBRARY:
  1452. case cmTarget::SHARED_LIBRARY:
  1453. case cmTarget::MODULE_LIBRARY:
  1454. {
  1455. // Get the location of the target's output file and depend on it.
  1456. if(const char* location = target->GetLocation(config))
  1457. {
  1458. return location;
  1459. }
  1460. }
  1461. break;
  1462. case cmTarget::UTILITY:
  1463. case cmTarget::GLOBAL_TARGET:
  1464. // Depending on a utility target may not work but just trust
  1465. // the user to have given a valid name.
  1466. return inName;
  1467. case cmTarget::INSTALL_FILES:
  1468. case cmTarget::INSTALL_PROGRAMS:
  1469. case cmTarget::INSTALL_DIRECTORY:
  1470. break;
  1471. }
  1472. }
  1473. // The name was not that of a CMake target. It must name a file.
  1474. if(cmSystemTools::FileIsFullPath(inName))
  1475. {
  1476. // This is a full path. Return it as given.
  1477. return inName;
  1478. }
  1479. // Treat the name as relative to the source directory in which it
  1480. // was given.
  1481. name = this->Makefile->GetCurrentDirectory();
  1482. name += "/";
  1483. name += inName;
  1484. return name;
  1485. }
  1486. //----------------------------------------------------------------------------
  1487. void cmLocalGenerator::AddSharedFlags(std::string& flags,
  1488. const char* lang,
  1489. bool shared)
  1490. {
  1491. std::string flagsVar;
  1492. // Add flags for dealing with shared libraries for this language.
  1493. if(shared)
  1494. {
  1495. flagsVar = "CMAKE_SHARED_LIBRARY_";
  1496. flagsVar += lang;
  1497. flagsVar += "_FLAGS";
  1498. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1499. }
  1500. // Add flags specific to shared builds.
  1501. if(cmSystemTools::IsOn(this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1502. {
  1503. flagsVar = "CMAKE_SHARED_BUILD_";
  1504. flagsVar += lang;
  1505. flagsVar += "_FLAGS";
  1506. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1507. }
  1508. }
  1509. //----------------------------------------------------------------------------
  1510. void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
  1511. const char* var,
  1512. const char* config)
  1513. {
  1514. // Add the flags from the variable itself.
  1515. std::string flagsVar = var;
  1516. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1517. // Add the flags from the build-type specific variable.
  1518. if(config && *config)
  1519. {
  1520. flagsVar += "_";
  1521. flagsVar += cmSystemTools::UpperCase(config);
  1522. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
  1523. }
  1524. }
  1525. //----------------------------------------------------------------------------
  1526. void cmLocalGenerator::AppendFlags(std::string& flags,
  1527. const char* newFlags)
  1528. {
  1529. if(newFlags && *newFlags)
  1530. {
  1531. if(flags.size())
  1532. {
  1533. flags += " ";
  1534. }
  1535. flags += newFlags;
  1536. }
  1537. }
  1538. //----------------------------------------------------------------------------
  1539. std::string
  1540. cmLocalGenerator::ConstructScript(const cmCustomCommandLines& commandLines,
  1541. const char* workingDirectory,
  1542. const char* newline)
  1543. {
  1544. // Store the script in a string.
  1545. std::string script;
  1546. if(workingDirectory)
  1547. {
  1548. script += "cd ";
  1549. script += this->Convert(workingDirectory, START_OUTPUT, SHELL);
  1550. script += newline;
  1551. }
  1552. // Write each command on a single line.
  1553. for(cmCustomCommandLines::const_iterator cl = commandLines.begin();
  1554. cl != commandLines.end(); ++cl)
  1555. {
  1556. // Start with the command name.
  1557. const cmCustomCommandLine& commandLine = *cl;
  1558. script += this->Convert(commandLine[0].c_str(),START_OUTPUT,SHELL);
  1559. // Add the arguments.
  1560. for(unsigned int j=1;j < commandLine.size(); ++j)
  1561. {
  1562. script += " ";
  1563. script += cmSystemTools::EscapeSpaces(commandLine[j].c_str());
  1564. }
  1565. // End the line.
  1566. script += newline;
  1567. }
  1568. return script;
  1569. }
  1570. //----------------------------------------------------------------------------
  1571. std::string
  1572. cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(const char* remote)
  1573. {
  1574. return this->Convert(remote, START_OUTPUT, SHELL, true);
  1575. }
  1576. //----------------------------------------------------------------------------
  1577. std::string cmLocalGenerator::Convert(const char* source,
  1578. RelativeRoot relative,
  1579. OutputFormat output,
  1580. bool optional)
  1581. {
  1582. // Convert the path to a relative path.
  1583. std::string result = source;
  1584. if (!optional || this->UseRelativePaths)
  1585. {
  1586. switch (relative)
  1587. {
  1588. case HOME:
  1589. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1590. result = this->GlobalGenerator->
  1591. ConvertToRelativePath(this->HomeDirectoryComponents, result.c_str());
  1592. break;
  1593. case START:
  1594. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1595. result = this->GlobalGenerator->
  1596. ConvertToRelativePath(this->StartDirectoryComponents, result.c_str());
  1597. break;
  1598. case HOME_OUTPUT:
  1599. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1600. result = this->GlobalGenerator->
  1601. ConvertToRelativePath(this->HomeOutputDirectoryComponents, result.c_str());
  1602. break;
  1603. case START_OUTPUT:
  1604. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1605. result = this->GlobalGenerator->
  1606. ConvertToRelativePath(this->StartOutputDirectoryComponents, result.c_str());
  1607. break;
  1608. case FULL:
  1609. result = cmSystemTools::CollapseFullPath(result.c_str());
  1610. break;
  1611. case NONE:
  1612. break;
  1613. }
  1614. }
  1615. // Now convert it to an output path.
  1616. if (output == MAKEFILE)
  1617. {
  1618. result = cmSystemTools::ConvertToOutputPath(result.c_str());
  1619. }
  1620. if( output == SHELL)
  1621. {
  1622. // for shell commands if force unix is on, but this->WindowsShell
  1623. // is true, then turn off force unix paths for the output path
  1624. // so that the path is windows style and will work with windows
  1625. // cmd.exe.
  1626. bool forceOn = cmSystemTools::GetForceUnixPaths();
  1627. if(forceOn && this->WindowsShell)
  1628. {
  1629. cmSystemTools::SetForceUnixPaths(false);
  1630. }
  1631. result = cmSystemTools::ConvertToOutputPath(result.c_str());
  1632. if(forceOn && this->WindowsShell)
  1633. {
  1634. cmSystemTools::SetForceUnixPaths(true);
  1635. }
  1636. }
  1637. return result;
  1638. }
  1639. //----------------------------------------------------------------------------
  1640. void
  1641. cmLocalGenerator
  1642. ::GenerateTargetInstallRules(
  1643. std::ostream& os, const char* config,
  1644. std::vector<std::string> const& configurationTypes)
  1645. {
  1646. // Convert the old-style install specification from each target to
  1647. // an install generator and run it.
  1648. cmTargets& tgts = this->Makefile->GetTargets();
  1649. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  1650. {
  1651. // Include the user-specified pre-install script for this target.
  1652. if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
  1653. {
  1654. cmInstallScriptGenerator g(preinstall);
  1655. g.Generate(os, config, configurationTypes);
  1656. }
  1657. // Install this target if a destination is given.
  1658. if(l->second.GetInstallPath() != "")
  1659. {
  1660. // Compute the full install destination. Note that converting
  1661. // to unix slashes also removes any trailing slash.
  1662. std::string destination = "${CMAKE_INSTALL_PREFIX}";
  1663. destination += l->second.GetInstallPath();
  1664. cmSystemTools::ConvertToUnixSlashes(destination);
  1665. // Generate the proper install generator for this target type.
  1666. switch(l->second.GetType())
  1667. {
  1668. case cmTarget::EXECUTABLE:
  1669. case cmTarget::STATIC_LIBRARY:
  1670. case cmTarget::MODULE_LIBRARY:
  1671. {
  1672. // Use a target install generator.
  1673. cmInstallTargetGenerator g(l->second, destination.c_str(), false);
  1674. g.Generate(os, config, configurationTypes);
  1675. }
  1676. break;
  1677. case cmTarget::SHARED_LIBRARY:
  1678. {
  1679. #if defined(_WIN32) || defined(__CYGWIN__)
  1680. // Special code to handle DLL. Install the import library
  1681. // to the normal destination and the DLL to the runtime
  1682. // destination.
  1683. cmInstallTargetGenerator g1(l->second, destination.c_str(), true);
  1684. g1.Generate(os, config, configurationTypes);
  1685. destination = "${CMAKE_INSTALL_PREFIX}";
  1686. destination += l->second.GetRuntimeInstallPath();
  1687. cmSystemTools::ConvertToUnixSlashes(destination);
  1688. cmInstallTargetGenerator g2(l->second, destination.c_str(), false);
  1689. g2.Generate(os, config, configurationTypes);
  1690. #else
  1691. // Use a target install generator.
  1692. cmInstallTargetGenerator g(l->second, destination.c_str(), false);
  1693. g.Generate(os, config, configurationTypes);
  1694. #endif
  1695. }
  1696. break;
  1697. case cmTarget::INSTALL_FILES:
  1698. {
  1699. // Use a file install generator.
  1700. const char* no_permissions = "";
  1701. const char* no_rename = "";
  1702. const char* no_component = "";
  1703. cmInstallFilesGenerator g(l->second.GetSourceLists(),
  1704. destination.c_str(), false,
  1705. no_permissions, no_component, no_rename);
  1706. g.Generate(os, config, configurationTypes);
  1707. }
  1708. break;
  1709. case cmTarget::INSTALL_PROGRAMS:
  1710. {
  1711. // Use a file install generator.
  1712. const char* no_permissions = "";
  1713. const char* no_rename = "";
  1714. const char* no_component = "";
  1715. cmInstallFilesGenerator g(l->second.GetSourceLists(),
  1716. destination.c_str(), true,
  1717. no_permissions, no_component, no_rename);
  1718. g.Generate(os, config, configurationTypes);
  1719. }
  1720. break;
  1721. case cmTarget::UTILITY:
  1722. default:
  1723. break;
  1724. }
  1725. }
  1726. // Include the user-specified post-install script for this target.
  1727. if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
  1728. {
  1729. cmInstallScriptGenerator g(postinstall);
  1730. g.Generate(os, config, configurationTypes);
  1731. }
  1732. }
  1733. }