cmLocalGenerator.cxx 86 KB

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