cmLocalGenerator.cxx 97 KB

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