cmLocalGenerator.cxx 98 KB

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