cmLocalGenerator.cxx 82 KB

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