cmLocalGenerator.cxx 98 KB

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