cmLocalGenerator.cxx 82 KB

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