cmLocalGenerator.cxx 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849
  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* newline)
  1664. {
  1665. // Store the script in a string.
  1666. std::string script;
  1667. // Write each command on a single line.
  1668. for(cmCustomCommandLines::const_iterator cl = commandLines.begin();
  1669. cl != commandLines.end(); ++cl)
  1670. {
  1671. // Start with the command name.
  1672. const cmCustomCommandLine& commandLine = *cl;
  1673. script += this->Convert(commandLine[0].c_str(),START_OUTPUT,SHELL);
  1674. // Add the arguments.
  1675. for(unsigned int j=1;j < commandLine.size(); ++j)
  1676. {
  1677. script += " ";
  1678. script += cmSystemTools::EscapeSpaces(commandLine[j].c_str());
  1679. }
  1680. // End the line.
  1681. script += newline;
  1682. }
  1683. return script;
  1684. }
  1685. //----------------------------------------------------------------------------
  1686. std::string
  1687. cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(const char* remote)
  1688. {
  1689. return this->Convert(remote, START_OUTPUT, SHELL, true);
  1690. }
  1691. //----------------------------------------------------------------------------
  1692. std::string cmLocalGenerator::Convert(const char* source,
  1693. RelativeRoot relative,
  1694. OutputFormat output,
  1695. bool optional)
  1696. {
  1697. // Convert the path to a relative path.
  1698. std::string result = source;
  1699. if (!optional || m_UseRelativePaths)
  1700. {
  1701. switch (relative)
  1702. {
  1703. case HOME:
  1704. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1705. result = m_GlobalGenerator->
  1706. ConvertToRelativePath(m_HomeDirectoryComponents, result.c_str());
  1707. break;
  1708. case START:
  1709. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1710. result = m_GlobalGenerator->
  1711. ConvertToRelativePath(m_StartDirectoryComponents, result.c_str());
  1712. break;
  1713. case HOME_OUTPUT:
  1714. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1715. result = m_GlobalGenerator->
  1716. ConvertToRelativePath(m_HomeOutputDirectoryComponents, result.c_str());
  1717. break;
  1718. case START_OUTPUT:
  1719. //result = cmSystemTools::CollapseFullPath(result.c_str());
  1720. result = m_GlobalGenerator->
  1721. ConvertToRelativePath(m_StartOutputDirectoryComponents, result.c_str());
  1722. break;
  1723. case FULL:
  1724. result = cmSystemTools::CollapseFullPath(result.c_str());
  1725. break;
  1726. case NONE:
  1727. break;
  1728. }
  1729. }
  1730. // Now convert it to an output path.
  1731. if (output == MAKEFILE)
  1732. {
  1733. result = cmSystemTools::ConvertToOutputPath(result.c_str());
  1734. }
  1735. if( output == SHELL)
  1736. {
  1737. // for shell commands if force unix is on, but m_WindowsShell
  1738. // is true, then turn off force unix paths for the output path
  1739. // so that the path is windows style and will work with windows
  1740. // cmd.exe.
  1741. bool forceOn = cmSystemTools::GetForceUnixPaths();
  1742. if(forceOn && m_WindowsShell)
  1743. {
  1744. cmSystemTools::SetForceUnixPaths(false);
  1745. }
  1746. result = cmSystemTools::ConvertToOutputPath(result.c_str());
  1747. if(forceOn && m_WindowsShell)
  1748. {
  1749. cmSystemTools::SetForceUnixPaths(true);
  1750. }
  1751. }
  1752. return result;
  1753. }