cmLocalGenerator.cxx 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmLocalGenerator.h"
  11. #include "cmComputeLinkInformation.h"
  12. #include "cmGeneratedFileStream.h"
  13. #include "cmGlobalGenerator.h"
  14. #include "cmInstallGenerator.h"
  15. #include "cmInstallFilesGenerator.h"
  16. #include "cmGeneratorExpressionEvaluationFile.h"
  17. #include "cmInstallScriptGenerator.h"
  18. #include "cmInstallTargetGenerator.h"
  19. #include "cmMakefile.h"
  20. #include "cmSourceFile.h"
  21. #include "cmTest.h"
  22. #include "cmTestGenerator.h"
  23. #include "cmCustomCommandGenerator.h"
  24. #include "cmVersion.h"
  25. #include "cmake.h"
  26. #include "cmAlgorithms.h"
  27. #if defined(CMAKE_BUILD_WITH_CMAKE)
  28. # define CM_LG_ENCODE_OBJECT_NAMES
  29. # include <cmsys/MD5.h>
  30. #endif
  31. #include <ctype.h> // for isalpha
  32. #include <assert.h>
  33. #if defined(__HAIKU__)
  34. #include <FindDirectory.h>
  35. #include <StorageDefs.h>
  36. #endif
  37. cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg,
  38. cmMakefile* makefile)
  39. : cmOutputConverter(makefile->GetStateSnapshot()),
  40. StateSnapshot(makefile->GetStateSnapshot())
  41. {
  42. this->GlobalGenerator = gg;
  43. this->Makefile = makefile;
  44. this->EmitUniversalBinaryFlags = true;
  45. this->BackwardsCompatibility = 0;
  46. this->BackwardsCompatibilityFinal = false;
  47. }
  48. cmLocalGenerator::~cmLocalGenerator()
  49. {
  50. }
  51. void cmLocalGenerator::IssueMessage(cmake::MessageType t,
  52. std::string const& text) const
  53. {
  54. cmListFileContext lfc;
  55. lfc.FilePath = this->StateSnapshot.GetDirectory().GetCurrentSource();
  56. lfc.FilePath += "/CMakeLists.txt";
  57. if(!this->GlobalGenerator->GetCMakeInstance()->GetIsInTryCompile())
  58. {
  59. cmOutputConverter converter(this->StateSnapshot);
  60. lfc.FilePath = converter.Convert(lfc.FilePath, cmLocalGenerator::HOME);
  61. }
  62. lfc.Line = 0;
  63. this->GlobalGenerator->GetCMakeInstance()->IssueMessage(t, text, lfc);
  64. }
  65. //----------------------------------------------------------------------------
  66. void cmLocalGenerator::ComputeObjectMaxPath()
  67. {
  68. // Choose a maximum object file name length.
  69. #if defined(_WIN32) || defined(__CYGWIN__)
  70. this->ObjectPathMax = 250;
  71. #else
  72. this->ObjectPathMax = 1000;
  73. #endif
  74. const char* plen = this->Makefile->GetDefinition("CMAKE_OBJECT_PATH_MAX");
  75. if(plen && *plen)
  76. {
  77. unsigned int pmax;
  78. if(sscanf(plen, "%u", &pmax) == 1)
  79. {
  80. if(pmax >= 128)
  81. {
  82. this->ObjectPathMax = pmax;
  83. }
  84. else
  85. {
  86. std::ostringstream w;
  87. w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
  88. << ", which is less than the minimum of 128. "
  89. << "The value will be ignored.";
  90. this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  91. }
  92. }
  93. else
  94. {
  95. std::ostringstream w;
  96. w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
  97. << "\", which fails to parse as a positive integer. "
  98. << "The value will be ignored.";
  99. this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  100. }
  101. }
  102. this->ObjectMaxPathViolations.clear();
  103. }
  104. void cmLocalGenerator::TraceDependencies()
  105. {
  106. std::vector<std::string> configs;
  107. this->Makefile->GetConfigurations(configs);
  108. if (configs.empty())
  109. {
  110. configs.push_back("");
  111. }
  112. for(std::vector<std::string>::const_iterator ci = configs.begin();
  113. ci != configs.end(); ++ci)
  114. {
  115. this->GlobalGenerator->CreateEvaluationSourceFiles(*ci);
  116. }
  117. // Generate the rule files for each target.
  118. cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets();
  119. for(cmGeneratorTargetsType::iterator t = targets.begin();
  120. t != targets.end(); ++t)
  121. {
  122. if (t->second->Target->IsImported()
  123. || t->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  124. {
  125. continue;
  126. }
  127. t->second->TraceDependencies();
  128. }
  129. }
  130. void cmLocalGenerator::GenerateTestFiles()
  131. {
  132. if ( !this->Makefile->IsOn("CMAKE_TESTING_ENABLED") )
  133. {
  134. return;
  135. }
  136. // Compute the set of configurations.
  137. std::vector<std::string> configurationTypes;
  138. const std::string& config =
  139. this->Makefile->GetConfigurations(configurationTypes, false);
  140. std::string file =
  141. this->StateSnapshot.GetDirectory().GetCurrentBinary();
  142. file += "/";
  143. file += "CTestTestfile.cmake";
  144. cmGeneratedFileStream fout(file.c_str());
  145. fout.SetCopyIfDifferent(true);
  146. fout << "# CMake generated Testfile for " << std::endl
  147. << "# Source directory: "
  148. << this->StateSnapshot.GetDirectory().GetCurrentSource()
  149. << std::endl
  150. << "# Build directory: "
  151. << this->StateSnapshot.GetDirectory().GetCurrentBinary()
  152. << std::endl
  153. << "# " << std::endl
  154. << "# This file includes the relevant testing commands "
  155. << "required for " << std::endl
  156. << "# testing this directory and lists subdirectories to "
  157. << "be tested as well." << std::endl;
  158. const char* testIncludeFile =
  159. this->Makefile->GetProperty("TEST_INCLUDE_FILE");
  160. if ( testIncludeFile )
  161. {
  162. fout << "include(\"" << testIncludeFile << "\")" << std::endl;
  163. }
  164. // Ask each test generator to write its code.
  165. std::vector<cmTestGenerator*> const&
  166. testers = this->Makefile->GetTestGenerators();
  167. for(std::vector<cmTestGenerator*>::const_iterator gi = testers.begin();
  168. gi != testers.end(); ++gi)
  169. {
  170. (*gi)->Compute(this);
  171. (*gi)->Generate(fout, config, configurationTypes);
  172. }
  173. size_t i;
  174. std::vector<cmState::Snapshot> children
  175. = this->Makefile->GetStateSnapshot().GetChildren();
  176. for(i = 0; i < children.size(); ++i)
  177. {
  178. // TODO: Use add_subdirectory instead?
  179. fout << "subdirs(";
  180. std::string outP = children[i].GetDirectory().GetCurrentBinary();
  181. fout << this->Convert(outP,START_OUTPUT);
  182. fout << ")" << std::endl;
  183. }
  184. }
  185. void cmLocalGenerator::CreateEvaluationFileOutputs(std::string const& config)
  186. {
  187. std::vector<cmGeneratorExpressionEvaluationFile*> ef =
  188. this->Makefile->GetEvaluationFiles();
  189. for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
  190. li = ef.begin(); li != ef.end(); ++li)
  191. {
  192. (*li)->CreateOutputFile(this, config);
  193. }
  194. }
  195. void cmLocalGenerator::ProcessEvaluationFiles(
  196. std::vector<std::string>& generatedFiles)
  197. {
  198. std::vector<cmGeneratorExpressionEvaluationFile*> ef =
  199. this->Makefile->GetEvaluationFiles();
  200. for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
  201. li = ef.begin();
  202. li != ef.end();
  203. ++li)
  204. {
  205. (*li)->Generate(this);
  206. if (cmSystemTools::GetFatalErrorOccured())
  207. {
  208. return;
  209. }
  210. std::vector<std::string> files = (*li)->GetFiles();
  211. std::sort(files.begin(), files.end());
  212. std::vector<std::string> intersection;
  213. std::set_intersection(files.begin(), files.end(),
  214. generatedFiles.begin(), generatedFiles.end(),
  215. std::back_inserter(intersection));
  216. if (!intersection.empty())
  217. {
  218. cmSystemTools::Error("Files to be generated by multiple different "
  219. "commands: ", cmWrap('"', intersection, '"', " ").c_str());
  220. return;
  221. }
  222. generatedFiles.insert(generatedFiles.end(), files.begin(), files.end());
  223. std::vector<std::string>::iterator newIt =
  224. generatedFiles.end() - files.size();
  225. std::inplace_merge(generatedFiles.begin(), newIt, generatedFiles.end());
  226. }
  227. }
  228. //----------------------------------------------------------------------------
  229. void cmLocalGenerator::GenerateInstallRules()
  230. {
  231. // Compute the install prefix.
  232. const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
  233. #if defined(_WIN32) && !defined(__CYGWIN__)
  234. std::string prefix_win32;
  235. if(!prefix)
  236. {
  237. if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32))
  238. {
  239. prefix_win32 = "C:";
  240. }
  241. const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
  242. if(project_name && project_name[0])
  243. {
  244. prefix_win32 += "/Program Files/";
  245. prefix_win32 += project_name;
  246. }
  247. else
  248. {
  249. prefix_win32 += "/InstalledCMakeProject";
  250. }
  251. prefix = prefix_win32.c_str();
  252. }
  253. #elif defined(__HAIKU__)
  254. char dir[B_PATH_NAME_LENGTH];
  255. if (!prefix)
  256. {
  257. if (find_directory(B_SYSTEM_DIRECTORY, -1, false, dir, sizeof(dir))
  258. == B_OK)
  259. {
  260. prefix = dir;
  261. }
  262. else
  263. {
  264. prefix = "/boot/system";
  265. }
  266. }
  267. #else
  268. if (!prefix)
  269. {
  270. prefix = "/usr/local";
  271. }
  272. #endif
  273. if (const char *stagingPrefix
  274. = this->Makefile->GetDefinition("CMAKE_STAGING_PREFIX"))
  275. {
  276. prefix = stagingPrefix;
  277. }
  278. // Compute the set of configurations.
  279. std::vector<std::string> configurationTypes;
  280. const std::string& config =
  281. this->Makefile->GetConfigurations(configurationTypes, false);
  282. // Choose a default install configuration.
  283. std::string default_config = config;
  284. const char* default_order[] = {"RELEASE", "MINSIZEREL",
  285. "RELWITHDEBINFO", "DEBUG", 0};
  286. for(const char** c = default_order; *c && default_config.empty(); ++c)
  287. {
  288. for(std::vector<std::string>::iterator i = configurationTypes.begin();
  289. i != configurationTypes.end(); ++i)
  290. {
  291. if(cmSystemTools::UpperCase(*i) == *c)
  292. {
  293. default_config = *i;
  294. }
  295. }
  296. }
  297. if(default_config.empty() && !configurationTypes.empty())
  298. {
  299. default_config = configurationTypes[0];
  300. }
  301. // Create the install script file.
  302. std::string file =
  303. this->StateSnapshot.GetDirectory().GetCurrentBinary();
  304. std::string homedir = this->GetState()->GetBinaryDirectory();
  305. int toplevel_install = 0;
  306. if (file == homedir)
  307. {
  308. toplevel_install = 1;
  309. }
  310. file += "/cmake_install.cmake";
  311. cmGeneratedFileStream fout(file.c_str());
  312. fout.SetCopyIfDifferent(true);
  313. // Write the header.
  314. fout << "# Install script for directory: "
  315. << this->StateSnapshot.GetDirectory().GetCurrentSource()
  316. << std::endl << std::endl;
  317. fout << "# Set the install prefix" << std::endl
  318. << "if(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  319. << " set(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
  320. << "endif()" << std::endl
  321. << "string(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
  322. << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
  323. << std::endl;
  324. // Write support code for generating per-configuration install rules.
  325. fout <<
  326. "# Set the install configuration name.\n"
  327. "if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  328. " if(BUILD_TYPE)\n"
  329. " string(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
  330. " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
  331. " else()\n"
  332. " set(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
  333. " endif()\n"
  334. " message(STATUS \"Install configuration: "
  335. "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
  336. "endif()\n"
  337. "\n";
  338. // Write support code for dealing with component-specific installs.
  339. fout <<
  340. "# Set the component getting installed.\n"
  341. "if(NOT CMAKE_INSTALL_COMPONENT)\n"
  342. " if(COMPONENT)\n"
  343. " message(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
  344. " set(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
  345. " else()\n"
  346. " set(CMAKE_INSTALL_COMPONENT)\n"
  347. " endif()\n"
  348. "endif()\n"
  349. "\n";
  350. // Copy user-specified install options to the install code.
  351. if(const char* so_no_exe =
  352. this->Makefile->GetDefinition("CMAKE_INSTALL_SO_NO_EXE"))
  353. {
  354. fout <<
  355. "# Install shared libraries without execute permission?\n"
  356. "if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
  357. " set(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe << "\")\n"
  358. "endif()\n"
  359. "\n";
  360. }
  361. // Ask each install generator to write its code.
  362. std::vector<cmInstallGenerator*> const& installers =
  363. this->Makefile->GetInstallGenerators();
  364. for(std::vector<cmInstallGenerator*>::const_iterator
  365. gi = installers.begin();
  366. gi != installers.end(); ++gi)
  367. {
  368. (*gi)->Generate(fout, config, configurationTypes);
  369. }
  370. // Write rules from old-style specification stored in targets.
  371. this->GenerateTargetInstallRules(fout, config, configurationTypes);
  372. // Include install scripts from subdirectories.
  373. std::vector<cmState::Snapshot> children
  374. = this->Makefile->GetStateSnapshot().GetChildren();
  375. if(!children.empty())
  376. {
  377. fout << "if(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
  378. fout << " # Include the install script for each subdirectory.\n";
  379. for(std::vector<cmState::Snapshot>::const_iterator
  380. ci = children.begin(); ci != children.end(); ++ci)
  381. {
  382. if(!ci->GetDirectory().GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  383. {
  384. std::string odir = ci->GetDirectory().GetCurrentBinary();
  385. cmSystemTools::ConvertToUnixSlashes(odir);
  386. fout << " include(\"" << odir
  387. << "/cmake_install.cmake\")" << std::endl;
  388. }
  389. }
  390. fout << "\n";
  391. fout << "endif()\n\n";
  392. }
  393. // Record the install manifest.
  394. if ( toplevel_install )
  395. {
  396. fout <<
  397. "if(CMAKE_INSTALL_COMPONENT)\n"
  398. " set(CMAKE_INSTALL_MANIFEST \"install_manifest_"
  399. "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
  400. "else()\n"
  401. " set(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
  402. "endif()\n"
  403. "\n"
  404. "string(REPLACE \";\" \"\\n\" CMAKE_INSTALL_MANIFEST_CONTENT\n"
  405. " \"${CMAKE_INSTALL_MANIFEST_FILES}\")\n"
  406. "file(WRITE \"" << homedir << "/${CMAKE_INSTALL_MANIFEST}\"\n"
  407. " \"${CMAKE_INSTALL_MANIFEST_CONTENT}\")\n";
  408. }
  409. }
  410. //----------------------------------------------------------------------------
  411. void cmLocalGenerator::ComputeTargetManifest()
  412. {
  413. // Collect the set of configuration types.
  414. std::vector<std::string> configNames;
  415. this->Makefile->GetConfigurations(configNames);
  416. if(configNames.empty())
  417. {
  418. configNames.push_back("");
  419. }
  420. // Add our targets to the manifest for each configuration.
  421. cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets();
  422. for(cmGeneratorTargetsType::iterator t = targets.begin();
  423. t != targets.end(); ++t)
  424. {
  425. cmGeneratorTarget& target = *t->second;
  426. if (target.Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  427. {
  428. continue;
  429. }
  430. if (target.Target->IsImported())
  431. {
  432. continue;
  433. }
  434. for(std::vector<std::string>::iterator ci = configNames.begin();
  435. ci != configNames.end(); ++ci)
  436. {
  437. const char* config = ci->c_str();
  438. target.ComputeTargetManifest(config);
  439. }
  440. }
  441. }
  442. cmState* cmLocalGenerator::GetState() const
  443. {
  444. return this->GlobalGenerator->GetCMakeInstance()->GetState();
  445. }
  446. cmState::Snapshot cmLocalGenerator::GetStateSnapshot() const
  447. {
  448. return this->Makefile->GetStateSnapshot();
  449. }
  450. // List of variables that are replaced when
  451. // rules are expanced. These variables are
  452. // replaced in the form <var> with GetSafeDefinition(var).
  453. // ${LANG} is replaced in the variable first with all enabled
  454. // languages.
  455. static const char* ruleReplaceVars[] =
  456. {
  457. "CMAKE_${LANG}_COMPILER",
  458. "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
  459. "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
  460. "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
  461. "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
  462. "CMAKE_${LANG}_LINK_FLAGS",
  463. "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
  464. "CMAKE_${LANG}_ARCHIVE",
  465. "CMAKE_AR",
  466. "CMAKE_CURRENT_SOURCE_DIR",
  467. "CMAKE_CURRENT_BINARY_DIR",
  468. "CMAKE_RANLIB",
  469. "CMAKE_LINKER",
  470. "CMAKE_CL_SHOWINCLUDES_PREFIX",
  471. 0
  472. };
  473. std::string
  474. cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
  475. const RuleVariables& replaceValues)
  476. {
  477. if(replaceValues.LinkFlags)
  478. {
  479. if(variable == "LINK_FLAGS")
  480. {
  481. return replaceValues.LinkFlags;
  482. }
  483. }
  484. if(replaceValues.Manifests)
  485. {
  486. if(variable == "MANIFESTS")
  487. {
  488. return replaceValues.Manifests;
  489. }
  490. }
  491. if(replaceValues.Flags)
  492. {
  493. if(variable == "FLAGS")
  494. {
  495. return replaceValues.Flags;
  496. }
  497. }
  498. if(replaceValues.Source)
  499. {
  500. if(variable == "SOURCE")
  501. {
  502. return replaceValues.Source;
  503. }
  504. }
  505. if(replaceValues.PreprocessedSource)
  506. {
  507. if(variable == "PREPROCESSED_SOURCE")
  508. {
  509. return replaceValues.PreprocessedSource;
  510. }
  511. }
  512. if(replaceValues.AssemblySource)
  513. {
  514. if(variable == "ASSEMBLY_SOURCE")
  515. {
  516. return replaceValues.AssemblySource;
  517. }
  518. }
  519. if(replaceValues.Object)
  520. {
  521. if(variable == "OBJECT")
  522. {
  523. return replaceValues.Object;
  524. }
  525. }
  526. if(replaceValues.ObjectDir)
  527. {
  528. if(variable == "OBJECT_DIR")
  529. {
  530. return replaceValues.ObjectDir;
  531. }
  532. }
  533. if(replaceValues.ObjectFileDir)
  534. {
  535. if(variable == "OBJECT_FILE_DIR")
  536. {
  537. return replaceValues.ObjectFileDir;
  538. }
  539. }
  540. if(replaceValues.Objects)
  541. {
  542. if(variable == "OBJECTS")
  543. {
  544. return replaceValues.Objects;
  545. }
  546. }
  547. if(replaceValues.ObjectsQuoted)
  548. {
  549. if(variable == "OBJECTS_QUOTED")
  550. {
  551. return replaceValues.ObjectsQuoted;
  552. }
  553. }
  554. if(replaceValues.Defines && variable == "DEFINES")
  555. {
  556. return replaceValues.Defines;
  557. }
  558. if(replaceValues.Includes && variable == "INCLUDES")
  559. {
  560. return replaceValues.Includes;
  561. }
  562. if(replaceValues.TargetPDB )
  563. {
  564. if(variable == "TARGET_PDB")
  565. {
  566. return replaceValues.TargetPDB;
  567. }
  568. }
  569. if(replaceValues.TargetCompilePDB)
  570. {
  571. if(variable == "TARGET_COMPILE_PDB")
  572. {
  573. return replaceValues.TargetCompilePDB;
  574. }
  575. }
  576. if(replaceValues.DependencyFile )
  577. {
  578. if(variable == "DEP_FILE")
  579. {
  580. return replaceValues.DependencyFile;
  581. }
  582. }
  583. if(replaceValues.Target)
  584. {
  585. if(variable == "TARGET_QUOTED")
  586. {
  587. std::string targetQuoted = replaceValues.Target;
  588. if(!targetQuoted.empty() && targetQuoted[0] != '\"')
  589. {
  590. targetQuoted = '\"';
  591. targetQuoted += replaceValues.Target;
  592. targetQuoted += '\"';
  593. }
  594. return targetQuoted;
  595. }
  596. if(variable == "TARGET_UNQUOTED")
  597. {
  598. std::string unquoted = replaceValues.Target;
  599. std::string::size_type sz = unquoted.size();
  600. if(sz > 2 && unquoted[0] == '\"' && unquoted[sz-1] == '\"')
  601. {
  602. unquoted = unquoted.substr(1, sz-2);
  603. }
  604. return unquoted;
  605. }
  606. if(replaceValues.LanguageCompileFlags)
  607. {
  608. if(variable == "LANGUAGE_COMPILE_FLAGS")
  609. {
  610. return replaceValues.LanguageCompileFlags;
  611. }
  612. }
  613. if(replaceValues.Target)
  614. {
  615. if(variable == "TARGET")
  616. {
  617. return replaceValues.Target;
  618. }
  619. }
  620. if(variable == "TARGET_IMPLIB")
  621. {
  622. return this->TargetImplib;
  623. }
  624. if(variable == "TARGET_VERSION_MAJOR")
  625. {
  626. if(replaceValues.TargetVersionMajor)
  627. {
  628. return replaceValues.TargetVersionMajor;
  629. }
  630. else
  631. {
  632. return "0";
  633. }
  634. }
  635. if(variable == "TARGET_VERSION_MINOR")
  636. {
  637. if(replaceValues.TargetVersionMinor)
  638. {
  639. return replaceValues.TargetVersionMinor;
  640. }
  641. else
  642. {
  643. return "0";
  644. }
  645. }
  646. if(replaceValues.Target)
  647. {
  648. if(variable == "TARGET_BASE")
  649. {
  650. // Strip the last extension off the target name.
  651. std::string targetBase = replaceValues.Target;
  652. std::string::size_type pos = targetBase.rfind(".");
  653. if(pos != targetBase.npos)
  654. {
  655. return targetBase.substr(0, pos);
  656. }
  657. else
  658. {
  659. return targetBase;
  660. }
  661. }
  662. }
  663. }
  664. if(variable == "TARGET_SONAME" || variable == "SONAME_FLAG" ||
  665. variable == "TARGET_INSTALLNAME_DIR")
  666. {
  667. // All these variables depend on TargetSOName
  668. if(replaceValues.TargetSOName)
  669. {
  670. if(variable == "TARGET_SONAME")
  671. {
  672. return replaceValues.TargetSOName;
  673. }
  674. if(variable == "SONAME_FLAG" && replaceValues.SONameFlag)
  675. {
  676. return replaceValues.SONameFlag;
  677. }
  678. if(replaceValues.TargetInstallNameDir &&
  679. variable == "TARGET_INSTALLNAME_DIR")
  680. {
  681. return replaceValues.TargetInstallNameDir;
  682. }
  683. }
  684. return "";
  685. }
  686. if(replaceValues.LinkLibraries)
  687. {
  688. if(variable == "LINK_LIBRARIES")
  689. {
  690. return replaceValues.LinkLibraries;
  691. }
  692. }
  693. if(replaceValues.Language)
  694. {
  695. if(variable == "LANGUAGE")
  696. {
  697. return replaceValues.Language;
  698. }
  699. }
  700. if(replaceValues.CMTarget)
  701. {
  702. if(variable == "TARGET_NAME")
  703. {
  704. return replaceValues.CMTarget->GetName();
  705. }
  706. if(variable == "TARGET_TYPE")
  707. {
  708. return cmTarget::GetTargetTypeName(replaceValues.CMTarget->GetType());
  709. }
  710. }
  711. if(replaceValues.Output)
  712. {
  713. if(variable == "OUTPUT")
  714. {
  715. return replaceValues.Output;
  716. }
  717. }
  718. if(variable == "CMAKE_COMMAND")
  719. {
  720. return this->Convert(cmSystemTools::GetCMakeCommand(), FULL, SHELL);
  721. }
  722. std::vector<std::string> enabledLanguages =
  723. this->GetState()->GetEnabledLanguages();
  724. // loop over language specific replace variables
  725. int pos = 0;
  726. while(ruleReplaceVars[pos])
  727. {
  728. for(std::vector<std::string>::iterator i = enabledLanguages.begin();
  729. i != enabledLanguages.end(); ++i)
  730. {
  731. const char* lang = i->c_str();
  732. std::string actualReplace = ruleReplaceVars[pos];
  733. // If this is the compiler then look for the extra variable
  734. // _COMPILER_ARG1 which must be the first argument to the compiler
  735. const char* compilerArg1 = 0;
  736. const char* compilerTarget = 0;
  737. const char* compilerOptionTarget = 0;
  738. const char* compilerExternalToolchain = 0;
  739. const char* compilerOptionExternalToolchain = 0;
  740. const char* compilerSysroot = 0;
  741. const char* compilerOptionSysroot = 0;
  742. if(actualReplace == "CMAKE_${LANG}_COMPILER")
  743. {
  744. std::string arg1 = actualReplace + "_ARG1";
  745. cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
  746. compilerArg1 = this->Makefile->GetDefinition(arg1);
  747. compilerTarget
  748. = this->Makefile->GetDefinition(
  749. std::string("CMAKE_") + lang + "_COMPILER_TARGET");
  750. compilerOptionTarget
  751. = this->Makefile->GetDefinition(
  752. std::string("CMAKE_") + lang +
  753. "_COMPILE_OPTIONS_TARGET");
  754. compilerExternalToolchain
  755. = this->Makefile->GetDefinition(
  756. std::string("CMAKE_") + lang +
  757. "_COMPILER_EXTERNAL_TOOLCHAIN");
  758. compilerOptionExternalToolchain
  759. = this->Makefile->GetDefinition(
  760. std::string("CMAKE_") + lang +
  761. "_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN");
  762. compilerSysroot
  763. = this->Makefile->GetDefinition("CMAKE_SYSROOT");
  764. compilerOptionSysroot
  765. = this->Makefile->GetDefinition(
  766. std::string("CMAKE_") + lang +
  767. "_COMPILE_OPTIONS_SYSROOT");
  768. }
  769. if(actualReplace.find("${LANG}") != actualReplace.npos)
  770. {
  771. cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
  772. }
  773. if(actualReplace == variable)
  774. {
  775. std::string replace =
  776. this->Makefile->GetSafeDefinition(variable);
  777. // if the variable is not a FLAG then treat it like a path
  778. if(variable.find("_FLAG") == variable.npos)
  779. {
  780. std::string ret = this->ConvertToOutputForExisting(replace);
  781. // if there is a required first argument to the compiler add it
  782. // to the compiler string
  783. if(compilerArg1)
  784. {
  785. ret += " ";
  786. ret += compilerArg1;
  787. }
  788. if (compilerTarget && compilerOptionTarget)
  789. {
  790. ret += " ";
  791. ret += compilerOptionTarget;
  792. ret += compilerTarget;
  793. }
  794. if (compilerExternalToolchain && compilerOptionExternalToolchain)
  795. {
  796. ret += " ";
  797. ret += compilerOptionExternalToolchain;
  798. ret += this->EscapeForShell(compilerExternalToolchain, true);
  799. }
  800. if (compilerSysroot && compilerOptionSysroot)
  801. {
  802. ret += " ";
  803. ret += compilerOptionSysroot;
  804. ret += this->EscapeForShell(compilerSysroot, true);
  805. }
  806. return ret;
  807. }
  808. return replace;
  809. }
  810. }
  811. pos++;
  812. }
  813. return variable;
  814. }
  815. void
  816. cmLocalGenerator::ExpandRuleVariables(std::string& s,
  817. const RuleVariables& replaceValues)
  818. {
  819. if(replaceValues.RuleLauncher)
  820. {
  821. this->InsertRuleLauncher(s, replaceValues.CMTarget,
  822. replaceValues.RuleLauncher);
  823. }
  824. std::string::size_type start = s.find('<');
  825. // no variables to expand
  826. if(start == s.npos)
  827. {
  828. return;
  829. }
  830. std::string::size_type pos = 0;
  831. std::string expandedInput;
  832. while(start != s.npos && start < s.size()-2)
  833. {
  834. std::string::size_type end = s.find('>', start);
  835. // if we find a < with no > we are done
  836. if(end == s.npos)
  837. {
  838. return;
  839. }
  840. char c = s[start+1];
  841. // if the next char after the < is not A-Za-z then
  842. // skip it and try to find the next < in the string
  843. if(!isalpha(c))
  844. {
  845. start = s.find('<', start+1);
  846. }
  847. else
  848. {
  849. // extract the var
  850. std::string var = s.substr(start+1, end - start-1);
  851. std::string replace = this->ExpandRuleVariable(var,
  852. replaceValues);
  853. expandedInput += s.substr(pos, start-pos);
  854. expandedInput += replace;
  855. // move to next one
  856. start = s.find('<', start+var.size()+2);
  857. pos = end+1;
  858. }
  859. }
  860. // add the rest of the input
  861. expandedInput += s.substr(pos, s.size()-pos);
  862. s = expandedInput;
  863. }
  864. //----------------------------------------------------------------------------
  865. const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target,
  866. const std::string& prop)
  867. {
  868. if(target)
  869. {
  870. return target->GetProperty(prop);
  871. }
  872. else
  873. {
  874. return this->Makefile->GetProperty(prop);
  875. }
  876. }
  877. //----------------------------------------------------------------------------
  878. void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target,
  879. const std::string& prop)
  880. {
  881. if(const char* val = this->GetRuleLauncher(target, prop))
  882. {
  883. std::ostringstream wrapped;
  884. wrapped << val << " " << s;
  885. s = wrapped.str();
  886. }
  887. }
  888. //----------------------------------------------------------------------------
  889. std::string
  890. cmLocalGenerator::ConvertToIncludeReference(std::string const& path,
  891. OutputFormat format,
  892. bool forceFullPaths)
  893. {
  894. return this->ConvertToOutputForExisting(
  895. path, forceFullPaths? FULL : START_OUTPUT, format);
  896. }
  897. //----------------------------------------------------------------------------
  898. std::string cmLocalGenerator::GetIncludeFlags(
  899. const std::vector<std::string> &includes,
  900. cmGeneratorTarget* target,
  901. const std::string& lang,
  902. bool forceFullPaths,
  903. bool forResponseFile,
  904. const std::string& config)
  905. {
  906. if(lang.empty())
  907. {
  908. return "";
  909. }
  910. OutputFormat shellFormat = forResponseFile? RESPONSE : SHELL;
  911. std::ostringstream includeFlags;
  912. std::string flagVar = "CMAKE_INCLUDE_FLAG_";
  913. flagVar += lang;
  914. const char* includeFlag =
  915. this->Makefile->GetSafeDefinition(flagVar);
  916. flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
  917. flagVar += lang;
  918. const char* sep = this->Makefile->GetDefinition(flagVar);
  919. bool quotePaths = false;
  920. if(this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
  921. {
  922. quotePaths = true;
  923. }
  924. bool repeatFlag = true;
  925. // should the include flag be repeated like ie. -IA -IB
  926. if(!sep)
  927. {
  928. sep = " ";
  929. }
  930. else
  931. {
  932. // if there is a separator then the flag is not repeated but is only
  933. // given once i.e. -classpath a:b:c
  934. repeatFlag = false;
  935. }
  936. // Support special system include flag if it is available and the
  937. // normal flag is repeated for each directory.
  938. std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
  939. sysFlagVar += lang;
  940. const char* sysIncludeFlag = 0;
  941. if(repeatFlag)
  942. {
  943. sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar);
  944. }
  945. std::string fwSearchFlagVar = "CMAKE_";
  946. fwSearchFlagVar += lang;
  947. fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
  948. const char* fwSearchFlag =
  949. this->Makefile->GetDefinition(fwSearchFlagVar);
  950. std::string sysFwSearchFlagVar = "CMAKE_";
  951. sysFwSearchFlagVar += lang;
  952. sysFwSearchFlagVar += "_SYSTEM_FRAMEWORK_SEARCH_FLAG";
  953. const char* sysFwSearchFlag =
  954. this->Makefile->GetDefinition(sysFwSearchFlagVar);
  955. bool flagUsed = false;
  956. std::set<std::string> emitted;
  957. #ifdef __APPLE__
  958. emitted.insert("/System/Library/Frameworks");
  959. #endif
  960. std::vector<std::string>::const_iterator i;
  961. for(i = includes.begin(); i != includes.end(); ++i)
  962. {
  963. if(fwSearchFlag && *fwSearchFlag && this->Makefile->IsOn("APPLE")
  964. && cmSystemTools::IsPathToFramework(i->c_str()))
  965. {
  966. std::string frameworkDir = *i;
  967. frameworkDir += "/../";
  968. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
  969. if(emitted.insert(frameworkDir).second)
  970. {
  971. if (sysFwSearchFlag && target &&
  972. target->IsSystemIncludeDirectory(*i, config))
  973. {
  974. includeFlags << sysFwSearchFlag;
  975. }
  976. else
  977. {
  978. includeFlags << fwSearchFlag;
  979. }
  980. includeFlags << this->ConvertToOutputFormat(frameworkDir, shellFormat)
  981. << " ";
  982. }
  983. continue;
  984. }
  985. if(!flagUsed || repeatFlag)
  986. {
  987. if(sysIncludeFlag && target &&
  988. target->IsSystemIncludeDirectory(*i, config))
  989. {
  990. includeFlags << sysIncludeFlag;
  991. }
  992. else
  993. {
  994. includeFlags << includeFlag;
  995. }
  996. flagUsed = true;
  997. }
  998. std::string includePath =
  999. this->ConvertToIncludeReference(*i, shellFormat, forceFullPaths);
  1000. if(quotePaths && !includePath.empty() && includePath[0] != '\"')
  1001. {
  1002. includeFlags << "\"";
  1003. }
  1004. includeFlags << includePath;
  1005. if(quotePaths && !includePath.empty() && includePath[0] != '\"')
  1006. {
  1007. includeFlags << "\"";
  1008. }
  1009. includeFlags << sep;
  1010. }
  1011. std::string flags = includeFlags.str();
  1012. // remove trailing separators
  1013. if((sep[0] != ' ') && !flags.empty() && flags[flags.size()-1] == sep[0])
  1014. {
  1015. flags[flags.size()-1] = ' ';
  1016. }
  1017. return flags;
  1018. }
  1019. //----------------------------------------------------------------------------
  1020. void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines,
  1021. cmTarget const* target,
  1022. const std::string& config,
  1023. const std::string& lang)
  1024. {
  1025. std::vector<std::string> targetDefines;
  1026. cmGeneratorTarget* gtgt = this->GlobalGenerator->GetGeneratorTarget(target);
  1027. gtgt->GetCompileDefinitions(targetDefines, config, lang);
  1028. this->AppendDefines(defines, targetDefines);
  1029. }
  1030. //----------------------------------------------------------------------------
  1031. void cmLocalGenerator::AddCompileOptions(
  1032. std::string& flags, cmTarget* target,
  1033. const std::string& lang, const std::string& config
  1034. )
  1035. {
  1036. std::string langFlagRegexVar = std::string("CMAKE_")+lang+"_FLAG_REGEX";
  1037. cmGeneratorTarget* gtgt =
  1038. this->GlobalGenerator->GetGeneratorTarget(target);
  1039. if(const char* langFlagRegexStr =
  1040. this->Makefile->GetDefinition(langFlagRegexVar))
  1041. {
  1042. // Filter flags acceptable to this language.
  1043. cmsys::RegularExpression r(langFlagRegexStr);
  1044. std::vector<std::string> opts;
  1045. if(const char* targetFlags = target->GetProperty("COMPILE_FLAGS"))
  1046. {
  1047. cmSystemTools::ParseWindowsCommandLine(targetFlags, opts);
  1048. }
  1049. gtgt->GetCompileOptions(opts, config, lang);
  1050. for(std::vector<std::string>::const_iterator i = opts.begin();
  1051. i != opts.end(); ++i)
  1052. {
  1053. if(r.find(i->c_str()))
  1054. {
  1055. // (Re-)Escape this flag. COMPILE_FLAGS were already parsed
  1056. // as a command line above, and COMPILE_OPTIONS are escaped.
  1057. this->AppendFlagEscape(flags, *i);
  1058. }
  1059. }
  1060. }
  1061. else
  1062. {
  1063. // Use all flags.
  1064. if(const char* targetFlags = target->GetProperty("COMPILE_FLAGS"))
  1065. {
  1066. // COMPILE_FLAGS are not escaped for historical reasons.
  1067. this->AppendFlags(flags, targetFlags);
  1068. }
  1069. std::vector<std::string> opts;
  1070. gtgt->GetCompileOptions(opts, config, lang);
  1071. for(std::vector<std::string>::const_iterator i = opts.begin();
  1072. i != opts.end(); ++i)
  1073. {
  1074. // COMPILE_OPTIONS are escaped.
  1075. this->AppendFlagEscape(flags, *i);
  1076. }
  1077. }
  1078. std::vector<std::string> features;
  1079. gtgt->GetCompileFeatures(features, config);
  1080. for(std::vector<std::string>::const_iterator it = features.begin();
  1081. it != features.end(); ++it)
  1082. {
  1083. if (!this->Makefile->AddRequiredTargetFeature(target, *it))
  1084. {
  1085. return;
  1086. }
  1087. }
  1088. for(std::map<std::string, std::string>::const_iterator it
  1089. = target->GetMaxLanguageStandards().begin();
  1090. it != target->GetMaxLanguageStandards().end(); ++it)
  1091. {
  1092. const char* standard = target->GetProperty(it->first + "_STANDARD");
  1093. if(!standard)
  1094. {
  1095. continue;
  1096. }
  1097. if (this->Makefile->IsLaterStandard(it->first, standard, it->second))
  1098. {
  1099. std::ostringstream e;
  1100. e << "The COMPILE_FEATURES property of target \""
  1101. << target->GetName() << "\" was evaluated when computing the link "
  1102. "implementation, and the \"" << it->first << "_STANDARD\" was \""
  1103. << it->second << "\" for that computation. Computing the "
  1104. "COMPILE_FEATURES based on the link implementation resulted in a "
  1105. "higher \"" << it->first << "_STANDARD\" \"" << standard << "\". "
  1106. "This is not permitted. The COMPILE_FEATURES may not both depend on "
  1107. "and be depended on by the link implementation." << std::endl;
  1108. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  1109. return;
  1110. }
  1111. }
  1112. this->AddCompilerRequirementFlag(flags, target, lang);
  1113. }
  1114. //----------------------------------------------------------------------------
  1115. void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
  1116. cmGeneratorTarget* target,
  1117. const std::string& lang,
  1118. const std::string& config,
  1119. bool stripImplicitInclDirs
  1120. ) const
  1121. {
  1122. // Need to decide whether to automatically include the source and
  1123. // binary directories at the beginning of the include path.
  1124. bool includeSourceDir = false;
  1125. bool includeBinaryDir = false;
  1126. // When automatic include directories are requested for a build then
  1127. // include the source and binary directories at the beginning of the
  1128. // include path to approximate include file behavior for an
  1129. // in-source build. This does not account for the case of a source
  1130. // file in a subdirectory of the current source directory but we
  1131. // cannot fix this because not all native build tools support
  1132. // per-source-file include paths.
  1133. if(this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
  1134. {
  1135. includeSourceDir = true;
  1136. includeBinaryDir = true;
  1137. }
  1138. // Do not repeat an include path.
  1139. std::set<std::string> emitted;
  1140. // Store the automatic include paths.
  1141. if(includeBinaryDir)
  1142. {
  1143. std::string binDir = this->StateSnapshot.GetDirectory().GetCurrentBinary();
  1144. if(emitted.find(binDir) == emitted.end())
  1145. {
  1146. dirs.push_back(binDir);
  1147. emitted.insert(binDir);
  1148. }
  1149. }
  1150. if(includeSourceDir)
  1151. {
  1152. std::string srcDir = this->StateSnapshot.GetDirectory().GetCurrentSource();
  1153. if(emitted.find(srcDir) == emitted.end())
  1154. {
  1155. dirs.push_back(srcDir);
  1156. emitted.insert(srcDir);
  1157. }
  1158. }
  1159. if(!target)
  1160. {
  1161. return;
  1162. }
  1163. std::string rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
  1164. std::vector<std::string> implicitDirs;
  1165. // Load implicit include directories for this language.
  1166. std::string impDirVar = "CMAKE_";
  1167. impDirVar += lang;
  1168. impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES";
  1169. if(const char* value = this->Makefile->GetDefinition(impDirVar))
  1170. {
  1171. std::vector<std::string> impDirVec;
  1172. cmSystemTools::ExpandListArgument(value, impDirVec);
  1173. for(std::vector<std::string>::const_iterator i = impDirVec.begin();
  1174. i != impDirVec.end(); ++i)
  1175. {
  1176. std::string d = rootPath + *i;
  1177. cmSystemTools::ConvertToUnixSlashes(d);
  1178. emitted.insert(d);
  1179. if (!stripImplicitInclDirs)
  1180. {
  1181. implicitDirs.push_back(*i);
  1182. }
  1183. }
  1184. }
  1185. // Get the target-specific include directories.
  1186. std::vector<std::string> includes;
  1187. includes = target->GetIncludeDirectories(config, lang);
  1188. // Support putting all the in-project include directories first if
  1189. // it is requested by the project.
  1190. if(this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
  1191. {
  1192. const char* topSourceDir = this->GetState()->GetSourceDirectory();
  1193. const char* topBinaryDir = this->GetState()->GetBinaryDirectory();
  1194. for(std::vector<std::string>::const_iterator i = includes.begin();
  1195. i != includes.end(); ++i)
  1196. {
  1197. // Emit this directory only if it is a subdirectory of the
  1198. // top-level source or binary tree.
  1199. if(cmSystemTools::ComparePath(*i, topSourceDir) ||
  1200. cmSystemTools::ComparePath(*i, topBinaryDir) ||
  1201. cmSystemTools::IsSubDirectory(*i, topSourceDir) ||
  1202. cmSystemTools::IsSubDirectory(*i, topBinaryDir))
  1203. {
  1204. if(emitted.insert(*i).second)
  1205. {
  1206. dirs.push_back(*i);
  1207. }
  1208. }
  1209. }
  1210. }
  1211. // Construct the final ordered include directory list.
  1212. for(std::vector<std::string>::const_iterator i = includes.begin();
  1213. i != includes.end(); ++i)
  1214. {
  1215. if(emitted.insert(*i).second)
  1216. {
  1217. dirs.push_back(*i);
  1218. }
  1219. }
  1220. for(std::vector<std::string>::const_iterator i = implicitDirs.begin();
  1221. i != implicitDirs.end(); ++i)
  1222. {
  1223. if(std::find(includes.begin(), includes.end(), *i) != includes.end())
  1224. {
  1225. dirs.push_back(*i);
  1226. }
  1227. }
  1228. }
  1229. void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
  1230. std::string const& config,
  1231. cmTarget* target)
  1232. {
  1233. this->AppendFlags(flags,
  1234. this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS"));
  1235. if(!config.empty())
  1236. {
  1237. std::string name = "CMAKE_STATIC_LINKER_FLAGS_" + config;
  1238. this->AppendFlags(flags, this->Makefile->GetSafeDefinition(name));
  1239. }
  1240. this->AppendFlags(flags, target->GetProperty("STATIC_LIBRARY_FLAGS"));
  1241. if(!config.empty())
  1242. {
  1243. std::string name = "STATIC_LIBRARY_FLAGS_" + config;
  1244. this->AppendFlags(flags, target->GetProperty(name));
  1245. }
  1246. }
  1247. void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
  1248. std::string& flags,
  1249. std::string& linkFlags,
  1250. std::string& frameworkPath,
  1251. std::string& linkPath,
  1252. cmGeneratorTarget* target,
  1253. bool useWatcomQuote)
  1254. {
  1255. std::string buildType =
  1256. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1257. buildType = cmSystemTools::UpperCase(buildType);
  1258. const char* libraryLinkVariable =
  1259. "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
  1260. switch(target->GetType())
  1261. {
  1262. case cmTarget::STATIC_LIBRARY:
  1263. this->GetStaticLibraryFlags(linkFlags, buildType, target->Target);
  1264. break;
  1265. case cmTarget::MODULE_LIBRARY:
  1266. libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
  1267. case cmTarget::SHARED_LIBRARY:
  1268. {
  1269. linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
  1270. linkFlags += " ";
  1271. if(!buildType.empty())
  1272. {
  1273. std::string build = libraryLinkVariable;
  1274. build += "_";
  1275. build += buildType;
  1276. linkFlags += this->Makefile->GetSafeDefinition(build);
  1277. linkFlags += " ";
  1278. }
  1279. if(this->Makefile->IsOn("WIN32") &&
  1280. !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
  1281. {
  1282. std::vector<cmSourceFile*> sources;
  1283. target->GetSourceFiles(sources, buildType);
  1284. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1285. i != sources.end(); ++i)
  1286. {
  1287. cmSourceFile* sf = *i;
  1288. if(sf->GetExtension() == "def")
  1289. {
  1290. linkFlags +=
  1291. this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1292. linkFlags += this->Convert(sf->GetFullPath(),
  1293. FULL, SHELL);
  1294. linkFlags += " ";
  1295. }
  1296. }
  1297. }
  1298. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  1299. if(targetLinkFlags)
  1300. {
  1301. linkFlags += targetLinkFlags;
  1302. linkFlags += " ";
  1303. }
  1304. if(!buildType.empty())
  1305. {
  1306. std::string configLinkFlags = "LINK_FLAGS_";
  1307. configLinkFlags += buildType;
  1308. targetLinkFlags = target->GetProperty(configLinkFlags);
  1309. if(targetLinkFlags)
  1310. {
  1311. linkFlags += targetLinkFlags;
  1312. linkFlags += " ";
  1313. }
  1314. }
  1315. this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
  1316. *target, false, false, useWatcomQuote);
  1317. }
  1318. break;
  1319. case cmTarget::EXECUTABLE:
  1320. {
  1321. linkFlags +=
  1322. this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1323. linkFlags += " ";
  1324. if(!buildType.empty())
  1325. {
  1326. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1327. build += buildType;
  1328. linkFlags += this->Makefile->GetSafeDefinition(build);
  1329. linkFlags += " ";
  1330. }
  1331. std::string linkLanguage = target->GetLinkerLanguage(buildType);
  1332. if(linkLanguage.empty())
  1333. {
  1334. cmSystemTools::Error
  1335. ("CMake can not determine linker language for target: ",
  1336. target->Target->GetName().c_str());
  1337. return;
  1338. }
  1339. this->AddLanguageFlags(flags, linkLanguage, buildType);
  1340. this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
  1341. *target, false, false, useWatcomQuote);
  1342. if(cmSystemTools::IsOn
  1343. (this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1344. {
  1345. std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_")
  1346. + linkLanguage + std::string("_FLAGS");
  1347. linkFlags += this->Makefile->GetSafeDefinition(sFlagVar);
  1348. linkFlags += " ";
  1349. }
  1350. if ( target->GetPropertyAsBool("WIN32_EXECUTABLE") )
  1351. {
  1352. linkFlags +=
  1353. this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1354. linkFlags += " ";
  1355. }
  1356. else
  1357. {
  1358. linkFlags +=
  1359. this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1360. linkFlags += " ";
  1361. }
  1362. if (target->Target->IsExecutableWithExports())
  1363. {
  1364. std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
  1365. exportFlagVar += linkLanguage;
  1366. exportFlagVar += "_FLAG";
  1367. linkFlags +=
  1368. this->Makefile->GetSafeDefinition(exportFlagVar);
  1369. linkFlags += " ";
  1370. }
  1371. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  1372. if(targetLinkFlags)
  1373. {
  1374. linkFlags += targetLinkFlags;
  1375. linkFlags += " ";
  1376. }
  1377. if(!buildType.empty())
  1378. {
  1379. std::string configLinkFlags = "LINK_FLAGS_";
  1380. configLinkFlags += buildType;
  1381. targetLinkFlags = target->GetProperty(configLinkFlags);
  1382. if(targetLinkFlags)
  1383. {
  1384. linkFlags += targetLinkFlags;
  1385. linkFlags += " ";
  1386. }
  1387. }
  1388. }
  1389. break;
  1390. default:
  1391. break;
  1392. }
  1393. }
  1394. std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib,
  1395. OutputFormat format)
  1396. {
  1397. #if defined(_WIN32) && !defined(__CYGWIN__)
  1398. // Work-ardound command line parsing limitations in MSVC 6.0
  1399. if(this->Makefile->IsOn("MSVC60"))
  1400. {
  1401. // Search for the last space.
  1402. std::string::size_type pos = lib.rfind(' ');
  1403. if(pos != lib.npos)
  1404. {
  1405. // Find the slash after the last space, if any.
  1406. pos = lib.find('/', pos);
  1407. // Convert the portion of the path with a space to a short path.
  1408. std::string sp;
  1409. if(cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp))
  1410. {
  1411. // Append the rest of the path with no space.
  1412. sp += lib.substr(pos);
  1413. // Convert to an output path.
  1414. return this->Convert(sp.c_str(), NONE, format);
  1415. }
  1416. }
  1417. }
  1418. #endif
  1419. // Normal behavior.
  1420. return this->Convert(lib, START_OUTPUT, format);
  1421. }
  1422. /**
  1423. * Output the linking rules on a command line. For executables,
  1424. * targetLibrary should be a NULL pointer. For libraries, it should point
  1425. * to the name of the library. This will not link a library against itself.
  1426. */
  1427. void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
  1428. std::string& frameworkPath,
  1429. std::string& linkPath,
  1430. cmGeneratorTarget &tgt,
  1431. bool relink,
  1432. bool forResponseFile,
  1433. bool useWatcomQuote)
  1434. {
  1435. OutputFormat shellFormat = (forResponseFile) ? RESPONSE :
  1436. ((useWatcomQuote) ? WATCOMQUOTE : SHELL);
  1437. bool escapeAllowMakeVars = !forResponseFile;
  1438. std::ostringstream fout;
  1439. std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1440. cmComputeLinkInformation* pcli = tgt.GetLinkInformation(config);
  1441. if(!pcli)
  1442. {
  1443. return;
  1444. }
  1445. cmComputeLinkInformation& cli = *pcli;
  1446. // Collect library linking flags command line options.
  1447. std::string linkLibs;
  1448. std::string linkLanguage = cli.GetLinkLanguage();
  1449. std::string libPathFlag =
  1450. this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
  1451. std::string libPathTerminator =
  1452. this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
  1453. // Flags to link an executable to shared libraries.
  1454. std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
  1455. linkFlagsVar += linkLanguage;
  1456. linkFlagsVar += "_FLAGS";
  1457. if( tgt.GetType() == cmTarget::EXECUTABLE )
  1458. {
  1459. linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar);
  1460. linkLibs += " ";
  1461. }
  1462. // Append the framework search path flags.
  1463. std::string fwSearchFlagVar = "CMAKE_";
  1464. fwSearchFlagVar += linkLanguage;
  1465. fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
  1466. const char* fwSearchFlag =
  1467. this->Makefile->GetDefinition(fwSearchFlagVar);
  1468. if(fwSearchFlag && *fwSearchFlag)
  1469. {
  1470. std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
  1471. for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
  1472. fdi != fwDirs.end(); ++fdi)
  1473. {
  1474. frameworkPath += fwSearchFlag;
  1475. frameworkPath += this->Convert(*fdi, NONE, shellFormat);
  1476. frameworkPath += " ";
  1477. }
  1478. }
  1479. // Append the library search path flags.
  1480. std::vector<std::string> const& libDirs = cli.GetDirectories();
  1481. for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
  1482. libDir != libDirs.end(); ++libDir)
  1483. {
  1484. std::string libpath = this->ConvertToOutputForExisting(*libDir,
  1485. START_OUTPUT,
  1486. shellFormat);
  1487. linkPath += " " + libPathFlag;
  1488. linkPath += libpath;
  1489. linkPath += libPathTerminator;
  1490. linkPath += " ";
  1491. }
  1492. // Append the link items.
  1493. typedef cmComputeLinkInformation::ItemVector ItemVector;
  1494. ItemVector const& items = cli.GetItems();
  1495. for(ItemVector::const_iterator li = items.begin(); li != items.end(); ++li)
  1496. {
  1497. if(li->Target && li->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  1498. {
  1499. continue;
  1500. }
  1501. if(li->IsPath)
  1502. {
  1503. linkLibs += this->ConvertToLinkReference(li->Value, shellFormat);
  1504. }
  1505. else
  1506. {
  1507. linkLibs += li->Value;
  1508. }
  1509. linkLibs += " ";
  1510. }
  1511. // Write the library flags to the build rule.
  1512. fout << linkLibs;
  1513. // Check what kind of rpath flags to use.
  1514. if(cli.GetRuntimeSep().empty())
  1515. {
  1516. // Each rpath entry gets its own option ("-R a -R b -R c")
  1517. std::vector<std::string> runtimeDirs;
  1518. cli.GetRPath(runtimeDirs, relink);
  1519. std::string rpath;
  1520. for(std::vector<std::string>::iterator ri = runtimeDirs.begin();
  1521. ri != runtimeDirs.end(); ++ri)
  1522. {
  1523. rpath += cli.GetRuntimeFlag();
  1524. rpath += this->Convert(*ri, NONE, shellFormat);
  1525. rpath += " ";
  1526. }
  1527. fout << rpath;
  1528. }
  1529. else
  1530. {
  1531. // All rpath entries are combined ("-Wl,-rpath,a:b:c").
  1532. std::string rpath = cli.GetRPathString(relink);
  1533. // Store the rpath option in the stream.
  1534. if(!rpath.empty())
  1535. {
  1536. fout << cli.GetRuntimeFlag();
  1537. fout << this->EscapeForShell(rpath, escapeAllowMakeVars);
  1538. fout << " ";
  1539. }
  1540. }
  1541. // Add the linker runtime search path if any.
  1542. std::string rpath_link = cli.GetRPathLinkString();
  1543. if(!cli.GetRPathLinkFlag().empty() && !rpath_link.empty())
  1544. {
  1545. fout << cli.GetRPathLinkFlag();
  1546. fout << this->EscapeForShell(rpath_link, escapeAllowMakeVars);
  1547. fout << " ";
  1548. }
  1549. // Add standard libraries for this language.
  1550. std::string standardLibsVar = "CMAKE_";
  1551. standardLibsVar += cli.GetLinkLanguage();
  1552. standardLibsVar += "_STANDARD_LIBRARIES";
  1553. if(const char* stdLibs =
  1554. this->Makefile->GetDefinition(standardLibsVar))
  1555. {
  1556. fout << stdLibs << " ";
  1557. }
  1558. linkLibraries = fout.str();
  1559. }
  1560. //----------------------------------------------------------------------------
  1561. void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
  1562. cmGeneratorTarget const* target,
  1563. const std::string& lang,
  1564. const std::string& config)
  1565. {
  1566. // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone):
  1567. if(!this->Makefile->IsOn("APPLE"))
  1568. {
  1569. return;
  1570. }
  1571. if(this->EmitUniversalBinaryFlags)
  1572. {
  1573. std::vector<std::string> archs;
  1574. target->GetAppleArchs(config, archs);
  1575. const char* sysroot = this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
  1576. if(sysroot && sysroot[0] == '/' && !sysroot[1])
  1577. { sysroot = 0; }
  1578. std::string sysrootFlagVar =
  1579. std::string("CMAKE_") + lang + "_SYSROOT_FLAG";
  1580. const char* sysrootFlag =
  1581. this->Makefile->GetDefinition(sysrootFlagVar);
  1582. const char* deploymentTarget =
  1583. this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
  1584. std::string deploymentTargetFlagVar =
  1585. std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG";
  1586. const char* deploymentTargetFlag =
  1587. this->Makefile->GetDefinition(deploymentTargetFlagVar);
  1588. if(!archs.empty() && !lang.empty() && (lang[0] =='C' || lang[0] == 'F'))
  1589. {
  1590. for(std::vector<std::string>::iterator i = archs.begin();
  1591. i != archs.end(); ++i)
  1592. {
  1593. flags += " -arch ";
  1594. flags += *i;
  1595. }
  1596. }
  1597. if(sysrootFlag && *sysrootFlag && sysroot && *sysroot)
  1598. {
  1599. flags += " ";
  1600. flags += sysrootFlag;
  1601. flags += " ";
  1602. flags += this->Convert(sysroot, NONE, SHELL);
  1603. }
  1604. if (deploymentTargetFlag && *deploymentTargetFlag &&
  1605. deploymentTarget && *deploymentTarget)
  1606. {
  1607. flags += " ";
  1608. flags += deploymentTargetFlag;
  1609. flags += deploymentTarget;
  1610. }
  1611. }
  1612. }
  1613. //----------------------------------------------------------------------------
  1614. void cmLocalGenerator::AddLanguageFlags(std::string& flags,
  1615. const std::string& lang,
  1616. const std::string& config)
  1617. {
  1618. // Add language-specific flags.
  1619. std::string flagsVar = "CMAKE_";
  1620. flagsVar += lang;
  1621. flagsVar += "_FLAGS";
  1622. this->AddConfigVariableFlags(flags, flagsVar, config);
  1623. }
  1624. //----------------------------------------------------------------------------
  1625. bool cmLocalGenerator::GetRealDependency(const std::string& inName,
  1626. const std::string& config,
  1627. std::string& dep)
  1628. {
  1629. // Older CMake code may specify the dependency using the target
  1630. // output file rather than the target name. Such code would have
  1631. // been written before there was support for target properties that
  1632. // modify the name so stripping down to just the file name should
  1633. // produce the target name in this case.
  1634. std::string name = cmSystemTools::GetFilenameName(inName);
  1635. // If the input name is the empty string, there is no real
  1636. // dependency. Short-circuit the other checks:
  1637. if(name == "")
  1638. {
  1639. return false;
  1640. }
  1641. if(cmSystemTools::GetFilenameLastExtension(name) == ".exe")
  1642. {
  1643. name = cmSystemTools::GetFilenameWithoutLastExtension(name);
  1644. }
  1645. // Look for a CMake target with the given name.
  1646. if(cmGeneratorTarget* target =
  1647. this->Makefile->FindGeneratorTargetToUse(name))
  1648. {
  1649. // make sure it is not just a coincidence that the target name
  1650. // found is part of the inName
  1651. if(cmSystemTools::FileIsFullPath(inName.c_str()))
  1652. {
  1653. std::string tLocation;
  1654. if(target->GetType() >= cmTarget::EXECUTABLE &&
  1655. target->GetType() <= cmTarget::MODULE_LIBRARY)
  1656. {
  1657. tLocation = target->GetLocation(config);
  1658. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1659. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  1660. }
  1661. std::string depLocation = cmSystemTools::GetFilenamePath(
  1662. std::string(inName));
  1663. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  1664. if(depLocation != tLocation)
  1665. {
  1666. // it is a full path to a depend that has the same name
  1667. // as a target but is in a different location so do not use
  1668. // the target as the depend
  1669. dep = inName;
  1670. return true;
  1671. }
  1672. }
  1673. switch (target->GetType())
  1674. {
  1675. case cmTarget::EXECUTABLE:
  1676. case cmTarget::STATIC_LIBRARY:
  1677. case cmTarget::SHARED_LIBRARY:
  1678. case cmTarget::MODULE_LIBRARY:
  1679. case cmTarget::UNKNOWN_LIBRARY:
  1680. dep = target->GetLocation(config);
  1681. return true;
  1682. case cmTarget::OBJECT_LIBRARY:
  1683. // An object library has no single file on which to depend.
  1684. // This was listed to get the target-level dependency.
  1685. return false;
  1686. case cmTarget::INTERFACE_LIBRARY:
  1687. // An interface library has no file on which to depend.
  1688. // This was listed to get the target-level dependency.
  1689. return false;
  1690. case cmTarget::UTILITY:
  1691. case cmTarget::GLOBAL_TARGET:
  1692. // A utility target has no file on which to depend. This was listed
  1693. // only to get the target-level dependency.
  1694. return false;
  1695. }
  1696. }
  1697. // The name was not that of a CMake target. It must name a file.
  1698. if(cmSystemTools::FileIsFullPath(inName.c_str()))
  1699. {
  1700. // This is a full path. Return it as given.
  1701. dep = inName;
  1702. return true;
  1703. }
  1704. // Check for a source file in this directory that matches the
  1705. // dependency.
  1706. if(cmSourceFile* sf = this->Makefile->GetSource(inName))
  1707. {
  1708. dep = sf->GetFullPath();
  1709. return true;
  1710. }
  1711. // Treat the name as relative to the source directory in which it
  1712. // was given.
  1713. dep = this->StateSnapshot.GetDirectory().GetCurrentSource();
  1714. dep += "/";
  1715. dep += inName;
  1716. return true;
  1717. }
  1718. //----------------------------------------------------------------------------
  1719. void cmLocalGenerator::AddSharedFlags(std::string& flags,
  1720. const std::string& lang,
  1721. bool shared)
  1722. {
  1723. std::string flagsVar;
  1724. // Add flags for dealing with shared libraries for this language.
  1725. if(shared)
  1726. {
  1727. flagsVar = "CMAKE_SHARED_LIBRARY_";
  1728. flagsVar += lang;
  1729. flagsVar += "_FLAGS";
  1730. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  1731. }
  1732. }
  1733. //----------------------------------------------------------------------------
  1734. void cmLocalGenerator::
  1735. AddCompilerRequirementFlag(std::string &flags, cmTarget const* target,
  1736. const std::string& lang)
  1737. {
  1738. if (lang.empty())
  1739. {
  1740. return;
  1741. }
  1742. const char* defaultStd
  1743. = this->Makefile->GetDefinition("CMAKE_" + lang + "_STANDARD_DEFAULT");
  1744. if (!defaultStd || !*defaultStd)
  1745. {
  1746. // This compiler has no notion of language standard levels.
  1747. return;
  1748. }
  1749. std::string stdProp = lang + "_STANDARD";
  1750. const char *standardProp = target->GetProperty(stdProp);
  1751. if (!standardProp)
  1752. {
  1753. return;
  1754. }
  1755. std::string extProp = lang + "_EXTENSIONS";
  1756. std::string type = "EXTENSION";
  1757. bool ext = true;
  1758. if (const char* extPropValue = target->GetProperty(extProp))
  1759. {
  1760. if (cmSystemTools::IsOff(extPropValue))
  1761. {
  1762. ext = false;
  1763. type = "STANDARD";
  1764. }
  1765. }
  1766. if (target->GetPropertyAsBool(lang + "_STANDARD_REQUIRED"))
  1767. {
  1768. std::string option_flag =
  1769. "CMAKE_" + lang + standardProp
  1770. + "_" + type + "_COMPILE_OPTION";
  1771. const char *opt = target->GetMakefile()->GetDefinition(option_flag);
  1772. if (!opt)
  1773. {
  1774. std::ostringstream e;
  1775. e << "Target \"" << target->GetName() << "\" requires the language "
  1776. "dialect \"" << lang << standardProp << "\" "
  1777. << (ext ? "(with compiler extensions)" : "") << ", but CMake "
  1778. "does not know the compile flags to use to enable it.";
  1779. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  1780. }
  1781. else
  1782. {
  1783. this->AppendFlagEscape(flags, opt);
  1784. }
  1785. return;
  1786. }
  1787. static std::map<std::string, std::vector<std::string> > langStdMap;
  1788. if (langStdMap.empty())
  1789. {
  1790. // Maintain sorted order, most recent first.
  1791. langStdMap["CXX"].push_back("14");
  1792. langStdMap["CXX"].push_back("11");
  1793. langStdMap["CXX"].push_back("98");
  1794. langStdMap["C"].push_back("11");
  1795. langStdMap["C"].push_back("99");
  1796. langStdMap["C"].push_back("90");
  1797. }
  1798. std::string standard(standardProp);
  1799. std::vector<std::string>& stds = langStdMap[lang];
  1800. std::vector<std::string>::const_iterator stdIt =
  1801. std::find(stds.begin(), stds.end(), standard);
  1802. if (stdIt == stds.end())
  1803. {
  1804. std::string e =
  1805. lang + "_STANDARD is set to invalid value '" + standard + "'";
  1806. this->GetGlobalGenerator()->GetCMakeInstance()
  1807. ->IssueMessage(cmake::FATAL_ERROR, e, target->GetBacktrace());
  1808. return;
  1809. }
  1810. std::vector<std::string>::const_iterator defaultStdIt =
  1811. std::find(stds.begin(), stds.end(), defaultStd);
  1812. if (defaultStdIt == stds.end())
  1813. {
  1814. std::string e =
  1815. "CMAKE_" + lang + "_STANDARD_DEFAULT is set to invalid value '" +
  1816. std::string(defaultStd) + "'";
  1817. this->IssueMessage(cmake::INTERNAL_ERROR, e);
  1818. return;
  1819. }
  1820. // Greater or equal because the standards are stored in
  1821. // backward chronological order.
  1822. if (stdIt >= defaultStdIt)
  1823. {
  1824. std::string option_flag =
  1825. "CMAKE_" + lang + *stdIt
  1826. + "_" + type + "_COMPILE_OPTION";
  1827. const char *opt =
  1828. target->GetMakefile()->GetRequiredDefinition(option_flag);
  1829. this->AppendFlagEscape(flags, opt);
  1830. return;
  1831. }
  1832. for ( ; stdIt < defaultStdIt; ++stdIt)
  1833. {
  1834. std::string option_flag =
  1835. "CMAKE_" + lang + *stdIt
  1836. + "_" + type + "_COMPILE_OPTION";
  1837. if (const char *opt = target->GetMakefile()->GetDefinition(option_flag))
  1838. {
  1839. this->AppendFlagEscape(flags, opt);
  1840. return;
  1841. }
  1842. }
  1843. }
  1844. static void AddVisibilityCompileOption(std::string &flags,
  1845. cmTarget const* target,
  1846. cmLocalGenerator *lg,
  1847. const std::string& lang,
  1848. std::string* warnCMP0063)
  1849. {
  1850. std::string l(lang);
  1851. std::string compileOption = "CMAKE_" + l + "_COMPILE_OPTIONS_VISIBILITY";
  1852. const char *opt = lg->GetMakefile()->GetDefinition(compileOption);
  1853. if (!opt)
  1854. {
  1855. return;
  1856. }
  1857. std::string flagDefine = l + "_VISIBILITY_PRESET";
  1858. const char *prop = target->GetProperty(flagDefine);
  1859. if (!prop)
  1860. {
  1861. return;
  1862. }
  1863. if (warnCMP0063)
  1864. {
  1865. *warnCMP0063 += " " + flagDefine + "\n";
  1866. return;
  1867. }
  1868. if (strcmp(prop, "hidden") != 0
  1869. && strcmp(prop, "default") != 0
  1870. && strcmp(prop, "protected") != 0
  1871. && strcmp(prop, "internal") != 0 )
  1872. {
  1873. std::ostringstream e;
  1874. e << "Target " << target->GetName() << " uses unsupported value \""
  1875. << prop << "\" for " << flagDefine << ".";
  1876. cmSystemTools::Error(e.str().c_str());
  1877. return;
  1878. }
  1879. std::string option = std::string(opt) + prop;
  1880. lg->AppendFlags(flags, option);
  1881. }
  1882. static void AddInlineVisibilityCompileOption(std::string &flags,
  1883. cmTarget const* target,
  1884. cmLocalGenerator *lg,
  1885. std::string* warnCMP0063)
  1886. {
  1887. std::string compileOption
  1888. = "CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN";
  1889. const char *opt = lg->GetMakefile()->GetDefinition(compileOption);
  1890. if (!opt)
  1891. {
  1892. return;
  1893. }
  1894. bool prop = target->GetPropertyAsBool("VISIBILITY_INLINES_HIDDEN");
  1895. if (!prop)
  1896. {
  1897. return;
  1898. }
  1899. if (warnCMP0063)
  1900. {
  1901. *warnCMP0063 += " VISIBILITY_INLINES_HIDDEN\n";
  1902. return;
  1903. }
  1904. lg->AppendFlags(flags, opt);
  1905. }
  1906. //----------------------------------------------------------------------------
  1907. void cmLocalGenerator
  1908. ::AddVisibilityPresetFlags(std::string &flags, cmTarget const* target,
  1909. const std::string& lang)
  1910. {
  1911. if (lang.empty())
  1912. {
  1913. return;
  1914. }
  1915. std::string warnCMP0063;
  1916. std::string *pWarnCMP0063 = 0;
  1917. if (target->GetType() != cmTarget::SHARED_LIBRARY &&
  1918. target->GetType() != cmTarget::MODULE_LIBRARY &&
  1919. !target->IsExecutableWithExports())
  1920. {
  1921. switch (target->GetPolicyStatusCMP0063())
  1922. {
  1923. case cmPolicies::OLD:
  1924. return;
  1925. case cmPolicies::WARN:
  1926. pWarnCMP0063 = &warnCMP0063;
  1927. break;
  1928. default:
  1929. break;
  1930. }
  1931. }
  1932. AddVisibilityCompileOption(flags, target, this, lang, pWarnCMP0063);
  1933. if(lang == "CXX")
  1934. {
  1935. AddInlineVisibilityCompileOption(flags, target, this, pWarnCMP0063);
  1936. }
  1937. if (!warnCMP0063.empty() &&
  1938. this->WarnCMP0063.insert(target).second)
  1939. {
  1940. std::ostringstream w;
  1941. w <<
  1942. cmPolicies::GetPolicyWarning(cmPolicies::CMP0063) << "\n"
  1943. "Target \"" << target->GetName() << "\" of "
  1944. "type \"" << cmTarget::GetTargetTypeName(target->GetType()) << "\" "
  1945. "has the following visibility properties set for " << lang << ":\n" <<
  1946. warnCMP0063 <<
  1947. "For compatibility CMake is not honoring them for this target.";
  1948. target->GetMakefile()->GetCMakeInstance()
  1949. ->IssueMessage(cmake::AUTHOR_WARNING, w.str(), target->GetBacktrace());
  1950. }
  1951. }
  1952. //----------------------------------------------------------------------------
  1953. void cmLocalGenerator::AddCMP0018Flags(std::string &flags,
  1954. cmTarget const* target,
  1955. std::string const& lang,
  1956. const std::string& config)
  1957. {
  1958. int targetType = target->GetType();
  1959. bool shared = ((targetType == cmTarget::SHARED_LIBRARY) ||
  1960. (targetType == cmTarget::MODULE_LIBRARY));
  1961. if (this->GetShouldUseOldFlags(shared, lang))
  1962. {
  1963. this->AddSharedFlags(flags, lang, shared);
  1964. }
  1965. else
  1966. {
  1967. if (target->GetType() == cmTarget::OBJECT_LIBRARY)
  1968. {
  1969. if (target->GetPropertyAsBool("POSITION_INDEPENDENT_CODE"))
  1970. {
  1971. this->AddPositionIndependentFlags(flags, lang, targetType);
  1972. }
  1973. return;
  1974. }
  1975. cmGeneratorTarget* gtgt =
  1976. this->GlobalGenerator->GetGeneratorTarget(target);
  1977. if (gtgt->GetLinkInterfaceDependentBoolProperty(
  1978. "POSITION_INDEPENDENT_CODE",
  1979. config))
  1980. {
  1981. this->AddPositionIndependentFlags(flags, lang, targetType);
  1982. }
  1983. if (shared)
  1984. {
  1985. this->AppendFeatureOptions(flags, lang, "DLL");
  1986. }
  1987. }
  1988. }
  1989. //----------------------------------------------------------------------------
  1990. bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
  1991. const std::string &lang) const
  1992. {
  1993. std::string originalFlags =
  1994. this->GlobalGenerator->GetSharedLibFlagsForLanguage(lang);
  1995. if (shared)
  1996. {
  1997. std::string flagsVar = "CMAKE_SHARED_LIBRARY_";
  1998. flagsVar += lang;
  1999. flagsVar += "_FLAGS";
  2000. const char* flags =
  2001. this->Makefile->GetSafeDefinition(flagsVar);
  2002. if (flags && flags != originalFlags)
  2003. {
  2004. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0018))
  2005. {
  2006. case cmPolicies::WARN:
  2007. {
  2008. std::ostringstream e;
  2009. e << "Variable " << flagsVar << " has been modified. CMake "
  2010. "will ignore the POSITION_INDEPENDENT_CODE target property for "
  2011. "shared libraries and will use the " << flagsVar << " variable "
  2012. "instead. This may cause errors if the original content of "
  2013. << flagsVar << " was removed.\n"
  2014. << cmPolicies::GetPolicyWarning(cmPolicies::CMP0018);
  2015. this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  2016. // fall through to OLD behaviour
  2017. }
  2018. case cmPolicies::OLD:
  2019. return true;
  2020. case cmPolicies::REQUIRED_IF_USED:
  2021. case cmPolicies::REQUIRED_ALWAYS:
  2022. case cmPolicies::NEW:
  2023. return false;
  2024. }
  2025. }
  2026. }
  2027. return false;
  2028. }
  2029. //----------------------------------------------------------------------------
  2030. void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
  2031. std::string const& lang,
  2032. int targetType)
  2033. {
  2034. const char* picFlags = 0;
  2035. if(targetType == cmTarget::EXECUTABLE)
  2036. {
  2037. std::string flagsVar = "CMAKE_";
  2038. flagsVar += lang;
  2039. flagsVar += "_COMPILE_OPTIONS_PIE";
  2040. picFlags = this->Makefile->GetSafeDefinition(flagsVar);
  2041. }
  2042. if (!picFlags)
  2043. {
  2044. std::string flagsVar = "CMAKE_";
  2045. flagsVar += lang;
  2046. flagsVar += "_COMPILE_OPTIONS_PIC";
  2047. picFlags = this->Makefile->GetSafeDefinition(flagsVar);
  2048. }
  2049. if (picFlags)
  2050. {
  2051. std::vector<std::string> options;
  2052. cmSystemTools::ExpandListArgument(picFlags, options);
  2053. for(std::vector<std::string>::const_iterator oi = options.begin();
  2054. oi != options.end(); ++oi)
  2055. {
  2056. this->AppendFlagEscape(flags, *oi);
  2057. }
  2058. }
  2059. }
  2060. //----------------------------------------------------------------------------
  2061. void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
  2062. const std::string& var,
  2063. const std::string& config)
  2064. {
  2065. // Add the flags from the variable itself.
  2066. std::string flagsVar = var;
  2067. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  2068. // Add the flags from the build-type specific variable.
  2069. if(!config.empty())
  2070. {
  2071. flagsVar += "_";
  2072. flagsVar += cmSystemTools::UpperCase(config);
  2073. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  2074. }
  2075. }
  2076. //----------------------------------------------------------------------------
  2077. void cmLocalGenerator::AppendFlags(std::string& flags,
  2078. const std::string& newFlags)
  2079. {
  2080. if(!newFlags.empty())
  2081. {
  2082. if(!flags.empty())
  2083. {
  2084. flags += " ";
  2085. }
  2086. flags += newFlags;
  2087. }
  2088. }
  2089. //----------------------------------------------------------------------------
  2090. void cmLocalGenerator::AppendFlags(std::string& flags,
  2091. const char* newFlags)
  2092. {
  2093. if(newFlags && *newFlags)
  2094. {
  2095. this->AppendFlags(flags, std::string(newFlags));
  2096. }
  2097. }
  2098. //----------------------------------------------------------------------------
  2099. void cmLocalGenerator::AppendFlagEscape(std::string& flags,
  2100. const std::string& rawFlag)
  2101. {
  2102. this->AppendFlags(flags, this->EscapeForShell(rawFlag));
  2103. }
  2104. //----------------------------------------------------------------------------
  2105. void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
  2106. const char* defines_list)
  2107. {
  2108. // Short-circuit if there are no definitions.
  2109. if(!defines_list)
  2110. {
  2111. return;
  2112. }
  2113. // Expand the list of definitions.
  2114. std::vector<std::string> defines_vec;
  2115. cmSystemTools::ExpandListArgument(defines_list, defines_vec);
  2116. this->AppendDefines(defines, defines_vec);
  2117. }
  2118. //----------------------------------------------------------------------------
  2119. void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
  2120. const std::vector<std::string> &defines_vec)
  2121. {
  2122. for(std::vector<std::string>::const_iterator di = defines_vec.begin();
  2123. di != defines_vec.end(); ++di)
  2124. {
  2125. // Skip unsupported definitions.
  2126. if(!this->CheckDefinition(*di))
  2127. {
  2128. continue;
  2129. }
  2130. defines.insert(*di);
  2131. }
  2132. }
  2133. //----------------------------------------------------------------------------
  2134. void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
  2135. std::string &definesString,
  2136. const std::string& lang)
  2137. {
  2138. // Lookup the define flag for the current language.
  2139. std::string dflag = "-D";
  2140. if(!lang.empty())
  2141. {
  2142. std::string defineFlagVar = "CMAKE_";
  2143. defineFlagVar += lang;
  2144. defineFlagVar += "_DEFINE_FLAG";
  2145. const char* df = this->Makefile->GetDefinition(defineFlagVar);
  2146. if(df && *df)
  2147. {
  2148. dflag = df;
  2149. }
  2150. }
  2151. std::set<std::string>::const_iterator defineIt = defines.begin();
  2152. const std::set<std::string>::const_iterator defineEnd = defines.end();
  2153. const char* itemSeparator = definesString.empty() ? "" : " ";
  2154. for( ; defineIt != defineEnd; ++defineIt)
  2155. {
  2156. // Append the definition with proper escaping.
  2157. std::string def = dflag;
  2158. if(this->GetState()->UseWatcomWMake())
  2159. {
  2160. // The Watcom compiler does its own command line parsing instead
  2161. // of using the windows shell rules. Definitions are one of
  2162. // -DNAME
  2163. // -DNAME=<cpp-token>
  2164. // -DNAME="c-string with spaces and other characters(?@#$)"
  2165. //
  2166. // Watcom will properly parse each of these cases from the
  2167. // command line without any escapes. However we still have to
  2168. // get the '$' and '#' characters through WMake as '$$' and
  2169. // '$#'.
  2170. for(const char* c = defineIt->c_str(); *c; ++c)
  2171. {
  2172. if(*c == '$' || *c == '#')
  2173. {
  2174. def += '$';
  2175. }
  2176. def += *c;
  2177. }
  2178. }
  2179. else
  2180. {
  2181. // Make the definition appear properly on the command line. Use
  2182. // -DNAME="value" instead of -D"NAME=value" to help VS6 parser.
  2183. std::string::size_type eq = defineIt->find("=");
  2184. def += defineIt->substr(0, eq);
  2185. if(eq != defineIt->npos)
  2186. {
  2187. def += "=";
  2188. def += this->EscapeForShell(defineIt->c_str() + eq + 1, true);
  2189. }
  2190. }
  2191. definesString += itemSeparator;
  2192. itemSeparator = " ";
  2193. definesString += def;
  2194. }
  2195. }
  2196. //----------------------------------------------------------------------------
  2197. void cmLocalGenerator::AppendFeatureOptions(
  2198. std::string& flags, const std::string& lang, const char* feature)
  2199. {
  2200. std::string optVar = "CMAKE_";
  2201. optVar += lang;
  2202. optVar += "_COMPILE_OPTIONS_";
  2203. optVar += feature;
  2204. if(const char* optionList = this->Makefile->GetDefinition(optVar))
  2205. {
  2206. std::vector<std::string> options;
  2207. cmSystemTools::ExpandListArgument(optionList, options);
  2208. for(std::vector<std::string>::const_iterator oi = options.begin();
  2209. oi != options.end(); ++oi)
  2210. {
  2211. this->AppendFlagEscape(flags, *oi);
  2212. }
  2213. }
  2214. }
  2215. //----------------------------------------------------------------------------
  2216. const char* cmLocalGenerator::GetFeature(const std::string& feature,
  2217. const std::string& config)
  2218. {
  2219. std::string featureName = feature;
  2220. // TODO: Define accumulation policy for features (prepend, append, replace).
  2221. // Currently we always replace.
  2222. if(!config.empty())
  2223. {
  2224. featureName += "_";
  2225. featureName += cmSystemTools::UpperCase(config);
  2226. }
  2227. cmState::Snapshot snp = this->StateSnapshot;
  2228. while(snp.IsValid())
  2229. {
  2230. if(const char* value = snp.GetDirectory().GetProperty(featureName))
  2231. {
  2232. return value;
  2233. }
  2234. snp = snp.GetBuildsystemDirectoryParent();
  2235. }
  2236. return 0;
  2237. }
  2238. //----------------------------------------------------------------------------
  2239. std::string
  2240. cmLocalGenerator::ConstructComment(cmCustomCommandGenerator const& ccg,
  2241. const char* default_comment)
  2242. {
  2243. // Check for a comment provided with the command.
  2244. if(ccg.GetComment())
  2245. {
  2246. return ccg.GetComment();
  2247. }
  2248. // Construct a reasonable default comment if possible.
  2249. if(!ccg.GetOutputs().empty())
  2250. {
  2251. std::string comment;
  2252. comment = "Generating ";
  2253. const char* sep = "";
  2254. for(std::vector<std::string>::const_iterator o = ccg.GetOutputs().begin();
  2255. o != ccg.GetOutputs().end(); ++o)
  2256. {
  2257. comment += sep;
  2258. comment += this->Convert(*o, cmLocalGenerator::START_OUTPUT);
  2259. sep = ", ";
  2260. }
  2261. return comment;
  2262. }
  2263. // Otherwise use the provided default.
  2264. return default_comment;
  2265. }
  2266. //----------------------------------------------------------------------------
  2267. class cmInstallTargetGeneratorLocal: public cmInstallTargetGenerator
  2268. {
  2269. public:
  2270. cmInstallTargetGeneratorLocal(cmLocalGenerator* lg, std::string const& t,
  2271. const char* dest, bool implib):
  2272. cmInstallTargetGenerator(
  2273. t, dest, implib, "", std::vector<std::string>(), "Unspecified",
  2274. cmInstallGenerator::SelectMessageLevel(lg->GetMakefile()),
  2275. false)
  2276. {
  2277. this->Compute(lg);
  2278. }
  2279. };
  2280. //----------------------------------------------------------------------------
  2281. void
  2282. cmLocalGenerator
  2283. ::GenerateTargetInstallRules(
  2284. std::ostream& os, const std::string& config,
  2285. std::vector<std::string> const& configurationTypes)
  2286. {
  2287. // Convert the old-style install specification from each target to
  2288. // an install generator and run it.
  2289. cmTargets& tgts = this->Makefile->GetTargets();
  2290. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  2291. {
  2292. if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  2293. {
  2294. continue;
  2295. }
  2296. // Include the user-specified pre-install script for this target.
  2297. if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
  2298. {
  2299. cmInstallScriptGenerator g(preinstall, false, 0);
  2300. g.Generate(os, config, configurationTypes);
  2301. }
  2302. // Install this target if a destination is given.
  2303. if(l->second.GetInstallPath() != "")
  2304. {
  2305. // Compute the full install destination. Note that converting
  2306. // to unix slashes also removes any trailing slash.
  2307. // We also skip over the leading slash given by the user.
  2308. std::string destination = l->second.GetInstallPath().substr(1);
  2309. cmSystemTools::ConvertToUnixSlashes(destination);
  2310. if(destination.empty())
  2311. {
  2312. destination = ".";
  2313. }
  2314. // Generate the proper install generator for this target type.
  2315. switch(l->second.GetType())
  2316. {
  2317. case cmTarget::EXECUTABLE:
  2318. case cmTarget::STATIC_LIBRARY:
  2319. case cmTarget::MODULE_LIBRARY:
  2320. {
  2321. // Use a target install generator.
  2322. cmInstallTargetGeneratorLocal
  2323. g(this, l->first, destination.c_str(), false);
  2324. g.Generate(os, config, configurationTypes);
  2325. }
  2326. break;
  2327. case cmTarget::SHARED_LIBRARY:
  2328. {
  2329. #if defined(_WIN32) || defined(__CYGWIN__)
  2330. // Special code to handle DLL. Install the import library
  2331. // to the normal destination and the DLL to the runtime
  2332. // destination.
  2333. cmInstallTargetGeneratorLocal
  2334. g1(this, l->first, destination.c_str(), true);
  2335. g1.Generate(os, config, configurationTypes);
  2336. // We also skip over the leading slash given by the user.
  2337. destination = l->second.GetRuntimeInstallPath().substr(1);
  2338. cmSystemTools::ConvertToUnixSlashes(destination);
  2339. cmInstallTargetGeneratorLocal
  2340. g2(this, l->first, destination.c_str(), false);
  2341. g2.Generate(os, config, configurationTypes);
  2342. #else
  2343. // Use a target install generator.
  2344. cmInstallTargetGeneratorLocal
  2345. g(this, l->first, destination.c_str(), false);
  2346. g.Generate(os, config, configurationTypes);
  2347. #endif
  2348. }
  2349. break;
  2350. default:
  2351. break;
  2352. }
  2353. }
  2354. // Include the user-specified post-install script for this target.
  2355. if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
  2356. {
  2357. cmInstallScriptGenerator g(postinstall, false, 0);
  2358. g.Generate(os, config, configurationTypes);
  2359. }
  2360. }
  2361. }
  2362. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2363. static std::string cmLocalGeneratorMD5(const char* input)
  2364. {
  2365. char md5out[32];
  2366. cmsysMD5* md5 = cmsysMD5_New();
  2367. cmsysMD5_Initialize(md5);
  2368. cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
  2369. cmsysMD5_FinalizeHex(md5, md5out);
  2370. cmsysMD5_Delete(md5);
  2371. return std::string(md5out, 32);
  2372. }
  2373. static bool
  2374. cmLocalGeneratorShortenObjectName(std::string& objName,
  2375. std::string::size_type max_len)
  2376. {
  2377. // Replace the beginning of the path portion of the object name with
  2378. // its own md5 sum.
  2379. std::string::size_type pos = objName.find('/', objName.size()-max_len+32);
  2380. if(pos != objName.npos)
  2381. {
  2382. std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
  2383. md5name += objName.substr(pos);
  2384. objName = md5name;
  2385. // The object name is now short enough.
  2386. return true;
  2387. }
  2388. else
  2389. {
  2390. // The object name could not be shortened enough.
  2391. return false;
  2392. }
  2393. }
  2394. static
  2395. bool cmLocalGeneratorCheckObjectName(std::string& objName,
  2396. std::string::size_type dir_len,
  2397. std::string::size_type max_total_len)
  2398. {
  2399. // Enforce the maximum file name length if possible.
  2400. std::string::size_type max_obj_len = max_total_len;
  2401. if(dir_len < max_total_len)
  2402. {
  2403. max_obj_len = max_total_len - dir_len;
  2404. if(objName.size() > max_obj_len)
  2405. {
  2406. // The current object file name is too long. Try to shorten it.
  2407. return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
  2408. }
  2409. else
  2410. {
  2411. // The object file name is short enough.
  2412. return true;
  2413. }
  2414. }
  2415. else
  2416. {
  2417. // The build directory in which the object will be stored is
  2418. // already too deep.
  2419. return false;
  2420. }
  2421. }
  2422. #endif
  2423. //----------------------------------------------------------------------------
  2424. std::string&
  2425. cmLocalGenerator
  2426. ::CreateSafeUniqueObjectFileName(const std::string& sin,
  2427. std::string const& dir_max)
  2428. {
  2429. // Look for an existing mapped name for this object file.
  2430. std::map<std::string,std::string>::iterator it =
  2431. this->UniqueObjectNamesMap.find(sin);
  2432. // If no entry exists create one.
  2433. if(it == this->UniqueObjectNamesMap.end())
  2434. {
  2435. // Start with the original name.
  2436. std::string ssin = sin;
  2437. // Avoid full paths by removing leading slashes.
  2438. ssin.erase(0, ssin.find_first_not_of("/"));
  2439. // Avoid full paths by removing colons.
  2440. cmSystemTools::ReplaceString(ssin, ":", "_");
  2441. // Avoid relative paths that go up the tree.
  2442. cmSystemTools::ReplaceString(ssin, "../", "__/");
  2443. // Avoid spaces.
  2444. cmSystemTools::ReplaceString(ssin, " ", "_");
  2445. // Mangle the name if necessary.
  2446. if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
  2447. {
  2448. bool done;
  2449. int cc = 0;
  2450. char rpstr[100];
  2451. sprintf(rpstr, "_p_");
  2452. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2453. std::string sssin = sin;
  2454. do
  2455. {
  2456. done = true;
  2457. for ( it = this->UniqueObjectNamesMap.begin();
  2458. it != this->UniqueObjectNamesMap.end();
  2459. ++ it )
  2460. {
  2461. if ( it->second == ssin )
  2462. {
  2463. done = false;
  2464. }
  2465. }
  2466. if ( done )
  2467. {
  2468. break;
  2469. }
  2470. sssin = ssin;
  2471. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2472. sprintf(rpstr, "_p%d_", cc++);
  2473. }
  2474. while ( !done );
  2475. }
  2476. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2477. if(!cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
  2478. this->ObjectPathMax))
  2479. {
  2480. // Warn if this is the first time the path has been seen.
  2481. if(this->ObjectMaxPathViolations.insert(dir_max).second)
  2482. {
  2483. std::ostringstream m;
  2484. m << "The object file directory\n"
  2485. << " " << dir_max << "\n"
  2486. << "has " << dir_max.size() << " characters. "
  2487. << "The maximum full path to an object file is "
  2488. << this->ObjectPathMax << " characters "
  2489. << "(see CMAKE_OBJECT_PATH_MAX). "
  2490. << "Object file\n"
  2491. << " " << ssin << "\n"
  2492. << "cannot be safely placed under this directory. "
  2493. << "The build may not work correctly.";
  2494. this->IssueMessage(cmake::WARNING, m.str());
  2495. }
  2496. }
  2497. #else
  2498. (void)dir_max;
  2499. #endif
  2500. // Insert the newly mapped object file name.
  2501. std::map<std::string, std::string>::value_type e(sin, ssin);
  2502. it = this->UniqueObjectNamesMap.insert(e).first;
  2503. }
  2504. // Return the map entry.
  2505. return it->second;
  2506. }
  2507. //----------------------------------------------------------------------------
  2508. void cmLocalGenerator::ComputeObjectFilenames(
  2509. std::map<cmSourceFile const*, std::string>&,
  2510. cmGeneratorTarget const*)
  2511. {
  2512. }
  2513. bool cmLocalGenerator::IsWindowsShell() const
  2514. {
  2515. return this->GetState()->UseWindowsShell();
  2516. }
  2517. bool cmLocalGenerator::IsWatcomWMake() const
  2518. {
  2519. return this->GetState()->UseWatcomWMake();
  2520. }
  2521. bool cmLocalGenerator::IsMinGWMake() const
  2522. {
  2523. return this->GetState()->UseMinGWMake();
  2524. }
  2525. bool cmLocalGenerator::IsNMake() const
  2526. {
  2527. return this->GetState()->UseNMake();
  2528. }
  2529. //----------------------------------------------------------------------------
  2530. std::string
  2531. cmLocalGenerator
  2532. ::GetObjectFileNameWithoutTarget(const cmSourceFile& source,
  2533. std::string const& dir_max,
  2534. bool* hasSourceExtension)
  2535. {
  2536. // Construct the object file name using the full path to the source
  2537. // file which is its only unique identification.
  2538. const char* fullPath = source.GetFullPath().c_str();
  2539. // Try referencing the source relative to the source tree.
  2540. std::string relFromSource = this->Convert(fullPath, START);
  2541. assert(!relFromSource.empty());
  2542. bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
  2543. bool subSource = relSource && relFromSource[0] != '.';
  2544. // Try referencing the source relative to the binary tree.
  2545. std::string relFromBinary = this->Convert(fullPath, START_OUTPUT);
  2546. assert(!relFromBinary.empty());
  2547. bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
  2548. bool subBinary = relBinary && relFromBinary[0] != '.';
  2549. // Select a nice-looking reference to the source file to construct
  2550. // the object file name.
  2551. std::string objectName;
  2552. if((relSource && !relBinary) || (subSource && !subBinary))
  2553. {
  2554. objectName = relFromSource;
  2555. }
  2556. else if((relBinary && !relSource) || (subBinary && !subSource))
  2557. {
  2558. objectName = relFromBinary;
  2559. }
  2560. else if(relFromBinary.length() < relFromSource.length())
  2561. {
  2562. objectName = relFromBinary;
  2563. }
  2564. else
  2565. {
  2566. objectName = relFromSource;
  2567. }
  2568. // if it is still a full path check for the try compile case
  2569. // try compile never have in source sources, and should not
  2570. // have conflicting source file names in the same target
  2571. if(cmSystemTools::FileIsFullPath(objectName.c_str()))
  2572. {
  2573. if(this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
  2574. {
  2575. objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
  2576. }
  2577. }
  2578. // Replace the original source file extension with the object file
  2579. // extension.
  2580. bool keptSourceExtension = true;
  2581. if(!source.GetPropertyAsBool("KEEP_EXTENSION"))
  2582. {
  2583. // Decide whether this language wants to replace the source
  2584. // extension with the object extension. For CMake 2.4
  2585. // compatibility do this by default.
  2586. bool replaceExt = this->NeedBackwardsCompatibility_2_4();
  2587. if(!replaceExt)
  2588. {
  2589. std::string lang = source.GetLanguage();
  2590. if(!lang.empty())
  2591. {
  2592. std::string repVar = "CMAKE_";
  2593. repVar += lang;
  2594. repVar += "_OUTPUT_EXTENSION_REPLACE";
  2595. replaceExt = this->Makefile->IsOn(repVar);
  2596. }
  2597. }
  2598. // Remove the source extension if it is to be replaced.
  2599. if(replaceExt)
  2600. {
  2601. keptSourceExtension = false;
  2602. std::string::size_type dot_pos = objectName.rfind(".");
  2603. if(dot_pos != std::string::npos)
  2604. {
  2605. objectName = objectName.substr(0, dot_pos);
  2606. }
  2607. }
  2608. // Store the new extension.
  2609. objectName +=
  2610. this->GlobalGenerator->GetLanguageOutputExtension(source);
  2611. }
  2612. if(hasSourceExtension)
  2613. {
  2614. *hasSourceExtension = keptSourceExtension;
  2615. }
  2616. // Convert to a safe name.
  2617. return this->CreateSafeUniqueObjectFileName(objectName, dir_max);
  2618. }
  2619. //----------------------------------------------------------------------------
  2620. std::string
  2621. cmLocalGenerator
  2622. ::GetSourceFileLanguage(const cmSourceFile& source)
  2623. {
  2624. return source.GetLanguage();
  2625. }
  2626. //----------------------------------------------------------------------------
  2627. std::string
  2628. cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
  2629. {
  2630. cmSystemTools::Error("GetTargetDirectory"
  2631. " called on cmLocalGenerator");
  2632. return "";
  2633. }
  2634. //----------------------------------------------------------------------------
  2635. cmIML_INT_uint64_t cmLocalGenerator::GetBackwardsCompatibility()
  2636. {
  2637. // The computed version may change until the project is fully
  2638. // configured.
  2639. if(!this->BackwardsCompatibilityFinal)
  2640. {
  2641. unsigned int major = 0;
  2642. unsigned int minor = 0;
  2643. unsigned int patch = 0;
  2644. if(const char* value
  2645. = this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"))
  2646. {
  2647. switch(sscanf(value, "%u.%u.%u", &major, &minor, &patch))
  2648. {
  2649. case 2: patch = 0; break;
  2650. case 1: minor = 0; patch = 0; break;
  2651. default: break;
  2652. }
  2653. }
  2654. this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
  2655. this->BackwardsCompatibilityFinal = true;
  2656. }
  2657. return this->BackwardsCompatibility;
  2658. }
  2659. //----------------------------------------------------------------------------
  2660. bool cmLocalGenerator::NeedBackwardsCompatibility_2_4()
  2661. {
  2662. // Check the policy to decide whether to pay attention to this
  2663. // variable.
  2664. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0001))
  2665. {
  2666. case cmPolicies::WARN:
  2667. // WARN is just OLD without warning because user code does not
  2668. // always affect whether this check is done.
  2669. case cmPolicies::OLD:
  2670. // Old behavior is to check the variable.
  2671. break;
  2672. case cmPolicies::NEW:
  2673. // New behavior is to ignore the variable.
  2674. return false;
  2675. case cmPolicies::REQUIRED_IF_USED:
  2676. case cmPolicies::REQUIRED_ALWAYS:
  2677. // This will never be the case because the only way to require
  2678. // the setting is to require the user to specify version policy
  2679. // 2.6 or higher. Once we add that requirement then this whole
  2680. // method can be removed anyway.
  2681. return false;
  2682. }
  2683. // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
  2684. // equal to or lower than the given version.
  2685. cmIML_INT_uint64_t actual_compat = this->GetBackwardsCompatibility();
  2686. return (actual_compat &&
  2687. actual_compat <= CMake_VERSION_ENCODE(2, 4, 255));
  2688. }
  2689. //----------------------------------------------------------------------------
  2690. bool cmLocalGenerator::CheckDefinition(std::string const& define) const
  2691. {
  2692. // Many compilers do not support -DNAME(arg)=sdf so we disable it.
  2693. std::string::size_type pos = define.find_first_of("(=");
  2694. if (pos != std::string::npos)
  2695. {
  2696. if (define[pos] == '(')
  2697. {
  2698. std::ostringstream e;
  2699. e << "WARNING: Function-style preprocessor definitions may not be "
  2700. << "passed on the compiler command line because many compilers "
  2701. << "do not support it.\n"
  2702. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2703. << "Consider defining the macro in a (configured) header file.\n";
  2704. cmSystemTools::Message(e.str().c_str());
  2705. return false;
  2706. }
  2707. }
  2708. // Many compilers do not support # in the value so we disable it.
  2709. if(define.find_first_of("#") != define.npos)
  2710. {
  2711. std::ostringstream e;
  2712. e << "WARNING: Preprocessor definitions containing '#' may not be "
  2713. << "passed on the compiler command line because many compilers "
  2714. << "do not support it.\n"
  2715. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2716. << "Consider defining the macro in a (configured) header file.\n";
  2717. cmSystemTools::Message(e.str().c_str());
  2718. return false;
  2719. }
  2720. // Assume it is supported.
  2721. return true;
  2722. }
  2723. //----------------------------------------------------------------------------
  2724. static void cmLGInfoProp(cmMakefile* mf, cmTarget* target,
  2725. const std::string& prop)
  2726. {
  2727. if(const char* val = target->GetProperty(prop))
  2728. {
  2729. mf->AddDefinition(prop, val);
  2730. }
  2731. }
  2732. //----------------------------------------------------------------------------
  2733. void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
  2734. const std::string& targetName,
  2735. const char* fname)
  2736. {
  2737. // Find the Info.plist template.
  2738. const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
  2739. std::string inFile = (in && *in)? in : "MacOSXBundleInfo.plist.in";
  2740. if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
  2741. {
  2742. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2743. if(!inMod.empty())
  2744. {
  2745. inFile = inMod;
  2746. }
  2747. }
  2748. if(!cmSystemTools::FileExists(inFile.c_str(), true))
  2749. {
  2750. std::ostringstream e;
  2751. e << "Target " << target->GetName() << " Info.plist template \""
  2752. << inFile << "\" could not be found.";
  2753. cmSystemTools::Error(e.str().c_str());
  2754. return;
  2755. }
  2756. // Convert target properties to variables in an isolated makefile
  2757. // scope to configure the file. If properties are set they will
  2758. // override user make variables. If not the configuration will fall
  2759. // back to the directory-level values set by the user.
  2760. cmMakefile* mf = this->Makefile;
  2761. mf->PushScope();
  2762. mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName.c_str());
  2763. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING");
  2764. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE");
  2765. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
  2766. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
  2767. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_NAME");
  2768. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
  2769. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
  2770. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
  2771. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2772. mf->PopScope();
  2773. }
  2774. //----------------------------------------------------------------------------
  2775. void cmLocalGenerator::GenerateFrameworkInfoPList(cmTarget* target,
  2776. const std::string& targetName,
  2777. const char* fname)
  2778. {
  2779. // Find the Info.plist template.
  2780. const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
  2781. std::string inFile = (in && *in)? in : "MacOSXFrameworkInfo.plist.in";
  2782. if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
  2783. {
  2784. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2785. if(!inMod.empty())
  2786. {
  2787. inFile = inMod;
  2788. }
  2789. }
  2790. if(!cmSystemTools::FileExists(inFile.c_str(), true))
  2791. {
  2792. std::ostringstream e;
  2793. e << "Target " << target->GetName() << " Info.plist template \""
  2794. << inFile << "\" could not be found.";
  2795. cmSystemTools::Error(e.str().c_str());
  2796. return;
  2797. }
  2798. // Convert target properties to variables in an isolated makefile
  2799. // scope to configure the file. If properties are set they will
  2800. // override user make variables. If not the configuration will fall
  2801. // back to the directory-level values set by the user.
  2802. cmMakefile* mf = this->Makefile;
  2803. mf->PushScope();
  2804. mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName.c_str());
  2805. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE");
  2806. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
  2807. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
  2808. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
  2809. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2810. mf->PopScope();
  2811. }