cmLocalGenerator.cxx 86 KB

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