cmLocalGenerator.cxx 59 KB

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