cmGeneratorTarget.cxx 140 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2012 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 "cmGeneratorTarget.h"
  11. #include "cmTarget.h"
  12. #include "cmMakefile.h"
  13. #include "cmLocalGenerator.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmSourceFile.h"
  16. #include "cmGeneratorExpression.h"
  17. #include "cmGeneratorExpressionDAGChecker.h"
  18. #include "cmComputeLinkInformation.h"
  19. #include "cmCustomCommandGenerator.h"
  20. #include "cmAlgorithms.h"
  21. #include <queue>
  22. #include <errno.h>
  23. #include "assert.h"
  24. #if defined(CMAKE_BUILD_WITH_CMAKE)
  25. #include <cmsys/hash_set.hxx>
  26. #define UNORDERED_SET cmsys::hash_set
  27. #else
  28. #define UNORDERED_SET std::set
  29. #endif
  30. class cmGeneratorTarget::TargetPropertyEntry {
  31. static cmLinkImplItem NoLinkImplItem;
  32. public:
  33. TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
  34. cmLinkImplItem const& item = NoLinkImplItem)
  35. : ge(cge), LinkImplItem(item)
  36. {}
  37. const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
  38. cmLinkImplItem const& LinkImplItem;
  39. };
  40. cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem;
  41. //----------------------------------------------------------------------------
  42. void reportBadObjLib(std::vector<cmSourceFile*> const& badObjLib,
  43. cmGeneratorTarget const* target, cmake *cm)
  44. {
  45. if(!badObjLib.empty())
  46. {
  47. std::ostringstream e;
  48. e << "OBJECT library \"" << target->GetName() << "\" contains:\n";
  49. for(std::vector<cmSourceFile*>::const_iterator i = badObjLib.begin();
  50. i != badObjLib.end(); ++i)
  51. {
  52. e << " " << (*i)->GetLocation().GetName() << "\n";
  53. }
  54. e << "but may contain only sources that compile, header files, and "
  55. "other files that would not affect linking of a normal library.";
  56. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  57. target->Target->GetBacktrace());
  58. }
  59. }
  60. struct ObjectSourcesTag {};
  61. struct CustomCommandsTag {};
  62. struct ExtraSourcesTag {};
  63. struct HeaderSourcesTag {};
  64. struct ExternalObjectsTag {};
  65. struct IDLSourcesTag {};
  66. struct ResxTag {};
  67. struct ModuleDefinitionFileTag {};
  68. struct AppManifestTag{};
  69. struct CertificatesTag{};
  70. struct XamlTag{};
  71. template<typename Tag, typename OtherTag>
  72. struct IsSameTag
  73. {
  74. enum {
  75. Result = false
  76. };
  77. };
  78. template<typename Tag>
  79. struct IsSameTag<Tag, Tag>
  80. {
  81. enum {
  82. Result = true
  83. };
  84. };
  85. template<bool>
  86. struct DoAccept
  87. {
  88. template <typename T> static void Do(T&, cmSourceFile*) {}
  89. };
  90. template<>
  91. struct DoAccept<true>
  92. {
  93. static void Do(std::vector<cmSourceFile const*>& files, cmSourceFile* f)
  94. {
  95. files.push_back(f);
  96. }
  97. static void Do(cmGeneratorTarget::ResxData& data, cmSourceFile* f)
  98. {
  99. // Build and save the name of the corresponding .h file
  100. // This relationship will be used later when building the project files.
  101. // Both names would have been auto generated from Visual Studio
  102. // where the user supplied the file name and Visual Studio
  103. // appended the suffix.
  104. std::string resx = f->GetFullPath();
  105. std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
  106. data.ExpectedResxHeaders.insert(hFileName);
  107. data.ResxSources.push_back(f);
  108. }
  109. static void Do(cmGeneratorTarget::XamlData& data, cmSourceFile* f)
  110. {
  111. // Build and save the name of the corresponding .h and .cpp file
  112. // This relationship will be used later when building the project files.
  113. // Both names would have been auto generated from Visual Studio
  114. // where the user supplied the file name and Visual Studio
  115. // appended the suffix.
  116. std::string xaml = f->GetFullPath();
  117. std::string hFileName = xaml + ".h";
  118. std::string cppFileName = xaml + ".cpp";
  119. data.ExpectedXamlHeaders.insert(hFileName);
  120. data.ExpectedXamlSources.insert(cppFileName);
  121. data.XamlSources.push_back(f);
  122. }
  123. static void Do(std::string& data, cmSourceFile* f)
  124. {
  125. data = f->GetFullPath();
  126. }
  127. };
  128. //----------------------------------------------------------------------------
  129. template<typename Tag, typename DataType = std::vector<cmSourceFile const*> >
  130. struct TagVisitor
  131. {
  132. DataType& Data;
  133. std::vector<cmSourceFile*> BadObjLibFiles;
  134. cmGeneratorTarget const* Target;
  135. cmGlobalGenerator *GlobalGenerator;
  136. cmsys::RegularExpression Header;
  137. bool IsObjLib;
  138. TagVisitor(cmGeneratorTarget const* target, DataType& data)
  139. : Data(data), Target(target),
  140. GlobalGenerator(target->GetLocalGenerator()->GetGlobalGenerator()),
  141. Header(CM_HEADER_REGEX),
  142. IsObjLib(target->GetType() == cmTarget::OBJECT_LIBRARY)
  143. {
  144. }
  145. ~TagVisitor()
  146. {
  147. reportBadObjLib(this->BadObjLibFiles, this->Target,
  148. this->GlobalGenerator->GetCMakeInstance());
  149. }
  150. void Accept(cmSourceFile *sf)
  151. {
  152. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  153. if(sf->GetCustomCommand())
  154. {
  155. DoAccept<IsSameTag<Tag, CustomCommandsTag>::Result>::Do(this->Data, sf);
  156. }
  157. else if(this->Target->GetType() == cmTarget::UTILITY)
  158. {
  159. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  160. }
  161. else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
  162. {
  163. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  164. }
  165. else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  166. {
  167. DoAccept<IsSameTag<Tag, ExternalObjectsTag>::Result>::Do(this->Data, sf);
  168. if(this->IsObjLib)
  169. {
  170. this->BadObjLibFiles.push_back(sf);
  171. }
  172. }
  173. else if(!sf->GetLanguage().empty())
  174. {
  175. DoAccept<IsSameTag<Tag, ObjectSourcesTag>::Result>::Do(this->Data, sf);
  176. }
  177. else if(ext == "def")
  178. {
  179. DoAccept<IsSameTag<Tag, ModuleDefinitionFileTag>::Result>::Do(this->Data,
  180. sf);
  181. if(this->IsObjLib)
  182. {
  183. this->BadObjLibFiles.push_back(sf);
  184. }
  185. }
  186. else if(ext == "idl")
  187. {
  188. DoAccept<IsSameTag<Tag, IDLSourcesTag>::Result>::Do(this->Data, sf);
  189. if(this->IsObjLib)
  190. {
  191. this->BadObjLibFiles.push_back(sf);
  192. }
  193. }
  194. else if(ext == "resx")
  195. {
  196. DoAccept<IsSameTag<Tag, ResxTag>::Result>::Do(this->Data, sf);
  197. }
  198. else if (ext == "appxmanifest")
  199. {
  200. DoAccept<IsSameTag<Tag, AppManifestTag>::Result>::Do(this->Data, sf);
  201. }
  202. else if (ext == "pfx")
  203. {
  204. DoAccept<IsSameTag<Tag, CertificatesTag>::Result>::Do(this->Data, sf);
  205. }
  206. else if (ext == "xaml")
  207. {
  208. DoAccept<IsSameTag<Tag, XamlTag>::Result>::Do(this->Data, sf);
  209. }
  210. else if(this->Header.find(sf->GetFullPath().c_str()))
  211. {
  212. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  213. }
  214. else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
  215. {
  216. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  217. }
  218. else
  219. {
  220. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  221. }
  222. }
  223. };
  224. void CreatePropertyGeneratorExpressions(
  225. cmStringRange const& entries,
  226. cmBacktraceRange const& backtraces,
  227. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& items,
  228. bool evaluateForBuildsystem = false)
  229. {
  230. std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin();
  231. for (std::vector<std::string>::const_iterator it = entries.begin();
  232. it != entries.end(); ++it, ++btIt)
  233. {
  234. cmGeneratorExpression ge(*btIt);
  235. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*it);
  236. cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
  237. items.push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  238. }
  239. }
  240. //----------------------------------------------------------------------------
  241. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  242. : Target(t),
  243. SourceFileFlagsConstructed(false),
  244. PolicyWarnedCMP0022(false),
  245. DebugIncludesDone(false),
  246. DebugCompileOptionsDone(false),
  247. DebugCompileFeaturesDone(false),
  248. DebugCompileDefinitionsDone(false)
  249. {
  250. this->Makefile = this->Target->GetMakefile();
  251. this->LocalGenerator = lg;
  252. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  253. CreatePropertyGeneratorExpressions(
  254. t->GetIncludeDirectoriesEntries(),
  255. t->GetIncludeDirectoriesBacktraces(),
  256. this->IncludeDirectoriesEntries);
  257. CreatePropertyGeneratorExpressions(
  258. t->GetCompileOptionsEntries(),
  259. t->GetCompileOptionsBacktraces(),
  260. this->CompileOptionsEntries);
  261. CreatePropertyGeneratorExpressions(
  262. t->GetCompileFeaturesEntries(),
  263. t->GetCompileFeaturesBacktraces(),
  264. this->CompileFeaturesEntries);
  265. CreatePropertyGeneratorExpressions(
  266. t->GetCompileDefinitionsEntries(),
  267. t->GetCompileDefinitionsBacktraces(),
  268. this->CompileDefinitionsEntries);
  269. }
  270. cmGeneratorTarget::~cmGeneratorTarget()
  271. {
  272. cmDeleteAll(this->IncludeDirectoriesEntries);
  273. cmDeleteAll(this->CompileOptionsEntries);
  274. cmDeleteAll(this->CompileFeaturesEntries);
  275. cmDeleteAll(this->CompileDefinitionsEntries);
  276. cmDeleteAll(this->LinkInformation);
  277. this->LinkInformation.clear();
  278. }
  279. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  280. {
  281. return this->LocalGenerator;
  282. }
  283. //----------------------------------------------------------------------------
  284. int cmGeneratorTarget::GetType() const
  285. {
  286. return this->Target->GetType();
  287. }
  288. //----------------------------------------------------------------------------
  289. std::string cmGeneratorTarget::GetName() const
  290. {
  291. return this->Target->GetName();
  292. }
  293. //----------------------------------------------------------------------------
  294. const char *cmGeneratorTarget::GetProperty(const std::string& prop) const
  295. {
  296. return this->Target->GetProperty(prop);
  297. }
  298. //----------------------------------------------------------------------------
  299. std::string cmGeneratorTarget::GetOutputName(const std::string& config,
  300. bool implib) const
  301. {
  302. // Lookup/compute/cache the output name for this configuration.
  303. OutputNameKey key(config, implib);
  304. cmGeneratorTarget::OutputNameMapType::iterator i =
  305. this->OutputNameMap.find(key);
  306. if(i == this->OutputNameMap.end())
  307. {
  308. // Add empty name in map to detect potential recursion.
  309. OutputNameMapType::value_type entry(key, "");
  310. i = this->OutputNameMap.insert(entry).first;
  311. // Compute output name.
  312. std::vector<std::string> props;
  313. std::string type = this->Target->GetOutputTargetType(implib);
  314. std::string configUpper = cmSystemTools::UpperCase(config);
  315. if(!type.empty() && !configUpper.empty())
  316. {
  317. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  318. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  319. }
  320. if(!type.empty())
  321. {
  322. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  323. props.push_back(type + "_OUTPUT_NAME");
  324. }
  325. if(!configUpper.empty())
  326. {
  327. // OUTPUT_NAME_<CONFIG>
  328. props.push_back("OUTPUT_NAME_" + configUpper);
  329. // <CONFIG>_OUTPUT_NAME
  330. props.push_back(configUpper + "_OUTPUT_NAME");
  331. }
  332. // OUTPUT_NAME
  333. props.push_back("OUTPUT_NAME");
  334. std::string outName;
  335. for(std::vector<std::string>::const_iterator it = props.begin();
  336. it != props.end(); ++it)
  337. {
  338. if (const char* outNameProp = this->Target->GetProperty(*it))
  339. {
  340. outName = outNameProp;
  341. break;
  342. }
  343. }
  344. if(outName.empty())
  345. {
  346. outName = this->GetName();
  347. }
  348. // Now evaluate genex and update the previously-prepared map entry.
  349. cmGeneratorExpression ge;
  350. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
  351. i->second = cge->Evaluate(this->Makefile, config);
  352. }
  353. else if(i->second.empty())
  354. {
  355. // An empty map entry indicates we have been called recursively
  356. // from the above block.
  357. this->Makefile->GetCMakeInstance()->IssueMessage(
  358. cmake::FATAL_ERROR,
  359. "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
  360. this->Target->GetBacktrace());
  361. }
  362. return i->second;
  363. }
  364. //----------------------------------------------------------------------------
  365. std::vector<cmSourceFile*> const*
  366. cmGeneratorTarget::GetSourceDepends(cmSourceFile const* sf) const
  367. {
  368. SourceEntriesType::const_iterator i = this->SourceEntries.find(sf);
  369. if(i != this->SourceEntries.end())
  370. {
  371. return &i->second.Depends;
  372. }
  373. return 0;
  374. }
  375. static void handleSystemIncludesDep(cmMakefile *mf, cmTarget const* depTgt,
  376. const std::string& config,
  377. cmTarget *headTarget,
  378. cmGeneratorExpressionDAGChecker *dagChecker,
  379. std::vector<std::string>& result,
  380. bool excludeImported)
  381. {
  382. if (const char* dirs =
  383. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES"))
  384. {
  385. cmGeneratorExpression ge;
  386. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  387. ->Evaluate(mf,
  388. config, false, headTarget,
  389. depTgt, dagChecker), result);
  390. }
  391. if (!depTgt->IsImported() || excludeImported)
  392. {
  393. return;
  394. }
  395. if (const char* dirs =
  396. depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES"))
  397. {
  398. cmGeneratorExpression ge;
  399. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  400. ->Evaluate(mf,
  401. config, false, headTarget,
  402. depTgt, dagChecker), result);
  403. }
  404. }
  405. #define IMPLEMENT_VISIT_IMPL(DATA, DATATYPE) \
  406. { \
  407. std::vector<cmSourceFile*> sourceFiles; \
  408. this->Target->GetSourceFiles(sourceFiles, config); \
  409. TagVisitor<DATA ## Tag DATATYPE> visitor(this, data); \
  410. for(std::vector<cmSourceFile*>::const_iterator si = sourceFiles.begin(); \
  411. si != sourceFiles.end(); ++si) \
  412. { \
  413. visitor.Accept(*si); \
  414. } \
  415. } \
  416. #define IMPLEMENT_VISIT(DATA) \
  417. IMPLEMENT_VISIT_IMPL(DATA, EMPTY) \
  418. #define EMPTY
  419. #define COMMA ,
  420. //----------------------------------------------------------------------------
  421. void
  422. cmGeneratorTarget
  423. ::GetObjectSources(std::vector<cmSourceFile const*> &data,
  424. const std::string& config) const
  425. {
  426. IMPLEMENT_VISIT(ObjectSources);
  427. if (!this->Objects.empty())
  428. {
  429. return;
  430. }
  431. for(std::vector<cmSourceFile const*>::const_iterator it = data.begin();
  432. it != data.end(); ++it)
  433. {
  434. this->Objects[*it];
  435. }
  436. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  437. }
  438. void cmGeneratorTarget::ComputeObjectMapping()
  439. {
  440. if(!this->Objects.empty())
  441. {
  442. return;
  443. }
  444. std::vector<std::string> configs;
  445. this->Makefile->GetConfigurations(configs);
  446. if (configs.empty())
  447. {
  448. configs.push_back("");
  449. }
  450. for(std::vector<std::string>::const_iterator ci = configs.begin();
  451. ci != configs.end(); ++ci)
  452. {
  453. std::vector<cmSourceFile const*> sourceFiles;
  454. this->GetObjectSources(sourceFiles, *ci);
  455. }
  456. }
  457. //----------------------------------------------------------------------------
  458. const char* cmGeneratorTarget::GetFeature(const std::string& feature,
  459. const std::string& config) const
  460. {
  461. if(!config.empty())
  462. {
  463. std::string featureConfig = feature;
  464. featureConfig += "_";
  465. featureConfig += cmSystemTools::UpperCase(config);
  466. if(const char* value = this->Target->GetProperty(featureConfig))
  467. {
  468. return value;
  469. }
  470. }
  471. if(const char* value = this->Target->GetProperty(feature))
  472. {
  473. return value;
  474. }
  475. return this->LocalGenerator->GetFeature(feature, config);
  476. }
  477. //----------------------------------------------------------------------------
  478. bool cmGeneratorTarget::GetFeatureAsBool(const std::string& feature,
  479. const std::string& config) const
  480. {
  481. return cmSystemTools::IsOn(this->GetFeature(feature, config));
  482. }
  483. //----------------------------------------------------------------------------
  484. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  485. {
  486. this->ComputeObjectMapping();
  487. return this->Objects[file];
  488. }
  489. //----------------------------------------------------------------------------
  490. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  491. {
  492. this->ExplicitObjectName.insert(sf);
  493. }
  494. //----------------------------------------------------------------------------
  495. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  496. {
  497. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  498. std::set<cmSourceFile const*>::const_iterator it
  499. = this->ExplicitObjectName.find(file);
  500. return it != this->ExplicitObjectName.end();
  501. }
  502. //----------------------------------------------------------------------------
  503. void cmGeneratorTarget
  504. ::GetIDLSources(std::vector<cmSourceFile const*>& data,
  505. const std::string& config) const
  506. {
  507. IMPLEMENT_VISIT(IDLSources);
  508. }
  509. //----------------------------------------------------------------------------
  510. void
  511. cmGeneratorTarget
  512. ::GetHeaderSources(std::vector<cmSourceFile const*>& data,
  513. const std::string& config) const
  514. {
  515. IMPLEMENT_VISIT(HeaderSources);
  516. }
  517. //----------------------------------------------------------------------------
  518. void cmGeneratorTarget
  519. ::GetExtraSources(std::vector<cmSourceFile const*>& data,
  520. const std::string& config) const
  521. {
  522. IMPLEMENT_VISIT(ExtraSources);
  523. }
  524. //----------------------------------------------------------------------------
  525. void
  526. cmGeneratorTarget
  527. ::GetCustomCommands(std::vector<cmSourceFile const*>& data,
  528. const std::string& config) const
  529. {
  530. IMPLEMENT_VISIT(CustomCommands);
  531. }
  532. //----------------------------------------------------------------------------
  533. void
  534. cmGeneratorTarget
  535. ::GetExternalObjects(std::vector<cmSourceFile const*>& data,
  536. const std::string& config) const
  537. {
  538. IMPLEMENT_VISIT(ExternalObjects);
  539. }
  540. //----------------------------------------------------------------------------
  541. void
  542. cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& srcs,
  543. const std::string& config) const
  544. {
  545. ResxData data;
  546. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  547. srcs = data.ExpectedResxHeaders;
  548. }
  549. //----------------------------------------------------------------------------
  550. void cmGeneratorTarget
  551. ::GetResxSources(std::vector<cmSourceFile const*>& srcs,
  552. const std::string& config) const
  553. {
  554. ResxData data;
  555. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  556. srcs = data.ResxSources;
  557. }
  558. //----------------------------------------------------------------------------
  559. void
  560. cmGeneratorTarget
  561. ::GetAppManifest(std::vector<cmSourceFile const*>& data,
  562. const std::string& config) const
  563. {
  564. IMPLEMENT_VISIT(AppManifest);
  565. }
  566. //----------------------------------------------------------------------------
  567. void
  568. cmGeneratorTarget
  569. ::GetCertificates(std::vector<cmSourceFile const*>& data,
  570. const std::string& config) const
  571. {
  572. IMPLEMENT_VISIT(Certificates);
  573. }
  574. //----------------------------------------------------------------------------
  575. void
  576. cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
  577. const std::string& config) const
  578. {
  579. XamlData data;
  580. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  581. headers = data.ExpectedXamlHeaders;
  582. }
  583. //----------------------------------------------------------------------------
  584. void
  585. cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
  586. const std::string& config) const
  587. {
  588. XamlData data;
  589. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  590. srcs = data.ExpectedXamlSources;
  591. }
  592. //----------------------------------------------------------------------------
  593. void cmGeneratorTarget
  594. ::GetXamlSources(std::vector<cmSourceFile const*>& srcs,
  595. const std::string& config) const
  596. {
  597. XamlData data;
  598. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  599. srcs = data.XamlSources;
  600. }
  601. //----------------------------------------------------------------------------
  602. const char* cmGeneratorTarget::GetLocation(const std::string& config) const
  603. {
  604. static std::string location;
  605. if (this->Target->IsImported())
  606. {
  607. location = this->Target->ImportedGetFullPath(config, false);
  608. }
  609. else
  610. {
  611. location = this->GetFullPath(config, false);
  612. }
  613. return location.c_str();
  614. }
  615. bool cmGeneratorTarget::IsImported() const
  616. {
  617. return this->Target->IsImported();
  618. }
  619. //----------------------------------------------------------------------------
  620. const char* cmGeneratorTarget::GetLocationForBuild() const
  621. {
  622. static std::string location;
  623. if(this->IsImported())
  624. {
  625. location = this->Target->ImportedGetFullPath("", false);
  626. return location.c_str();
  627. }
  628. // Now handle the deprecated build-time configuration location.
  629. location = this->Target->GetDirectory();
  630. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  631. if(cfgid && strcmp(cfgid, ".") != 0)
  632. {
  633. location += "/";
  634. location += cfgid;
  635. }
  636. if(this->Target->IsAppBundleOnApple())
  637. {
  638. std::string macdir = this->BuildMacContentDirectory("", "",
  639. false);
  640. if(!macdir.empty())
  641. {
  642. location += "/";
  643. location += macdir;
  644. }
  645. }
  646. location += "/";
  647. location += this->GetFullName("", false);
  648. return location.c_str();
  649. }
  650. //----------------------------------------------------------------------------
  651. bool cmGeneratorTarget::IsSystemIncludeDirectory(const std::string& dir,
  652. const std::string& config) const
  653. {
  654. assert(this->GetType() != cmTarget::INTERFACE_LIBRARY);
  655. std::string config_upper;
  656. if(!config.empty())
  657. {
  658. config_upper = cmSystemTools::UpperCase(config);
  659. }
  660. typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
  661. IncludeCacheType::const_iterator iter =
  662. this->SystemIncludesCache.find(config_upper);
  663. if (iter == this->SystemIncludesCache.end())
  664. {
  665. cmGeneratorExpressionDAGChecker dagChecker(
  666. this->GetName(),
  667. "SYSTEM_INCLUDE_DIRECTORIES", 0, 0);
  668. bool excludeImported
  669. = this->Target->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  670. std::vector<std::string> result;
  671. for (std::set<std::string>::const_iterator
  672. it = this->Target->GetSystemIncludeDirectories().begin();
  673. it != this->Target->GetSystemIncludeDirectories().end(); ++it)
  674. {
  675. cmGeneratorExpression ge;
  676. cmSystemTools::ExpandListArgument(ge.Parse(*it)
  677. ->Evaluate(this->Makefile,
  678. config, false, this->Target,
  679. &dagChecker), result);
  680. }
  681. std::vector<cmTarget const*> const& deps =
  682. this->GetLinkImplementationClosure(config);
  683. for(std::vector<cmTarget const*>::const_iterator
  684. li = deps.begin(), le = deps.end(); li != le; ++li)
  685. {
  686. handleSystemIncludesDep(this->Makefile, *li, config, this->Target,
  687. &dagChecker, result, excludeImported);
  688. }
  689. std::set<std::string> unique;
  690. for(std::vector<std::string>::iterator li = result.begin();
  691. li != result.end(); ++li)
  692. {
  693. cmSystemTools::ConvertToUnixSlashes(*li);
  694. unique.insert(*li);
  695. }
  696. result.clear();
  697. result.insert(result.end(), unique.begin(), unique.end());
  698. IncludeCacheType::value_type entry(config_upper, result);
  699. iter = this->SystemIncludesCache.insert(entry).first;
  700. }
  701. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  702. }
  703. //----------------------------------------------------------------------------
  704. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  705. {
  706. return this->Target->GetPropertyAsBool(prop);
  707. }
  708. //----------------------------------------------------------------------------
  709. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
  710. const std::string& config) const
  711. {
  712. this->Target->GetSourceFiles(files, config);
  713. }
  714. //----------------------------------------------------------------------------
  715. std::string
  716. cmGeneratorTarget::GetCompilePDBName(const std::string& config) const
  717. {
  718. std::string prefix;
  719. std::string base;
  720. std::string suffix;
  721. this->GetFullNameInternal(config, false, prefix, base, suffix);
  722. // Check for a per-configuration output directory target property.
  723. std::string configUpper = cmSystemTools::UpperCase(config);
  724. std::string configProp = "COMPILE_PDB_NAME_";
  725. configProp += configUpper;
  726. const char* config_name = this->Target->GetProperty(configProp);
  727. if(config_name && *config_name)
  728. {
  729. return prefix + config_name + ".pdb";
  730. }
  731. const char* name = this->Target->GetProperty("COMPILE_PDB_NAME");
  732. if(name && *name)
  733. {
  734. return prefix + name + ".pdb";
  735. }
  736. return "";
  737. }
  738. //----------------------------------------------------------------------------
  739. std::string
  740. cmGeneratorTarget::GetCompilePDBPath(const std::string& config) const
  741. {
  742. std::string dir = this->GetCompilePDBDirectory(config);
  743. std::string name = this->GetCompilePDBName(config);
  744. if(dir.empty() && !name.empty())
  745. {
  746. dir = this->Target->GetPDBDirectory(config);
  747. }
  748. if(!dir.empty())
  749. {
  750. dir += "/";
  751. }
  752. return dir + name;
  753. }
  754. //----------------------------------------------------------------------------
  755. bool cmGeneratorTarget::HasSOName(const std::string& config) const
  756. {
  757. // soname is supported only for shared libraries and modules,
  758. // and then only when the platform supports an soname flag.
  759. return ((this->GetType() == cmTarget::SHARED_LIBRARY) &&
  760. !this->GetPropertyAsBool("NO_SONAME") &&
  761. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  762. }
  763. //----------------------------------------------------------------------------
  764. bool
  765. cmGeneratorTarget::NeedRelinkBeforeInstall(const std::string& config) const
  766. {
  767. // Only executables and shared libraries can have an rpath and may
  768. // need relinking.
  769. if(this->GetType() != cmTarget::EXECUTABLE &&
  770. this->GetType() != cmTarget::SHARED_LIBRARY &&
  771. this->GetType() != cmTarget::MODULE_LIBRARY)
  772. {
  773. return false;
  774. }
  775. // If there is no install location this target will not be installed
  776. // and therefore does not need relinking.
  777. if(!this->Target->GetHaveInstallRule())
  778. {
  779. return false;
  780. }
  781. // If skipping all rpaths completely then no relinking is needed.
  782. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  783. {
  784. return false;
  785. }
  786. // If building with the install-tree rpath no relinking is needed.
  787. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  788. {
  789. return false;
  790. }
  791. // If chrpath is going to be used no relinking is needed.
  792. if(this->IsChrpathUsed(config))
  793. {
  794. return false;
  795. }
  796. // Check for rpath support on this platform.
  797. std::string ll = this->GetLinkerLanguage(config);
  798. if(!ll.empty())
  799. {
  800. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  801. flagVar += ll;
  802. flagVar += "_FLAG";
  803. if(!this->Makefile->IsSet(flagVar))
  804. {
  805. // There is no rpath support on this platform so nothing needs
  806. // relinking.
  807. return false;
  808. }
  809. }
  810. else
  811. {
  812. // No linker language is known. This error will be reported by
  813. // other code.
  814. return false;
  815. }
  816. // If either a build or install tree rpath is set then the rpath
  817. // will likely change between the build tree and install tree and
  818. // this target must be relinked.
  819. return this->Target->HaveBuildTreeRPATH(config)
  820. || this->Target->HaveInstallTreeRPATH();
  821. }
  822. //----------------------------------------------------------------------------
  823. bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
  824. {
  825. // Only certain target types have an rpath.
  826. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  827. this->GetType() == cmTarget::MODULE_LIBRARY ||
  828. this->GetType() == cmTarget::EXECUTABLE))
  829. {
  830. return false;
  831. }
  832. // If the target will not be installed we do not need to change its
  833. // rpath.
  834. if(!this->Target->GetHaveInstallRule())
  835. {
  836. return false;
  837. }
  838. // Skip chrpath if skipping rpath altogether.
  839. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  840. {
  841. return false;
  842. }
  843. // Skip chrpath if it does not need to be changed at install time.
  844. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  845. {
  846. return false;
  847. }
  848. // Allow the user to disable builtin chrpath explicitly.
  849. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  850. {
  851. return false;
  852. }
  853. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  854. {
  855. return true;
  856. }
  857. #if defined(CMAKE_USE_ELF_PARSER)
  858. // Enable if the rpath flag uses a separator and the target uses ELF
  859. // binaries.
  860. std::string ll = this->GetLinkerLanguage(config);
  861. if(!ll.empty())
  862. {
  863. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  864. sepVar += ll;
  865. sepVar += "_FLAG_SEP";
  866. const char* sep = this->Makefile->GetDefinition(sepVar);
  867. if(sep && *sep)
  868. {
  869. // TODO: Add ELF check to ABI detection and get rid of
  870. // CMAKE_EXECUTABLE_FORMAT.
  871. if(const char* fmt =
  872. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  873. {
  874. return strcmp(fmt, "ELF") == 0;
  875. }
  876. }
  877. }
  878. #endif
  879. static_cast<void>(config);
  880. return false;
  881. }
  882. //----------------------------------------------------------------------------
  883. std::string cmGeneratorTarget::GetSOName(const std::string& config) const
  884. {
  885. if(this->Target->IsImported())
  886. {
  887. // Lookup the imported soname.
  888. if(cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config))
  889. {
  890. if(info->NoSOName)
  891. {
  892. // The imported library has no builtin soname so the name
  893. // searched at runtime will be just the filename.
  894. return cmSystemTools::GetFilenameName(info->Location);
  895. }
  896. else
  897. {
  898. // Use the soname given if any.
  899. if(info->SOName.find("@rpath/") == 0)
  900. {
  901. return info->SOName.substr(6);
  902. }
  903. return info->SOName;
  904. }
  905. }
  906. else
  907. {
  908. return "";
  909. }
  910. }
  911. else
  912. {
  913. // Compute the soname that will be built.
  914. std::string name;
  915. std::string soName;
  916. std::string realName;
  917. std::string impName;
  918. std::string pdbName;
  919. this->GetLibraryNames(name, soName, realName,
  920. impName, pdbName, config);
  921. return soName;
  922. }
  923. }
  924. //----------------------------------------------------------------------------
  925. std::string
  926. cmGeneratorTarget::GetAppBundleDirectory(const std::string& config,
  927. bool contentOnly) const
  928. {
  929. std::string fpath = this->GetFullName(config, false);
  930. fpath += ".app";
  931. if(!this->Makefile->PlatformIsAppleIos())
  932. {
  933. fpath += "/Contents";
  934. if(!contentOnly)
  935. fpath += "/MacOS";
  936. }
  937. return fpath;
  938. }
  939. //----------------------------------------------------------------------------
  940. bool cmGeneratorTarget::IsBundleOnApple() const
  941. {
  942. return this->Target->IsFrameworkOnApple()
  943. || this->Target->IsAppBundleOnApple()
  944. || this->Target->IsCFBundleOnApple();
  945. }
  946. //----------------------------------------------------------------------------
  947. std::string cmGeneratorTarget::GetCFBundleDirectory(const std::string& config,
  948. bool contentOnly) const
  949. {
  950. std::string fpath;
  951. fpath += this->GetOutputName(config, false);
  952. fpath += ".";
  953. const char *ext = this->Target->GetProperty("BUNDLE_EXTENSION");
  954. if (!ext)
  955. {
  956. if (this->Target->IsXCTestOnApple())
  957. {
  958. ext = "xctest";
  959. }
  960. else
  961. {
  962. ext = "bundle";
  963. }
  964. }
  965. fpath += ext;
  966. if(!this->Makefile->PlatformIsAppleIos())
  967. {
  968. fpath += "/Contents";
  969. if(!contentOnly)
  970. fpath += "/MacOS";
  971. }
  972. return fpath;
  973. }
  974. //----------------------------------------------------------------------------
  975. std::string
  976. cmGeneratorTarget::GetFrameworkDirectory(const std::string& config,
  977. bool rootDir) const
  978. {
  979. std::string fpath;
  980. fpath += this->GetOutputName(config, false);
  981. fpath += ".framework";
  982. if(!rootDir && !this->Makefile->PlatformIsAppleIos())
  983. {
  984. fpath += "/Versions/";
  985. fpath += this->Target->GetFrameworkVersion();
  986. }
  987. return fpath;
  988. }
  989. //----------------------------------------------------------------------------
  990. std::string
  991. cmGeneratorTarget::GetFullName(const std::string& config, bool implib) const
  992. {
  993. if(this->Target->IsImported())
  994. {
  995. return this->Target->GetFullNameImported(config, implib);
  996. }
  997. else
  998. {
  999. return this->GetFullNameInternal(config, implib);
  1000. }
  1001. }
  1002. //----------------------------------------------------------------------------
  1003. std::string
  1004. cmGeneratorTarget::GetInstallNameDirForBuildTree(
  1005. const std::string& config) const
  1006. {
  1007. // If building directly for installation then the build tree install_name
  1008. // is the same as the install tree.
  1009. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  1010. {
  1011. return this->GetInstallNameDirForInstallTree();
  1012. }
  1013. // Use the build tree directory for the target.
  1014. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  1015. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  1016. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  1017. {
  1018. std::string dir;
  1019. if(this->Target->MacOSXRpathInstallNameDirDefault())
  1020. {
  1021. dir = "@rpath";
  1022. }
  1023. else
  1024. {
  1025. dir = this->Target->GetDirectory(config);
  1026. }
  1027. dir += "/";
  1028. return dir;
  1029. }
  1030. else
  1031. {
  1032. return "";
  1033. }
  1034. }
  1035. //----------------------------------------------------------------------------
  1036. std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const
  1037. {
  1038. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  1039. {
  1040. std::string dir;
  1041. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  1042. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  1043. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  1044. {
  1045. if(install_name_dir && *install_name_dir)
  1046. {
  1047. dir = install_name_dir;
  1048. dir += "/";
  1049. }
  1050. }
  1051. if(!install_name_dir)
  1052. {
  1053. if(this->Target->MacOSXRpathInstallNameDirDefault())
  1054. {
  1055. dir = "@rpath/";
  1056. }
  1057. }
  1058. return dir;
  1059. }
  1060. else
  1061. {
  1062. return "";
  1063. }
  1064. }
  1065. //----------------------------------------------------------------------------
  1066. class cmTargetCollectLinkLanguages
  1067. {
  1068. public:
  1069. cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
  1070. const std::string& config,
  1071. UNORDERED_SET<std::string>& languages,
  1072. cmTarget const* head):
  1073. Config(config), Languages(languages), HeadTarget(head),
  1074. Makefile(target->Target->GetMakefile()), Target(target)
  1075. { this->Visited.insert(target->Target); }
  1076. void Visit(cmLinkItem const& item)
  1077. {
  1078. if(!item.Target)
  1079. {
  1080. if(item.find("::") != std::string::npos)
  1081. {
  1082. bool noMessage = false;
  1083. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1084. std::stringstream e;
  1085. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0028))
  1086. {
  1087. case cmPolicies::WARN:
  1088. {
  1089. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
  1090. messageType = cmake::AUTHOR_WARNING;
  1091. }
  1092. break;
  1093. case cmPolicies::OLD:
  1094. noMessage = true;
  1095. case cmPolicies::REQUIRED_IF_USED:
  1096. case cmPolicies::REQUIRED_ALWAYS:
  1097. case cmPolicies::NEW:
  1098. // Issue the fatal message.
  1099. break;
  1100. }
  1101. if(!noMessage)
  1102. {
  1103. e << "Target \"" << this->Target->GetName()
  1104. << "\" links to target \"" << item
  1105. << "\" but the target was not found. Perhaps a find_package() "
  1106. "call is missing for an IMPORTED target, or an ALIAS target is "
  1107. "missing?";
  1108. this->Makefile->GetCMakeInstance()->IssueMessage(
  1109. messageType, e.str(), this->Target->Target->GetBacktrace());
  1110. }
  1111. }
  1112. return;
  1113. }
  1114. if(!this->Visited.insert(item.Target).second)
  1115. {
  1116. return;
  1117. }
  1118. cmGeneratorTarget* gtgt =
  1119. this->Target->GetLocalGenerator()->GetGlobalGenerator()
  1120. ->GetGeneratorTarget(item.Target);
  1121. cmLinkInterface const* iface =
  1122. gtgt->GetLinkInterface(this->Config, this->HeadTarget);
  1123. if(!iface) { return; }
  1124. for(std::vector<std::string>::const_iterator
  1125. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  1126. {
  1127. this->Languages.insert(*li);
  1128. }
  1129. for(std::vector<cmLinkItem>::const_iterator
  1130. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  1131. {
  1132. this->Visit(*li);
  1133. }
  1134. }
  1135. private:
  1136. std::string Config;
  1137. UNORDERED_SET<std::string>& Languages;
  1138. cmTarget const* HeadTarget;
  1139. cmMakefile* Makefile;
  1140. const cmGeneratorTarget* Target;
  1141. std::set<cmTarget const*> Visited;
  1142. };
  1143. //----------------------------------------------------------------------------
  1144. cmGeneratorTarget::LinkClosure const*
  1145. cmGeneratorTarget::GetLinkClosure(const std::string& config) const
  1146. {
  1147. std::string key(cmSystemTools::UpperCase(config));
  1148. LinkClosureMapType::iterator
  1149. i = this->LinkClosureMap.find(key);
  1150. if(i == this->LinkClosureMap.end())
  1151. {
  1152. LinkClosure lc;
  1153. this->ComputeLinkClosure(config, lc);
  1154. LinkClosureMapType::value_type entry(key, lc);
  1155. i = this->LinkClosureMap.insert(entry).first;
  1156. }
  1157. return &i->second;
  1158. }
  1159. //----------------------------------------------------------------------------
  1160. class cmTargetSelectLinker
  1161. {
  1162. int Preference;
  1163. cmGeneratorTarget const* Target;
  1164. cmMakefile* Makefile;
  1165. cmGlobalGenerator* GG;
  1166. std::set<std::string> Preferred;
  1167. public:
  1168. cmTargetSelectLinker(cmGeneratorTarget const* target)
  1169. : Preference(0), Target(target)
  1170. {
  1171. this->Makefile = this->Target->Makefile;
  1172. this->GG = this->Makefile->GetGlobalGenerator();
  1173. }
  1174. void Consider(const char* lang)
  1175. {
  1176. int preference = this->GG->GetLinkerPreference(lang);
  1177. if(preference > this->Preference)
  1178. {
  1179. this->Preference = preference;
  1180. this->Preferred.clear();
  1181. }
  1182. if(preference == this->Preference)
  1183. {
  1184. this->Preferred.insert(lang);
  1185. }
  1186. }
  1187. std::string Choose()
  1188. {
  1189. if(this->Preferred.empty())
  1190. {
  1191. return "";
  1192. }
  1193. else if(this->Preferred.size() > 1)
  1194. {
  1195. std::stringstream e;
  1196. e << "Target " << this->Target->GetName()
  1197. << " contains multiple languages with the highest linker preference"
  1198. << " (" << this->Preference << "):\n";
  1199. for(std::set<std::string>::const_iterator
  1200. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  1201. {
  1202. e << " " << *li << "\n";
  1203. }
  1204. e << "Set the LINKER_LANGUAGE property for this target.";
  1205. cmake* cm = this->Makefile->GetCMakeInstance();
  1206. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  1207. this->Target->Target->GetBacktrace());
  1208. }
  1209. return *this->Preferred.begin();
  1210. }
  1211. };
  1212. //----------------------------------------------------------------------------
  1213. void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  1214. LinkClosure& lc) const
  1215. {
  1216. // Get languages built in this target.
  1217. UNORDERED_SET<std::string> languages;
  1218. cmLinkImplementation const* impl =
  1219. this->Target->GetLinkImplementation(config);
  1220. assert(impl);
  1221. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1222. li != impl->Languages.end(); ++li)
  1223. {
  1224. languages.insert(*li);
  1225. }
  1226. // Add interface languages from linked targets.
  1227. cmTargetCollectLinkLanguages cll(this, config, languages, this->Target);
  1228. for(std::vector<cmLinkImplItem>::const_iterator li = impl->Libraries.begin();
  1229. li != impl->Libraries.end(); ++li)
  1230. {
  1231. cll.Visit(*li);
  1232. }
  1233. // Store the transitive closure of languages.
  1234. for(UNORDERED_SET<std::string>::const_iterator li = languages.begin();
  1235. li != languages.end(); ++li)
  1236. {
  1237. lc.Languages.push_back(*li);
  1238. }
  1239. // Choose the language whose linker should be used.
  1240. if(this->GetProperty("HAS_CXX"))
  1241. {
  1242. lc.LinkerLanguage = "CXX";
  1243. }
  1244. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  1245. {
  1246. lc.LinkerLanguage = linkerLang;
  1247. }
  1248. else
  1249. {
  1250. // Find the language with the highest preference value.
  1251. cmTargetSelectLinker tsl(this);
  1252. // First select from the languages compiled directly in this target.
  1253. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1254. li != impl->Languages.end(); ++li)
  1255. {
  1256. tsl.Consider(li->c_str());
  1257. }
  1258. // Now consider languages that propagate from linked targets.
  1259. for(UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
  1260. sit != languages.end(); ++sit)
  1261. {
  1262. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  1263. if(this->Makefile->IsOn(propagates))
  1264. {
  1265. tsl.Consider(sit->c_str());
  1266. }
  1267. }
  1268. lc.LinkerLanguage = tsl.Choose();
  1269. }
  1270. }
  1271. //----------------------------------------------------------------------------
  1272. void cmGeneratorTarget::GetFullNameComponents(std::string& prefix,
  1273. std::string& base,
  1274. std::string& suffix,
  1275. const std::string& config,
  1276. bool implib) const
  1277. {
  1278. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  1279. }
  1280. //----------------------------------------------------------------------------
  1281. std::string
  1282. cmGeneratorTarget::BuildMacContentDirectory(const std::string& base,
  1283. const std::string& config,
  1284. bool contentOnly) const
  1285. {
  1286. std::string fpath = base;
  1287. if(this->Target->IsAppBundleOnApple())
  1288. {
  1289. fpath += this->GetAppBundleDirectory(config, contentOnly);
  1290. }
  1291. if(this->Target->IsFrameworkOnApple())
  1292. {
  1293. fpath += this->GetFrameworkDirectory(config, contentOnly);
  1294. }
  1295. if(this->Target->IsCFBundleOnApple())
  1296. {
  1297. fpath += this->GetCFBundleDirectory(config, contentOnly);
  1298. }
  1299. return fpath;
  1300. }
  1301. //----------------------------------------------------------------------------
  1302. std::string
  1303. cmGeneratorTarget::GetMacContentDirectory(const std::string& config,
  1304. bool implib) const
  1305. {
  1306. // Start with the output directory for the target.
  1307. std::string fpath = this->Target->GetDirectory(config, implib);
  1308. fpath += "/";
  1309. bool contentOnly = true;
  1310. if(this->Target->IsFrameworkOnApple())
  1311. {
  1312. // additional files with a framework go into the version specific
  1313. // directory
  1314. contentOnly = false;
  1315. }
  1316. fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
  1317. return fpath;
  1318. }
  1319. //----------------------------------------------------------------------------
  1320. cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
  1321. const std::string& config) const
  1322. {
  1323. // There is no compile information for imported targets.
  1324. if(this->IsImported())
  1325. {
  1326. return 0;
  1327. }
  1328. if(this->GetType() > cmTarget::OBJECT_LIBRARY)
  1329. {
  1330. std::string msg = "cmTarget::GetCompileInfo called for ";
  1331. msg += this->GetName();
  1332. msg += " which has type ";
  1333. msg += cmTarget::GetTargetTypeName(this->Target->GetType());
  1334. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1335. return 0;
  1336. }
  1337. // Lookup/compute/cache the compile information for this configuration.
  1338. std::string config_upper;
  1339. if(!config.empty())
  1340. {
  1341. config_upper = cmSystemTools::UpperCase(config);
  1342. }
  1343. CompileInfoMapType::const_iterator i =
  1344. this->CompileInfoMap.find(config_upper);
  1345. if(i == this->CompileInfoMap.end())
  1346. {
  1347. CompileInfo info;
  1348. this->Target
  1349. ->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  1350. CompileInfoMapType::value_type entry(config_upper, info);
  1351. i = this->CompileInfoMap.insert(entry).first;
  1352. }
  1353. return &i->second;
  1354. }
  1355. //----------------------------------------------------------------------------
  1356. std::string
  1357. cmGeneratorTarget::GetModuleDefinitionFile(const std::string& config) const
  1358. {
  1359. std::string data;
  1360. IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, COMMA std::string)
  1361. return data;
  1362. }
  1363. //----------------------------------------------------------------------------
  1364. void
  1365. cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs,
  1366. const std::string &config) const
  1367. {
  1368. std::vector<cmSourceFile const*> objectFiles;
  1369. this->GetExternalObjects(objectFiles, config);
  1370. std::vector<cmTarget*> objectLibraries;
  1371. for(std::vector<cmSourceFile const*>::const_iterator
  1372. it = objectFiles.begin(); it != objectFiles.end(); ++it)
  1373. {
  1374. std::string objLib = (*it)->GetObjectLibrary();
  1375. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  1376. {
  1377. objectLibraries.push_back(tgt);
  1378. }
  1379. }
  1380. std::vector<cmTarget*>::const_iterator end
  1381. = cmRemoveDuplicates(objectLibraries);
  1382. for(std::vector<cmTarget*>::const_iterator
  1383. ti = objectLibraries.begin();
  1384. ti != end; ++ti)
  1385. {
  1386. cmTarget* objLib = *ti;
  1387. cmGeneratorTarget* ogt =
  1388. this->GlobalGenerator->GetGeneratorTarget(objLib);
  1389. std::vector<cmSourceFile const*> objectSources;
  1390. ogt->GetObjectSources(objectSources, config);
  1391. for(std::vector<cmSourceFile const*>::const_iterator
  1392. si = objectSources.begin();
  1393. si != objectSources.end(); ++si)
  1394. {
  1395. std::string obj = ogt->ObjectDirectory;
  1396. obj += ogt->Objects[*si];
  1397. objs.push_back(obj);
  1398. }
  1399. }
  1400. }
  1401. //----------------------------------------------------------------------------
  1402. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string> &result,
  1403. const std::string& config) const
  1404. {
  1405. const char *prop
  1406. = this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS",
  1407. config);
  1408. if (!prop)
  1409. {
  1410. return;
  1411. }
  1412. cmGeneratorExpression ge;
  1413. cmGeneratorExpressionDAGChecker dagChecker(
  1414. this->GetName(),
  1415. "AUTOUIC_OPTIONS", 0, 0);
  1416. cmSystemTools::ExpandListArgument(ge.Parse(prop)
  1417. ->Evaluate(this->Makefile,
  1418. config,
  1419. false,
  1420. this->Target,
  1421. &dagChecker),
  1422. result);
  1423. }
  1424. //----------------------------------------------------------------------------
  1425. void processILibs(const std::string& config,
  1426. cmTarget const* headTarget,
  1427. cmLinkItem const& item,
  1428. cmGlobalGenerator* gg,
  1429. std::vector<cmTarget const*>& tgts,
  1430. std::set<cmTarget const*>& emitted)
  1431. {
  1432. if (item.Target && emitted.insert(item.Target).second)
  1433. {
  1434. tgts.push_back(item.Target);
  1435. cmGeneratorTarget* gt = gg->GetGeneratorTarget(item.Target);
  1436. if(cmLinkInterfaceLibraries const* iface =
  1437. gt->GetLinkInterfaceLibraries(config, headTarget, true))
  1438. {
  1439. for(std::vector<cmLinkItem>::const_iterator
  1440. it = iface->Libraries.begin();
  1441. it != iface->Libraries.end(); ++it)
  1442. {
  1443. processILibs(config, headTarget, *it, gg, tgts, emitted);
  1444. }
  1445. }
  1446. }
  1447. }
  1448. //----------------------------------------------------------------------------
  1449. const std::vector<const cmTarget*>&
  1450. cmGeneratorTarget::GetLinkImplementationClosure(
  1451. const std::string& config) const
  1452. {
  1453. LinkImplClosure& tgts =
  1454. this->LinkImplClosureMap[config];
  1455. if(!tgts.Done)
  1456. {
  1457. tgts.Done = true;
  1458. std::set<cmTarget const*> emitted;
  1459. cmLinkImplementationLibraries const* impl
  1460. = this->Target->GetLinkImplementationLibraries(config);
  1461. for(std::vector<cmLinkImplItem>::const_iterator
  1462. it = impl->Libraries.begin();
  1463. it != impl->Libraries.end(); ++it)
  1464. {
  1465. processILibs(config, this->Target, *it,
  1466. this->LocalGenerator->GetGlobalGenerator(),
  1467. tgts , emitted);
  1468. }
  1469. }
  1470. return tgts;
  1471. }
  1472. //----------------------------------------------------------------------------
  1473. class cmTargetTraceDependencies
  1474. {
  1475. public:
  1476. cmTargetTraceDependencies(cmGeneratorTarget* target);
  1477. void Trace();
  1478. private:
  1479. cmTarget* Target;
  1480. cmGeneratorTarget* GeneratorTarget;
  1481. cmMakefile* Makefile;
  1482. cmGlobalGenerator const* GlobalGenerator;
  1483. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  1484. SourceEntry* CurrentEntry;
  1485. std::queue<cmSourceFile*> SourceQueue;
  1486. std::set<cmSourceFile*> SourcesQueued;
  1487. typedef std::map<std::string, cmSourceFile*> NameMapType;
  1488. NameMapType NameMap;
  1489. std::vector<std::string> NewSources;
  1490. void QueueSource(cmSourceFile* sf);
  1491. void FollowName(std::string const& name);
  1492. void FollowNames(std::vector<std::string> const& names);
  1493. bool IsUtility(std::string const& dep);
  1494. void CheckCustomCommand(cmCustomCommand const& cc);
  1495. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  1496. void FollowCommandDepends(cmCustomCommand const& cc,
  1497. const std::string& config,
  1498. std::set<std::string>& emitted);
  1499. };
  1500. //----------------------------------------------------------------------------
  1501. cmTargetTraceDependencies
  1502. ::cmTargetTraceDependencies(cmGeneratorTarget* target):
  1503. Target(target->Target), GeneratorTarget(target)
  1504. {
  1505. // Convenience.
  1506. this->Makefile = this->Target->GetMakefile();
  1507. this->GlobalGenerator = target->GetLocalGenerator()->GetGlobalGenerator();
  1508. this->CurrentEntry = 0;
  1509. // Queue all the source files already specified for the target.
  1510. if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  1511. {
  1512. std::vector<std::string> configs;
  1513. this->Makefile->GetConfigurations(configs);
  1514. if (configs.empty())
  1515. {
  1516. configs.push_back("");
  1517. }
  1518. std::set<cmSourceFile*> emitted;
  1519. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1520. ci != configs.end(); ++ci)
  1521. {
  1522. std::vector<cmSourceFile*> sources;
  1523. this->Target->GetSourceFiles(sources, *ci);
  1524. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1525. si != sources.end(); ++si)
  1526. {
  1527. cmSourceFile* sf = *si;
  1528. const std::set<cmTarget const*> tgts =
  1529. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  1530. if (tgts.find(this->Target) != tgts.end())
  1531. {
  1532. std::ostringstream e;
  1533. e << "Evaluation output file\n \"" << sf->GetFullPath()
  1534. << "\"\ndepends on the sources of a target it is used in. This "
  1535. "is a dependency loop and is not allowed.";
  1536. this->GeneratorTarget
  1537. ->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  1538. return;
  1539. }
  1540. if(emitted.insert(sf).second && this->SourcesQueued.insert(sf).second)
  1541. {
  1542. this->SourceQueue.push(sf);
  1543. }
  1544. }
  1545. }
  1546. }
  1547. // Queue pre-build, pre-link, and post-build rule dependencies.
  1548. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  1549. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  1550. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  1551. }
  1552. //----------------------------------------------------------------------------
  1553. void cmTargetTraceDependencies::Trace()
  1554. {
  1555. // Process one dependency at a time until the queue is empty.
  1556. while(!this->SourceQueue.empty())
  1557. {
  1558. // Get the next source from the queue.
  1559. cmSourceFile* sf = this->SourceQueue.front();
  1560. this->SourceQueue.pop();
  1561. this->CurrentEntry = &this->GeneratorTarget->SourceEntries[sf];
  1562. // Queue dependencies added explicitly by the user.
  1563. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  1564. {
  1565. std::vector<std::string> objDeps;
  1566. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  1567. for(std::vector<std::string>::iterator odi = objDeps.begin();
  1568. odi != objDeps.end(); ++odi)
  1569. {
  1570. if (cmSystemTools::FileIsFullPath(*odi))
  1571. {
  1572. *odi = cmSystemTools::CollapseFullPath(*odi);
  1573. }
  1574. }
  1575. this->FollowNames(objDeps);
  1576. }
  1577. // Queue the source needed to generate this file, if any.
  1578. this->FollowName(sf->GetFullPath());
  1579. // Queue dependencies added programatically by commands.
  1580. this->FollowNames(sf->GetDepends());
  1581. // Queue custom command dependencies.
  1582. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  1583. {
  1584. this->CheckCustomCommand(*cc);
  1585. }
  1586. }
  1587. this->CurrentEntry = 0;
  1588. this->Target->AddTracedSources(this->NewSources);
  1589. }
  1590. //----------------------------------------------------------------------------
  1591. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  1592. {
  1593. if(this->SourcesQueued.insert(sf).second)
  1594. {
  1595. this->SourceQueue.push(sf);
  1596. // Make sure this file is in the target at the end.
  1597. this->NewSources.push_back(sf->GetFullPath());
  1598. }
  1599. }
  1600. //----------------------------------------------------------------------------
  1601. void cmTargetTraceDependencies::FollowName(std::string const& name)
  1602. {
  1603. NameMapType::iterator i = this->NameMap.find(name);
  1604. if(i == this->NameMap.end())
  1605. {
  1606. // Check if we know how to generate this file.
  1607. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  1608. NameMapType::value_type entry(name, sf);
  1609. i = this->NameMap.insert(entry).first;
  1610. }
  1611. if(cmSourceFile* sf = i->second)
  1612. {
  1613. // Record the dependency we just followed.
  1614. if(this->CurrentEntry)
  1615. {
  1616. this->CurrentEntry->Depends.push_back(sf);
  1617. }
  1618. this->QueueSource(sf);
  1619. }
  1620. }
  1621. //----------------------------------------------------------------------------
  1622. void
  1623. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  1624. {
  1625. for(std::vector<std::string>::const_iterator i = names.begin();
  1626. i != names.end(); ++i)
  1627. {
  1628. this->FollowName(*i);
  1629. }
  1630. }
  1631. //----------------------------------------------------------------------------
  1632. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  1633. {
  1634. // Dependencies on targets (utilities) are supposed to be named by
  1635. // just the target name. However for compatibility we support
  1636. // naming the output file generated by the target (assuming there is
  1637. // no output-name property which old code would not have set). In
  1638. // that case the target name will be the file basename of the
  1639. // dependency.
  1640. std::string util = cmSystemTools::GetFilenameName(dep);
  1641. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  1642. {
  1643. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  1644. }
  1645. // Check for a target with this name.
  1646. if(cmGeneratorTarget* t
  1647. = this->Makefile->FindGeneratorTargetToUse(util))
  1648. {
  1649. // If we find the target and the dep was given as a full path,
  1650. // then make sure it was not a full path to something else, and
  1651. // the fact that the name matched a target was just a coincidence.
  1652. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  1653. {
  1654. if(t->GetType() >= cmTarget::EXECUTABLE &&
  1655. t->GetType() <= cmTarget::MODULE_LIBRARY)
  1656. {
  1657. // This is really only for compatibility so we do not need to
  1658. // worry about configuration names and output names.
  1659. std::string tLocation = t->GetLocationForBuild();
  1660. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1661. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  1662. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  1663. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  1664. if(depLocation == tLocation)
  1665. {
  1666. this->Target->AddUtility(util);
  1667. return true;
  1668. }
  1669. }
  1670. }
  1671. else
  1672. {
  1673. // The original name of the dependency was not a full path. It
  1674. // must name a target, so add the target-level dependency.
  1675. this->Target->AddUtility(util);
  1676. return true;
  1677. }
  1678. }
  1679. // The dependency does not name a target built in this project.
  1680. return false;
  1681. }
  1682. //----------------------------------------------------------------------------
  1683. void
  1684. cmTargetTraceDependencies
  1685. ::CheckCustomCommand(cmCustomCommand const& cc)
  1686. {
  1687. // Transform command names that reference targets built in this
  1688. // project to corresponding target-level dependencies.
  1689. cmGeneratorExpression ge(cc.GetBacktrace());
  1690. // Add target-level dependencies referenced by generator expressions.
  1691. std::set<cmTarget*> targets;
  1692. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  1693. cit != cc.GetCommandLines().end(); ++cit)
  1694. {
  1695. std::string const& command = *cit->begin();
  1696. // Check for a target with this name.
  1697. if(cmTarget* t = this->Makefile->FindTargetToUse(command))
  1698. {
  1699. if(t->GetType() == cmTarget::EXECUTABLE)
  1700. {
  1701. // The command refers to an executable target built in
  1702. // this project. Add the target-level dependency to make
  1703. // sure the executable is up to date before this custom
  1704. // command possibly runs.
  1705. this->Target->AddUtility(command);
  1706. }
  1707. }
  1708. // Check for target references in generator expressions.
  1709. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  1710. cli != cit->end(); ++cli)
  1711. {
  1712. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  1713. = ge.Parse(*cli);
  1714. cge->Evaluate(this->Makefile, "", true);
  1715. std::set<cmTarget*> geTargets = cge->GetTargets();
  1716. targets.insert(geTargets.begin(), geTargets.end());
  1717. }
  1718. }
  1719. for(std::set<cmTarget*>::iterator ti = targets.begin();
  1720. ti != targets.end(); ++ti)
  1721. {
  1722. this->Target->AddUtility((*ti)->GetName());
  1723. }
  1724. // Queue the custom command dependencies.
  1725. std::vector<std::string> configs;
  1726. std::set<std::string> emitted;
  1727. this->Makefile->GetConfigurations(configs);
  1728. if (configs.empty())
  1729. {
  1730. configs.push_back("");
  1731. }
  1732. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1733. ci != configs.end(); ++ci)
  1734. {
  1735. this->FollowCommandDepends(cc, *ci, emitted);
  1736. }
  1737. }
  1738. //----------------------------------------------------------------------------
  1739. void cmTargetTraceDependencies::FollowCommandDepends(cmCustomCommand const& cc,
  1740. const std::string& config,
  1741. std::set<std::string>& emitted)
  1742. {
  1743. cmCustomCommandGenerator ccg(cc, config,
  1744. this->GeneratorTarget->LocalGenerator);
  1745. const std::vector<std::string>& depends = ccg.GetDepends();
  1746. for(std::vector<std::string>::const_iterator di = depends.begin();
  1747. di != depends.end(); ++di)
  1748. {
  1749. std::string const& dep = *di;
  1750. if(emitted.insert(dep).second)
  1751. {
  1752. if(!this->IsUtility(dep))
  1753. {
  1754. // The dependency does not name a target and may be a file we
  1755. // know how to generate. Queue it.
  1756. this->FollowName(dep);
  1757. }
  1758. }
  1759. }
  1760. }
  1761. //----------------------------------------------------------------------------
  1762. void
  1763. cmTargetTraceDependencies
  1764. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  1765. {
  1766. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  1767. cli != commands.end(); ++cli)
  1768. {
  1769. this->CheckCustomCommand(*cli);
  1770. }
  1771. }
  1772. //----------------------------------------------------------------------------
  1773. void cmGeneratorTarget::TraceDependencies()
  1774. {
  1775. // CMake-generated targets have no dependencies to trace. Normally tracing
  1776. // would find nothing anyway, but when building CMake itself the "install"
  1777. // target command ends up referencing the "cmake" target but we do not
  1778. // really want the dependency because "install" depend on "all" anyway.
  1779. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  1780. {
  1781. return;
  1782. }
  1783. // Use a helper object to trace the dependencies.
  1784. cmTargetTraceDependencies tracer(this);
  1785. tracer.Trace();
  1786. }
  1787. std::string
  1788. cmGeneratorTarget::GetCompilePDBDirectory(const std::string& config) const
  1789. {
  1790. if(CompileInfo const* info = this->GetCompileInfo(config))
  1791. {
  1792. return info->CompilePdbDir;
  1793. }
  1794. return "";
  1795. }
  1796. //----------------------------------------------------------------------------
  1797. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  1798. std::vector<std::string>& archVec) const
  1799. {
  1800. const char* archs = 0;
  1801. if(!config.empty())
  1802. {
  1803. std::string defVarName = "OSX_ARCHITECTURES_";
  1804. defVarName += cmSystemTools::UpperCase(config);
  1805. archs = this->Target->GetProperty(defVarName);
  1806. }
  1807. if(!archs)
  1808. {
  1809. archs = this->Target->GetProperty("OSX_ARCHITECTURES");
  1810. }
  1811. if(archs)
  1812. {
  1813. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  1814. }
  1815. }
  1816. //----------------------------------------------------------------------------
  1817. std::string
  1818. cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang,
  1819. std::string const& config) const
  1820. {
  1821. switch(this->GetType())
  1822. {
  1823. case cmTarget::STATIC_LIBRARY:
  1824. {
  1825. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  1826. if(this->GetFeatureAsBool(
  1827. "INTERPROCEDURAL_OPTIMIZATION", config))
  1828. {
  1829. std::string varIPO = var + "_IPO";
  1830. if(this->Makefile->GetDefinition(varIPO))
  1831. {
  1832. return varIPO;
  1833. }
  1834. }
  1835. return var;
  1836. }
  1837. case cmTarget::SHARED_LIBRARY:
  1838. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  1839. case cmTarget::MODULE_LIBRARY:
  1840. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  1841. case cmTarget::EXECUTABLE:
  1842. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  1843. default:
  1844. break;
  1845. }
  1846. return "";
  1847. }
  1848. //----------------------------------------------------------------------------
  1849. static void processIncludeDirectories(cmGeneratorTarget const* tgt,
  1850. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  1851. std::vector<std::string> &includes,
  1852. UNORDERED_SET<std::string> &uniqueIncludes,
  1853. cmGeneratorExpressionDAGChecker *dagChecker,
  1854. const std::string& config, bool debugIncludes,
  1855. const std::string& language)
  1856. {
  1857. cmMakefile *mf = tgt->Target->GetMakefile();
  1858. for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
  1859. it = entries.begin(), end = entries.end(); it != end; ++it)
  1860. {
  1861. cmLinkImplItem const& item = (*it)->LinkImplItem;
  1862. std::string const& targetName = item;
  1863. bool const fromImported = item.Target && item.Target->IsImported();
  1864. bool const checkCMP0027 = item.FromGenex;
  1865. std::vector<std::string> entryIncludes;
  1866. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  1867. config,
  1868. false,
  1869. tgt->Target,
  1870. dagChecker, language),
  1871. entryIncludes);
  1872. std::string usedIncludes;
  1873. for(std::vector<std::string>::iterator
  1874. li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
  1875. {
  1876. if (fromImported
  1877. && !cmSystemTools::FileExists(li->c_str()))
  1878. {
  1879. std::ostringstream e;
  1880. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1881. if (checkCMP0027)
  1882. {
  1883. switch(tgt->Target->GetPolicyStatusCMP0027())
  1884. {
  1885. case cmPolicies::WARN:
  1886. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
  1887. case cmPolicies::OLD:
  1888. messageType = cmake::AUTHOR_WARNING;
  1889. break;
  1890. case cmPolicies::REQUIRED_ALWAYS:
  1891. case cmPolicies::REQUIRED_IF_USED:
  1892. case cmPolicies::NEW:
  1893. break;
  1894. }
  1895. }
  1896. e << "Imported target \"" << targetName << "\" includes "
  1897. "non-existent path\n \"" << *li << "\"\nin its "
  1898. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  1899. "* The path was deleted, renamed, or moved to another "
  1900. "location.\n"
  1901. "* An install or uninstall procedure did not complete "
  1902. "successfully.\n"
  1903. "* The installation package was faulty and references files it "
  1904. "does not provide.\n";
  1905. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  1906. return;
  1907. }
  1908. if (!cmSystemTools::FileIsFullPath(li->c_str()))
  1909. {
  1910. std::ostringstream e;
  1911. bool noMessage = false;
  1912. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1913. if (!targetName.empty())
  1914. {
  1915. e << "Target \"" << targetName << "\" contains relative "
  1916. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  1917. " \"" << *li << "\"";
  1918. }
  1919. else
  1920. {
  1921. switch(tgt->Target->GetPolicyStatusCMP0021())
  1922. {
  1923. case cmPolicies::WARN:
  1924. {
  1925. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n";
  1926. messageType = cmake::AUTHOR_WARNING;
  1927. }
  1928. break;
  1929. case cmPolicies::OLD:
  1930. noMessage = true;
  1931. case cmPolicies::REQUIRED_IF_USED:
  1932. case cmPolicies::REQUIRED_ALWAYS:
  1933. case cmPolicies::NEW:
  1934. // Issue the fatal message.
  1935. break;
  1936. }
  1937. e << "Found relative path while evaluating include directories of "
  1938. "\"" << tgt->GetName() << "\":\n \"" << *li << "\"\n";
  1939. }
  1940. if (!noMessage)
  1941. {
  1942. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  1943. if (messageType == cmake::FATAL_ERROR)
  1944. {
  1945. return;
  1946. }
  1947. }
  1948. }
  1949. if (!cmSystemTools::IsOff(li->c_str()))
  1950. {
  1951. cmSystemTools::ConvertToUnixSlashes(*li);
  1952. }
  1953. std::string inc = *li;
  1954. if(uniqueIncludes.insert(inc).second)
  1955. {
  1956. includes.push_back(inc);
  1957. if (debugIncludes)
  1958. {
  1959. usedIncludes += " * " + inc + "\n";
  1960. }
  1961. }
  1962. }
  1963. if (!usedIncludes.empty())
  1964. {
  1965. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  1966. std::string("Used includes for target ")
  1967. + tgt->GetName() + ":\n"
  1968. + usedIncludes, (*it)->ge->GetBacktrace());
  1969. }
  1970. }
  1971. }
  1972. //----------------------------------------------------------------------------
  1973. static void AddInterfaceEntries(
  1974. cmGeneratorTarget const* thisTarget, std::string const& config,
  1975. std::string const& prop,
  1976. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
  1977. {
  1978. if(cmLinkImplementationLibraries const* impl =
  1979. thisTarget->Target->GetLinkImplementationLibraries(config))
  1980. {
  1981. for (std::vector<cmLinkImplItem>::const_iterator
  1982. it = impl->Libraries.begin(), end = impl->Libraries.end();
  1983. it != end; ++it)
  1984. {
  1985. if(it->Target)
  1986. {
  1987. std::string genex =
  1988. "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
  1989. cmGeneratorExpression ge(it->Backtrace);
  1990. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  1991. cge->SetEvaluateForBuildsystem(true);
  1992. entries.push_back(
  1993. new cmGeneratorTarget::TargetPropertyEntry(cge, *it));
  1994. }
  1995. }
  1996. }
  1997. }
  1998. //----------------------------------------------------------------------------
  1999. std::vector<std::string>
  2000. cmGeneratorTarget::GetIncludeDirectories(const std::string& config,
  2001. const std::string& lang) const
  2002. {
  2003. std::vector<std::string> includes;
  2004. UNORDERED_SET<std::string> uniqueIncludes;
  2005. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2006. "INCLUDE_DIRECTORIES", 0, 0);
  2007. std::vector<std::string> debugProperties;
  2008. const char *debugProp =
  2009. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2010. if (debugProp)
  2011. {
  2012. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2013. }
  2014. bool debugIncludes = !this->DebugIncludesDone
  2015. && std::find(debugProperties.begin(),
  2016. debugProperties.end(),
  2017. "INCLUDE_DIRECTORIES")
  2018. != debugProperties.end();
  2019. if (this->Makefile->IsConfigured())
  2020. {
  2021. this->DebugIncludesDone = true;
  2022. }
  2023. processIncludeDirectories(this,
  2024. this->IncludeDirectoriesEntries,
  2025. includes,
  2026. uniqueIncludes,
  2027. &dagChecker,
  2028. config,
  2029. debugIncludes,
  2030. lang);
  2031. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2032. linkInterfaceIncludeDirectoriesEntries;
  2033. AddInterfaceEntries(
  2034. this, config, "INTERFACE_INCLUDE_DIRECTORIES",
  2035. linkInterfaceIncludeDirectoriesEntries);
  2036. if(this->Makefile->IsOn("APPLE"))
  2037. {
  2038. cmLinkImplementationLibraries const* impl =
  2039. this->Target->GetLinkImplementationLibraries(config);
  2040. for(std::vector<cmLinkImplItem>::const_iterator
  2041. it = impl->Libraries.begin();
  2042. it != impl->Libraries.end(); ++it)
  2043. {
  2044. std::string libDir = cmSystemTools::CollapseFullPath(*it);
  2045. static cmsys::RegularExpression
  2046. frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  2047. if(!frameworkCheck.find(libDir))
  2048. {
  2049. continue;
  2050. }
  2051. libDir = frameworkCheck.match(1);
  2052. cmGeneratorExpression ge;
  2053. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2054. ge.Parse(libDir.c_str());
  2055. linkInterfaceIncludeDirectoriesEntries
  2056. .push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  2057. }
  2058. }
  2059. processIncludeDirectories(this,
  2060. linkInterfaceIncludeDirectoriesEntries,
  2061. includes,
  2062. uniqueIncludes,
  2063. &dagChecker,
  2064. config,
  2065. debugIncludes,
  2066. lang);
  2067. cmDeleteAll(linkInterfaceIncludeDirectoriesEntries);
  2068. return includes;
  2069. }
  2070. //----------------------------------------------------------------------------
  2071. static void processCompileOptionsInternal(cmGeneratorTarget const* tgt,
  2072. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2073. std::vector<std::string> &options,
  2074. UNORDERED_SET<std::string> &uniqueOptions,
  2075. cmGeneratorExpressionDAGChecker *dagChecker,
  2076. const std::string& config, bool debugOptions, const char *logName,
  2077. std::string const& language)
  2078. {
  2079. cmMakefile *mf = tgt->Target->GetMakefile();
  2080. for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
  2081. it = entries.begin(), end = entries.end(); it != end; ++it)
  2082. {
  2083. std::vector<std::string> entryOptions;
  2084. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  2085. config,
  2086. false,
  2087. tgt->Target,
  2088. dagChecker,
  2089. language),
  2090. entryOptions);
  2091. std::string usedOptions;
  2092. for(std::vector<std::string>::iterator
  2093. li = entryOptions.begin(); li != entryOptions.end(); ++li)
  2094. {
  2095. std::string const& opt = *li;
  2096. if(uniqueOptions.insert(opt).second)
  2097. {
  2098. options.push_back(opt);
  2099. if (debugOptions)
  2100. {
  2101. usedOptions += " * " + opt + "\n";
  2102. }
  2103. }
  2104. }
  2105. if (!usedOptions.empty())
  2106. {
  2107. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  2108. std::string("Used compile ") + logName
  2109. + std::string(" for target ")
  2110. + tgt->GetName() + ":\n"
  2111. + usedOptions, (*it)->ge->GetBacktrace());
  2112. }
  2113. }
  2114. }
  2115. //----------------------------------------------------------------------------
  2116. static void processCompileOptions(cmGeneratorTarget const* tgt,
  2117. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2118. std::vector<std::string> &options,
  2119. UNORDERED_SET<std::string> &uniqueOptions,
  2120. cmGeneratorExpressionDAGChecker *dagChecker,
  2121. const std::string& config, bool debugOptions,
  2122. std::string const& language)
  2123. {
  2124. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2125. dagChecker, config, debugOptions, "options",
  2126. language);
  2127. }
  2128. //----------------------------------------------------------------------------
  2129. void cmGeneratorTarget::GetCompileOptions(std::vector<std::string> &result,
  2130. const std::string& config,
  2131. const std::string& language) const
  2132. {
  2133. UNORDERED_SET<std::string> uniqueOptions;
  2134. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2135. "COMPILE_OPTIONS", 0, 0);
  2136. std::vector<std::string> debugProperties;
  2137. const char *debugProp =
  2138. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2139. if (debugProp)
  2140. {
  2141. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2142. }
  2143. bool debugOptions = !this->DebugCompileOptionsDone
  2144. && std::find(debugProperties.begin(),
  2145. debugProperties.end(),
  2146. "COMPILE_OPTIONS")
  2147. != debugProperties.end();
  2148. if (this->Makefile->IsConfigured())
  2149. {
  2150. this->DebugCompileOptionsDone = true;
  2151. }
  2152. processCompileOptions(this,
  2153. this->CompileOptionsEntries,
  2154. result,
  2155. uniqueOptions,
  2156. &dagChecker,
  2157. config,
  2158. debugOptions,
  2159. language);
  2160. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2161. linkInterfaceCompileOptionsEntries;
  2162. AddInterfaceEntries(
  2163. this, config, "INTERFACE_COMPILE_OPTIONS",
  2164. linkInterfaceCompileOptionsEntries);
  2165. processCompileOptions(this,
  2166. linkInterfaceCompileOptionsEntries,
  2167. result,
  2168. uniqueOptions,
  2169. &dagChecker,
  2170. config,
  2171. debugOptions,
  2172. language);
  2173. cmDeleteAll(linkInterfaceCompileOptionsEntries);
  2174. }
  2175. //----------------------------------------------------------------------------
  2176. static void processCompileFeatures(cmGeneratorTarget const* tgt,
  2177. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2178. std::vector<std::string> &options,
  2179. UNORDERED_SET<std::string> &uniqueOptions,
  2180. cmGeneratorExpressionDAGChecker *dagChecker,
  2181. const std::string& config, bool debugOptions)
  2182. {
  2183. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2184. dagChecker, config, debugOptions, "features",
  2185. std::string());
  2186. }
  2187. //----------------------------------------------------------------------------
  2188. void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string> &result,
  2189. const std::string& config) const
  2190. {
  2191. UNORDERED_SET<std::string> uniqueFeatures;
  2192. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2193. "COMPILE_FEATURES",
  2194. 0, 0);
  2195. std::vector<std::string> debugProperties;
  2196. const char *debugProp =
  2197. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2198. if (debugProp)
  2199. {
  2200. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2201. }
  2202. bool debugFeatures = !this->DebugCompileFeaturesDone
  2203. && std::find(debugProperties.begin(),
  2204. debugProperties.end(),
  2205. "COMPILE_FEATURES")
  2206. != debugProperties.end();
  2207. if (this->Makefile->IsConfigured())
  2208. {
  2209. this->DebugCompileFeaturesDone = true;
  2210. }
  2211. processCompileFeatures(this,
  2212. this->CompileFeaturesEntries,
  2213. result,
  2214. uniqueFeatures,
  2215. &dagChecker,
  2216. config,
  2217. debugFeatures);
  2218. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2219. linkInterfaceCompileFeaturesEntries;
  2220. AddInterfaceEntries(
  2221. this, config, "INTERFACE_COMPILE_FEATURES",
  2222. linkInterfaceCompileFeaturesEntries);
  2223. processCompileFeatures(this,
  2224. linkInterfaceCompileFeaturesEntries,
  2225. result,
  2226. uniqueFeatures,
  2227. &dagChecker,
  2228. config,
  2229. debugFeatures);
  2230. cmDeleteAll(linkInterfaceCompileFeaturesEntries);
  2231. }
  2232. //----------------------------------------------------------------------------
  2233. static void processCompileDefinitions(cmGeneratorTarget const* tgt,
  2234. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2235. std::vector<std::string> &options,
  2236. UNORDERED_SET<std::string> &uniqueOptions,
  2237. cmGeneratorExpressionDAGChecker *dagChecker,
  2238. const std::string& config, bool debugOptions,
  2239. std::string const& language)
  2240. {
  2241. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2242. dagChecker, config, debugOptions,
  2243. "definitions", language);
  2244. }
  2245. //----------------------------------------------------------------------------
  2246. void cmGeneratorTarget::GetCompileDefinitions(std::vector<std::string> &list,
  2247. const std::string& config,
  2248. const std::string& language) const
  2249. {
  2250. UNORDERED_SET<std::string> uniqueOptions;
  2251. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2252. "COMPILE_DEFINITIONS", 0, 0);
  2253. std::vector<std::string> debugProperties;
  2254. const char *debugProp =
  2255. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2256. if (debugProp)
  2257. {
  2258. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2259. }
  2260. bool debugDefines = !this->DebugCompileDefinitionsDone
  2261. && std::find(debugProperties.begin(),
  2262. debugProperties.end(),
  2263. "COMPILE_DEFINITIONS")
  2264. != debugProperties.end();
  2265. if (this->Makefile->IsConfigured())
  2266. {
  2267. this->DebugCompileDefinitionsDone = true;
  2268. }
  2269. processCompileDefinitions(this,
  2270. this->CompileDefinitionsEntries,
  2271. list,
  2272. uniqueOptions,
  2273. &dagChecker,
  2274. config,
  2275. debugDefines,
  2276. language);
  2277. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2278. linkInterfaceCompileDefinitionsEntries;
  2279. AddInterfaceEntries(
  2280. this, config, "INTERFACE_COMPILE_DEFINITIONS",
  2281. linkInterfaceCompileDefinitionsEntries);
  2282. if (!config.empty())
  2283. {
  2284. std::string configPropName = "COMPILE_DEFINITIONS_"
  2285. + cmSystemTools::UpperCase(config);
  2286. const char *configProp = this->Target->GetProperty(configPropName);
  2287. if (configProp)
  2288. {
  2289. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
  2290. {
  2291. case cmPolicies::WARN:
  2292. {
  2293. std::ostringstream e;
  2294. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
  2295. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING,
  2296. e.str());
  2297. }
  2298. case cmPolicies::OLD:
  2299. {
  2300. cmGeneratorExpression ge;
  2301. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2302. ge.Parse(configProp);
  2303. linkInterfaceCompileDefinitionsEntries
  2304. .push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  2305. }
  2306. break;
  2307. case cmPolicies::NEW:
  2308. case cmPolicies::REQUIRED_ALWAYS:
  2309. case cmPolicies::REQUIRED_IF_USED:
  2310. break;
  2311. }
  2312. }
  2313. }
  2314. processCompileDefinitions(this,
  2315. linkInterfaceCompileDefinitionsEntries,
  2316. list,
  2317. uniqueOptions,
  2318. &dagChecker,
  2319. config,
  2320. debugDefines,
  2321. language);
  2322. cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
  2323. }
  2324. //----------------------------------------------------------------------------
  2325. void cmGeneratorTarget::GenerateTargetManifest(
  2326. const std::string& config) const
  2327. {
  2328. if (this->Target->IsImported())
  2329. {
  2330. return;
  2331. }
  2332. cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
  2333. // Get the names.
  2334. std::string name;
  2335. std::string soName;
  2336. std::string realName;
  2337. std::string impName;
  2338. std::string pdbName;
  2339. if(this->GetType() == cmTarget::EXECUTABLE)
  2340. {
  2341. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2342. }
  2343. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  2344. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2345. this->GetType() == cmTarget::MODULE_LIBRARY)
  2346. {
  2347. this->GetLibraryNames(name, soName, realName, impName, pdbName,
  2348. config);
  2349. }
  2350. else
  2351. {
  2352. return;
  2353. }
  2354. // Get the directory.
  2355. std::string dir = this->Target->GetDirectory(config, false);
  2356. // Add each name.
  2357. std::string f;
  2358. if(!name.empty())
  2359. {
  2360. f = dir;
  2361. f += "/";
  2362. f += name;
  2363. gg->AddToManifest(f);
  2364. }
  2365. if(!soName.empty())
  2366. {
  2367. f = dir;
  2368. f += "/";
  2369. f += soName;
  2370. gg->AddToManifest(f);
  2371. }
  2372. if(!realName.empty())
  2373. {
  2374. f = dir;
  2375. f += "/";
  2376. f += realName;
  2377. gg->AddToManifest(f);
  2378. }
  2379. if(!pdbName.empty())
  2380. {
  2381. f = dir;
  2382. f += "/";
  2383. f += pdbName;
  2384. gg->AddToManifest(f);
  2385. }
  2386. if(!impName.empty())
  2387. {
  2388. f = this->Target->GetDirectory(config, true);
  2389. f += "/";
  2390. f += impName;
  2391. gg->AddToManifest(f);
  2392. }
  2393. }
  2394. //----------------------------------------------------------------------------
  2395. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  2396. bool implib, bool realname) const
  2397. {
  2398. if(this->Target->IsImported())
  2399. {
  2400. return this->Target->ImportedGetFullPath(config, implib);
  2401. }
  2402. else
  2403. {
  2404. return this->NormalGetFullPath(config, implib, realname);
  2405. }
  2406. }
  2407. std::string cmGeneratorTarget::NormalGetFullPath(const std::string& config,
  2408. bool implib,
  2409. bool realname) const
  2410. {
  2411. std::string fpath = this->Target->GetDirectory(config, implib);
  2412. fpath += "/";
  2413. if(this->Target->IsAppBundleOnApple())
  2414. {
  2415. fpath = this->BuildMacContentDirectory(fpath, config, false);
  2416. fpath += "/";
  2417. }
  2418. // Add the full name of the target.
  2419. if(implib)
  2420. {
  2421. fpath += this->GetFullName(config, true);
  2422. }
  2423. else if(realname)
  2424. {
  2425. fpath += this->NormalGetRealName(config);
  2426. }
  2427. else
  2428. {
  2429. fpath += this->GetFullName(config, false);
  2430. }
  2431. return fpath;
  2432. }
  2433. //----------------------------------------------------------------------------
  2434. std::string
  2435. cmGeneratorTarget::NormalGetRealName(const std::string& config) const
  2436. {
  2437. // This should not be called for imported targets.
  2438. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2439. // enforcement of the limited imported target API.
  2440. if(this->Target->IsImported())
  2441. {
  2442. std::string msg = "NormalGetRealName called on imported target: ";
  2443. msg += this->GetName();
  2444. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2445. }
  2446. if(this->GetType() == cmTarget::EXECUTABLE)
  2447. {
  2448. // Compute the real name that will be built.
  2449. std::string name;
  2450. std::string realName;
  2451. std::string impName;
  2452. std::string pdbName;
  2453. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2454. return realName;
  2455. }
  2456. else
  2457. {
  2458. // Compute the real name that will be built.
  2459. std::string name;
  2460. std::string soName;
  2461. std::string realName;
  2462. std::string impName;
  2463. std::string pdbName;
  2464. this->GetLibraryNames(name, soName, realName,
  2465. impName, pdbName, config);
  2466. return realName;
  2467. }
  2468. }
  2469. //----------------------------------------------------------------------------
  2470. void cmGeneratorTarget::GetLibraryNames(std::string& name,
  2471. std::string& soName,
  2472. std::string& realName,
  2473. std::string& impName,
  2474. std::string& pdbName,
  2475. const std::string& config) const
  2476. {
  2477. // This should not be called for imported targets.
  2478. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2479. // enforcement of the limited imported target API.
  2480. if(this->Target->IsImported())
  2481. {
  2482. std::string msg = "GetLibraryNames called on imported target: ";
  2483. msg += this->GetName();
  2484. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR,
  2485. msg);
  2486. return;
  2487. }
  2488. // Check for library version properties.
  2489. const char* version = this->GetProperty("VERSION");
  2490. const char* soversion = this->GetProperty("SOVERSION");
  2491. if(!this->HasSOName(config) ||
  2492. this->Target->IsFrameworkOnApple())
  2493. {
  2494. // Versioning is supported only for shared libraries and modules,
  2495. // and then only when the platform supports an soname flag.
  2496. version = 0;
  2497. soversion = 0;
  2498. }
  2499. if(version && !soversion)
  2500. {
  2501. // The soversion must be set if the library version is set. Use
  2502. // the library version as the soversion.
  2503. soversion = version;
  2504. }
  2505. if(!version && soversion)
  2506. {
  2507. // Use the soversion as the library version.
  2508. version = soversion;
  2509. }
  2510. // Get the components of the library name.
  2511. std::string prefix;
  2512. std::string base;
  2513. std::string suffix;
  2514. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2515. // The library name.
  2516. name = prefix+base+suffix;
  2517. if(this->Target->IsFrameworkOnApple())
  2518. {
  2519. realName = prefix;
  2520. if(!this->Makefile->PlatformIsAppleIos())
  2521. {
  2522. realName += "Versions/";
  2523. realName += this->Target->GetFrameworkVersion();
  2524. realName += "/";
  2525. }
  2526. realName += base;
  2527. soName = realName;
  2528. }
  2529. else
  2530. {
  2531. // The library's soname.
  2532. this->Target->ComputeVersionedName(soName, prefix, base, suffix,
  2533. name, soversion);
  2534. // The library's real name on disk.
  2535. this->Target->ComputeVersionedName(realName, prefix, base, suffix,
  2536. name, version);
  2537. }
  2538. // The import library name.
  2539. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  2540. this->GetType() == cmTarget::MODULE_LIBRARY)
  2541. {
  2542. impName = this->GetFullNameInternal(config, true);
  2543. }
  2544. else
  2545. {
  2546. impName = "";
  2547. }
  2548. // The program database file name.
  2549. pdbName = this->GetPDBName(config);
  2550. }
  2551. //----------------------------------------------------------------------------
  2552. void cmGeneratorTarget::GetExecutableNames(std::string& name,
  2553. std::string& realName,
  2554. std::string& impName,
  2555. std::string& pdbName,
  2556. const std::string& config) const
  2557. {
  2558. // This should not be called for imported targets.
  2559. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2560. // enforcement of the limited imported target API.
  2561. if(this->Target->IsImported())
  2562. {
  2563. std::string msg =
  2564. "GetExecutableNames called on imported target: ";
  2565. msg += this->GetName();
  2566. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2567. }
  2568. // This versioning is supported only for executables and then only
  2569. // when the platform supports symbolic links.
  2570. #if defined(_WIN32) && !defined(__CYGWIN__)
  2571. const char* version = 0;
  2572. #else
  2573. // Check for executable version properties.
  2574. const char* version = this->GetProperty("VERSION");
  2575. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  2576. {
  2577. version = 0;
  2578. }
  2579. #endif
  2580. // Get the components of the executable name.
  2581. std::string prefix;
  2582. std::string base;
  2583. std::string suffix;
  2584. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2585. // The executable name.
  2586. name = prefix+base+suffix;
  2587. // The executable's real name on disk.
  2588. #if defined(__CYGWIN__)
  2589. realName = prefix+base;
  2590. #else
  2591. realName = name;
  2592. #endif
  2593. if(version)
  2594. {
  2595. realName += "-";
  2596. realName += version;
  2597. }
  2598. #if defined(__CYGWIN__)
  2599. realName += suffix;
  2600. #endif
  2601. // The import library name.
  2602. impName = this->GetFullNameInternal(config, true);
  2603. // The program database file name.
  2604. pdbName = this->GetPDBName(config);
  2605. }
  2606. //----------------------------------------------------------------------------
  2607. std::string cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  2608. bool implib) const
  2609. {
  2610. std::string prefix;
  2611. std::string base;
  2612. std::string suffix;
  2613. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  2614. return prefix+base+suffix;
  2615. }
  2616. //----------------------------------------------------------------------------
  2617. void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  2618. bool implib,
  2619. std::string& outPrefix,
  2620. std::string& outBase,
  2621. std::string& outSuffix) const
  2622. {
  2623. // Use just the target name for non-main target types.
  2624. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  2625. this->GetType() != cmTarget::SHARED_LIBRARY &&
  2626. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2627. this->GetType() != cmTarget::EXECUTABLE)
  2628. {
  2629. outPrefix = "";
  2630. outBase = this->GetName();
  2631. outSuffix = "";
  2632. return;
  2633. }
  2634. // Return an empty name for the import library if this platform
  2635. // does not support import libraries.
  2636. if(implib &&
  2637. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  2638. {
  2639. outPrefix = "";
  2640. outBase = "";
  2641. outSuffix = "";
  2642. return;
  2643. }
  2644. // The implib option is only allowed for shared libraries, module
  2645. // libraries, and executables.
  2646. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  2647. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2648. this->GetType() != cmTarget::EXECUTABLE)
  2649. {
  2650. implib = false;
  2651. }
  2652. // Compute the full name for main target types.
  2653. const char* targetPrefix = (implib
  2654. ? this->GetProperty("IMPORT_PREFIX")
  2655. : this->GetProperty("PREFIX"));
  2656. const char* targetSuffix = (implib
  2657. ? this->GetProperty("IMPORT_SUFFIX")
  2658. : this->GetProperty("SUFFIX"));
  2659. const char* configPostfix = 0;
  2660. if(!config.empty())
  2661. {
  2662. std::string configProp = cmSystemTools::UpperCase(config);
  2663. configProp += "_POSTFIX";
  2664. configPostfix = this->GetProperty(configProp);
  2665. // Mac application bundles and frameworks have no postfix.
  2666. if(configPostfix &&
  2667. (this->Target->IsAppBundleOnApple()
  2668. || this->Target->IsFrameworkOnApple()))
  2669. {
  2670. configPostfix = 0;
  2671. }
  2672. }
  2673. const char* prefixVar = this->Target->GetPrefixVariableInternal(implib);
  2674. const char* suffixVar = this->Target->GetSuffixVariableInternal(implib);
  2675. // Check for language-specific default prefix and suffix.
  2676. std::string ll = this->GetLinkerLanguage(config);
  2677. if(!ll.empty())
  2678. {
  2679. if(!targetSuffix && suffixVar && *suffixVar)
  2680. {
  2681. std::string langSuff = suffixVar + std::string("_") + ll;
  2682. targetSuffix = this->Makefile->GetDefinition(langSuff);
  2683. }
  2684. if(!targetPrefix && prefixVar && *prefixVar)
  2685. {
  2686. std::string langPrefix = prefixVar + std::string("_") + ll;
  2687. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  2688. }
  2689. }
  2690. // if there is no prefix on the target use the cmake definition
  2691. if(!targetPrefix && prefixVar)
  2692. {
  2693. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  2694. }
  2695. // if there is no suffix on the target use the cmake definition
  2696. if(!targetSuffix && suffixVar)
  2697. {
  2698. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  2699. }
  2700. // frameworks have directory prefix but no suffix
  2701. std::string fw_prefix;
  2702. if(this->Target->IsFrameworkOnApple())
  2703. {
  2704. fw_prefix = this->GetOutputName(config, false);
  2705. fw_prefix += ".framework/";
  2706. targetPrefix = fw_prefix.c_str();
  2707. targetSuffix = 0;
  2708. }
  2709. if(this->Target->IsCFBundleOnApple())
  2710. {
  2711. fw_prefix = this->GetCFBundleDirectory(config, false);
  2712. fw_prefix += "/";
  2713. targetPrefix = fw_prefix.c_str();
  2714. targetSuffix = 0;
  2715. }
  2716. // Begin the final name with the prefix.
  2717. outPrefix = targetPrefix?targetPrefix:"";
  2718. // Append the target name or property-specified name.
  2719. outBase += this->GetOutputName(config, implib);
  2720. // Append the per-configuration postfix.
  2721. outBase += configPostfix?configPostfix:"";
  2722. // Name shared libraries with their version number on some platforms.
  2723. if(const char* soversion = this->GetProperty("SOVERSION"))
  2724. {
  2725. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  2726. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  2727. {
  2728. outBase += "-";
  2729. outBase += soversion;
  2730. }
  2731. }
  2732. // Append the suffix.
  2733. outSuffix = targetSuffix?targetSuffix:"";
  2734. }
  2735. //----------------------------------------------------------------------------
  2736. std::string
  2737. cmGeneratorTarget::GetLinkerLanguage(const std::string& config) const
  2738. {
  2739. return this->GetLinkClosure(config)->LinkerLanguage;
  2740. }
  2741. //----------------------------------------------------------------------------
  2742. std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
  2743. {
  2744. std::string prefix;
  2745. std::string base;
  2746. std::string suffix;
  2747. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2748. std::vector<std::string> props;
  2749. std::string configUpper =
  2750. cmSystemTools::UpperCase(config);
  2751. if(!configUpper.empty())
  2752. {
  2753. // PDB_NAME_<CONFIG>
  2754. props.push_back("PDB_NAME_" + configUpper);
  2755. }
  2756. // PDB_NAME
  2757. props.push_back("PDB_NAME");
  2758. for(std::vector<std::string>::const_iterator i = props.begin();
  2759. i != props.end(); ++i)
  2760. {
  2761. if(const char* outName = this->GetProperty(*i))
  2762. {
  2763. base = outName;
  2764. break;
  2765. }
  2766. }
  2767. return prefix+base+".pdb";
  2768. }
  2769. bool cmStrictTargetComparison::operator()(cmTarget const* t1,
  2770. cmTarget const* t2) const
  2771. {
  2772. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  2773. if (nameResult == 0)
  2774. {
  2775. return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory(),
  2776. t2->GetMakefile()->GetCurrentBinaryDirectory()) < 0;
  2777. }
  2778. return nameResult < 0;
  2779. }
  2780. //----------------------------------------------------------------------------
  2781. struct cmGeneratorTarget::SourceFileFlags
  2782. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  2783. {
  2784. struct SourceFileFlags flags;
  2785. this->ConstructSourceFileFlags();
  2786. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  2787. this->SourceFlagsMap.find(sf);
  2788. if(si != this->SourceFlagsMap.end())
  2789. {
  2790. flags = si->second;
  2791. }
  2792. else
  2793. {
  2794. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  2795. // were not listed in one of the other lists.
  2796. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  2797. {
  2798. flags.MacFolder = location;
  2799. if(strcmp(location, "Resources") == 0)
  2800. {
  2801. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  2802. }
  2803. else
  2804. {
  2805. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  2806. }
  2807. }
  2808. }
  2809. return flags;
  2810. }
  2811. //----------------------------------------------------------------------------
  2812. void cmGeneratorTarget::ConstructSourceFileFlags() const
  2813. {
  2814. if(this->SourceFileFlagsConstructed)
  2815. {
  2816. return;
  2817. }
  2818. this->SourceFileFlagsConstructed = true;
  2819. // Process public headers to mark the source files.
  2820. if(const char* files = this->Target->GetProperty("PUBLIC_HEADER"))
  2821. {
  2822. std::vector<std::string> relFiles;
  2823. cmSystemTools::ExpandListArgument(files, relFiles);
  2824. for(std::vector<std::string>::iterator it = relFiles.begin();
  2825. it != relFiles.end(); ++it)
  2826. {
  2827. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  2828. {
  2829. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2830. flags.MacFolder = "Headers";
  2831. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  2832. }
  2833. }
  2834. }
  2835. // Process private headers after public headers so that they take
  2836. // precedence if a file is listed in both.
  2837. if(const char* files = this->Target->GetProperty("PRIVATE_HEADER"))
  2838. {
  2839. std::vector<std::string> relFiles;
  2840. cmSystemTools::ExpandListArgument(files, relFiles);
  2841. for(std::vector<std::string>::iterator it = relFiles.begin();
  2842. it != relFiles.end(); ++it)
  2843. {
  2844. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  2845. {
  2846. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2847. flags.MacFolder = "PrivateHeaders";
  2848. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  2849. }
  2850. }
  2851. }
  2852. // Mark sources listed as resources.
  2853. if(const char* files = this->Target->GetProperty("RESOURCE"))
  2854. {
  2855. std::vector<std::string> relFiles;
  2856. cmSystemTools::ExpandListArgument(files, relFiles);
  2857. for(std::vector<std::string>::iterator it = relFiles.begin();
  2858. it != relFiles.end(); ++it)
  2859. {
  2860. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  2861. {
  2862. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  2863. flags.MacFolder = "Resources";
  2864. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  2865. }
  2866. }
  2867. }
  2868. }
  2869. //----------------------------------------------------------------------------
  2870. const cmGeneratorTarget::CompatibleInterfacesBase&
  2871. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  2872. {
  2873. cmGeneratorTarget::CompatibleInterfaces& compat =
  2874. this->CompatibleInterfacesMap[config];
  2875. if(!compat.Done)
  2876. {
  2877. compat.Done = true;
  2878. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  2879. compat.PropsString.insert("AUTOUIC_OPTIONS");
  2880. std::vector<cmTarget const*> const& deps =
  2881. this->GetLinkImplementationClosure(config);
  2882. for(std::vector<cmTarget const*>::const_iterator li = deps.begin();
  2883. li != deps.end(); ++li)
  2884. {
  2885. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  2886. if(const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) \
  2887. { \
  2888. std::vector<std::string> props; \
  2889. cmSystemTools::ExpandListArgument(prop, props); \
  2890. compat.Props##x.insert(props.begin(), props.end()); \
  2891. }
  2892. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  2893. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  2894. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  2895. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  2896. #undef CM_READ_COMPATIBLE_INTERFACE
  2897. }
  2898. }
  2899. return compat;
  2900. }
  2901. //----------------------------------------------------------------------------
  2902. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  2903. const std::string &p, const std::string& config) const
  2904. {
  2905. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2906. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2907. {
  2908. return false;
  2909. }
  2910. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  2911. }
  2912. //----------------------------------------------------------------------------
  2913. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  2914. const std::string &p, const std::string& config) const
  2915. {
  2916. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2917. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2918. {
  2919. return false;
  2920. }
  2921. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  2922. }
  2923. //----------------------------------------------------------------------------
  2924. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  2925. const std::string &p, const std::string& config) const
  2926. {
  2927. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2928. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2929. {
  2930. return false;
  2931. }
  2932. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  2933. }
  2934. //----------------------------------------------------------------------------
  2935. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  2936. const std::string &p, const std::string& config) const
  2937. {
  2938. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  2939. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  2940. {
  2941. return false;
  2942. }
  2943. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  2944. }
  2945. enum CompatibleType
  2946. {
  2947. BoolType,
  2948. StringType,
  2949. NumberMinType,
  2950. NumberMaxType
  2951. };
  2952. template<typename PropertyType>
  2953. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2954. const std::string& prop,
  2955. const std::string& config,
  2956. CompatibleType,
  2957. PropertyType *);
  2958. template<>
  2959. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2960. const std::string& prop,
  2961. const std::string& config,
  2962. CompatibleType, bool *)
  2963. {
  2964. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  2965. }
  2966. template<>
  2967. const char * getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  2968. const std::string& prop,
  2969. const std::string& config,
  2970. CompatibleType t,
  2971. const char **)
  2972. {
  2973. switch(t)
  2974. {
  2975. case BoolType:
  2976. assert(0 && "String compatibility check function called for boolean");
  2977. return 0;
  2978. case StringType:
  2979. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  2980. case NumberMinType:
  2981. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  2982. case NumberMaxType:
  2983. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  2984. }
  2985. assert(0 && "Unreachable!");
  2986. return 0;
  2987. }
  2988. //----------------------------------------------------------------------------
  2989. template<typename PropertyType>
  2990. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  2991. cmTarget const* dependee,
  2992. const std::string& propName,
  2993. std::set<std::string> &emitted,
  2994. const std::string& config,
  2995. CompatibleType t,
  2996. PropertyType *)
  2997. {
  2998. const char *prop = dependee->GetProperty(propName);
  2999. if (!prop)
  3000. {
  3001. return;
  3002. }
  3003. std::vector<std::string> props;
  3004. cmSystemTools::ExpandListArgument(prop, props);
  3005. std::string pdir =
  3006. dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
  3007. pdir += "/Help/prop_tgt/";
  3008. for(std::vector<std::string>::iterator pi = props.begin();
  3009. pi != props.end(); ++pi)
  3010. {
  3011. std::string pname = cmSystemTools::HelpFileName(*pi);
  3012. std::string pfile = pdir + pname + ".rst";
  3013. if(cmSystemTools::FileExists(pfile.c_str(), true))
  3014. {
  3015. std::ostringstream e;
  3016. e << "Target \"" << dependee->GetName() << "\" has property \""
  3017. << *pi << "\" listed in its " << propName << " property. "
  3018. "This is not allowed. Only user-defined properties may appear "
  3019. "listed in the " << propName << " property.";
  3020. depender->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
  3021. return;
  3022. }
  3023. if(emitted.insert(*pi).second)
  3024. {
  3025. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  3026. t, 0);
  3027. if (cmSystemTools::GetErrorOccuredFlag())
  3028. {
  3029. return;
  3030. }
  3031. }
  3032. }
  3033. }
  3034. static std::string intersect(const std::set<std::string> &s1,
  3035. const std::set<std::string> &s2)
  3036. {
  3037. std::set<std::string> intersect;
  3038. std::set_intersection(s1.begin(),s1.end(),
  3039. s2.begin(),s2.end(),
  3040. std::inserter(intersect,intersect.begin()));
  3041. if (!intersect.empty())
  3042. {
  3043. return *intersect.begin();
  3044. }
  3045. return "";
  3046. }
  3047. static std::string intersect(const std::set<std::string> &s1,
  3048. const std::set<std::string> &s2,
  3049. const std::set<std::string> &s3)
  3050. {
  3051. std::string result;
  3052. result = intersect(s1, s2);
  3053. if (!result.empty())
  3054. return result;
  3055. result = intersect(s1, s3);
  3056. if (!result.empty())
  3057. return result;
  3058. return intersect(s2, s3);
  3059. }
  3060. static std::string intersect(const std::set<std::string> &s1,
  3061. const std::set<std::string> &s2,
  3062. const std::set<std::string> &s3,
  3063. const std::set<std::string> &s4)
  3064. {
  3065. std::string result;
  3066. result = intersect(s1, s2);
  3067. if (!result.empty())
  3068. return result;
  3069. result = intersect(s1, s3);
  3070. if (!result.empty())
  3071. return result;
  3072. result = intersect(s1, s4);
  3073. if (!result.empty())
  3074. return result;
  3075. return intersect(s2, s3, s4);
  3076. }
  3077. //----------------------------------------------------------------------------
  3078. void cmGeneratorTarget::CheckPropertyCompatibility(
  3079. cmComputeLinkInformation *info, const std::string& config) const
  3080. {
  3081. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  3082. std::set<std::string> emittedBools;
  3083. static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  3084. std::set<std::string> emittedStrings;
  3085. static std::string strString = "COMPATIBLE_INTERFACE_STRING";
  3086. std::set<std::string> emittedMinNumbers;
  3087. static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  3088. std::set<std::string> emittedMaxNumbers;
  3089. static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  3090. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  3091. deps.begin(); li != deps.end(); ++li)
  3092. {
  3093. if (!li->Target)
  3094. {
  3095. continue;
  3096. }
  3097. checkPropertyConsistency<bool>(this, li->Target,
  3098. strBool,
  3099. emittedBools, config, BoolType, 0);
  3100. if (cmSystemTools::GetErrorOccuredFlag())
  3101. {
  3102. return;
  3103. }
  3104. checkPropertyConsistency<const char *>(this, li->Target,
  3105. strString,
  3106. emittedStrings, config,
  3107. StringType, 0);
  3108. if (cmSystemTools::GetErrorOccuredFlag())
  3109. {
  3110. return;
  3111. }
  3112. checkPropertyConsistency<const char *>(this, li->Target,
  3113. strNumMin,
  3114. emittedMinNumbers, config,
  3115. NumberMinType, 0);
  3116. if (cmSystemTools::GetErrorOccuredFlag())
  3117. {
  3118. return;
  3119. }
  3120. checkPropertyConsistency<const char *>(this, li->Target,
  3121. strNumMax,
  3122. emittedMaxNumbers, config,
  3123. NumberMaxType, 0);
  3124. if (cmSystemTools::GetErrorOccuredFlag())
  3125. {
  3126. return;
  3127. }
  3128. }
  3129. std::string prop = intersect(emittedBools,
  3130. emittedStrings,
  3131. emittedMinNumbers,
  3132. emittedMaxNumbers);
  3133. if (!prop.empty())
  3134. {
  3135. // Use a sorted std::vector to keep the error message sorted.
  3136. std::vector<std::string> props;
  3137. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  3138. if (i != emittedBools.end())
  3139. {
  3140. props.push_back(strBool);
  3141. }
  3142. i = emittedStrings.find(prop);
  3143. if (i != emittedStrings.end())
  3144. {
  3145. props.push_back(strString);
  3146. }
  3147. i = emittedMinNumbers.find(prop);
  3148. if (i != emittedMinNumbers.end())
  3149. {
  3150. props.push_back(strNumMin);
  3151. }
  3152. i = emittedMaxNumbers.find(prop);
  3153. if (i != emittedMaxNumbers.end())
  3154. {
  3155. props.push_back(strNumMax);
  3156. }
  3157. std::sort(props.begin(), props.end());
  3158. std::string propsString = cmJoin(cmMakeRange(props).retreat(1), ", ");
  3159. propsString += " and the " + props.back();
  3160. std::ostringstream e;
  3161. e << "Property \"" << prop << "\" appears in both the "
  3162. << propsString <<
  3163. " property in the dependencies of target \"" << this->GetName() <<
  3164. "\". This is not allowed. A property may only require compatibility "
  3165. "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
  3166. "string interpretation, but not a mixture.";
  3167. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  3168. }
  3169. }
  3170. //----------------------------------------------------------------------------
  3171. std::string compatibilityType(CompatibleType t)
  3172. {
  3173. switch(t)
  3174. {
  3175. case BoolType:
  3176. return "Boolean compatibility";
  3177. case StringType:
  3178. return "String compatibility";
  3179. case NumberMaxType:
  3180. return "Numeric maximum compatibility";
  3181. case NumberMinType:
  3182. return "Numeric minimum compatibility";
  3183. }
  3184. assert(0 && "Unreachable!");
  3185. return "";
  3186. }
  3187. //----------------------------------------------------------------------------
  3188. std::string compatibilityAgree(CompatibleType t, bool dominant)
  3189. {
  3190. switch(t)
  3191. {
  3192. case BoolType:
  3193. case StringType:
  3194. return dominant ? "(Disagree)\n" : "(Agree)\n";
  3195. case NumberMaxType:
  3196. case NumberMinType:
  3197. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  3198. }
  3199. assert(0 && "Unreachable!");
  3200. return "";
  3201. }
  3202. //----------------------------------------------------------------------------
  3203. template<typename PropertyType>
  3204. PropertyType getTypedProperty(cmTarget const* tgt, const std::string& prop);
  3205. //----------------------------------------------------------------------------
  3206. template<>
  3207. bool getTypedProperty<bool>(cmTarget const* tgt, const std::string& prop)
  3208. {
  3209. return tgt->GetPropertyAsBool(prop);
  3210. }
  3211. //----------------------------------------------------------------------------
  3212. template<>
  3213. const char *getTypedProperty<const char *>(cmTarget const* tgt,
  3214. const std::string& prop)
  3215. {
  3216. return tgt->GetProperty(prop);
  3217. }
  3218. template<typename PropertyType>
  3219. std::string valueAsString(PropertyType);
  3220. template<>
  3221. std::string valueAsString<bool>(bool value)
  3222. {
  3223. return value ? "TRUE" : "FALSE";
  3224. }
  3225. template<>
  3226. std::string valueAsString<const char*>(const char* value)
  3227. {
  3228. return value ? value : "(unset)";
  3229. }
  3230. template<typename PropertyType>
  3231. PropertyType impliedValue(PropertyType);
  3232. template<>
  3233. bool impliedValue<bool>(bool)
  3234. {
  3235. return false;
  3236. }
  3237. template<>
  3238. const char* impliedValue<const char*>(const char*)
  3239. {
  3240. return "";
  3241. }
  3242. //----------------------------------------------------------------------------
  3243. template<typename PropertyType>
  3244. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  3245. PropertyType rhs,
  3246. CompatibleType t);
  3247. //----------------------------------------------------------------------------
  3248. template<>
  3249. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  3250. CompatibleType)
  3251. {
  3252. return std::make_pair(lhs == rhs, lhs);
  3253. }
  3254. //----------------------------------------------------------------------------
  3255. std::pair<bool, const char*> consistentStringProperty(const char *lhs,
  3256. const char *rhs)
  3257. {
  3258. const bool b = strcmp(lhs, rhs) == 0;
  3259. return std::make_pair(b, b ? lhs : 0);
  3260. }
  3261. //----------------------------------------------------------------------------
  3262. std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
  3263. const char *rhs,
  3264. CompatibleType t)
  3265. {
  3266. char *pEnd;
  3267. const char* const null_ptr = 0;
  3268. long lnum = strtol(lhs, &pEnd, 0);
  3269. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
  3270. {
  3271. return std::pair<bool, const char*>(false, null_ptr);
  3272. }
  3273. long rnum = strtol(rhs, &pEnd, 0);
  3274. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
  3275. {
  3276. return std::pair<bool, const char*>(false, null_ptr);
  3277. }
  3278. if (t == NumberMaxType)
  3279. {
  3280. return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs);
  3281. }
  3282. else
  3283. {
  3284. return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs);
  3285. }
  3286. }
  3287. //----------------------------------------------------------------------------
  3288. template<>
  3289. std::pair<bool, const char*> consistentProperty(const char *lhs,
  3290. const char *rhs,
  3291. CompatibleType t)
  3292. {
  3293. if (!lhs && !rhs)
  3294. {
  3295. return std::make_pair(true, lhs);
  3296. }
  3297. if (!lhs)
  3298. {
  3299. return std::make_pair(true, rhs);
  3300. }
  3301. if (!rhs)
  3302. {
  3303. return std::make_pair(true, lhs);
  3304. }
  3305. const char* const null_ptr = 0;
  3306. switch(t)
  3307. {
  3308. case BoolType:
  3309. assert(0 && "consistentProperty for strings called with BoolType");
  3310. return std::pair<bool, const char*>(false, null_ptr);
  3311. case StringType:
  3312. return consistentStringProperty(lhs, rhs);
  3313. case NumberMinType:
  3314. case NumberMaxType:
  3315. return consistentNumberProperty(lhs, rhs, t);
  3316. }
  3317. assert(0 && "Unreachable!");
  3318. return std::pair<bool, const char*>(false, null_ptr);
  3319. }
  3320. //----------------------------------------------------------------------------
  3321. template<typename PropertyType>
  3322. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  3323. const std::string &p,
  3324. const std::string& config,
  3325. const char *defaultValue,
  3326. CompatibleType t,
  3327. PropertyType *)
  3328. {
  3329. PropertyType propContent = getTypedProperty<PropertyType>(tgt->Target, p);
  3330. const bool explicitlySet = tgt->Target->GetProperties()
  3331. .find(p)
  3332. != tgt->Target->GetProperties().end();
  3333. const bool impliedByUse =
  3334. tgt->Target->IsNullImpliedByLinkLibraries(p);
  3335. assert((impliedByUse ^ explicitlySet)
  3336. || (!impliedByUse && !explicitlySet));
  3337. std::vector<cmTarget const*> const& deps =
  3338. tgt->GetLinkImplementationClosure(config);
  3339. if(deps.empty())
  3340. {
  3341. return propContent;
  3342. }
  3343. bool propInitialized = explicitlySet;
  3344. std::string report = " * Target \"";
  3345. report += tgt->GetName();
  3346. if (explicitlySet)
  3347. {
  3348. report += "\" has property content \"";
  3349. report += valueAsString<PropertyType>(propContent);
  3350. report += "\"\n";
  3351. }
  3352. else if (impliedByUse)
  3353. {
  3354. report += "\" property is implied by use.\n";
  3355. }
  3356. else
  3357. {
  3358. report += "\" property not set.\n";
  3359. }
  3360. std::string interfaceProperty = "INTERFACE_" + p;
  3361. for(std::vector<cmTarget const*>::const_iterator li =
  3362. deps.begin();
  3363. li != deps.end(); ++li)
  3364. {
  3365. // An error should be reported if one dependency
  3366. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  3367. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  3368. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  3369. // with a dependency.
  3370. cmTarget const* theTarget = *li;
  3371. const bool ifaceIsSet = theTarget->GetProperties()
  3372. .find(interfaceProperty)
  3373. != theTarget->GetProperties().end();
  3374. PropertyType ifacePropContent =
  3375. getTypedProperty<PropertyType>(theTarget,
  3376. interfaceProperty);
  3377. std::string reportEntry;
  3378. if (ifaceIsSet)
  3379. {
  3380. reportEntry += " * Target \"";
  3381. reportEntry += theTarget->GetName();
  3382. reportEntry += "\" property value \"";
  3383. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  3384. reportEntry += "\" ";
  3385. }
  3386. if (explicitlySet)
  3387. {
  3388. if (ifaceIsSet)
  3389. {
  3390. std::pair<bool, PropertyType> consistent =
  3391. consistentProperty(propContent,
  3392. ifacePropContent, t);
  3393. report += reportEntry;
  3394. report += compatibilityAgree(t, propContent != consistent.second);
  3395. if (!consistent.first)
  3396. {
  3397. std::ostringstream e;
  3398. e << "Property " << p << " on target \""
  3399. << tgt->GetName() << "\" does\nnot match the "
  3400. "INTERFACE_" << p << " property requirement\nof "
  3401. "dependency \"" << theTarget->GetName() << "\".\n";
  3402. cmSystemTools::Error(e.str().c_str());
  3403. break;
  3404. }
  3405. else
  3406. {
  3407. propContent = consistent.second;
  3408. continue;
  3409. }
  3410. }
  3411. else
  3412. {
  3413. // Explicitly set on target and not set in iface. Can't disagree.
  3414. continue;
  3415. }
  3416. }
  3417. else if (impliedByUse)
  3418. {
  3419. propContent = impliedValue<PropertyType>(propContent);
  3420. if (ifaceIsSet)
  3421. {
  3422. std::pair<bool, PropertyType> consistent =
  3423. consistentProperty(propContent,
  3424. ifacePropContent, t);
  3425. report += reportEntry;
  3426. report += compatibilityAgree(t, propContent != consistent.second);
  3427. if (!consistent.first)
  3428. {
  3429. std::ostringstream e;
  3430. e << "Property " << p << " on target \""
  3431. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  3432. << " because it was used to determine the link libraries\n"
  3433. "already. The INTERFACE_" << p << " property on\ndependency \""
  3434. << theTarget->GetName() << "\" is in conflict.\n";
  3435. cmSystemTools::Error(e.str().c_str());
  3436. break;
  3437. }
  3438. else
  3439. {
  3440. propContent = consistent.second;
  3441. continue;
  3442. }
  3443. }
  3444. else
  3445. {
  3446. // Implicitly set on target and not set in iface. Can't disagree.
  3447. continue;
  3448. }
  3449. }
  3450. else
  3451. {
  3452. if (ifaceIsSet)
  3453. {
  3454. if (propInitialized)
  3455. {
  3456. std::pair<bool, PropertyType> consistent =
  3457. consistentProperty(propContent,
  3458. ifacePropContent, t);
  3459. report += reportEntry;
  3460. report += compatibilityAgree(t, propContent != consistent.second);
  3461. if (!consistent.first)
  3462. {
  3463. std::ostringstream e;
  3464. e << "The INTERFACE_" << p << " property of \""
  3465. << theTarget->GetName() << "\" does\nnot agree with the value "
  3466. "of " << p << " already determined\nfor \""
  3467. << tgt->GetName() << "\".\n";
  3468. cmSystemTools::Error(e.str().c_str());
  3469. break;
  3470. }
  3471. else
  3472. {
  3473. propContent = consistent.second;
  3474. continue;
  3475. }
  3476. }
  3477. else
  3478. {
  3479. report += reportEntry + "(Interface set)\n";
  3480. propContent = ifacePropContent;
  3481. propInitialized = true;
  3482. }
  3483. }
  3484. else
  3485. {
  3486. // Not set. Nothing to agree on.
  3487. continue;
  3488. }
  3489. }
  3490. }
  3491. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  3492. report, compatibilityType(t));
  3493. return propContent;
  3494. }
  3495. //----------------------------------------------------------------------------
  3496. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  3497. const std::string &p, const std::string& config) const
  3498. {
  3499. return checkInterfacePropertyCompatibility<bool>(this, p, config,
  3500. "FALSE",
  3501. BoolType, 0);
  3502. }
  3503. //----------------------------------------------------------------------------
  3504. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  3505. const std::string &p,
  3506. const std::string& config) const
  3507. {
  3508. return checkInterfacePropertyCompatibility<const char *>(this,
  3509. p,
  3510. config,
  3511. "empty",
  3512. StringType, 0);
  3513. }
  3514. //----------------------------------------------------------------------------
  3515. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  3516. const std::string &p,
  3517. const std::string& config) const
  3518. {
  3519. return checkInterfacePropertyCompatibility<const char *>(this,
  3520. p,
  3521. config,
  3522. "empty",
  3523. NumberMinType, 0);
  3524. }
  3525. //----------------------------------------------------------------------------
  3526. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  3527. const std::string &p,
  3528. const std::string& config) const
  3529. {
  3530. return checkInterfacePropertyCompatibility<const char *>(this,
  3531. p,
  3532. config,
  3533. "empty",
  3534. NumberMaxType, 0);
  3535. }
  3536. //----------------------------------------------------------------------------
  3537. cmComputeLinkInformation*
  3538. cmGeneratorTarget::GetLinkInformation(const std::string& config) const
  3539. {
  3540. // Lookup any existing information for this configuration.
  3541. std::string key(cmSystemTools::UpperCase(config));
  3542. cmTargetLinkInformationMap::iterator
  3543. i = this->LinkInformation.find(key);
  3544. if(i == this->LinkInformation.end())
  3545. {
  3546. // Compute information for this configuration.
  3547. cmComputeLinkInformation* info =
  3548. new cmComputeLinkInformation(this, config);
  3549. if(!info || !info->Compute())
  3550. {
  3551. delete info;
  3552. info = 0;
  3553. }
  3554. // Store the information for this configuration.
  3555. cmTargetLinkInformationMap::value_type entry(key, info);
  3556. i = this->LinkInformation.insert(entry).first;
  3557. if (info)
  3558. {
  3559. this->CheckPropertyCompatibility(info, config);
  3560. }
  3561. }
  3562. return i->second;
  3563. }
  3564. //----------------------------------------------------------------------------
  3565. void
  3566. cmGeneratorTarget::ReportPropertyOrigin(const std::string &p,
  3567. const std::string &result,
  3568. const std::string &report,
  3569. const std::string &compatibilityType) const
  3570. {
  3571. std::vector<std::string> debugProperties;
  3572. const char *debugProp = this->Target->GetMakefile()
  3573. ->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  3574. if (debugProp)
  3575. {
  3576. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  3577. }
  3578. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
  3579. && std::find(debugProperties.begin(),
  3580. debugProperties.end(),
  3581. p)
  3582. != debugProperties.end();
  3583. if (this->Target->GetMakefile()->IsConfigured())
  3584. {
  3585. this->DebugCompatiblePropertiesDone[p] = true;
  3586. }
  3587. if (!debugOrigin)
  3588. {
  3589. return;
  3590. }
  3591. std::string areport = compatibilityType;
  3592. areport += std::string(" of property \"") + p + "\" for target \"";
  3593. areport += std::string(this->GetName());
  3594. areport += "\" (result: \"";
  3595. areport += result;
  3596. areport += "\"):\n" + report;
  3597. this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
  3598. }
  3599. //----------------------------------------------------------------------------
  3600. void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
  3601. std::vector<cmLinkItem>& items) const
  3602. {
  3603. for(std::vector<std::string>::const_iterator i = names.begin();
  3604. i != names.end(); ++i)
  3605. {
  3606. std::string name = this->Target->CheckCMP0004(*i);
  3607. if(name == this->GetName() || name.empty())
  3608. {
  3609. continue;
  3610. }
  3611. items.push_back(cmLinkItem(name, this->Target->FindTargetToLink(name)));
  3612. }
  3613. }
  3614. //----------------------------------------------------------------------------
  3615. void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
  3616. std::string const& value,
  3617. std::string const& config,
  3618. cmTarget const* headTarget,
  3619. bool usage_requirements_only,
  3620. std::vector<cmLinkItem>& items,
  3621. bool& hadHeadSensitiveCondition) const
  3622. {
  3623. cmGeneratorExpression ge;
  3624. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0);
  3625. // The $<LINK_ONLY> expression may be in a link interface to specify private
  3626. // link dependencies that are otherwise excluded from usage requirements.
  3627. if(usage_requirements_only)
  3628. {
  3629. dagChecker.SetTransitivePropertiesOnly();
  3630. }
  3631. std::vector<std::string> libs;
  3632. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  3633. cmSystemTools::ExpandListArgument(cge->Evaluate(
  3634. this->Makefile,
  3635. config,
  3636. false,
  3637. headTarget,
  3638. this->Target, &dagChecker), libs);
  3639. this->LookupLinkItems(libs, items);
  3640. hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  3641. }
  3642. //----------------------------------------------------------------------------
  3643. cmLinkInterface const*
  3644. cmGeneratorTarget::GetLinkInterface(const std::string& config,
  3645. cmTarget const* head) const
  3646. {
  3647. // Imported targets have their own link interface.
  3648. if(this->IsImported())
  3649. {
  3650. return this->GetImportLinkInterface(config, head, false);
  3651. }
  3652. // Link interfaces are not supported for executables that do not
  3653. // export symbols.
  3654. if(this->GetType() == cmTarget::EXECUTABLE &&
  3655. !this->Target->IsExecutableWithExports())
  3656. {
  3657. return 0;
  3658. }
  3659. // Lookup any existing link interface for this configuration.
  3660. cmHeadToLinkInterfaceMap& hm =
  3661. this->GetHeadToLinkInterfaceMap(config);
  3662. // If the link interface does not depend on the head target
  3663. // then return the one we computed first.
  3664. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3665. {
  3666. return &hm.begin()->second;
  3667. }
  3668. cmOptionalLinkInterface& iface = hm[head];
  3669. if(!iface.LibrariesDone)
  3670. {
  3671. iface.LibrariesDone = true;
  3672. this->ComputeLinkInterfaceLibraries(
  3673. config, iface, head, false);
  3674. }
  3675. if(!iface.AllDone)
  3676. {
  3677. iface.AllDone = true;
  3678. if(iface.Exists)
  3679. {
  3680. this->ComputeLinkInterface(config, iface, head);
  3681. }
  3682. }
  3683. return iface.Exists? &iface : 0;
  3684. }
  3685. //----------------------------------------------------------------------------
  3686. void cmGeneratorTarget::ComputeLinkInterface(const std::string& config,
  3687. cmOptionalLinkInterface &iface,
  3688. cmTarget const* headTarget) const
  3689. {
  3690. if(iface.ExplicitLibraries)
  3691. {
  3692. if(this->GetType() == cmTarget::SHARED_LIBRARY
  3693. || this->GetType() == cmTarget::STATIC_LIBRARY
  3694. || this->GetType() == cmTarget::INTERFACE_LIBRARY)
  3695. {
  3696. // Shared libraries may have runtime implementation dependencies
  3697. // on other shared libraries that are not in the interface.
  3698. UNORDERED_SET<std::string> emitted;
  3699. for(std::vector<cmLinkItem>::const_iterator
  3700. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  3701. {
  3702. emitted.insert(*li);
  3703. }
  3704. if (this->GetType() != cmTarget::INTERFACE_LIBRARY)
  3705. {
  3706. cmLinkImplementation const* impl =
  3707. this->Target->GetLinkImplementation(config);
  3708. for(std::vector<cmLinkImplItem>::const_iterator
  3709. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  3710. {
  3711. if(emitted.insert(*li).second)
  3712. {
  3713. if(li->Target)
  3714. {
  3715. // This is a runtime dependency on another shared library.
  3716. if(li->Target->GetType() == cmTarget::SHARED_LIBRARY)
  3717. {
  3718. iface.SharedDeps.push_back(*li);
  3719. }
  3720. }
  3721. else
  3722. {
  3723. // TODO: Recognize shared library file names. Perhaps this
  3724. // should be moved to cmComputeLinkInformation, but that creates
  3725. // a chicken-and-egg problem since this list is needed for its
  3726. // construction.
  3727. }
  3728. }
  3729. }
  3730. }
  3731. }
  3732. }
  3733. else if (this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN
  3734. || this->Target->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  3735. {
  3736. // The link implementation is the default link interface.
  3737. cmLinkImplementationLibraries const*
  3738. impl = this->Target->GetLinkImplementationLibrariesInternal(config,
  3739. headTarget);
  3740. iface.ImplementationIsInterface = true;
  3741. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  3742. }
  3743. if(this->Target->LinkLanguagePropagatesToDependents())
  3744. {
  3745. // Targets using this archive need its language runtime libraries.
  3746. if(cmLinkImplementation const* impl =
  3747. this->Target->GetLinkImplementation(config))
  3748. {
  3749. iface.Languages = impl->Languages;
  3750. }
  3751. }
  3752. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  3753. {
  3754. // Construct the property name suffix for this configuration.
  3755. std::string suffix = "_";
  3756. if(!config.empty())
  3757. {
  3758. suffix += cmSystemTools::UpperCase(config);
  3759. }
  3760. else
  3761. {
  3762. suffix += "NOCONFIG";
  3763. }
  3764. // How many repetitions are needed if this library has cyclic
  3765. // dependencies?
  3766. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  3767. propName += suffix;
  3768. if(const char* config_reps = this->GetProperty(propName))
  3769. {
  3770. sscanf(config_reps, "%u", &iface.Multiplicity);
  3771. }
  3772. else if(const char* reps =
  3773. this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  3774. {
  3775. sscanf(reps, "%u", &iface.Multiplicity);
  3776. }
  3777. }
  3778. }
  3779. //----------------------------------------------------------------------------
  3780. const cmLinkInterfaceLibraries *
  3781. cmGeneratorTarget::GetLinkInterfaceLibraries(const std::string& config,
  3782. cmTarget const* head,
  3783. bool usage_requirements_only) const
  3784. {
  3785. // Imported targets have their own link interface.
  3786. if(this->IsImported())
  3787. {
  3788. return this->GetImportLinkInterface(config, head,
  3789. usage_requirements_only);
  3790. }
  3791. // Link interfaces are not supported for executables that do not
  3792. // export symbols.
  3793. if(this->GetType() == cmTarget::EXECUTABLE &&
  3794. !this->Target->IsExecutableWithExports())
  3795. {
  3796. return 0;
  3797. }
  3798. // Lookup any existing link interface for this configuration.
  3799. std::string CONFIG = cmSystemTools::UpperCase(config);
  3800. cmHeadToLinkInterfaceMap& hm =
  3801. (usage_requirements_only ?
  3802. this->GetHeadToLinkInterfaceUsageRequirementsMap(config) :
  3803. this->GetHeadToLinkInterfaceMap(config));
  3804. // If the link interface does not depend on the head target
  3805. // then return the one we computed first.
  3806. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3807. {
  3808. return &hm.begin()->second;
  3809. }
  3810. cmOptionalLinkInterface& iface = hm[head];
  3811. if(!iface.LibrariesDone)
  3812. {
  3813. iface.LibrariesDone = true;
  3814. this->ComputeLinkInterfaceLibraries(
  3815. config, iface, head, usage_requirements_only);
  3816. }
  3817. return iface.Exists? &iface : 0;
  3818. }
  3819. //----------------------------------------------------------------------------
  3820. void
  3821. cmGeneratorTarget::ComputeLinkInterfaceLibraries(
  3822. const std::string& config,
  3823. cmOptionalLinkInterface& iface,
  3824. cmTarget const* headTarget,
  3825. bool usage_requirements_only) const
  3826. {
  3827. // Construct the property name suffix for this configuration.
  3828. std::string suffix = "_";
  3829. if(!config.empty())
  3830. {
  3831. suffix += cmSystemTools::UpperCase(config);
  3832. }
  3833. else
  3834. {
  3835. suffix += "NOCONFIG";
  3836. }
  3837. // An explicit list of interface libraries may be set for shared
  3838. // libraries and executables that export symbols.
  3839. const char* explicitLibraries = 0;
  3840. std::string linkIfaceProp;
  3841. if(this->Target->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  3842. this->Target->GetPolicyStatusCMP0022() != cmPolicies::WARN)
  3843. {
  3844. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  3845. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  3846. explicitLibraries = this->GetProperty(linkIfaceProp);
  3847. }
  3848. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3849. this->Target->IsExecutableWithExports())
  3850. {
  3851. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  3852. // shared lib or executable.
  3853. // Lookup the per-configuration property.
  3854. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  3855. linkIfaceProp += suffix;
  3856. explicitLibraries = this->GetProperty(linkIfaceProp);
  3857. // If not set, try the generic property.
  3858. if(!explicitLibraries)
  3859. {
  3860. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  3861. explicitLibraries = this->GetProperty(linkIfaceProp);
  3862. }
  3863. }
  3864. if(explicitLibraries &&
  3865. this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  3866. !this->PolicyWarnedCMP0022)
  3867. {
  3868. // Compare the explicitly set old link interface properties to the
  3869. // preferred new link interface property one and warn if different.
  3870. const char* newExplicitLibraries =
  3871. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  3872. if (newExplicitLibraries
  3873. && strcmp(newExplicitLibraries, explicitLibraries) != 0)
  3874. {
  3875. std::ostringstream w;
  3876. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  3877. "Target \"" << this->GetName() << "\" has an "
  3878. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  3879. linkIfaceProp << " properties."
  3880. "\n"
  3881. "INTERFACE_LINK_LIBRARIES:\n"
  3882. " " << newExplicitLibraries << "\n" <<
  3883. linkIfaceProp << ":\n"
  3884. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  3885. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  3886. this->PolicyWarnedCMP0022 = true;
  3887. }
  3888. }
  3889. // There is no implicit link interface for executables or modules
  3890. // so if none was explicitly set then there is no link interface.
  3891. if(!explicitLibraries &&
  3892. (this->GetType() == cmTarget::EXECUTABLE ||
  3893. (this->GetType() == cmTarget::MODULE_LIBRARY)))
  3894. {
  3895. return;
  3896. }
  3897. iface.Exists = true;
  3898. iface.ExplicitLibraries = explicitLibraries;
  3899. if(explicitLibraries)
  3900. {
  3901. // The interface libraries have been explicitly set.
  3902. this->ExpandLinkItems(linkIfaceProp, explicitLibraries,
  3903. config,
  3904. headTarget, usage_requirements_only,
  3905. iface.Libraries,
  3906. iface.HadHeadSensitiveCondition);
  3907. }
  3908. else if (this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN
  3909. || this->Target->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  3910. // If CMP0022 is NEW then the plain tll signature sets the
  3911. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  3912. // cleared the property explicitly and we should not fall back
  3913. // to the link implementation.
  3914. {
  3915. // The link implementation is the default link interface.
  3916. cmLinkImplementationLibraries const* impl =
  3917. this->Target->GetLinkImplementationLibrariesInternal(config,
  3918. headTarget);
  3919. iface.Libraries.insert(iface.Libraries.end(),
  3920. impl->Libraries.begin(), impl->Libraries.end());
  3921. if(this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  3922. !this->PolicyWarnedCMP0022 && !usage_requirements_only)
  3923. {
  3924. // Compare the link implementation fallback link interface to the
  3925. // preferred new link interface property and warn if different.
  3926. std::vector<cmLinkItem> ifaceLibs;
  3927. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  3928. if(const char* newExplicitLibraries = this->GetProperty(newProp))
  3929. {
  3930. bool hadHeadSensitiveConditionDummy = false;
  3931. this->ExpandLinkItems(newProp, newExplicitLibraries, config,
  3932. headTarget, usage_requirements_only,
  3933. ifaceLibs, hadHeadSensitiveConditionDummy);
  3934. }
  3935. if (ifaceLibs != iface.Libraries)
  3936. {
  3937. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  3938. std::string newLibraries = cmJoin(ifaceLibs, ";");
  3939. if(oldLibraries.empty())
  3940. { oldLibraries = "(empty)"; }
  3941. if(newLibraries.empty())
  3942. { newLibraries = "(empty)"; }
  3943. std::ostringstream w;
  3944. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  3945. "Target \"" << this->GetName() << "\" has an "
  3946. "INTERFACE_LINK_LIBRARIES property. "
  3947. "This should be preferred as the source of the link interface "
  3948. "for this library but because CMP0022 is not set CMake is "
  3949. "ignoring the property and using the link implementation "
  3950. "as the link interface instead."
  3951. "\n"
  3952. "INTERFACE_LINK_LIBRARIES:\n"
  3953. " " << newLibraries << "\n"
  3954. "Link implementation:\n"
  3955. " " << oldLibraries << "\n";
  3956. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  3957. this->PolicyWarnedCMP0022 = true;
  3958. }
  3959. }
  3960. }
  3961. }
  3962. //----------------------------------------------------------------------------
  3963. const cmLinkInterface *
  3964. cmGeneratorTarget::GetImportLinkInterface(const std::string& config,
  3965. cmTarget const* headTarget,
  3966. bool usage_requirements_only) const
  3967. {
  3968. cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config);
  3969. if(!info)
  3970. {
  3971. return 0;
  3972. }
  3973. std::string CONFIG = cmSystemTools::UpperCase(config);
  3974. cmHeadToLinkInterfaceMap& hm =
  3975. (usage_requirements_only ?
  3976. this->GetHeadToLinkInterfaceUsageRequirementsMap(config) :
  3977. this->GetHeadToLinkInterfaceMap(config));
  3978. // If the link interface does not depend on the head target
  3979. // then return the one we computed first.
  3980. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3981. {
  3982. return &hm.begin()->second;
  3983. }
  3984. cmOptionalLinkInterface& iface = hm[headTarget];
  3985. if(!iface.AllDone)
  3986. {
  3987. iface.AllDone = true;
  3988. iface.Multiplicity = info->Multiplicity;
  3989. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  3990. this->ExpandLinkItems(info->LibrariesProp, info->Libraries,
  3991. config,
  3992. headTarget, usage_requirements_only,
  3993. iface.Libraries,
  3994. iface.HadHeadSensitiveCondition);
  3995. std::vector<std::string> deps;
  3996. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  3997. this->LookupLinkItems(deps, iface.SharedDeps);
  3998. }
  3999. return &iface;
  4000. }
  4001. cmHeadToLinkInterfaceMap&
  4002. cmGeneratorTarget::GetHeadToLinkInterfaceMap(const std::string &config) const
  4003. {
  4004. std::string CONFIG = cmSystemTools::UpperCase(config);
  4005. return this->LinkInterfaceMap[CONFIG];
  4006. }
  4007. cmHeadToLinkInterfaceMap&
  4008. cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap(
  4009. const std::string &config) const
  4010. {
  4011. std::string CONFIG = cmSystemTools::UpperCase(config);
  4012. return this->LinkInterfaceUsageRequirementsOnlyMap[CONFIG];
  4013. }