cmGeneratorTarget.cxx 133 KB

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