cmLocalGenerator.cxx 96 KB

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