cmTarget.cxx 134 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmTarget.h"
  11. #include "cmake.h"
  12. #include "cmMakefile.h"
  13. #include "cmSourceFile.h"
  14. #include "cmOutputConverter.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmComputeLinkInformation.h"
  17. #include "cmListFileCache.h"
  18. #include "cmGeneratorExpression.h"
  19. #include "cmGeneratorExpressionDAGChecker.h"
  20. #include "cmAlgorithms.h"
  21. #include <cmsys/RegularExpression.hxx>
  22. #include <map>
  23. #include <set>
  24. #include <stdlib.h> // required for atof
  25. #include <assert.h>
  26. #include <errno.h>
  27. #if defined(CMAKE_BUILD_WITH_CMAKE)
  28. #include <cmsys/hash_set.hxx>
  29. #define UNORDERED_SET cmsys::hash_set
  30. #else
  31. #define UNORDERED_SET std::set
  32. #endif
  33. const char* cmTarget::GetTargetTypeName(TargetType targetType)
  34. {
  35. switch( targetType )
  36. {
  37. case cmTarget::STATIC_LIBRARY:
  38. return "STATIC_LIBRARY";
  39. case cmTarget::MODULE_LIBRARY:
  40. return "MODULE_LIBRARY";
  41. case cmTarget::SHARED_LIBRARY:
  42. return "SHARED_LIBRARY";
  43. case cmTarget::OBJECT_LIBRARY:
  44. return "OBJECT_LIBRARY";
  45. case cmTarget::EXECUTABLE:
  46. return "EXECUTABLE";
  47. case cmTarget::UTILITY:
  48. return "UTILITY";
  49. case cmTarget::GLOBAL_TARGET:
  50. return "GLOBAL_TARGET";
  51. case cmTarget::INTERFACE_LIBRARY:
  52. return "INTERFACE_LIBRARY";
  53. case cmTarget::UNKNOWN_LIBRARY:
  54. return "UNKNOWN_LIBRARY";
  55. }
  56. assert(0 && "Unexpected target type");
  57. return 0;
  58. }
  59. //----------------------------------------------------------------------------
  60. struct cmTarget::OutputInfo
  61. {
  62. std::string OutDir;
  63. std::string ImpDir;
  64. std::string PdbDir;
  65. bool empty() const
  66. { return OutDir.empty() && ImpDir.empty() && PdbDir.empty(); }
  67. };
  68. //----------------------------------------------------------------------------
  69. class cmTargetInternals
  70. {
  71. public:
  72. cmTargetInternals()
  73. : Backtrace()
  74. {
  75. this->UtilityItemsDone = false;
  76. }
  77. cmTargetInternals(cmTargetInternals const&)
  78. : Backtrace()
  79. {
  80. this->UtilityItemsDone = false;
  81. }
  82. ~cmTargetInternals();
  83. // The backtrace when the target was created.
  84. cmListFileBacktrace Backtrace;
  85. typedef std::map<std::string, cmTarget::OutputInfo> OutputInfoMapType;
  86. OutputInfoMapType OutputInfoMap;
  87. typedef std::map<std::string, cmTarget::ImportInfo> ImportInfoMapType;
  88. ImportInfoMapType ImportInfoMap;
  89. // Cache link implementation computation from each configuration.
  90. struct OptionalLinkImplementation: public cmTarget::LinkImplementation
  91. {
  92. OptionalLinkImplementation():
  93. LibrariesDone(false), LanguagesDone(false),
  94. HadHeadSensitiveCondition(false) {}
  95. bool LibrariesDone;
  96. bool LanguagesDone;
  97. bool HadHeadSensitiveCondition;
  98. };
  99. void ComputeLinkImplementationLibraries(cmTarget const* thisTarget,
  100. const std::string& config,
  101. OptionalLinkImplementation& impl,
  102. cmTarget const* head) const;
  103. void ComputeLinkImplementationLanguages(cmTarget const* thisTarget,
  104. const std::string& config,
  105. OptionalLinkImplementation& impl
  106. ) const;
  107. struct HeadToLinkImplementationMap:
  108. public std::map<cmTarget const*, OptionalLinkImplementation> {};
  109. typedef std::map<std::string,
  110. HeadToLinkImplementationMap> LinkImplMapType;
  111. LinkImplMapType LinkImplMap;
  112. typedef std::map<std::string, std::vector<cmSourceFile*> >
  113. SourceFilesMapType;
  114. SourceFilesMapType SourceFilesMap;
  115. std::set<cmLinkItem> UtilityItems;
  116. bool UtilityItemsDone;
  117. class TargetPropertyEntry {
  118. static cmLinkImplItem NoLinkImplItem;
  119. public:
  120. TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
  121. cmLinkImplItem const& item = NoLinkImplItem)
  122. : ge(cge), LinkImplItem(item)
  123. {}
  124. const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
  125. cmLinkImplItem const& LinkImplItem;
  126. };
  127. std::vector<std::string> IncludeDirectoriesEntries;
  128. std::vector<cmListFileBacktrace> IncludeDirectoriesBacktraces;
  129. std::vector<std::string> CompileOptionsEntries;
  130. std::vector<cmListFileBacktrace> CompileOptionsBacktraces;
  131. std::vector<std::string> CompileFeaturesEntries;
  132. std::vector<cmListFileBacktrace> CompileFeaturesBacktraces;
  133. std::vector<TargetPropertyEntry*> CompileFeaturesItems;
  134. std::vector<std::string> CompileDefinitionsEntries;
  135. std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces;
  136. std::vector<TargetPropertyEntry*> CompileDefinitionsItems;
  137. std::vector<TargetPropertyEntry*> SourceEntries;
  138. std::vector<cmValueWithOrigin> LinkImplementationPropertyEntries;
  139. void AddInterfaceEntries(
  140. cmTarget const* thisTarget, std::string const& config,
  141. std::string const& prop, std::vector<TargetPropertyEntry*>& entries);
  142. };
  143. cmLinkImplItem cmTargetInternals::TargetPropertyEntry::NoLinkImplItem;
  144. //----------------------------------------------------------------------------
  145. cmTargetInternals::~cmTargetInternals()
  146. {
  147. }
  148. //----------------------------------------------------------------------------
  149. cmTarget::cmTarget()
  150. {
  151. this->Makefile = 0;
  152. #if defined(_WIN32) && !defined(__CYGWIN__)
  153. this->LinkLibrariesForVS6Analyzed = false;
  154. #endif
  155. this->HaveInstallRule = false;
  156. this->DLLPlatform = false;
  157. this->IsAndroid = false;
  158. this->IsApple = false;
  159. this->IsImportedTarget = false;
  160. this->BuildInterfaceIncludesAppended = false;
  161. this->DebugCompileFeaturesDone = false;
  162. this->DebugCompileDefinitionsDone = false;
  163. this->DebugSourcesDone = false;
  164. this->LinkImplementationLanguageIsContextDependent = true;
  165. }
  166. void cmTarget::SetType(TargetType type, const std::string& name)
  167. {
  168. this->Name = name;
  169. // only add dependency information for library targets
  170. this->TargetTypeValue = type;
  171. if(this->TargetTypeValue >= STATIC_LIBRARY
  172. && this->TargetTypeValue <= MODULE_LIBRARY)
  173. {
  174. this->RecordDependencies = true;
  175. }
  176. else
  177. {
  178. this->RecordDependencies = false;
  179. }
  180. }
  181. //----------------------------------------------------------------------------
  182. void cmTarget::SetMakefile(cmMakefile* mf)
  183. {
  184. // Set our makefile.
  185. this->Makefile = mf;
  186. // Check whether this is a DLL platform.
  187. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  188. this->Makefile->IsOn("CYGWIN") ||
  189. this->Makefile->IsOn("MINGW"));
  190. // Check whether we are targeting an Android platform.
  191. this->IsAndroid =
  192. strcmp(this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME"),
  193. "Android") == 0;
  194. // Check whether we are targeting an Apple platform.
  195. this->IsApple = this->Makefile->IsOn("APPLE");
  196. // Setup default property values.
  197. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  198. {
  199. this->SetPropertyDefault("ANDROID_API", 0);
  200. this->SetPropertyDefault("ANDROID_API_MIN", 0);
  201. this->SetPropertyDefault("ANDROID_ARCH", 0);
  202. this->SetPropertyDefault("ANDROID_STL_TYPE", 0);
  203. this->SetPropertyDefault("ANDROID_SKIP_ANT_STEP", 0);
  204. this->SetPropertyDefault("ANDROID_PROCESS_MAX", 0);
  205. this->SetPropertyDefault("ANDROID_PROGUARD", 0);
  206. this->SetPropertyDefault("ANDROID_PROGUARD_CONFIG_PATH", 0);
  207. this->SetPropertyDefault("ANDROID_SECURE_PROPS_PATH", 0);
  208. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DIRECTORIES", 0);
  209. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DEPENDENCIES", 0);
  210. this->SetPropertyDefault("ANDROID_JAVA_SOURCE_DIR", 0);
  211. this->SetPropertyDefault("ANDROID_JAR_DIRECTORIES", 0);
  212. this->SetPropertyDefault("ANDROID_JAR_DEPENDENCIES", 0);
  213. this->SetPropertyDefault("ANDROID_ASSETS_DIRECTORIES", 0);
  214. this->SetPropertyDefault("ANDROID_ANT_ADDITIONAL_OPTIONS", 0);
  215. this->SetPropertyDefault("INSTALL_NAME_DIR", 0);
  216. this->SetPropertyDefault("INSTALL_RPATH", "");
  217. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  218. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  219. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  220. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
  221. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
  222. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
  223. this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
  224. this->SetPropertyDefault("COMPILE_PDB_OUTPUT_DIRECTORY", 0);
  225. this->SetPropertyDefault("Fortran_FORMAT", 0);
  226. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
  227. this->SetPropertyDefault("GNUtoMS", 0);
  228. this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
  229. this->SetPropertyDefault("AUTOMOC", 0);
  230. this->SetPropertyDefault("AUTOUIC", 0);
  231. this->SetPropertyDefault("AUTORCC", 0);
  232. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
  233. this->SetPropertyDefault("AUTOUIC_OPTIONS", 0);
  234. this->SetPropertyDefault("AUTORCC_OPTIONS", 0);
  235. this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
  236. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
  237. this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
  238. this->SetPropertyDefault("MACOSX_BUNDLE", 0);
  239. this->SetPropertyDefault("MACOSX_RPATH", 0);
  240. this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0);
  241. this->SetPropertyDefault("C_COMPILER_LAUNCHER", 0);
  242. this->SetPropertyDefault("C_INCLUDE_WHAT_YOU_USE", 0);
  243. this->SetPropertyDefault("C_STANDARD", 0);
  244. this->SetPropertyDefault("C_STANDARD_REQUIRED", 0);
  245. this->SetPropertyDefault("C_EXTENSIONS", 0);
  246. this->SetPropertyDefault("CXX_COMPILER_LAUNCHER", 0);
  247. this->SetPropertyDefault("CXX_INCLUDE_WHAT_YOU_USE", 0);
  248. this->SetPropertyDefault("CXX_STANDARD", 0);
  249. this->SetPropertyDefault("CXX_STANDARD_REQUIRED", 0);
  250. this->SetPropertyDefault("CXX_EXTENSIONS", 0);
  251. this->SetPropertyDefault("LINK_SEARCH_START_STATIC", 0);
  252. this->SetPropertyDefault("LINK_SEARCH_END_STATIC", 0);
  253. }
  254. // Collect the set of configuration types.
  255. std::vector<std::string> configNames;
  256. mf->GetConfigurations(configNames);
  257. // Setup per-configuration property default values.
  258. if (this->GetType() != UTILITY)
  259. {
  260. const char* configProps[] = {
  261. "ARCHIVE_OUTPUT_DIRECTORY_",
  262. "LIBRARY_OUTPUT_DIRECTORY_",
  263. "RUNTIME_OUTPUT_DIRECTORY_",
  264. "PDB_OUTPUT_DIRECTORY_",
  265. "COMPILE_PDB_OUTPUT_DIRECTORY_",
  266. "MAP_IMPORTED_CONFIG_",
  267. 0};
  268. for(std::vector<std::string>::iterator ci = configNames.begin();
  269. ci != configNames.end(); ++ci)
  270. {
  271. std::string configUpper = cmSystemTools::UpperCase(*ci);
  272. for(const char** p = configProps; *p; ++p)
  273. {
  274. if (this->TargetTypeValue == INTERFACE_LIBRARY
  275. && strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0)
  276. {
  277. continue;
  278. }
  279. std::string property = *p;
  280. property += configUpper;
  281. this->SetPropertyDefault(property, 0);
  282. }
  283. // Initialize per-configuration name postfix property from the
  284. // variable only for non-executable targets. This preserves
  285. // compatibility with previous CMake versions in which executables
  286. // did not support this variable. Projects may still specify the
  287. // property directly.
  288. if(this->TargetTypeValue != cmTarget::EXECUTABLE
  289. && this->TargetTypeValue != cmTarget::INTERFACE_LIBRARY)
  290. {
  291. std::string property = cmSystemTools::UpperCase(*ci);
  292. property += "_POSTFIX";
  293. this->SetPropertyDefault(property, 0);
  294. }
  295. }
  296. }
  297. // Save the backtrace of target construction.
  298. this->Internal->Backtrace = this->Makefile->GetBacktrace();
  299. if (!this->IsImported())
  300. {
  301. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  302. // of the same directory property:
  303. const cmStringRange parentIncludes =
  304. this->Makefile->GetIncludeDirectoriesEntries();
  305. const cmBacktraceRange parentIncludesBts =
  306. this->Makefile->GetIncludeDirectoriesBacktraces();
  307. this->Internal->IncludeDirectoriesEntries.insert(
  308. this->Internal->IncludeDirectoriesEntries.end(),
  309. parentIncludes.begin(), parentIncludes.end());
  310. this->Internal->IncludeDirectoriesBacktraces.insert(
  311. this->Internal->IncludeDirectoriesBacktraces.end(),
  312. parentIncludesBts.begin(), parentIncludesBts.end());
  313. const std::set<std::string> parentSystemIncludes =
  314. this->Makefile->GetSystemIncludeDirectories();
  315. this->SystemIncludeDirectories.insert(parentSystemIncludes.begin(),
  316. parentSystemIncludes.end());
  317. const cmStringRange parentOptions =
  318. this->Makefile->GetCompileOptionsEntries();
  319. const cmBacktraceRange parentOptionsBts =
  320. this->Makefile->GetCompileOptionsBacktraces();
  321. this->Internal->CompileOptionsEntries.insert(
  322. this->Internal->CompileOptionsEntries.end(),
  323. parentOptions.begin(), parentOptions.end());
  324. this->Internal->CompileOptionsBacktraces.insert(
  325. this->Internal->CompileOptionsBacktraces.end(),
  326. parentOptionsBts.begin(), parentOptionsBts.end());
  327. }
  328. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  329. {
  330. this->SetPropertyDefault("C_VISIBILITY_PRESET", 0);
  331. this->SetPropertyDefault("CXX_VISIBILITY_PRESET", 0);
  332. this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
  333. }
  334. if(this->TargetTypeValue == cmTarget::EXECUTABLE)
  335. {
  336. this->SetPropertyDefault("ANDROID_GUI", 0);
  337. this->SetPropertyDefault("CROSSCOMPILING_EMULATOR", 0);
  338. }
  339. if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
  340. || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
  341. {
  342. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  343. }
  344. if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY)
  345. {
  346. this->SetPropertyDefault("WINDOWS_EXPORT_ALL_SYMBOLS", 0);
  347. }
  348. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  349. {
  350. this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
  351. }
  352. // Record current policies for later use.
  353. this->Makefile->RecordPolicies(this->PolicyMap);
  354. if (this->TargetTypeValue == INTERFACE_LIBRARY)
  355. {
  356. // This policy is checked in a few conditions. The properties relevant
  357. // to the policy are always ignored for INTERFACE_LIBRARY targets,
  358. // so ensure that the conditions don't lead to nonsense.
  359. this->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
  360. }
  361. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  362. {
  363. this->SetPropertyDefault("JOB_POOL_COMPILE", 0);
  364. this->SetPropertyDefault("JOB_POOL_LINK", 0);
  365. }
  366. }
  367. void CreatePropertyGeneratorExpressions(
  368. std::vector<std::string> const& entries,
  369. std::vector<cmListFileBacktrace> const& backtraces,
  370. std::vector<cmTargetInternals::TargetPropertyEntry*>& items)
  371. {
  372. std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin();
  373. for (std::vector<std::string>::const_iterator it = entries.begin();
  374. it != entries.end(); ++it, ++btIt)
  375. {
  376. cmGeneratorExpression ge(*btIt);
  377. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*it);
  378. items.push_back(new cmTargetInternals::TargetPropertyEntry(cge));
  379. }
  380. }
  381. void cmTarget::Compute()
  382. {
  383. CreatePropertyGeneratorExpressions(
  384. this->Internal->CompileFeaturesEntries,
  385. this->Internal->CompileFeaturesBacktraces,
  386. this->Internal->CompileFeaturesItems);
  387. CreatePropertyGeneratorExpressions(
  388. this->Internal->CompileDefinitionsEntries,
  389. this->Internal->CompileDefinitionsBacktraces,
  390. this->Internal->CompileDefinitionsItems);
  391. }
  392. //----------------------------------------------------------------------------
  393. void cmTarget::AddUtility(const std::string& u, cmMakefile *makefile)
  394. {
  395. if(this->Utilities.insert(u).second && makefile)
  396. {
  397. UtilityBacktraces.insert(std::make_pair(u, makefile->GetBacktrace()));
  398. }
  399. }
  400. //----------------------------------------------------------------------------
  401. cmListFileBacktrace const* cmTarget::GetUtilityBacktrace(
  402. const std::string& u) const
  403. {
  404. std::map<std::string, cmListFileBacktrace>::const_iterator i =
  405. this->UtilityBacktraces.find(u);
  406. if(i == this->UtilityBacktraces.end()) return 0;
  407. return &i->second;
  408. }
  409. //----------------------------------------------------------------------------
  410. std::set<cmLinkItem> const& cmTarget::GetUtilityItems() const
  411. {
  412. if(!this->Internal->UtilityItemsDone)
  413. {
  414. this->Internal->UtilityItemsDone = true;
  415. for(std::set<std::string>::const_iterator i = this->Utilities.begin();
  416. i != this->Utilities.end(); ++i)
  417. {
  418. this->Internal->UtilityItems.insert(
  419. cmLinkItem(*i, this->Makefile->FindTargetToUse(*i)));
  420. }
  421. }
  422. return this->Internal->UtilityItems;
  423. }
  424. //----------------------------------------------------------------------------
  425. void cmTarget::FinishConfigure()
  426. {
  427. // Erase any cached link information that might have been comptued
  428. // on-demand during the configuration. This ensures that build
  429. // system generation uses up-to-date information even if other cache
  430. // invalidation code in this source file is buggy.
  431. this->ClearLinkMaps();
  432. #if defined(_WIN32) && !defined(__CYGWIN__)
  433. // Do old-style link dependency analysis only for CM_USE_OLD_VS6.
  434. if(this->Makefile->GetGlobalGenerator()->IsForVS6())
  435. {
  436. this->AnalyzeLibDependenciesForVS6(*this->Makefile);
  437. }
  438. #endif
  439. }
  440. //----------------------------------------------------------------------------
  441. void cmTarget::ClearLinkMaps()
  442. {
  443. this->LinkImplementationLanguageIsContextDependent = true;
  444. this->Internal->LinkImplMap.clear();
  445. this->Internal->SourceFilesMap.clear();
  446. }
  447. //----------------------------------------------------------------------------
  448. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  449. {
  450. return this->Internal->Backtrace;
  451. }
  452. //----------------------------------------------------------------------------
  453. std::string cmTarget::GetSupportDirectory() const
  454. {
  455. std::string dir = this->Makefile->GetCurrentBinaryDirectory();
  456. dir += cmake::GetCMakeFilesDirectory();
  457. dir += "/";
  458. dir += this->Name;
  459. #if defined(__VMS)
  460. dir += "_dir";
  461. #else
  462. dir += ".dir";
  463. #endif
  464. return dir;
  465. }
  466. //----------------------------------------------------------------------------
  467. bool cmTarget::IsExecutableWithExports() const
  468. {
  469. return (this->GetType() == cmTarget::EXECUTABLE &&
  470. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  471. }
  472. //----------------------------------------------------------------------------
  473. bool cmTarget::IsLinkable() const
  474. {
  475. return (this->GetType() == cmTarget::STATIC_LIBRARY ||
  476. this->GetType() == cmTarget::SHARED_LIBRARY ||
  477. this->GetType() == cmTarget::MODULE_LIBRARY ||
  478. this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
  479. this->GetType() == cmTarget::INTERFACE_LIBRARY ||
  480. this->IsExecutableWithExports());
  481. }
  482. //----------------------------------------------------------------------------
  483. bool cmTarget::HasImportLibrary() const
  484. {
  485. return (this->DLLPlatform &&
  486. (this->GetType() == cmTarget::SHARED_LIBRARY ||
  487. this->IsExecutableWithExports()));
  488. }
  489. //----------------------------------------------------------------------------
  490. bool cmTarget::IsFrameworkOnApple() const
  491. {
  492. return (this->GetType() == cmTarget::SHARED_LIBRARY &&
  493. this->Makefile->IsOn("APPLE") &&
  494. this->GetPropertyAsBool("FRAMEWORK"));
  495. }
  496. //----------------------------------------------------------------------------
  497. bool cmTarget::IsAppBundleOnApple() const
  498. {
  499. return (this->GetType() == cmTarget::EXECUTABLE &&
  500. this->Makefile->IsOn("APPLE") &&
  501. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  502. }
  503. //----------------------------------------------------------------------------
  504. bool cmTarget::IsCFBundleOnApple() const
  505. {
  506. return (this->GetType() == cmTarget::MODULE_LIBRARY &&
  507. this->Makefile->IsOn("APPLE") &&
  508. this->GetPropertyAsBool("BUNDLE"));
  509. }
  510. //----------------------------------------------------------------------------
  511. bool cmTarget::IsXCTestOnApple() const
  512. {
  513. return (this->IsCFBundleOnApple() &&
  514. this->GetPropertyAsBool("XCTEST"));
  515. }
  516. //----------------------------------------------------------------------------
  517. static bool processSources(cmTarget const* tgt,
  518. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  519. std::vector<std::string> &srcs,
  520. UNORDERED_SET<std::string> &uniqueSrcs,
  521. cmGeneratorExpressionDAGChecker *dagChecker,
  522. std::string const& config, bool debugSources)
  523. {
  524. cmMakefile *mf = tgt->GetMakefile();
  525. bool contextDependent = false;
  526. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  527. it = entries.begin(), end = entries.end(); it != end; ++it)
  528. {
  529. cmLinkImplItem const& item = (*it)->LinkImplItem;
  530. std::string const& targetName = item;
  531. std::vector<std::string> entrySources;
  532. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  533. config,
  534. false,
  535. tgt,
  536. tgt,
  537. dagChecker),
  538. entrySources);
  539. if ((*it)->ge->GetHadContextSensitiveCondition())
  540. {
  541. contextDependent = true;
  542. }
  543. for(std::vector<std::string>::iterator i = entrySources.begin();
  544. i != entrySources.end(); ++i)
  545. {
  546. std::string& src = *i;
  547. cmSourceFile* sf = mf->GetOrCreateSource(src);
  548. std::string e;
  549. std::string fullPath = sf->GetFullPath(&e);
  550. if(fullPath.empty())
  551. {
  552. if(!e.empty())
  553. {
  554. cmake* cm = mf->GetCMakeInstance();
  555. cm->IssueMessage(cmake::FATAL_ERROR, e,
  556. tgt->GetBacktrace());
  557. }
  558. return contextDependent;
  559. }
  560. if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src.c_str()))
  561. {
  562. std::ostringstream err;
  563. if (!targetName.empty())
  564. {
  565. err << "Target \"" << targetName << "\" contains relative "
  566. "path in its INTERFACE_SOURCES:\n"
  567. " \"" << src << "\"";
  568. }
  569. else
  570. {
  571. err << "Found relative path while evaluating sources of "
  572. "\"" << tgt->GetName() << "\":\n \"" << src << "\"\n";
  573. }
  574. tgt->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, err.str());
  575. return contextDependent;
  576. }
  577. src = fullPath;
  578. }
  579. std::string usedSources;
  580. for(std::vector<std::string>::iterator
  581. li = entrySources.begin(); li != entrySources.end(); ++li)
  582. {
  583. std::string src = *li;
  584. if(uniqueSrcs.insert(src).second)
  585. {
  586. srcs.push_back(src);
  587. if (debugSources)
  588. {
  589. usedSources += " * " + src + "\n";
  590. }
  591. }
  592. }
  593. if (!usedSources.empty())
  594. {
  595. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  596. std::string("Used sources for target ")
  597. + tgt->GetName() + ":\n"
  598. + usedSources, (*it)->ge->GetBacktrace());
  599. }
  600. }
  601. return contextDependent;
  602. }
  603. //----------------------------------------------------------------------------
  604. void cmTarget::GetSourceFiles(std::vector<std::string> &files,
  605. const std::string& config) const
  606. {
  607. assert(this->GetType() != INTERFACE_LIBRARY);
  608. if (!this->Makefile->IsConfigured())
  609. {
  610. // At configure-time, this method can be called as part of getting the
  611. // LOCATION property or to export() a file to be include()d. However
  612. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  613. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  614. // behavior of CMP0024 and CMP0026 only.
  615. typedef cmTargetInternals::TargetPropertyEntry
  616. TargetPropertyEntry;
  617. for(std::vector<TargetPropertyEntry*>::const_iterator
  618. i = this->Internal->SourceEntries.begin();
  619. i != this->Internal->SourceEntries.end(); ++i)
  620. {
  621. std::string entry = (*i)->ge->GetInput();
  622. std::vector<std::string> items;
  623. cmSystemTools::ExpandListArgument(entry, items);
  624. for (std::vector<std::string>::const_iterator
  625. li = items.begin(); li != items.end(); ++li)
  626. {
  627. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  628. (*li)[li->size() - 1] == '>')
  629. {
  630. continue;
  631. }
  632. files.push_back(*li);
  633. }
  634. }
  635. return;
  636. }
  637. std::vector<std::string> debugProperties;
  638. const char *debugProp =
  639. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  640. if (debugProp)
  641. {
  642. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  643. }
  644. bool debugSources = !this->DebugSourcesDone
  645. && std::find(debugProperties.begin(),
  646. debugProperties.end(),
  647. "SOURCES")
  648. != debugProperties.end();
  649. if (this->Makefile->IsConfigured())
  650. {
  651. this->DebugSourcesDone = true;
  652. }
  653. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  654. "SOURCES", 0, 0);
  655. UNORDERED_SET<std::string> uniqueSrcs;
  656. bool contextDependentDirectSources = processSources(this,
  657. this->Internal->SourceEntries,
  658. files,
  659. uniqueSrcs,
  660. &dagChecker,
  661. config,
  662. debugSources);
  663. std::vector<cmTargetInternals::TargetPropertyEntry*>
  664. linkInterfaceSourcesEntries;
  665. this->Internal->AddInterfaceEntries(
  666. this, config, "INTERFACE_SOURCES",
  667. linkInterfaceSourcesEntries);
  668. std::vector<std::string>::size_type numFilesBefore = files.size();
  669. bool contextDependentInterfaceSources = processSources(this,
  670. linkInterfaceSourcesEntries,
  671. files,
  672. uniqueSrcs,
  673. &dagChecker,
  674. config,
  675. debugSources);
  676. if (!contextDependentDirectSources
  677. && !(contextDependentInterfaceSources && numFilesBefore < files.size()))
  678. {
  679. this->LinkImplementationLanguageIsContextDependent = false;
  680. }
  681. cmDeleteAll(linkInterfaceSourcesEntries);
  682. }
  683. //----------------------------------------------------------------------------
  684. bool
  685. cmTarget::GetConfigCommonSourceFiles(std::vector<cmSourceFile*>& files) const
  686. {
  687. std::vector<std::string> configs;
  688. this->Makefile->GetConfigurations(configs);
  689. if (configs.empty())
  690. {
  691. configs.push_back("");
  692. }
  693. std::vector<std::string>::const_iterator it = configs.begin();
  694. const std::string& firstConfig = *it;
  695. this->GetSourceFiles(files, firstConfig);
  696. for ( ; it != configs.end(); ++it)
  697. {
  698. std::vector<cmSourceFile*> configFiles;
  699. this->GetSourceFiles(configFiles, *it);
  700. if (configFiles != files)
  701. {
  702. std::string firstConfigFiles;
  703. const char* sep = "";
  704. for (std::vector<cmSourceFile*>::const_iterator fi = files.begin();
  705. fi != files.end(); ++fi)
  706. {
  707. firstConfigFiles += sep;
  708. firstConfigFiles += (*fi)->GetFullPath();
  709. sep = "\n ";
  710. }
  711. std::string thisConfigFiles;
  712. sep = "";
  713. for (std::vector<cmSourceFile*>::const_iterator fi = configFiles.begin();
  714. fi != configFiles.end(); ++fi)
  715. {
  716. thisConfigFiles += sep;
  717. thisConfigFiles += (*fi)->GetFullPath();
  718. sep = "\n ";
  719. }
  720. std::ostringstream e;
  721. e << "Target \"" << this->Name << "\" has source files which vary by "
  722. "configuration. This is not supported by the \""
  723. << this->Makefile->GetGlobalGenerator()->GetName()
  724. << "\" generator.\n"
  725. "Config \"" << firstConfig << "\":\n"
  726. " " << firstConfigFiles << "\n"
  727. "Config \"" << *it << "\":\n"
  728. " " << thisConfigFiles << "\n";
  729. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  730. return false;
  731. }
  732. }
  733. return true;
  734. }
  735. //----------------------------------------------------------------------------
  736. void cmTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
  737. const std::string& config) const
  738. {
  739. // Lookup any existing link implementation for this configuration.
  740. std::string key = cmSystemTools::UpperCase(config);
  741. if(!this->LinkImplementationLanguageIsContextDependent)
  742. {
  743. files = this->Internal->SourceFilesMap.begin()->second;
  744. return;
  745. }
  746. cmTargetInternals::SourceFilesMapType::iterator
  747. it = this->Internal->SourceFilesMap.find(key);
  748. if(it != this->Internal->SourceFilesMap.end())
  749. {
  750. files = it->second;
  751. }
  752. else
  753. {
  754. std::vector<std::string> srcs;
  755. this->GetSourceFiles(srcs, config);
  756. std::set<cmSourceFile*> emitted;
  757. for(std::vector<std::string>::const_iterator i = srcs.begin();
  758. i != srcs.end(); ++i)
  759. {
  760. cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
  761. if (emitted.insert(sf).second)
  762. {
  763. files.push_back(sf);
  764. }
  765. }
  766. this->Internal->SourceFilesMap[key] = files;
  767. }
  768. }
  769. //----------------------------------------------------------------------------
  770. void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
  771. {
  772. std::string srcFiles = cmJoin(srcs, ";");
  773. if (!srcFiles.empty())
  774. {
  775. this->Internal->SourceFilesMap.clear();
  776. this->LinkImplementationLanguageIsContextDependent = true;
  777. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  778. cmGeneratorExpression ge(lfbt);
  779. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
  780. cge->SetEvaluateForBuildsystem(true);
  781. this->Internal->SourceEntries.push_back(
  782. new cmTargetInternals::TargetPropertyEntry(cge));
  783. }
  784. }
  785. //----------------------------------------------------------------------------
  786. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  787. {
  788. std::string srcFiles;
  789. const char* sep = "";
  790. for(std::vector<std::string>::const_iterator i = srcs.begin();
  791. i != srcs.end(); ++i)
  792. {
  793. std::string filename = *i;
  794. const char* src = filename.c_str();
  795. if(!(src[0] == '$' && src[1] == '<'))
  796. {
  797. if(!filename.empty())
  798. {
  799. filename = this->ProcessSourceItemCMP0049(filename);
  800. if(filename.empty())
  801. {
  802. return;
  803. }
  804. }
  805. this->Makefile->GetOrCreateSource(filename);
  806. }
  807. srcFiles += sep;
  808. srcFiles += filename;
  809. sep = ";";
  810. }
  811. if (!srcFiles.empty())
  812. {
  813. this->Internal->SourceFilesMap.clear();
  814. this->LinkImplementationLanguageIsContextDependent = true;
  815. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  816. cmGeneratorExpression ge(lfbt);
  817. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
  818. cge->SetEvaluateForBuildsystem(true);
  819. this->Internal->SourceEntries.push_back(
  820. new cmTargetInternals::TargetPropertyEntry(cge));
  821. }
  822. }
  823. //----------------------------------------------------------------------------
  824. std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
  825. {
  826. std::string src = s;
  827. // For backwards compatibility replace varibles in source names.
  828. // This should eventually be removed.
  829. this->Makefile->ExpandVariablesInString(src);
  830. if (src != s)
  831. {
  832. std::ostringstream e;
  833. bool noMessage = false;
  834. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  835. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0049))
  836. {
  837. case cmPolicies::WARN:
  838. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0049) << "\n";
  839. break;
  840. case cmPolicies::OLD:
  841. noMessage = true;
  842. break;
  843. case cmPolicies::REQUIRED_ALWAYS:
  844. case cmPolicies::REQUIRED_IF_USED:
  845. case cmPolicies::NEW:
  846. messageType = cmake::FATAL_ERROR;
  847. }
  848. if (!noMessage)
  849. {
  850. e << "Legacy variable expansion in source file \""
  851. << s << "\" expanded to \"" << src << "\" in target \""
  852. << this->GetName() << "\". This behavior will be removed in a "
  853. "future version of CMake.";
  854. this->Makefile->IssueMessage(messageType, e.str());
  855. if (messageType == cmake::FATAL_ERROR)
  856. {
  857. return "";
  858. }
  859. }
  860. }
  861. return src;
  862. }
  863. //----------------------------------------------------------------------------
  864. cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s)
  865. {
  866. std::string src = this->ProcessSourceItemCMP0049(s);
  867. if(!s.empty() && src.empty())
  868. {
  869. return 0;
  870. }
  871. return this->AddSource(src);
  872. }
  873. //----------------------------------------------------------------------------
  874. struct CreateLocation
  875. {
  876. cmMakefile const* Makefile;
  877. CreateLocation(cmMakefile const* mf)
  878. : Makefile(mf)
  879. {
  880. }
  881. cmSourceFileLocation operator()(const std::string& filename)
  882. {
  883. return cmSourceFileLocation(this->Makefile, filename);
  884. }
  885. };
  886. //----------------------------------------------------------------------------
  887. struct LocationMatcher
  888. {
  889. const cmSourceFileLocation& Needle;
  890. LocationMatcher(const cmSourceFileLocation& needle)
  891. : Needle(needle)
  892. {
  893. }
  894. bool operator()(cmSourceFileLocation &loc)
  895. {
  896. return loc.Matches(this->Needle);
  897. }
  898. };
  899. //----------------------------------------------------------------------------
  900. struct TargetPropertyEntryFinder
  901. {
  902. private:
  903. const cmSourceFileLocation& Needle;
  904. public:
  905. TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
  906. : Needle(needle)
  907. {
  908. }
  909. bool operator()(cmTargetInternals::TargetPropertyEntry* entry)
  910. {
  911. std::vector<std::string> files;
  912. cmSystemTools::ExpandListArgument(entry->ge->GetInput(), files);
  913. std::vector<cmSourceFileLocation> locations(files.size());
  914. std::transform(files.begin(), files.end(), locations.begin(),
  915. CreateLocation(this->Needle.GetMakefile()));
  916. return std::find_if(locations.begin(), locations.end(),
  917. LocationMatcher(this->Needle)) != locations.end();
  918. }
  919. };
  920. //----------------------------------------------------------------------------
  921. cmSourceFile* cmTarget::AddSource(const std::string& src)
  922. {
  923. cmSourceFileLocation sfl(this->Makefile, src);
  924. if (std::find_if(this->Internal->SourceEntries.begin(),
  925. this->Internal->SourceEntries.end(),
  926. TargetPropertyEntryFinder(sfl))
  927. == this->Internal->SourceEntries.end())
  928. {
  929. this->Internal->SourceFilesMap.clear();
  930. this->LinkImplementationLanguageIsContextDependent = true;
  931. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  932. cmGeneratorExpression ge(lfbt);
  933. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  934. cge->SetEvaluateForBuildsystem(true);
  935. this->Internal->SourceEntries.push_back(
  936. new cmTargetInternals::TargetPropertyEntry(cge));
  937. }
  938. if (cmGeneratorExpression::Find(src) != std::string::npos)
  939. {
  940. return 0;
  941. }
  942. return this->Makefile->GetOrCreateSource(src);
  943. }
  944. //----------------------------------------------------------------------------
  945. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  946. const std::string& selfname,
  947. const LinkLibraryVectorType& libs )
  948. {
  949. // Only add on libraries we haven't added on before.
  950. // Assumption: the global link libraries could only grow, never shrink
  951. LinkLibraryVectorType::const_iterator i = libs.begin();
  952. i += this->PrevLinkedLibraries.size();
  953. for( ; i != libs.end(); ++i )
  954. {
  955. // This is equivalent to the target_link_libraries plain signature.
  956. this->AddLinkLibrary( mf, selfname, i->first, i->second );
  957. this->AppendProperty("INTERFACE_LINK_LIBRARIES",
  958. this->GetDebugGeneratorExpressions(i->first, i->second).c_str());
  959. }
  960. this->PrevLinkedLibraries = libs;
  961. }
  962. //----------------------------------------------------------------------------
  963. void cmTarget::AddLinkDirectory(const std::string& d)
  964. {
  965. // Make sure we don't add unnecessary search directories.
  966. if(this->LinkDirectoriesEmmitted.insert(d).second)
  967. {
  968. this->LinkDirectories.push_back(d);
  969. }
  970. }
  971. //----------------------------------------------------------------------------
  972. const std::vector<std::string>& cmTarget::GetLinkDirectories() const
  973. {
  974. return this->LinkDirectories;
  975. }
  976. //----------------------------------------------------------------------------
  977. cmTarget::LinkLibraryType cmTarget::ComputeLinkType(
  978. const std::string& config) const
  979. {
  980. // No configuration is always optimized.
  981. if(config.empty())
  982. {
  983. return cmTarget::OPTIMIZED;
  984. }
  985. // Get the list of configurations considered to be DEBUG.
  986. std::vector<std::string> debugConfigs =
  987. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  988. // Check if any entry in the list matches this configuration.
  989. std::string configUpper = cmSystemTools::UpperCase(config);
  990. if (std::find(debugConfigs.begin(), debugConfigs.end(), configUpper) !=
  991. debugConfigs.end())
  992. {
  993. return cmTarget::DEBUG;
  994. }
  995. // The current configuration is not a debug configuration.
  996. return cmTarget::OPTIMIZED;
  997. }
  998. //----------------------------------------------------------------------------
  999. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  1000. const std::string& target )
  1001. {
  1002. // Clear the dependencies. The cache variable must exist iff we are
  1003. // recording dependency information for this target.
  1004. std::string depname = target;
  1005. depname += "_LIB_DEPENDS";
  1006. if (this->RecordDependencies)
  1007. {
  1008. mf.AddCacheDefinition(depname, "",
  1009. "Dependencies for target", cmState::STATIC);
  1010. }
  1011. else
  1012. {
  1013. if (mf.GetDefinition( depname ))
  1014. {
  1015. std::string message = "Target ";
  1016. message += target;
  1017. message += " has dependency information when it shouldn't.\n";
  1018. message += "Your cache is probably stale. Please remove the entry\n ";
  1019. message += depname;
  1020. message += "\nfrom the cache.";
  1021. cmSystemTools::Error( message.c_str() );
  1022. }
  1023. }
  1024. }
  1025. //----------------------------------------------------------------------------
  1026. bool cmTarget::NameResolvesToFramework(const std::string& libname) const
  1027. {
  1028. return this->Makefile->GetGlobalGenerator()->
  1029. NameResolvesToFramework(libname);
  1030. }
  1031. //----------------------------------------------------------------------------
  1032. std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
  1033. cmTarget::LinkLibraryType llt) const
  1034. {
  1035. if (llt == GENERAL)
  1036. {
  1037. return value;
  1038. }
  1039. // Get the list of configurations considered to be DEBUG.
  1040. std::vector<std::string> debugConfigs =
  1041. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  1042. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  1043. if (debugConfigs.size() > 1)
  1044. {
  1045. for(std::vector<std::string>::const_iterator
  1046. li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
  1047. {
  1048. configString += ",$<CONFIG:" + *li + ">";
  1049. }
  1050. configString = "$<OR:" + configString + ">";
  1051. }
  1052. if (llt == OPTIMIZED)
  1053. {
  1054. configString = "$<NOT:" + configString + ">";
  1055. }
  1056. return "$<" + configString + ":" + value + ">";
  1057. }
  1058. //----------------------------------------------------------------------------
  1059. static std::string targetNameGenex(const std::string& lib)
  1060. {
  1061. return "$<TARGET_NAME:" + lib + ">";
  1062. }
  1063. //----------------------------------------------------------------------------
  1064. bool cmTarget::PushTLLCommandTrace(TLLSignature signature,
  1065. cmListFileContext const& lfc)
  1066. {
  1067. bool ret = true;
  1068. if (!this->TLLCommands.empty())
  1069. {
  1070. if (this->TLLCommands.back().first != signature)
  1071. {
  1072. ret = false;
  1073. }
  1074. }
  1075. if (this->TLLCommands.empty() || this->TLLCommands.back().second != lfc)
  1076. {
  1077. this->TLLCommands.push_back(std::make_pair(signature, lfc));
  1078. }
  1079. return ret;
  1080. }
  1081. //----------------------------------------------------------------------------
  1082. void cmTarget::GetTllSignatureTraces(std::ostringstream &s,
  1083. TLLSignature sig) const
  1084. {
  1085. const char *sigString = (sig == cmTarget::KeywordTLLSignature ? "keyword"
  1086. : "plain");
  1087. s << "The uses of the " << sigString << " signature are here:\n";
  1088. typedef std::vector<std::pair<TLLSignature, cmListFileContext> > Container;
  1089. cmOutputConverter converter(this->GetMakefile()->GetStateSnapshot());
  1090. for(Container::const_iterator it = this->TLLCommands.begin();
  1091. it != this->TLLCommands.end(); ++it)
  1092. {
  1093. if (it->first == sig)
  1094. {
  1095. cmListFileContext lfc = it->second;
  1096. lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
  1097. s << " * " << lfc << std::endl;
  1098. }
  1099. }
  1100. }
  1101. //----------------------------------------------------------------------------
  1102. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  1103. const std::string& target,
  1104. const std::string& lib,
  1105. LinkLibraryType llt)
  1106. {
  1107. cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
  1108. {
  1109. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  1110. const std::string libName = (isNonImportedTarget && llt != GENERAL)
  1111. ? targetNameGenex(lib)
  1112. : lib;
  1113. this->AppendProperty("LINK_LIBRARIES",
  1114. this->GetDebugGeneratorExpressions(libName,
  1115. llt).c_str());
  1116. }
  1117. if (cmGeneratorExpression::Find(lib) != std::string::npos
  1118. || (tgt && tgt->GetType() == INTERFACE_LIBRARY)
  1119. || (target == lib ))
  1120. {
  1121. return;
  1122. }
  1123. cmTarget::LibraryID tmp;
  1124. tmp.first = lib;
  1125. tmp.second = llt;
  1126. #if defined(_WIN32) && !defined(__CYGWIN__)
  1127. this->LinkLibrariesForVS6.push_back( tmp );
  1128. #endif
  1129. this->OriginalLinkLibraries.push_back(tmp);
  1130. this->ClearLinkMaps();
  1131. // Add the explicit dependency information for this target. This is
  1132. // simply a set of libraries separated by ";". There should always
  1133. // be a trailing ";". These library names are not canonical, in that
  1134. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  1135. // We shouldn't remove duplicates here because external libraries
  1136. // may be purposefully duplicated to handle recursive dependencies,
  1137. // and we removing one instance will break the link line. Duplicates
  1138. // will be appropriately eliminated at emit time.
  1139. if(this->RecordDependencies)
  1140. {
  1141. std::string targetEntry = target;
  1142. targetEntry += "_LIB_DEPENDS";
  1143. std::string dependencies;
  1144. const char* old_val = mf.GetDefinition( targetEntry );
  1145. if( old_val )
  1146. {
  1147. dependencies += old_val;
  1148. }
  1149. switch (llt)
  1150. {
  1151. case cmTarget::GENERAL:
  1152. dependencies += "general";
  1153. break;
  1154. case cmTarget::DEBUG:
  1155. dependencies += "debug";
  1156. break;
  1157. case cmTarget::OPTIMIZED:
  1158. dependencies += "optimized";
  1159. break;
  1160. }
  1161. dependencies += ";";
  1162. dependencies += lib;
  1163. dependencies += ";";
  1164. mf.AddCacheDefinition( targetEntry, dependencies.c_str(),
  1165. "Dependencies for the target",
  1166. cmState::STATIC );
  1167. }
  1168. }
  1169. //----------------------------------------------------------------------------
  1170. void
  1171. cmTarget::AddSystemIncludeDirectories(const std::set<std::string> &incs)
  1172. {
  1173. this->SystemIncludeDirectories.insert(incs.begin(), incs.end());
  1174. }
  1175. cmStringRange cmTarget::GetIncludeDirectoriesEntries() const
  1176. {
  1177. return cmMakeRange(this->Internal->IncludeDirectoriesEntries);
  1178. }
  1179. cmBacktraceRange cmTarget::GetIncludeDirectoriesBacktraces() const
  1180. {
  1181. return cmMakeRange(this->Internal->IncludeDirectoriesBacktraces);
  1182. }
  1183. cmStringRange cmTarget::GetCompileOptionsEntries() const
  1184. {
  1185. return cmMakeRange(this->Internal->CompileOptionsEntries);
  1186. }
  1187. cmBacktraceRange cmTarget::GetCompileOptionsBacktraces() const
  1188. {
  1189. return cmMakeRange(this->Internal->CompileOptionsBacktraces);
  1190. }
  1191. #if defined(_WIN32) && !defined(__CYGWIN__)
  1192. //----------------------------------------------------------------------------
  1193. void
  1194. cmTarget::AnalyzeLibDependenciesForVS6( const cmMakefile& mf )
  1195. {
  1196. // There are two key parts of the dependency analysis: (1)
  1197. // determining the libraries in the link line, and (2) constructing
  1198. // the dependency graph for those libraries.
  1199. //
  1200. // The latter is done using the cache entries that record the
  1201. // dependencies of each library.
  1202. //
  1203. // The former is a more thorny issue, since it is not clear how to
  1204. // determine if two libraries listed on the link line refer to the a
  1205. // single library or not. For example, consider the link "libraries"
  1206. // /usr/lib/libtiff.so -ltiff
  1207. // Is this one library or two? The solution implemented here is the
  1208. // simplest (and probably the only practical) one: two libraries are
  1209. // the same if their "link strings" are identical. Thus, the two
  1210. // libraries above are considered distinct. This also means that for
  1211. // dependency analysis to be effective, the CMake user must specify
  1212. // libraries build by his project without using any linker flags or
  1213. // file extensions. That is,
  1214. // LINK_LIBRARIES( One Two )
  1215. // instead of
  1216. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  1217. // The former is probably what most users would do, but it never
  1218. // hurts to document the assumptions. :-) Therefore, in the analysis
  1219. // code, the "canonical name" of a library is simply its name as
  1220. // given to a LINK_LIBRARIES command.
  1221. //
  1222. // Also, we will leave the original link line intact; we will just add any
  1223. // dependencies that were missing.
  1224. //
  1225. // There is a problem with recursive external libraries
  1226. // (i.e. libraries with no dependency information that are
  1227. // recursively dependent). We must make sure that the we emit one of
  1228. // the libraries twice to satisfy the recursion, but we shouldn't
  1229. // emit it more times than necessary. In particular, we must make
  1230. // sure that handling this improbable case doesn't cost us when
  1231. // dealing with the common case of non-recursive libraries. The
  1232. // solution is to assume that the recursion is satisfied at one node
  1233. // of the dependency tree. To illustrate, assume libA and libB are
  1234. // extrenal and mutually dependent. Suppose libX depends on
  1235. // libA, and libY on libA and libX. Then
  1236. // TARGET_LINK_LIBRARIES( Y X A B A )
  1237. // TARGET_LINK_LIBRARIES( X A B A )
  1238. // TARGET_LINK_LIBRARIES( Exec Y )
  1239. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  1240. // specify the dependencies, since the mutual dependency of A and B
  1241. // is resolved *every time libA is specified*.
  1242. //
  1243. // Something like
  1244. // TARGET_LINK_LIBRARIES( Y X A B A )
  1245. // TARGET_LINK_LIBRARIES( X A B )
  1246. // TARGET_LINK_LIBRARIES( Exec Y )
  1247. // would result in "-lY -lX -lA -lB", and the mutual dependency
  1248. // information is lost. This is because in some case (Y), the mutual
  1249. // dependency of A and B is listed, while in another other case (X),
  1250. // it is not. Depending on which line actually emits A, the mutual
  1251. // dependency may or may not be on the final link line. We can't
  1252. // handle this pathalogical case cleanly without emitting extra
  1253. // libraries for the normal cases. Besides, the dependency
  1254. // information for X is wrong anyway: if we build an executable
  1255. // depending on X alone, we would not have the mutual dependency on
  1256. // A and B resolved.
  1257. //
  1258. // IMPROVEMENTS:
  1259. // -- The current algorithm will not always pick the "optimal" link line
  1260. // when recursive dependencies are present. It will instead break the
  1261. // cycles at an aribtrary point. The majority of projects won't have
  1262. // cyclic dependencies, so this is probably not a big deal. Note that
  1263. // the link line is always correct, just not necessary optimal.
  1264. {
  1265. // Expand variables in link library names. This is for backwards
  1266. // compatibility with very early CMake versions and should
  1267. // eventually be removed. This code was moved here from the end of
  1268. // old source list processing code which was called just before this
  1269. // method.
  1270. for(LinkLibraryVectorType::iterator p = this->LinkLibrariesForVS6.begin();
  1271. p != this->LinkLibrariesForVS6.end(); ++p)
  1272. {
  1273. this->Makefile->ExpandVariablesInString(p->first, true, true);
  1274. }
  1275. }
  1276. // The dependency map.
  1277. DependencyMap dep_map;
  1278. // 1. Build the dependency graph
  1279. //
  1280. for(LinkLibraryVectorType::reverse_iterator lib
  1281. = this->LinkLibrariesForVS6.rbegin();
  1282. lib != this->LinkLibrariesForVS6.rend(); ++lib)
  1283. {
  1284. this->GatherDependenciesForVS6( mf, *lib, dep_map);
  1285. }
  1286. // 2. Remove any dependencies that are already satisfied in the original
  1287. // link line.
  1288. //
  1289. for(LinkLibraryVectorType::iterator lib = this->LinkLibrariesForVS6.begin();
  1290. lib != this->LinkLibrariesForVS6.end(); ++lib)
  1291. {
  1292. for( LinkLibraryVectorType::iterator lib2 = lib;
  1293. lib2 != this->LinkLibrariesForVS6.end(); ++lib2)
  1294. {
  1295. this->DeleteDependencyForVS6( dep_map, *lib, *lib2);
  1296. }
  1297. }
  1298. // 3. Create the new link line by simply emitting any dependencies that are
  1299. // missing. Start from the back and keep adding.
  1300. //
  1301. std::set<DependencyMap::key_type> done, visited;
  1302. std::vector<DependencyMap::key_type> newLinkLibrariesForVS6;
  1303. for(LinkLibraryVectorType::reverse_iterator lib =
  1304. this->LinkLibrariesForVS6.rbegin();
  1305. lib != this->LinkLibrariesForVS6.rend(); ++lib)
  1306. {
  1307. // skip zero size library entries, this may happen
  1308. // if a variable expands to nothing.
  1309. if (!lib->first.empty())
  1310. {
  1311. this->EmitForVS6( *lib, dep_map, done, visited, newLinkLibrariesForVS6 );
  1312. }
  1313. }
  1314. // 4. Add the new libraries to the link line.
  1315. //
  1316. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  1317. newLinkLibrariesForVS6.rbegin();
  1318. k != newLinkLibrariesForVS6.rend(); ++k )
  1319. {
  1320. // get the llt from the dep_map
  1321. this->LinkLibrariesForVS6.push_back( std::make_pair(k->first,k->second) );
  1322. }
  1323. this->LinkLibrariesForVS6Analyzed = true;
  1324. }
  1325. //----------------------------------------------------------------------------
  1326. void cmTarget::InsertDependencyForVS6( DependencyMap& depMap,
  1327. const LibraryID& lib,
  1328. const LibraryID& dep)
  1329. {
  1330. depMap[lib].push_back(dep);
  1331. }
  1332. //----------------------------------------------------------------------------
  1333. void cmTarget::DeleteDependencyForVS6( DependencyMap& depMap,
  1334. const LibraryID& lib,
  1335. const LibraryID& dep)
  1336. {
  1337. // Make sure there is an entry in the map for lib. If so, delete all
  1338. // dependencies to dep. There may be repeated entries because of
  1339. // external libraries that are specified multiple times.
  1340. DependencyMap::iterator map_itr = depMap.find( lib );
  1341. if( map_itr != depMap.end() )
  1342. {
  1343. DependencyList& depList = map_itr->second;
  1344. DependencyList::iterator begin =
  1345. std::remove(depList.begin(), depList.end(), dep);
  1346. depList.erase(begin, depList.end());
  1347. }
  1348. }
  1349. //----------------------------------------------------------------------------
  1350. void cmTarget::EmitForVS6(const LibraryID lib,
  1351. const DependencyMap& dep_map,
  1352. std::set<LibraryID>& emitted,
  1353. std::set<LibraryID>& visited,
  1354. DependencyList& link_line )
  1355. {
  1356. // It's already been emitted
  1357. if( emitted.find(lib) != emitted.end() )
  1358. {
  1359. return;
  1360. }
  1361. // Emit the dependencies only if this library node hasn't been
  1362. // visited before. If it has, then we have a cycle. The recursion
  1363. // that got us here should take care of everything.
  1364. if( visited.insert(lib).second )
  1365. {
  1366. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  1367. {
  1368. const DependencyList& dep_on = dep_map.find( lib )->second;
  1369. DependencyList::const_reverse_iterator i;
  1370. // To cater for recursive external libraries, we must emit
  1371. // duplicates on this link line *unless* they were emitted by
  1372. // some other node, in which case we assume that the recursion
  1373. // was resolved then. We making the simplifying assumption that
  1374. // any duplicates on a single link line are on purpose, and must
  1375. // be preserved.
  1376. // This variable will keep track of the libraries that were
  1377. // emitted directly from the current node, and not from a
  1378. // recursive call. This way, if we come across a library that
  1379. // has already been emitted, we repeat it iff it has been
  1380. // emitted here.
  1381. std::set<DependencyMap::key_type> emitted_here;
  1382. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  1383. {
  1384. if( emitted_here.find(*i) != emitted_here.end() )
  1385. {
  1386. // a repeat. Must emit.
  1387. emitted.insert(*i);
  1388. link_line.push_back( *i );
  1389. }
  1390. else
  1391. {
  1392. // Emit only if no-one else has
  1393. if( emitted.find(*i) == emitted.end() )
  1394. {
  1395. // emit dependencies
  1396. this->EmitForVS6( *i, dep_map, emitted, visited, link_line );
  1397. // emit self
  1398. emitted.insert(*i);
  1399. emitted_here.insert(*i);
  1400. link_line.push_back( *i );
  1401. }
  1402. }
  1403. }
  1404. }
  1405. }
  1406. }
  1407. //----------------------------------------------------------------------------
  1408. void cmTarget::GatherDependenciesForVS6( const cmMakefile& mf,
  1409. const LibraryID& lib,
  1410. DependencyMap& dep_map)
  1411. {
  1412. // If the library is already in the dependency map, then it has
  1413. // already been fully processed.
  1414. if( dep_map.find(lib) != dep_map.end() )
  1415. {
  1416. return;
  1417. }
  1418. const char* deps = mf.GetDefinition( lib.first+"_LIB_DEPENDS" );
  1419. if( deps && strcmp(deps,"") != 0 )
  1420. {
  1421. // Make sure this library is in the map, even if it has an empty
  1422. // set of dependencies. This distinguishes the case of explicitly
  1423. // no dependencies with that of unspecified dependencies.
  1424. dep_map[lib];
  1425. // Parse the dependency information, which is a set of
  1426. // type, library pairs separated by ";". There is always a trailing ";".
  1427. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  1428. std::string depline = deps;
  1429. std::string::size_type start = 0;
  1430. std::string::size_type end;
  1431. end = depline.find( ";", start );
  1432. while( end != std::string::npos )
  1433. {
  1434. std::string l = depline.substr( start, end-start );
  1435. if(!l.empty())
  1436. {
  1437. if (l == "debug")
  1438. {
  1439. llt = cmTarget::DEBUG;
  1440. }
  1441. else if (l == "optimized")
  1442. {
  1443. llt = cmTarget::OPTIMIZED;
  1444. }
  1445. else if (l == "general")
  1446. {
  1447. llt = cmTarget::GENERAL;
  1448. }
  1449. else
  1450. {
  1451. LibraryID lib2(l,llt);
  1452. this->InsertDependencyForVS6( dep_map, lib, lib2);
  1453. this->GatherDependenciesForVS6( mf, lib2, dep_map);
  1454. llt = cmTarget::GENERAL;
  1455. }
  1456. }
  1457. start = end+1; // skip the ;
  1458. end = depline.find( ";", start );
  1459. }
  1460. // cannot depend on itself
  1461. this->DeleteDependencyForVS6( dep_map, lib, lib);
  1462. }
  1463. }
  1464. #endif
  1465. //----------------------------------------------------------------------------
  1466. static bool whiteListedInterfaceProperty(const std::string& prop)
  1467. {
  1468. if(cmHasLiteralPrefix(prop, "INTERFACE_"))
  1469. {
  1470. return true;
  1471. }
  1472. static UNORDERED_SET<std::string> builtIns;
  1473. if (builtIns.empty())
  1474. {
  1475. builtIns.insert("COMPATIBLE_INTERFACE_BOOL");
  1476. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");
  1477. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MIN");
  1478. builtIns.insert("COMPATIBLE_INTERFACE_STRING");
  1479. builtIns.insert("EXPORT_NAME");
  1480. builtIns.insert("IMPORTED");
  1481. builtIns.insert("NAME");
  1482. builtIns.insert("TYPE");
  1483. }
  1484. if (builtIns.count(prop))
  1485. {
  1486. return true;
  1487. }
  1488. if (cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_"))
  1489. {
  1490. return true;
  1491. }
  1492. return false;
  1493. }
  1494. //----------------------------------------------------------------------------
  1495. void cmTarget::SetProperty(const std::string& prop, const char* value)
  1496. {
  1497. if (this->GetType() == INTERFACE_LIBRARY
  1498. && !whiteListedInterfaceProperty(prop))
  1499. {
  1500. std::ostringstream e;
  1501. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1502. "The property \"" << prop << "\" is not allowed.";
  1503. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1504. return;
  1505. }
  1506. else if (prop == "NAME")
  1507. {
  1508. std::ostringstream e;
  1509. e << "NAME property is read-only\n";
  1510. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1511. return;
  1512. }
  1513. else if(prop == "INCLUDE_DIRECTORIES")
  1514. {
  1515. this->Internal->IncludeDirectoriesEntries.clear();
  1516. this->Internal->IncludeDirectoriesBacktraces.clear();
  1517. this->Internal->IncludeDirectoriesEntries.push_back(value);
  1518. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1519. this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
  1520. }
  1521. else if(prop == "COMPILE_OPTIONS")
  1522. {
  1523. this->Internal->CompileOptionsEntries.clear();
  1524. this->Internal->CompileOptionsBacktraces.clear();
  1525. this->Internal->CompileOptionsEntries.push_back(value);
  1526. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1527. this->Internal->CompileOptionsBacktraces.push_back(lfbt);
  1528. }
  1529. else if(prop == "COMPILE_FEATURES")
  1530. {
  1531. this->Internal->CompileFeaturesEntries.clear();
  1532. this->Internal->CompileFeaturesBacktraces.clear();
  1533. this->Internal->CompileFeaturesEntries.push_back(value);
  1534. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1535. this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
  1536. }
  1537. else if(prop == "COMPILE_DEFINITIONS")
  1538. {
  1539. this->Internal->CompileDefinitionsEntries.clear();
  1540. this->Internal->CompileDefinitionsBacktraces.clear();
  1541. this->Internal->CompileDefinitionsEntries.push_back(value);
  1542. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1543. this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
  1544. }
  1545. else if(prop == "EXPORT_NAME" && this->IsImported())
  1546. {
  1547. std::ostringstream e;
  1548. e << "EXPORT_NAME property can't be set on imported targets (\""
  1549. << this->Name << "\")\n";
  1550. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1551. }
  1552. else if (prop == "LINK_LIBRARIES")
  1553. {
  1554. this->Internal->LinkImplementationPropertyEntries.clear();
  1555. if (value)
  1556. {
  1557. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1558. cmValueWithOrigin entry(value, lfbt);
  1559. this->Internal->LinkImplementationPropertyEntries.push_back(entry);
  1560. }
  1561. }
  1562. else if (prop == "SOURCES")
  1563. {
  1564. if(this->IsImported())
  1565. {
  1566. std::ostringstream e;
  1567. e << "SOURCES property can't be set on imported targets (\""
  1568. << this->Name << "\")\n";
  1569. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1570. return;
  1571. }
  1572. this->Internal->SourceFilesMap.clear();
  1573. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1574. cmGeneratorExpression ge(lfbt);
  1575. this->Internal->SourceEntries.clear();
  1576. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1577. this->Internal->SourceEntries.push_back(
  1578. new cmTargetInternals::TargetPropertyEntry(cge));
  1579. }
  1580. else
  1581. {
  1582. this->Properties.SetProperty(prop, value);
  1583. this->MaybeInvalidatePropertyCache(prop);
  1584. }
  1585. }
  1586. //----------------------------------------------------------------------------
  1587. void cmTarget::AppendProperty(const std::string& prop, const char* value,
  1588. bool asString)
  1589. {
  1590. if (this->GetType() == INTERFACE_LIBRARY
  1591. && !whiteListedInterfaceProperty(prop))
  1592. {
  1593. std::ostringstream e;
  1594. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1595. "The property \"" << prop << "\" is not allowed.";
  1596. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1597. return;
  1598. }
  1599. else if (prop == "NAME")
  1600. {
  1601. std::ostringstream e;
  1602. e << "NAME property is read-only\n";
  1603. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1604. return;
  1605. }
  1606. else if(prop == "INCLUDE_DIRECTORIES")
  1607. {
  1608. this->Internal->IncludeDirectoriesEntries.push_back(value);
  1609. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1610. this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
  1611. }
  1612. else if(prop == "COMPILE_OPTIONS")
  1613. {
  1614. this->Internal->CompileOptionsEntries.push_back(value);
  1615. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1616. this->Internal->CompileOptionsBacktraces.push_back(lfbt);
  1617. }
  1618. else if(prop == "COMPILE_FEATURES")
  1619. {
  1620. this->Internal->CompileFeaturesEntries.push_back(value);
  1621. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1622. this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
  1623. }
  1624. else if(prop == "COMPILE_DEFINITIONS")
  1625. {
  1626. this->Internal->CompileDefinitionsEntries.push_back(value);
  1627. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1628. this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
  1629. }
  1630. else if(prop == "EXPORT_NAME" && this->IsImported())
  1631. {
  1632. std::ostringstream e;
  1633. e << "EXPORT_NAME property can't be set on imported targets (\""
  1634. << this->Name << "\")\n";
  1635. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1636. }
  1637. else if (prop == "LINK_LIBRARIES")
  1638. {
  1639. if (value)
  1640. {
  1641. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1642. cmValueWithOrigin entry(value, lfbt);
  1643. this->Internal->LinkImplementationPropertyEntries.push_back(entry);
  1644. }
  1645. }
  1646. else if (prop == "SOURCES")
  1647. {
  1648. if(this->IsImported())
  1649. {
  1650. std::ostringstream e;
  1651. e << "SOURCES property can't be set on imported targets (\""
  1652. << this->Name << "\")\n";
  1653. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1654. return;
  1655. }
  1656. this->Internal->SourceFilesMap.clear();
  1657. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1658. cmGeneratorExpression ge(lfbt);
  1659. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1660. this->Internal->SourceEntries.push_back(
  1661. new cmTargetInternals::TargetPropertyEntry(cge));
  1662. }
  1663. else
  1664. {
  1665. this->Properties.AppendProperty(prop, value, asString);
  1666. this->MaybeInvalidatePropertyCache(prop);
  1667. }
  1668. }
  1669. //----------------------------------------------------------------------------
  1670. std::string cmTarget::GetExportName() const
  1671. {
  1672. const char *exportName = this->GetProperty("EXPORT_NAME");
  1673. if (exportName && *exportName)
  1674. {
  1675. if (!cmGeneratorExpression::IsValidTargetName(exportName))
  1676. {
  1677. std::ostringstream e;
  1678. e << "EXPORT_NAME property \"" << exportName << "\" for \""
  1679. << this->GetName() << "\": is not valid.";
  1680. cmSystemTools::Error(e.str().c_str());
  1681. return "";
  1682. }
  1683. return exportName;
  1684. }
  1685. return this->GetName();
  1686. }
  1687. //----------------------------------------------------------------------------
  1688. void cmTarget::AppendBuildInterfaceIncludes()
  1689. {
  1690. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  1691. this->GetType() != cmTarget::STATIC_LIBRARY &&
  1692. this->GetType() != cmTarget::MODULE_LIBRARY &&
  1693. this->GetType() != cmTarget::INTERFACE_LIBRARY &&
  1694. !this->IsExecutableWithExports())
  1695. {
  1696. return;
  1697. }
  1698. if (this->BuildInterfaceIncludesAppended)
  1699. {
  1700. return;
  1701. }
  1702. this->BuildInterfaceIncludesAppended = true;
  1703. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE"))
  1704. {
  1705. const char *binDir = this->Makefile->GetCurrentBinaryDirectory();
  1706. const char *srcDir = this->Makefile->GetCurrentSourceDirectory();
  1707. const std::string dirs = std::string(binDir ? binDir : "")
  1708. + std::string(binDir ? ";" : "")
  1709. + std::string(srcDir ? srcDir : "");
  1710. if (!dirs.empty())
  1711. {
  1712. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  1713. ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
  1714. }
  1715. }
  1716. }
  1717. //----------------------------------------------------------------------------
  1718. void cmTarget::InsertInclude(std::string const& entry,
  1719. cmListFileBacktrace const& bt,
  1720. bool before)
  1721. {
  1722. std::vector<std::string>::iterator position =
  1723. before ? this->Internal->IncludeDirectoriesEntries.begin()
  1724. : this->Internal->IncludeDirectoriesEntries.end();
  1725. std::vector<cmListFileBacktrace>::iterator btPosition =
  1726. before ? this->Internal->IncludeDirectoriesBacktraces.begin()
  1727. : this->Internal->IncludeDirectoriesBacktraces.end();
  1728. this->Internal->IncludeDirectoriesEntries.insert(position, entry);
  1729. this->Internal->IncludeDirectoriesBacktraces.insert(btPosition, bt);
  1730. }
  1731. //----------------------------------------------------------------------------
  1732. void cmTarget::InsertCompileOption(std::string const& entry,
  1733. cmListFileBacktrace const& bt,
  1734. bool before)
  1735. {
  1736. std::vector<std::string>::iterator position =
  1737. before ? this->Internal->CompileOptionsEntries.begin()
  1738. : this->Internal->CompileOptionsEntries.end();
  1739. std::vector<cmListFileBacktrace>::iterator btPosition =
  1740. before ? this->Internal->CompileOptionsBacktraces.begin()
  1741. : this->Internal->CompileOptionsBacktraces.end();
  1742. this->Internal->CompileOptionsEntries.insert(position, entry);
  1743. this->Internal->CompileOptionsBacktraces.insert(btPosition, bt);
  1744. }
  1745. //----------------------------------------------------------------------------
  1746. void cmTarget::InsertCompileDefinition(std::string const& entry,
  1747. cmListFileBacktrace const& bt)
  1748. {
  1749. this->Internal->CompileDefinitionsEntries.push_back(entry);
  1750. this->Internal->CompileDefinitionsBacktraces.push_back(bt);
  1751. }
  1752. //----------------------------------------------------------------------------
  1753. static void processCompileOptionsInternal(cmTarget const* tgt,
  1754. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  1755. std::vector<std::string> &options,
  1756. UNORDERED_SET<std::string> &uniqueOptions,
  1757. cmGeneratorExpressionDAGChecker *dagChecker,
  1758. const std::string& config, bool debugOptions, const char *logName,
  1759. std::string const& language)
  1760. {
  1761. cmMakefile *mf = tgt->GetMakefile();
  1762. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  1763. it = entries.begin(), end = entries.end(); it != end; ++it)
  1764. {
  1765. std::vector<std::string> entryOptions;
  1766. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  1767. config,
  1768. false,
  1769. tgt,
  1770. dagChecker,
  1771. language),
  1772. entryOptions);
  1773. std::string usedOptions;
  1774. for(std::vector<std::string>::iterator
  1775. li = entryOptions.begin(); li != entryOptions.end(); ++li)
  1776. {
  1777. std::string const& opt = *li;
  1778. if(uniqueOptions.insert(opt).second)
  1779. {
  1780. options.push_back(opt);
  1781. if (debugOptions)
  1782. {
  1783. usedOptions += " * " + opt + "\n";
  1784. }
  1785. }
  1786. }
  1787. if (!usedOptions.empty())
  1788. {
  1789. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  1790. std::string("Used compile ") + logName
  1791. + std::string(" for target ")
  1792. + tgt->GetName() + ":\n"
  1793. + usedOptions, (*it)->ge->GetBacktrace());
  1794. }
  1795. }
  1796. }
  1797. //----------------------------------------------------------------------------
  1798. static void processCompileDefinitions(cmTarget const* tgt,
  1799. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  1800. std::vector<std::string> &options,
  1801. UNORDERED_SET<std::string> &uniqueOptions,
  1802. cmGeneratorExpressionDAGChecker *dagChecker,
  1803. const std::string& config, bool debugOptions,
  1804. std::string const& language)
  1805. {
  1806. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  1807. dagChecker, config, debugOptions,
  1808. "definitions", language);
  1809. }
  1810. //----------------------------------------------------------------------------
  1811. void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
  1812. const std::string& config,
  1813. const std::string& language) const
  1814. {
  1815. UNORDERED_SET<std::string> uniqueOptions;
  1816. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  1817. "COMPILE_DEFINITIONS", 0, 0);
  1818. std::vector<std::string> debugProperties;
  1819. const char *debugProp =
  1820. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  1821. if (debugProp)
  1822. {
  1823. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  1824. }
  1825. bool debugDefines = !this->DebugCompileDefinitionsDone
  1826. && std::find(debugProperties.begin(),
  1827. debugProperties.end(),
  1828. "COMPILE_DEFINITIONS")
  1829. != debugProperties.end();
  1830. if (this->Makefile->IsConfigured())
  1831. {
  1832. this->DebugCompileDefinitionsDone = true;
  1833. }
  1834. processCompileDefinitions(this,
  1835. this->Internal->CompileDefinitionsItems,
  1836. list,
  1837. uniqueOptions,
  1838. &dagChecker,
  1839. config,
  1840. debugDefines,
  1841. language);
  1842. std::vector<cmTargetInternals::TargetPropertyEntry*>
  1843. linkInterfaceCompileDefinitionsEntries;
  1844. this->Internal->AddInterfaceEntries(
  1845. this, config, "INTERFACE_COMPILE_DEFINITIONS",
  1846. linkInterfaceCompileDefinitionsEntries);
  1847. if (!config.empty())
  1848. {
  1849. std::string configPropName = "COMPILE_DEFINITIONS_"
  1850. + cmSystemTools::UpperCase(config);
  1851. const char *configProp = this->GetProperty(configPropName);
  1852. if (configProp)
  1853. {
  1854. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
  1855. {
  1856. case cmPolicies::WARN:
  1857. {
  1858. std::ostringstream e;
  1859. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
  1860. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
  1861. e.str());
  1862. }
  1863. case cmPolicies::OLD:
  1864. {
  1865. cmGeneratorExpression ge;
  1866. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1867. ge.Parse(configProp);
  1868. linkInterfaceCompileDefinitionsEntries
  1869. .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
  1870. }
  1871. break;
  1872. case cmPolicies::NEW:
  1873. case cmPolicies::REQUIRED_ALWAYS:
  1874. case cmPolicies::REQUIRED_IF_USED:
  1875. break;
  1876. }
  1877. }
  1878. }
  1879. processCompileDefinitions(this,
  1880. linkInterfaceCompileDefinitionsEntries,
  1881. list,
  1882. uniqueOptions,
  1883. &dagChecker,
  1884. config,
  1885. debugDefines,
  1886. language);
  1887. cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
  1888. }
  1889. //----------------------------------------------------------------------------
  1890. static void processCompileFeatures(cmTarget const* tgt,
  1891. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  1892. std::vector<std::string> &options,
  1893. UNORDERED_SET<std::string> &uniqueOptions,
  1894. cmGeneratorExpressionDAGChecker *dagChecker,
  1895. const std::string& config, bool debugOptions)
  1896. {
  1897. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  1898. dagChecker, config, debugOptions, "features",
  1899. std::string());
  1900. }
  1901. //----------------------------------------------------------------------------
  1902. void cmTarget::GetCompileFeatures(std::vector<std::string> &result,
  1903. const std::string& config) const
  1904. {
  1905. UNORDERED_SET<std::string> uniqueFeatures;
  1906. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  1907. "COMPILE_FEATURES",
  1908. 0, 0);
  1909. std::vector<std::string> debugProperties;
  1910. const char *debugProp =
  1911. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  1912. if (debugProp)
  1913. {
  1914. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  1915. }
  1916. bool debugFeatures = !this->DebugCompileFeaturesDone
  1917. && std::find(debugProperties.begin(),
  1918. debugProperties.end(),
  1919. "COMPILE_FEATURES")
  1920. != debugProperties.end();
  1921. if (this->Makefile->IsConfigured())
  1922. {
  1923. this->DebugCompileFeaturesDone = true;
  1924. }
  1925. processCompileFeatures(this,
  1926. this->Internal->CompileFeaturesItems,
  1927. result,
  1928. uniqueFeatures,
  1929. &dagChecker,
  1930. config,
  1931. debugFeatures);
  1932. std::vector<cmTargetInternals::TargetPropertyEntry*>
  1933. linkInterfaceCompileFeaturesEntries;
  1934. this->Internal->AddInterfaceEntries(
  1935. this, config, "INTERFACE_COMPILE_FEATURES",
  1936. linkInterfaceCompileFeaturesEntries);
  1937. processCompileFeatures(this,
  1938. linkInterfaceCompileFeaturesEntries,
  1939. result,
  1940. uniqueFeatures,
  1941. &dagChecker,
  1942. config,
  1943. debugFeatures);
  1944. cmDeleteAll(linkInterfaceCompileFeaturesEntries);
  1945. }
  1946. //----------------------------------------------------------------------------
  1947. void cmTarget::MaybeInvalidatePropertyCache(const std::string& prop)
  1948. {
  1949. // Wipe out maps caching information affected by this property.
  1950. if(this->IsImported() && cmHasLiteralPrefix(prop, "IMPORTED"))
  1951. {
  1952. this->Internal->ImportInfoMap.clear();
  1953. }
  1954. if(!this->IsImported() && cmHasLiteralPrefix(prop, "LINK_INTERFACE_"))
  1955. {
  1956. this->ClearLinkMaps();
  1957. }
  1958. }
  1959. //----------------------------------------------------------------------------
  1960. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
  1961. const std::string& prop, const char* value, cmMakefile* context,
  1962. bool imported)
  1963. {
  1964. // Look for link-type keywords in the value.
  1965. static cmsys::RegularExpression
  1966. keys("(^|;)(debug|optimized|general)(;|$)");
  1967. if(!keys.find(value))
  1968. {
  1969. return;
  1970. }
  1971. // Support imported and non-imported versions of the property.
  1972. const char* base = (imported?
  1973. "IMPORTED_LINK_INTERFACE_LIBRARIES" :
  1974. "LINK_INTERFACE_LIBRARIES");
  1975. // Report an error.
  1976. std::ostringstream e;
  1977. e << "Property " << prop << " may not contain link-type keyword \""
  1978. << keys.match(2) << "\". "
  1979. << "The " << base << " property has a per-configuration "
  1980. << "version called " << base << "_<CONFIG> which may be "
  1981. << "used to specify per-configuration rules.";
  1982. if(!imported)
  1983. {
  1984. e << " "
  1985. << "Alternatively, an IMPORTED library may be created, configured "
  1986. << "with a per-configuration location, and then named in the "
  1987. << "property value. "
  1988. << "See the add_library command's IMPORTED mode for details."
  1989. << "\n"
  1990. << "If you have a list of libraries that already contains the "
  1991. << "keyword, use the target_link_libraries command with its "
  1992. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  1993. << "The command automatically recognizes link-type keywords and sets "
  1994. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  1995. << "properties accordingly.";
  1996. }
  1997. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  1998. }
  1999. //----------------------------------------------------------------------------
  2000. static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
  2001. cmMakefile* context)
  2002. {
  2003. // Look for link-type keywords in the value.
  2004. static cmsys::RegularExpression
  2005. keys("(^|;)(debug|optimized|general)(;|$)");
  2006. if(!keys.find(value))
  2007. {
  2008. return;
  2009. }
  2010. // Report an error.
  2011. std::ostringstream e;
  2012. e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
  2013. "keyword \"" << keys.match(2) << "\". The INTERFACE_LINK_LIBRARIES "
  2014. "property may contain configuration-sensitive generator-expressions "
  2015. "which may be used to specify per-configuration rules.";
  2016. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2017. }
  2018. //----------------------------------------------------------------------------
  2019. void cmTarget::CheckProperty(const std::string& prop,
  2020. cmMakefile* context) const
  2021. {
  2022. // Certain properties need checking.
  2023. if(cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES"))
  2024. {
  2025. if(const char* value = this->GetProperty(prop))
  2026. {
  2027. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  2028. }
  2029. }
  2030. if(cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES"))
  2031. {
  2032. if(const char* value = this->GetProperty(prop))
  2033. {
  2034. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  2035. }
  2036. }
  2037. if(cmHasLiteralPrefix(prop, "INTERFACE_LINK_LIBRARIES"))
  2038. {
  2039. if(const char* value = this->GetProperty(prop))
  2040. {
  2041. cmTargetCheckINTERFACE_LINK_LIBRARIES(value, context);
  2042. }
  2043. }
  2044. }
  2045. //----------------------------------------------------------------------------
  2046. void cmTarget::MarkAsImported()
  2047. {
  2048. this->IsImportedTarget = true;
  2049. }
  2050. //----------------------------------------------------------------------------
  2051. bool cmTarget::HaveWellDefinedOutputFiles() const
  2052. {
  2053. return
  2054. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2055. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2056. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2057. this->GetType() == cmTarget::EXECUTABLE;
  2058. }
  2059. //----------------------------------------------------------------------------
  2060. cmTarget::OutputInfo const* cmTarget::GetOutputInfo(
  2061. const std::string& config) const
  2062. {
  2063. // There is no output information for imported targets.
  2064. if(this->IsImported())
  2065. {
  2066. return 0;
  2067. }
  2068. // Only libraries and executables have well-defined output files.
  2069. if(!this->HaveWellDefinedOutputFiles())
  2070. {
  2071. std::string msg = "cmTarget::GetOutputInfo called for ";
  2072. msg += this->GetName();
  2073. msg += " which has type ";
  2074. msg += cmTarget::GetTargetTypeName(this->GetType());
  2075. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2076. return 0;
  2077. }
  2078. // Lookup/compute/cache the output information for this configuration.
  2079. std::string config_upper;
  2080. if(!config.empty())
  2081. {
  2082. config_upper = cmSystemTools::UpperCase(config);
  2083. }
  2084. typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
  2085. OutputInfoMapType::iterator i =
  2086. this->Internal->OutputInfoMap.find(config_upper);
  2087. if(i == this->Internal->OutputInfoMap.end())
  2088. {
  2089. // Add empty info in map to detect potential recursion.
  2090. OutputInfo info;
  2091. OutputInfoMapType::value_type entry(config_upper, info);
  2092. i = this->Internal->OutputInfoMap.insert(entry).first;
  2093. // Compute output directories.
  2094. this->ComputeOutputDir(config, false, info.OutDir);
  2095. this->ComputeOutputDir(config, true, info.ImpDir);
  2096. if(!this->ComputePDBOutputDir("PDB", config, info.PdbDir))
  2097. {
  2098. info.PdbDir = info.OutDir;
  2099. }
  2100. // Now update the previously-prepared map entry.
  2101. i->second = info;
  2102. }
  2103. else if(i->second.empty())
  2104. {
  2105. // An empty map entry indicates we have been called recursively
  2106. // from the above block.
  2107. this->Makefile->GetCMakeInstance()->IssueMessage(
  2108. cmake::FATAL_ERROR,
  2109. "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.",
  2110. this->GetBacktrace());
  2111. return 0;
  2112. }
  2113. return &i->second;
  2114. }
  2115. //----------------------------------------------------------------------------
  2116. std::string cmTarget::GetDirectory(const std::string& config,
  2117. bool implib) const
  2118. {
  2119. if (this->IsImported())
  2120. {
  2121. // Return the directory from which the target is imported.
  2122. return
  2123. cmSystemTools::GetFilenamePath(
  2124. this->ImportedGetFullPath(config, implib));
  2125. }
  2126. else if(OutputInfo const* info = this->GetOutputInfo(config))
  2127. {
  2128. // Return the directory in which the target will be built.
  2129. return implib? info->ImpDir : info->OutDir;
  2130. }
  2131. return "";
  2132. }
  2133. //----------------------------------------------------------------------------
  2134. std::string cmTarget::GetPDBDirectory(const std::string& config) const
  2135. {
  2136. if(OutputInfo const* info = this->GetOutputInfo(config))
  2137. {
  2138. // Return the directory in which the target will be built.
  2139. return info->PdbDir;
  2140. }
  2141. return "";
  2142. }
  2143. //----------------------------------------------------------------------------
  2144. const char* cmTarget::ImportedGetLocation(const std::string& config) const
  2145. {
  2146. static std::string location;
  2147. assert(this->IsImported());
  2148. location = this->ImportedGetFullPath(config, false);
  2149. return location.c_str();
  2150. }
  2151. //----------------------------------------------------------------------------
  2152. void cmTarget::GetTargetVersion(int& major, int& minor) const
  2153. {
  2154. int patch;
  2155. this->GetTargetVersion(false, major, minor, patch);
  2156. }
  2157. //----------------------------------------------------------------------------
  2158. void cmTarget::GetTargetVersion(bool soversion,
  2159. int& major, int& minor, int& patch) const
  2160. {
  2161. // Set the default values.
  2162. major = 0;
  2163. minor = 0;
  2164. patch = 0;
  2165. assert(this->GetType() != INTERFACE_LIBRARY);
  2166. // Look for a VERSION or SOVERSION property.
  2167. const char* prop = soversion? "SOVERSION" : "VERSION";
  2168. if(const char* version = this->GetProperty(prop))
  2169. {
  2170. // Try to parse the version number and store the results that were
  2171. // successfully parsed.
  2172. int parsed_major;
  2173. int parsed_minor;
  2174. int parsed_patch;
  2175. switch(sscanf(version, "%d.%d.%d",
  2176. &parsed_major, &parsed_minor, &parsed_patch))
  2177. {
  2178. case 3: patch = parsed_patch; // no break!
  2179. case 2: minor = parsed_minor; // no break!
  2180. case 1: major = parsed_major; // no break!
  2181. default: break;
  2182. }
  2183. }
  2184. }
  2185. //----------------------------------------------------------------------------
  2186. bool cmTarget::HandleLocationPropertyPolicy(cmMakefile* context) const
  2187. {
  2188. if (this->IsImported())
  2189. {
  2190. return true;
  2191. }
  2192. std::ostringstream e;
  2193. const char *modal = 0;
  2194. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  2195. switch (context->GetPolicyStatus(cmPolicies::CMP0026))
  2196. {
  2197. case cmPolicies::WARN:
  2198. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0026) << "\n";
  2199. modal = "should";
  2200. case cmPolicies::OLD:
  2201. break;
  2202. case cmPolicies::REQUIRED_ALWAYS:
  2203. case cmPolicies::REQUIRED_IF_USED:
  2204. case cmPolicies::NEW:
  2205. modal = "may";
  2206. messageType = cmake::FATAL_ERROR;
  2207. }
  2208. if (modal)
  2209. {
  2210. e << "The LOCATION property " << modal << " not be read from target \""
  2211. << this->GetName() << "\". Use the target name directly with "
  2212. "add_custom_command, or use the generator expression $<TARGET_FILE>, "
  2213. "as appropriate.\n";
  2214. context->IssueMessage(messageType, e.str());
  2215. }
  2216. return messageType != cmake::FATAL_ERROR;
  2217. }
  2218. //----------------------------------------------------------------------------
  2219. const char *cmTarget::GetProperty(const std::string& prop) const
  2220. {
  2221. return this->GetProperty(prop, this->Makefile);
  2222. }
  2223. //----------------------------------------------------------------------------
  2224. const char *cmTarget::GetProperty(const std::string& prop,
  2225. cmMakefile* context) const
  2226. {
  2227. if (this->GetType() == INTERFACE_LIBRARY
  2228. && !whiteListedInterfaceProperty(prop))
  2229. {
  2230. std::ostringstream e;
  2231. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  2232. "The property \"" << prop << "\" is not allowed.";
  2233. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2234. return 0;
  2235. }
  2236. // Watch for special "computed" properties that are dependent on
  2237. // other properties or variables. Always recompute them.
  2238. if(this->GetType() == cmTarget::EXECUTABLE ||
  2239. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2240. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2241. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2242. this->GetType() == cmTarget::UNKNOWN_LIBRARY)
  2243. {
  2244. static const std::string propLOCATION = "LOCATION";
  2245. if(prop == propLOCATION)
  2246. {
  2247. if (!this->HandleLocationPropertyPolicy(context))
  2248. {
  2249. return 0;
  2250. }
  2251. // Set the LOCATION property of the target.
  2252. //
  2253. // For an imported target this is the location of an arbitrary
  2254. // available configuration.
  2255. //
  2256. if(this->IsImported())
  2257. {
  2258. this->Properties.SetProperty(
  2259. propLOCATION, this->ImportedGetFullPath("", false).c_str());
  2260. }
  2261. else
  2262. {
  2263. // For a non-imported target this is deprecated because it
  2264. // cannot take into account the per-configuration name of the
  2265. // target because the configuration type may not be known at
  2266. // CMake time.
  2267. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  2268. gg->CreateGenerationObjects();
  2269. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  2270. this->Properties.SetProperty(propLOCATION,
  2271. gt->GetLocationForBuild());
  2272. }
  2273. }
  2274. // Support "LOCATION_<CONFIG>".
  2275. else if(cmHasLiteralPrefix(prop, "LOCATION_"))
  2276. {
  2277. if (!this->HandleLocationPropertyPolicy(context))
  2278. {
  2279. return 0;
  2280. }
  2281. const char* configName = prop.c_str() + 9;
  2282. if (this->IsImported())
  2283. {
  2284. this->Properties.SetProperty(
  2285. prop, this->ImportedGetFullPath(configName, false).c_str());
  2286. }
  2287. else
  2288. {
  2289. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  2290. gg->CreateGenerationObjects();
  2291. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  2292. this->Properties.SetProperty(
  2293. prop, gt->GetFullPath(configName, false).c_str());
  2294. }
  2295. }
  2296. // Support "<CONFIG>_LOCATION".
  2297. else if(cmHasLiteralSuffix(prop, "_LOCATION"))
  2298. {
  2299. std::string configName(prop.c_str(), prop.size() - 9);
  2300. if(configName != "IMPORTED")
  2301. {
  2302. if (!this->HandleLocationPropertyPolicy(context))
  2303. {
  2304. return 0;
  2305. }
  2306. if (this->IsImported())
  2307. {
  2308. this->Properties.SetProperty(
  2309. prop, this->ImportedGetFullPath(configName, false).c_str());
  2310. }
  2311. else
  2312. {
  2313. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  2314. gg->CreateGenerationObjects();
  2315. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  2316. this->Properties.SetProperty(
  2317. prop, gt->GetFullPath(configName, false).c_str());
  2318. }
  2319. }
  2320. }
  2321. }
  2322. static UNORDERED_SET<std::string> specialProps;
  2323. #define MAKE_STATIC_PROP(PROP) \
  2324. static const std::string prop##PROP = #PROP
  2325. MAKE_STATIC_PROP(LINK_LIBRARIES);
  2326. MAKE_STATIC_PROP(TYPE);
  2327. MAKE_STATIC_PROP(INCLUDE_DIRECTORIES);
  2328. MAKE_STATIC_PROP(COMPILE_FEATURES);
  2329. MAKE_STATIC_PROP(COMPILE_OPTIONS);
  2330. MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
  2331. MAKE_STATIC_PROP(IMPORTED);
  2332. MAKE_STATIC_PROP(NAME);
  2333. MAKE_STATIC_PROP(BINARY_DIR);
  2334. MAKE_STATIC_PROP(SOURCE_DIR);
  2335. MAKE_STATIC_PROP(SOURCES);
  2336. #undef MAKE_STATIC_PROP
  2337. if(specialProps.empty())
  2338. {
  2339. specialProps.insert(propLINK_LIBRARIES);
  2340. specialProps.insert(propTYPE);
  2341. specialProps.insert(propINCLUDE_DIRECTORIES);
  2342. specialProps.insert(propCOMPILE_FEATURES);
  2343. specialProps.insert(propCOMPILE_OPTIONS);
  2344. specialProps.insert(propCOMPILE_DEFINITIONS);
  2345. specialProps.insert(propIMPORTED);
  2346. specialProps.insert(propNAME);
  2347. specialProps.insert(propBINARY_DIR);
  2348. specialProps.insert(propSOURCE_DIR);
  2349. specialProps.insert(propSOURCES);
  2350. }
  2351. if(specialProps.count(prop))
  2352. {
  2353. if(prop == propLINK_LIBRARIES)
  2354. {
  2355. if (this->Internal->LinkImplementationPropertyEntries.empty())
  2356. {
  2357. return 0;
  2358. }
  2359. static std::string output;
  2360. output = "";
  2361. std::string sep;
  2362. for (std::vector<cmValueWithOrigin>::const_iterator
  2363. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  2364. end = this->Internal->LinkImplementationPropertyEntries.end();
  2365. it != end; ++it)
  2366. {
  2367. output += sep;
  2368. output += it->Value;
  2369. sep = ";";
  2370. }
  2371. return output.c_str();
  2372. }
  2373. // the type property returns what type the target is
  2374. else if (prop == propTYPE)
  2375. {
  2376. return cmTarget::GetTargetTypeName(this->GetType());
  2377. }
  2378. else if(prop == propINCLUDE_DIRECTORIES)
  2379. {
  2380. if (this->Internal->IncludeDirectoriesEntries.empty())
  2381. {
  2382. return 0;
  2383. }
  2384. static std::string output;
  2385. output = cmJoin(this->Internal->IncludeDirectoriesEntries, ";");
  2386. return output.c_str();
  2387. }
  2388. else if(prop == propCOMPILE_FEATURES)
  2389. {
  2390. if (this->Internal->CompileFeaturesEntries.empty())
  2391. {
  2392. return 0;
  2393. }
  2394. static std::string output;
  2395. output = cmJoin(this->Internal->CompileFeaturesEntries, ";");
  2396. return output.c_str();
  2397. }
  2398. else if(prop == propCOMPILE_OPTIONS)
  2399. {
  2400. if (this->Internal->CompileOptionsEntries.empty())
  2401. {
  2402. return 0;
  2403. }
  2404. static std::string output;
  2405. output = cmJoin(this->Internal->CompileOptionsEntries, ";");
  2406. return output.c_str();
  2407. }
  2408. else if(prop == propCOMPILE_DEFINITIONS)
  2409. {
  2410. if (this->Internal->CompileDefinitionsEntries.empty())
  2411. {
  2412. return 0;
  2413. }
  2414. static std::string output;
  2415. output = cmJoin(this->Internal->CompileDefinitionsEntries, ";");
  2416. return output.c_str();
  2417. }
  2418. else if (prop == propIMPORTED)
  2419. {
  2420. return this->IsImported()?"TRUE":"FALSE";
  2421. }
  2422. else if (prop == propNAME)
  2423. {
  2424. return this->GetName().c_str();
  2425. }
  2426. else if (prop == propBINARY_DIR)
  2427. {
  2428. return this->GetMakefile()->GetCurrentBinaryDirectory();
  2429. }
  2430. else if (prop == propSOURCE_DIR)
  2431. {
  2432. return this->GetMakefile()->GetCurrentSourceDirectory();
  2433. }
  2434. else if(prop == propSOURCES)
  2435. {
  2436. if (this->Internal->SourceEntries.empty())
  2437. {
  2438. return 0;
  2439. }
  2440. std::ostringstream ss;
  2441. const char* sep = "";
  2442. typedef cmTargetInternals::TargetPropertyEntry
  2443. TargetPropertyEntry;
  2444. for(std::vector<TargetPropertyEntry*>::const_iterator
  2445. i = this->Internal->SourceEntries.begin();
  2446. i != this->Internal->SourceEntries.end(); ++i)
  2447. {
  2448. std::string entry = (*i)->ge->GetInput();
  2449. std::vector<std::string> files;
  2450. cmSystemTools::ExpandListArgument(entry, files);
  2451. for (std::vector<std::string>::const_iterator
  2452. li = files.begin(); li != files.end(); ++li)
  2453. {
  2454. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  2455. (*li)[li->size() - 1] == '>')
  2456. {
  2457. std::string objLibName = li->substr(17, li->size()-18);
  2458. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  2459. {
  2460. ss << sep;
  2461. sep = ";";
  2462. ss << *li;
  2463. continue;
  2464. }
  2465. bool addContent = false;
  2466. bool noMessage = true;
  2467. std::ostringstream e;
  2468. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  2469. switch(context->GetPolicyStatus(cmPolicies::CMP0051))
  2470. {
  2471. case cmPolicies::WARN:
  2472. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
  2473. noMessage = false;
  2474. case cmPolicies::OLD:
  2475. break;
  2476. case cmPolicies::REQUIRED_ALWAYS:
  2477. case cmPolicies::REQUIRED_IF_USED:
  2478. case cmPolicies::NEW:
  2479. addContent = true;
  2480. }
  2481. if (!noMessage)
  2482. {
  2483. e << "Target \"" << this->Name << "\" contains "
  2484. "$<TARGET_OBJECTS> generator expression in its sources list. "
  2485. "This content was not previously part of the SOURCES property "
  2486. "when that property was read at configure time. Code reading "
  2487. "that property needs to be adapted to ignore the generator "
  2488. "expression using the string(GENEX_STRIP) command.";
  2489. context->IssueMessage(messageType, e.str());
  2490. }
  2491. if (addContent)
  2492. {
  2493. ss << sep;
  2494. sep = ";";
  2495. ss << *li;
  2496. }
  2497. }
  2498. else if (cmGeneratorExpression::Find(*li) == std::string::npos)
  2499. {
  2500. ss << sep;
  2501. sep = ";";
  2502. ss << *li;
  2503. }
  2504. else
  2505. {
  2506. cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li);
  2507. // Construct what is known about this source file location.
  2508. cmSourceFileLocation const& location = sf->GetLocation();
  2509. std::string sname = location.GetDirectory();
  2510. if(!sname.empty())
  2511. {
  2512. sname += "/";
  2513. }
  2514. sname += location.GetName();
  2515. ss << sep;
  2516. sep = ";";
  2517. // Append this list entry.
  2518. ss << sname;
  2519. }
  2520. }
  2521. }
  2522. this->Properties.SetProperty("SOURCES", ss.str().c_str());
  2523. }
  2524. }
  2525. const char *retVal = this->Properties.GetPropertyValue(prop);
  2526. if (!retVal)
  2527. {
  2528. const bool chain = this->GetMakefile()->GetState()->
  2529. IsPropertyChained(prop, cmProperty::TARGET);
  2530. if (chain)
  2531. {
  2532. return this->Makefile->GetProperty(prop, chain);
  2533. }
  2534. }
  2535. return retVal;
  2536. }
  2537. //----------------------------------------------------------------------------
  2538. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  2539. {
  2540. return cmSystemTools::IsOn(this->GetProperty(prop));
  2541. }
  2542. //----------------------------------------------------------------------------
  2543. const char* cmTarget::GetSuffixVariableInternal(bool implib) const
  2544. {
  2545. switch(this->GetType())
  2546. {
  2547. case cmTarget::STATIC_LIBRARY:
  2548. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  2549. case cmTarget::SHARED_LIBRARY:
  2550. return (implib
  2551. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2552. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  2553. case cmTarget::MODULE_LIBRARY:
  2554. return (implib
  2555. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2556. : "CMAKE_SHARED_MODULE_SUFFIX");
  2557. case cmTarget::EXECUTABLE:
  2558. return (implib
  2559. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2560. // Android GUI application packages store the native
  2561. // binary as a shared library.
  2562. : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
  2563. "CMAKE_SHARED_LIBRARY_SUFFIX" : "CMAKE_EXECUTABLE_SUFFIX"));
  2564. default:
  2565. break;
  2566. }
  2567. return "";
  2568. }
  2569. //----------------------------------------------------------------------------
  2570. const char* cmTarget::GetPrefixVariableInternal(bool implib) const
  2571. {
  2572. switch(this->GetType())
  2573. {
  2574. case cmTarget::STATIC_LIBRARY:
  2575. return "CMAKE_STATIC_LIBRARY_PREFIX";
  2576. case cmTarget::SHARED_LIBRARY:
  2577. return (implib
  2578. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2579. : "CMAKE_SHARED_LIBRARY_PREFIX");
  2580. case cmTarget::MODULE_LIBRARY:
  2581. return (implib
  2582. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2583. : "CMAKE_SHARED_MODULE_PREFIX");
  2584. case cmTarget::EXECUTABLE:
  2585. return (implib
  2586. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2587. // Android GUI application packages store the native
  2588. // binary as a shared library.
  2589. : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
  2590. "CMAKE_SHARED_LIBRARY_PREFIX" : ""));
  2591. default:
  2592. break;
  2593. }
  2594. return "";
  2595. }
  2596. //----------------------------------------------------------------------------
  2597. bool cmTarget::HasMacOSXRpathInstallNameDir(const std::string& config) const
  2598. {
  2599. bool install_name_is_rpath = false;
  2600. bool macosx_rpath = false;
  2601. if(!this->IsImportedTarget)
  2602. {
  2603. if(this->GetType() != cmTarget::SHARED_LIBRARY)
  2604. {
  2605. return false;
  2606. }
  2607. const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
  2608. bool use_install_name =
  2609. this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  2610. if(install_name && use_install_name &&
  2611. std::string(install_name) == "@rpath")
  2612. {
  2613. install_name_is_rpath = true;
  2614. }
  2615. else if(install_name && use_install_name)
  2616. {
  2617. return false;
  2618. }
  2619. if(!install_name_is_rpath)
  2620. {
  2621. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  2622. }
  2623. }
  2624. else
  2625. {
  2626. // Lookup the imported soname.
  2627. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2628. {
  2629. if(!info->NoSOName && !info->SOName.empty())
  2630. {
  2631. if(info->SOName.find("@rpath/") == 0)
  2632. {
  2633. install_name_is_rpath = true;
  2634. }
  2635. }
  2636. else
  2637. {
  2638. std::string install_name;
  2639. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  2640. if(install_name.find("@rpath") != std::string::npos)
  2641. {
  2642. install_name_is_rpath = true;
  2643. }
  2644. }
  2645. }
  2646. }
  2647. if(!install_name_is_rpath && !macosx_rpath)
  2648. {
  2649. return false;
  2650. }
  2651. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  2652. {
  2653. std::ostringstream w;
  2654. w << "Attempting to use";
  2655. if(macosx_rpath)
  2656. {
  2657. w << " MACOSX_RPATH";
  2658. }
  2659. else
  2660. {
  2661. w << " @rpath";
  2662. }
  2663. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  2664. w << " This could be because you are using a Mac OS X version";
  2665. w << " less than 10.5 or because CMake's platform configuration is";
  2666. w << " corrupt.";
  2667. cmake* cm = this->Makefile->GetCMakeInstance();
  2668. cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
  2669. }
  2670. return true;
  2671. }
  2672. //----------------------------------------------------------------------------
  2673. bool cmTarget::MacOSXRpathInstallNameDirDefault() const
  2674. {
  2675. // we can't do rpaths when unsupported
  2676. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  2677. {
  2678. return false;
  2679. }
  2680. const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  2681. if(macosx_rpath_str)
  2682. {
  2683. return this->GetPropertyAsBool("MACOSX_RPATH");
  2684. }
  2685. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  2686. if(cmp0042 == cmPolicies::WARN)
  2687. {
  2688. this->Makefile->GetGlobalGenerator()->
  2689. AddCMP0042WarnTarget(this->GetName());
  2690. }
  2691. if(cmp0042 == cmPolicies::NEW)
  2692. {
  2693. return true;
  2694. }
  2695. return false;
  2696. }
  2697. //----------------------------------------------------------------------------
  2698. bool cmTarget::IsImportedSharedLibWithoutSOName(
  2699. const std::string& config) const
  2700. {
  2701. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  2702. {
  2703. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2704. {
  2705. return info->NoSOName;
  2706. }
  2707. }
  2708. return false;
  2709. }
  2710. //----------------------------------------------------------------------------
  2711. std::string
  2712. cmTarget::GetFullNameImported(const std::string& config, bool implib) const
  2713. {
  2714. return cmSystemTools::GetFilenameName(
  2715. this->ImportedGetFullPath(config, implib));
  2716. }
  2717. //----------------------------------------------------------------------------
  2718. std::string
  2719. cmTarget::ImportedGetFullPath(const std::string& config, bool implib) const
  2720. {
  2721. std::string result;
  2722. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2723. {
  2724. result = implib? info->ImportLibrary : info->Location;
  2725. }
  2726. if(result.empty())
  2727. {
  2728. result = this->GetName();
  2729. result += "-NOTFOUND";
  2730. }
  2731. return result;
  2732. }
  2733. //----------------------------------------------------------------------------
  2734. void cmTarget::ComputeVersionedName(std::string& vName,
  2735. std::string const& prefix,
  2736. std::string const& base,
  2737. std::string const& suffix,
  2738. std::string const& name,
  2739. const char* version) const
  2740. {
  2741. vName = this->IsApple? (prefix+base) : name;
  2742. if(version)
  2743. {
  2744. vName += ".";
  2745. vName += version;
  2746. }
  2747. vName += this->IsApple? suffix : std::string();
  2748. }
  2749. //----------------------------------------------------------------------------
  2750. bool cmTarget::HasImplibGNUtoMS() const
  2751. {
  2752. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  2753. }
  2754. //----------------------------------------------------------------------------
  2755. bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
  2756. std::string& out, const char* newExt) const
  2757. {
  2758. if(this->HasImplibGNUtoMS() &&
  2759. gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
  2760. {
  2761. out = gnuName.substr(0, gnuName.size()-6);
  2762. out += newExt? newExt : ".lib";
  2763. return true;
  2764. }
  2765. return false;
  2766. }
  2767. //----------------------------------------------------------------------------
  2768. void cmTarget::SetPropertyDefault(const std::string& property,
  2769. const char* default_value)
  2770. {
  2771. // Compute the name of the variable holding the default value.
  2772. std::string var = "CMAKE_";
  2773. var += property;
  2774. if(const char* value = this->Makefile->GetDefinition(var))
  2775. {
  2776. this->SetProperty(property, value);
  2777. }
  2778. else if(default_value)
  2779. {
  2780. this->SetProperty(property, default_value);
  2781. }
  2782. }
  2783. //----------------------------------------------------------------------------
  2784. bool cmTarget::HaveBuildTreeRPATH(const std::string& config) const
  2785. {
  2786. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  2787. {
  2788. return false;
  2789. }
  2790. if(cmLinkImplementationLibraries const* impl =
  2791. this->GetLinkImplementationLibraries(config))
  2792. {
  2793. return !impl->Libraries.empty();
  2794. }
  2795. return false;
  2796. }
  2797. //----------------------------------------------------------------------------
  2798. bool cmTarget::HaveInstallTreeRPATH() const
  2799. {
  2800. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  2801. return (install_rpath && *install_rpath) &&
  2802. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  2803. }
  2804. //----------------------------------------------------------------------------
  2805. const char* cmTarget::GetOutputTargetType(bool implib) const
  2806. {
  2807. switch(this->GetType())
  2808. {
  2809. case cmTarget::SHARED_LIBRARY:
  2810. if(this->DLLPlatform)
  2811. {
  2812. if(implib)
  2813. {
  2814. // A DLL import library is treated as an archive target.
  2815. return "ARCHIVE";
  2816. }
  2817. else
  2818. {
  2819. // A DLL shared library is treated as a runtime target.
  2820. return "RUNTIME";
  2821. }
  2822. }
  2823. else
  2824. {
  2825. // For non-DLL platforms shared libraries are treated as
  2826. // library targets.
  2827. return "LIBRARY";
  2828. }
  2829. case cmTarget::STATIC_LIBRARY:
  2830. // Static libraries are always treated as archive targets.
  2831. return "ARCHIVE";
  2832. case cmTarget::MODULE_LIBRARY:
  2833. if(implib)
  2834. {
  2835. // Module libraries are always treated as library targets.
  2836. return "ARCHIVE";
  2837. }
  2838. else
  2839. {
  2840. // Module import libraries are treated as archive targets.
  2841. return "LIBRARY";
  2842. }
  2843. case cmTarget::EXECUTABLE:
  2844. if(implib)
  2845. {
  2846. // Executable import libraries are treated as archive targets.
  2847. return "ARCHIVE";
  2848. }
  2849. else
  2850. {
  2851. // Executables are always treated as runtime targets.
  2852. return "RUNTIME";
  2853. }
  2854. default:
  2855. break;
  2856. }
  2857. return "";
  2858. }
  2859. //----------------------------------------------------------------------------
  2860. bool cmTarget::ComputeOutputDir(const std::string& config,
  2861. bool implib, std::string& out) const
  2862. {
  2863. bool usesDefaultOutputDir = false;
  2864. std::string conf = config;
  2865. // Look for a target property defining the target output directory
  2866. // based on the target type.
  2867. std::string targetTypeName = this->GetOutputTargetType(implib);
  2868. const char* propertyName = 0;
  2869. std::string propertyNameStr = targetTypeName;
  2870. if(!propertyNameStr.empty())
  2871. {
  2872. propertyNameStr += "_OUTPUT_DIRECTORY";
  2873. propertyName = propertyNameStr.c_str();
  2874. }
  2875. // Check for a per-configuration output directory target property.
  2876. std::string configUpper = cmSystemTools::UpperCase(conf);
  2877. const char* configProp = 0;
  2878. std::string configPropStr = targetTypeName;
  2879. if(!configPropStr.empty())
  2880. {
  2881. configPropStr += "_OUTPUT_DIRECTORY_";
  2882. configPropStr += configUpper;
  2883. configProp = configPropStr.c_str();
  2884. }
  2885. // Select an output directory.
  2886. if(const char* config_outdir = this->GetProperty(configProp))
  2887. {
  2888. // Use the user-specified per-configuration output directory.
  2889. cmGeneratorExpression ge;
  2890. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2891. ge.Parse(config_outdir);
  2892. out = cge->Evaluate(this->Makefile, config);
  2893. // Skip per-configuration subdirectory.
  2894. conf = "";
  2895. }
  2896. else if(const char* outdir = this->GetProperty(propertyName))
  2897. {
  2898. // Use the user-specified output directory.
  2899. cmGeneratorExpression ge;
  2900. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2901. ge.Parse(outdir);
  2902. out = cge->Evaluate(this->Makefile, config);
  2903. // Skip per-configuration subdirectory if the value contained a
  2904. // generator expression.
  2905. if (out != outdir)
  2906. {
  2907. conf = "";
  2908. }
  2909. }
  2910. else if(this->GetType() == cmTarget::EXECUTABLE)
  2911. {
  2912. // Lookup the output path for executables.
  2913. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  2914. }
  2915. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  2916. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2917. this->GetType() == cmTarget::MODULE_LIBRARY)
  2918. {
  2919. // Lookup the output path for libraries.
  2920. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  2921. }
  2922. if(out.empty())
  2923. {
  2924. // Default to the current output directory.
  2925. usesDefaultOutputDir = true;
  2926. out = ".";
  2927. }
  2928. // Convert the output path to a full path in case it is
  2929. // specified as a relative path. Treat a relative path as
  2930. // relative to the current output directory for this makefile.
  2931. out = (cmSystemTools::CollapseFullPath
  2932. (out, this->Makefile->GetCurrentBinaryDirectory()));
  2933. // The generator may add the configuration's subdirectory.
  2934. if(!conf.empty())
  2935. {
  2936. const char *platforms = this->Makefile->GetDefinition(
  2937. "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
  2938. std::string suffix =
  2939. usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
  2940. this->Makefile->GetGlobalGenerator()->
  2941. AppendDirectoryForConfig("/", conf, suffix, out);
  2942. }
  2943. return usesDefaultOutputDir;
  2944. }
  2945. //----------------------------------------------------------------------------
  2946. bool cmTarget::ComputePDBOutputDir(const std::string& kind,
  2947. const std::string& config,
  2948. std::string& out) const
  2949. {
  2950. // Look for a target property defining the target output directory
  2951. // based on the target type.
  2952. const char* propertyName = 0;
  2953. std::string propertyNameStr = kind;
  2954. if(!propertyNameStr.empty())
  2955. {
  2956. propertyNameStr += "_OUTPUT_DIRECTORY";
  2957. propertyName = propertyNameStr.c_str();
  2958. }
  2959. std::string conf = config;
  2960. // Check for a per-configuration output directory target property.
  2961. std::string configUpper = cmSystemTools::UpperCase(conf);
  2962. const char* configProp = 0;
  2963. std::string configPropStr = kind;
  2964. if(!configPropStr.empty())
  2965. {
  2966. configPropStr += "_OUTPUT_DIRECTORY_";
  2967. configPropStr += configUpper;
  2968. configProp = configPropStr.c_str();
  2969. }
  2970. // Select an output directory.
  2971. if(const char* config_outdir = this->GetProperty(configProp))
  2972. {
  2973. // Use the user-specified per-configuration output directory.
  2974. out = config_outdir;
  2975. // Skip per-configuration subdirectory.
  2976. conf = "";
  2977. }
  2978. else if(const char* outdir = this->GetProperty(propertyName))
  2979. {
  2980. // Use the user-specified output directory.
  2981. out = outdir;
  2982. }
  2983. if(out.empty())
  2984. {
  2985. return false;
  2986. }
  2987. // Convert the output path to a full path in case it is
  2988. // specified as a relative path. Treat a relative path as
  2989. // relative to the current output directory for this makefile.
  2990. out = (cmSystemTools::CollapseFullPath
  2991. (out, this->Makefile->GetCurrentBinaryDirectory()));
  2992. // The generator may add the configuration's subdirectory.
  2993. if(!conf.empty())
  2994. {
  2995. this->Makefile->GetGlobalGenerator()->
  2996. AppendDirectoryForConfig("/", conf, "", out);
  2997. }
  2998. return true;
  2999. }
  3000. //----------------------------------------------------------------------------
  3001. bool cmTarget::UsesDefaultOutputDir(const std::string& config,
  3002. bool implib) const
  3003. {
  3004. std::string dir;
  3005. return this->ComputeOutputDir(config, implib, dir);
  3006. }
  3007. //----------------------------------------------------------------------------
  3008. std::string cmTarget::GetFrameworkVersion() const
  3009. {
  3010. assert(this->GetType() != INTERFACE_LIBRARY);
  3011. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  3012. {
  3013. return fversion;
  3014. }
  3015. else if(const char* tversion = this->GetProperty("VERSION"))
  3016. {
  3017. return tversion;
  3018. }
  3019. else
  3020. {
  3021. return "A";
  3022. }
  3023. }
  3024. //----------------------------------------------------------------------------
  3025. const char* cmTarget::GetExportMacro() const
  3026. {
  3027. // Define the symbol for targets that export symbols.
  3028. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3029. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3030. this->IsExecutableWithExports())
  3031. {
  3032. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  3033. {
  3034. this->ExportMacro = custom_export_name;
  3035. }
  3036. else
  3037. {
  3038. std::string in = this->GetName();
  3039. in += "_EXPORTS";
  3040. this->ExportMacro = cmSystemTools::MakeCindentifier(in);
  3041. }
  3042. return this->ExportMacro.c_str();
  3043. }
  3044. else
  3045. {
  3046. return 0;
  3047. }
  3048. }
  3049. //----------------------------------------------------------------------------
  3050. bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p) const
  3051. {
  3052. return this->LinkImplicitNullProperties.find(p)
  3053. != this->LinkImplicitNullProperties.end();
  3054. }
  3055. //----------------------------------------------------------------------------
  3056. void
  3057. cmTarget::GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const
  3058. {
  3059. // At configure-time, this method can be called as part of getting the
  3060. // LOCATION property or to export() a file to be include()d. However
  3061. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  3062. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  3063. // behavior of CMP0024 and CMP0026 only.
  3064. typedef cmTargetInternals::TargetPropertyEntry
  3065. TargetPropertyEntry;
  3066. for(std::vector<TargetPropertyEntry*>::const_iterator
  3067. i = this->Internal->SourceEntries.begin();
  3068. i != this->Internal->SourceEntries.end(); ++i)
  3069. {
  3070. std::string entry = (*i)->ge->GetInput();
  3071. std::vector<std::string> files;
  3072. cmSystemTools::ExpandListArgument(entry, files);
  3073. for (std::vector<std::string>::const_iterator
  3074. li = files.begin(); li != files.end(); ++li)
  3075. {
  3076. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  3077. (*li)[li->size() - 1] == '>')
  3078. {
  3079. std::string objLibName = li->substr(17, li->size()-18);
  3080. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  3081. {
  3082. continue;
  3083. }
  3084. cmTarget *objLib = this->Makefile->FindTargetToUse(objLibName);
  3085. if(objLib)
  3086. {
  3087. objlibs.push_back(objLib);
  3088. }
  3089. }
  3090. }
  3091. }
  3092. }
  3093. //----------------------------------------------------------------------------
  3094. void cmTarget::GetLanguages(std::set<std::string>& languages,
  3095. const std::string& config) const
  3096. {
  3097. std::vector<cmSourceFile*> sourceFiles;
  3098. this->GetSourceFiles(sourceFiles, config);
  3099. for(std::vector<cmSourceFile*>::const_iterator
  3100. i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
  3101. {
  3102. const std::string& lang = (*i)->GetLanguage();
  3103. if(!lang.empty())
  3104. {
  3105. languages.insert(lang);
  3106. }
  3107. }
  3108. std::vector<cmTarget*> objectLibraries;
  3109. std::vector<cmSourceFile const*> externalObjects;
  3110. if (!this->Makefile->IsConfigured())
  3111. {
  3112. this->GetObjectLibrariesCMP0026(objectLibraries);
  3113. }
  3114. else
  3115. {
  3116. cmGeneratorTarget* gt = this->Makefile->GetGlobalGenerator()
  3117. ->GetGeneratorTarget(this);
  3118. gt->GetExternalObjects(externalObjects, config);
  3119. for(std::vector<cmSourceFile const*>::const_iterator
  3120. i = externalObjects.begin(); i != externalObjects.end(); ++i)
  3121. {
  3122. std::string objLib = (*i)->GetObjectLibrary();
  3123. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  3124. {
  3125. objectLibraries.push_back(tgt);
  3126. }
  3127. }
  3128. }
  3129. for(std::vector<cmTarget*>::const_iterator
  3130. i = objectLibraries.begin(); i != objectLibraries.end(); ++i)
  3131. {
  3132. (*i)->GetLanguages(languages, config);
  3133. }
  3134. }
  3135. //----------------------------------------------------------------------------
  3136. cmTarget::ImportInfo const*
  3137. cmTarget::GetImportInfo(const std::string& config) const
  3138. {
  3139. // There is no imported information for non-imported targets.
  3140. if(!this->IsImported())
  3141. {
  3142. return 0;
  3143. }
  3144. // Lookup/compute/cache the import information for this
  3145. // configuration.
  3146. std::string config_upper;
  3147. if(!config.empty())
  3148. {
  3149. config_upper = cmSystemTools::UpperCase(config);
  3150. }
  3151. else
  3152. {
  3153. config_upper = "NOCONFIG";
  3154. }
  3155. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  3156. ImportInfoMapType::const_iterator i =
  3157. this->Internal->ImportInfoMap.find(config_upper);
  3158. if(i == this->Internal->ImportInfoMap.end())
  3159. {
  3160. ImportInfo info;
  3161. this->ComputeImportInfo(config_upper, info);
  3162. ImportInfoMapType::value_type entry(config_upper, info);
  3163. i = this->Internal->ImportInfoMap.insert(entry).first;
  3164. }
  3165. if(this->GetType() == INTERFACE_LIBRARY)
  3166. {
  3167. return &i->second;
  3168. }
  3169. // If the location is empty then the target is not available for
  3170. // this configuration.
  3171. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  3172. {
  3173. return 0;
  3174. }
  3175. // Return the import information.
  3176. return &i->second;
  3177. }
  3178. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  3179. const char** loc,
  3180. const char** imp,
  3181. std::string& suffix) const
  3182. {
  3183. if (this->GetType() == INTERFACE_LIBRARY)
  3184. {
  3185. // This method attempts to find a config-specific LOCATION for the
  3186. // IMPORTED library. In the case of INTERFACE_LIBRARY, there is no
  3187. // LOCATION at all, so leaving *loc and *imp unchanged is the appropriate
  3188. // and valid response.
  3189. return true;
  3190. }
  3191. // Track the configuration-specific property suffix.
  3192. suffix = "_";
  3193. suffix += desired_config;
  3194. std::vector<std::string> mappedConfigs;
  3195. {
  3196. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  3197. mapProp += desired_config;
  3198. if(const char* mapValue = this->GetProperty(mapProp))
  3199. {
  3200. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  3201. }
  3202. }
  3203. // If we needed to find one of the mapped configurations but did not
  3204. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  3205. // library or an executable with exports.
  3206. bool allowImp = this->HasImportLibrary();
  3207. // If a mapping was found, check its configurations.
  3208. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  3209. !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
  3210. {
  3211. // Look for this configuration.
  3212. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  3213. std::string locProp = "IMPORTED_LOCATION_";
  3214. locProp += mcUpper;
  3215. *loc = this->GetProperty(locProp);
  3216. if(allowImp)
  3217. {
  3218. std::string impProp = "IMPORTED_IMPLIB_";
  3219. impProp += mcUpper;
  3220. *imp = this->GetProperty(impProp);
  3221. }
  3222. // If it was found, use it for all properties below.
  3223. if(*loc || *imp)
  3224. {
  3225. suffix = "_";
  3226. suffix += mcUpper;
  3227. }
  3228. }
  3229. // If we needed to find one of the mapped configurations but did not
  3230. // then the target is not found. The project does not want any
  3231. // other configuration.
  3232. if(!mappedConfigs.empty() && !*loc && !*imp)
  3233. {
  3234. return false;
  3235. }
  3236. // If we have not yet found it then there are no mapped
  3237. // configurations. Look for an exact-match.
  3238. if(!*loc && !*imp)
  3239. {
  3240. std::string locProp = "IMPORTED_LOCATION";
  3241. locProp += suffix;
  3242. *loc = this->GetProperty(locProp);
  3243. if(allowImp)
  3244. {
  3245. std::string impProp = "IMPORTED_IMPLIB";
  3246. impProp += suffix;
  3247. *imp = this->GetProperty(impProp);
  3248. }
  3249. }
  3250. // If we have not yet found it then there are no mapped
  3251. // configurations and no exact match.
  3252. if(!*loc && !*imp)
  3253. {
  3254. // The suffix computed above is not useful.
  3255. suffix = "";
  3256. // Look for a configuration-less location. This may be set by
  3257. // manually-written code.
  3258. *loc = this->GetProperty("IMPORTED_LOCATION");
  3259. if(allowImp)
  3260. {
  3261. *imp = this->GetProperty("IMPORTED_IMPLIB");
  3262. }
  3263. }
  3264. // If we have not yet found it then the project is willing to try
  3265. // any available configuration.
  3266. if(!*loc && !*imp)
  3267. {
  3268. std::vector<std::string> availableConfigs;
  3269. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  3270. {
  3271. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  3272. }
  3273. for(std::vector<std::string>::const_iterator
  3274. aci = availableConfigs.begin();
  3275. !*loc && !*imp && aci != availableConfigs.end(); ++aci)
  3276. {
  3277. suffix = "_";
  3278. suffix += cmSystemTools::UpperCase(*aci);
  3279. std::string locProp = "IMPORTED_LOCATION";
  3280. locProp += suffix;
  3281. *loc = this->GetProperty(locProp);
  3282. if(allowImp)
  3283. {
  3284. std::string impProp = "IMPORTED_IMPLIB";
  3285. impProp += suffix;
  3286. *imp = this->GetProperty(impProp);
  3287. }
  3288. }
  3289. }
  3290. // If we have not yet found it then the target is not available.
  3291. if(!*loc && !*imp)
  3292. {
  3293. return false;
  3294. }
  3295. return true;
  3296. }
  3297. //----------------------------------------------------------------------------
  3298. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  3299. ImportInfo& info) const
  3300. {
  3301. // This method finds information about an imported target from its
  3302. // properties. The "IMPORTED_" namespace is reserved for properties
  3303. // defined by the project exporting the target.
  3304. // Initialize members.
  3305. info.NoSOName = false;
  3306. const char* loc = 0;
  3307. const char* imp = 0;
  3308. std::string suffix;
  3309. if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
  3310. {
  3311. return;
  3312. }
  3313. // Get the link interface.
  3314. {
  3315. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  3316. const char *propertyLibs = this->GetProperty(linkProp);
  3317. if (this->GetType() != INTERFACE_LIBRARY)
  3318. {
  3319. if(!propertyLibs)
  3320. {
  3321. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  3322. linkProp += suffix;
  3323. propertyLibs = this->GetProperty(linkProp);
  3324. }
  3325. if(!propertyLibs)
  3326. {
  3327. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  3328. propertyLibs = this->GetProperty(linkProp);
  3329. }
  3330. }
  3331. if(propertyLibs)
  3332. {
  3333. info.LibrariesProp = linkProp;
  3334. info.Libraries = propertyLibs;
  3335. }
  3336. }
  3337. if(this->GetType() == INTERFACE_LIBRARY)
  3338. {
  3339. return;
  3340. }
  3341. // A provided configuration has been chosen. Load the
  3342. // configuration's properties.
  3343. // Get the location.
  3344. if(loc)
  3345. {
  3346. info.Location = loc;
  3347. }
  3348. else
  3349. {
  3350. std::string impProp = "IMPORTED_LOCATION";
  3351. impProp += suffix;
  3352. if(const char* config_location = this->GetProperty(impProp))
  3353. {
  3354. info.Location = config_location;
  3355. }
  3356. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  3357. {
  3358. info.Location = location;
  3359. }
  3360. }
  3361. // Get the soname.
  3362. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3363. {
  3364. std::string soProp = "IMPORTED_SONAME";
  3365. soProp += suffix;
  3366. if(const char* config_soname = this->GetProperty(soProp))
  3367. {
  3368. info.SOName = config_soname;
  3369. }
  3370. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  3371. {
  3372. info.SOName = soname;
  3373. }
  3374. }
  3375. // Get the "no-soname" mark.
  3376. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3377. {
  3378. std::string soProp = "IMPORTED_NO_SONAME";
  3379. soProp += suffix;
  3380. if(const char* config_no_soname = this->GetProperty(soProp))
  3381. {
  3382. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  3383. }
  3384. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  3385. {
  3386. info.NoSOName = cmSystemTools::IsOn(no_soname);
  3387. }
  3388. }
  3389. // Get the import library.
  3390. if(imp)
  3391. {
  3392. info.ImportLibrary = imp;
  3393. }
  3394. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3395. this->IsExecutableWithExports())
  3396. {
  3397. std::string impProp = "IMPORTED_IMPLIB";
  3398. impProp += suffix;
  3399. if(const char* config_implib = this->GetProperty(impProp))
  3400. {
  3401. info.ImportLibrary = config_implib;
  3402. }
  3403. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  3404. {
  3405. info.ImportLibrary = implib;
  3406. }
  3407. }
  3408. // Get the link dependencies.
  3409. {
  3410. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  3411. linkProp += suffix;
  3412. if(const char* config_libs = this->GetProperty(linkProp))
  3413. {
  3414. info.SharedDeps = config_libs;
  3415. }
  3416. else if(const char* libs =
  3417. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  3418. {
  3419. info.SharedDeps = libs;
  3420. }
  3421. }
  3422. // Get the link languages.
  3423. if(this->LinkLanguagePropagatesToDependents())
  3424. {
  3425. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  3426. linkProp += suffix;
  3427. if(const char* config_libs = this->GetProperty(linkProp))
  3428. {
  3429. info.Languages = config_libs;
  3430. }
  3431. else if(const char* libs =
  3432. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  3433. {
  3434. info.Languages = libs;
  3435. }
  3436. }
  3437. // Get the cyclic repetition count.
  3438. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  3439. {
  3440. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  3441. linkProp += suffix;
  3442. if(const char* config_reps = this->GetProperty(linkProp))
  3443. {
  3444. sscanf(config_reps, "%u", &info.Multiplicity);
  3445. }
  3446. else if(const char* reps =
  3447. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  3448. {
  3449. sscanf(reps, "%u", &info.Multiplicity);
  3450. }
  3451. }
  3452. }
  3453. //----------------------------------------------------------------------------
  3454. void cmTargetInternals::AddInterfaceEntries(
  3455. cmTarget const* thisTarget, std::string const& config,
  3456. std::string const& prop, std::vector<TargetPropertyEntry*>& entries)
  3457. {
  3458. if(cmLinkImplementationLibraries const* impl =
  3459. thisTarget->GetLinkImplementationLibraries(config))
  3460. {
  3461. for (std::vector<cmLinkImplItem>::const_iterator
  3462. it = impl->Libraries.begin(), end = impl->Libraries.end();
  3463. it != end; ++it)
  3464. {
  3465. if(it->Target)
  3466. {
  3467. std::string genex =
  3468. "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
  3469. cmGeneratorExpression ge(it->Backtrace);
  3470. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  3471. cge->SetEvaluateForBuildsystem(true);
  3472. entries.push_back(
  3473. new cmTargetInternals::TargetPropertyEntry(cge, *it));
  3474. }
  3475. }
  3476. }
  3477. }
  3478. //----------------------------------------------------------------------------
  3479. cmTarget::LinkImplementation const*
  3480. cmTarget::GetLinkImplementation(const std::string& config) const
  3481. {
  3482. // There is no link implementation for imported targets.
  3483. if(this->IsImported())
  3484. {
  3485. return 0;
  3486. }
  3487. // Populate the link implementation for this configuration.
  3488. std::string CONFIG = cmSystemTools::UpperCase(config);
  3489. cmTargetInternals::OptionalLinkImplementation&
  3490. impl = this->Internal->LinkImplMap[CONFIG][this];
  3491. if(!impl.LibrariesDone)
  3492. {
  3493. impl.LibrariesDone = true;
  3494. this->Internal
  3495. ->ComputeLinkImplementationLibraries(this, config, impl, this);
  3496. }
  3497. if(!impl.LanguagesDone)
  3498. {
  3499. impl.LanguagesDone = true;
  3500. this->Internal->ComputeLinkImplementationLanguages(this, config, impl);
  3501. }
  3502. return &impl;
  3503. }
  3504. //----------------------------------------------------------------------------
  3505. cmLinkImplementationLibraries const*
  3506. cmTarget::GetLinkImplementationLibraries(const std::string& config) const
  3507. {
  3508. return this->GetLinkImplementationLibrariesInternal(config, this);
  3509. }
  3510. //----------------------------------------------------------------------------
  3511. cmLinkImplementationLibraries const*
  3512. cmTarget::GetLinkImplementationLibrariesInternal(const std::string& config,
  3513. cmTarget const* head) const
  3514. {
  3515. // There is no link implementation for imported targets.
  3516. if(this->IsImported())
  3517. {
  3518. return 0;
  3519. }
  3520. // Populate the link implementation libraries for this configuration.
  3521. std::string CONFIG = cmSystemTools::UpperCase(config);
  3522. cmTargetInternals::HeadToLinkImplementationMap& hm =
  3523. this->Internal->LinkImplMap[CONFIG];
  3524. // If the link implementation does not depend on the head target
  3525. // then return the one we computed first.
  3526. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3527. {
  3528. return &hm.begin()->second;
  3529. }
  3530. cmTargetInternals::OptionalLinkImplementation& impl = hm[head];
  3531. if(!impl.LibrariesDone)
  3532. {
  3533. impl.LibrariesDone = true;
  3534. this->Internal
  3535. ->ComputeLinkImplementationLibraries(this, config, impl, head);
  3536. }
  3537. return &impl;
  3538. }
  3539. //----------------------------------------------------------------------------
  3540. void
  3541. cmTargetInternals::ComputeLinkImplementationLibraries(
  3542. cmTarget const* thisTarget,
  3543. const std::string& config,
  3544. OptionalLinkImplementation& impl,
  3545. cmTarget const* head) const
  3546. {
  3547. // Collect libraries directly linked in this configuration.
  3548. for (std::vector<cmValueWithOrigin>::const_iterator
  3549. le = this->LinkImplementationPropertyEntries.begin(),
  3550. end = this->LinkImplementationPropertyEntries.end();
  3551. le != end; ++le)
  3552. {
  3553. std::vector<std::string> llibs;
  3554. cmGeneratorExpressionDAGChecker dagChecker(
  3555. thisTarget->GetName(),
  3556. "LINK_LIBRARIES", 0, 0);
  3557. cmGeneratorExpression ge(le->Backtrace);
  3558. cmsys::auto_ptr<cmCompiledGeneratorExpression> const cge =
  3559. ge.Parse(le->Value);
  3560. std::string const evaluated =
  3561. cge->Evaluate(thisTarget->Makefile, config, false, head, &dagChecker);
  3562. cmSystemTools::ExpandListArgument(evaluated, llibs);
  3563. if(cge->GetHadHeadSensitiveCondition())
  3564. {
  3565. impl.HadHeadSensitiveCondition = true;
  3566. }
  3567. for(std::vector<std::string>::const_iterator li = llibs.begin();
  3568. li != llibs.end(); ++li)
  3569. {
  3570. // Skip entries that resolve to the target itself or are empty.
  3571. std::string name = thisTarget->CheckCMP0004(*li);
  3572. if(name == thisTarget->GetName() || name.empty())
  3573. {
  3574. if(name == thisTarget->GetName())
  3575. {
  3576. bool noMessage = false;
  3577. cmake::MessageType messageType = cmake::FATAL_ERROR;
  3578. std::ostringstream e;
  3579. switch(thisTarget->GetPolicyStatusCMP0038())
  3580. {
  3581. case cmPolicies::WARN:
  3582. {
  3583. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
  3584. messageType = cmake::AUTHOR_WARNING;
  3585. }
  3586. break;
  3587. case cmPolicies::OLD:
  3588. noMessage = true;
  3589. case cmPolicies::REQUIRED_IF_USED:
  3590. case cmPolicies::REQUIRED_ALWAYS:
  3591. case cmPolicies::NEW:
  3592. // Issue the fatal message.
  3593. break;
  3594. }
  3595. if(!noMessage)
  3596. {
  3597. e << "Target \"" << thisTarget->GetName() << "\" links to itself.";
  3598. thisTarget->Makefile->GetCMakeInstance()->IssueMessage(
  3599. messageType, e.str(), thisTarget->GetBacktrace());
  3600. if (messageType == cmake::FATAL_ERROR)
  3601. {
  3602. return;
  3603. }
  3604. }
  3605. }
  3606. continue;
  3607. }
  3608. // The entry is meant for this configuration.
  3609. impl.Libraries.push_back(
  3610. cmLinkImplItem(name, thisTarget->FindTargetToLink(name),
  3611. le->Backtrace, evaluated != le->Value));
  3612. }
  3613. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  3614. for (std::set<std::string>::const_iterator it = seenProps.begin();
  3615. it != seenProps.end(); ++it)
  3616. {
  3617. if (!thisTarget->GetProperty(*it))
  3618. {
  3619. thisTarget->LinkImplicitNullProperties.insert(*it);
  3620. }
  3621. }
  3622. cge->GetMaxLanguageStandard(thisTarget, thisTarget->MaxLanguageStandards);
  3623. }
  3624. cmTarget::LinkLibraryType linkType = thisTarget->ComputeLinkType(config);
  3625. cmTarget::LinkLibraryVectorType const& oldllibs =
  3626. thisTarget->GetOriginalLinkLibraries();
  3627. for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  3628. li != oldllibs.end(); ++li)
  3629. {
  3630. if(li->second != cmTarget::GENERAL && li->second != linkType)
  3631. {
  3632. std::string name = thisTarget->CheckCMP0004(li->first);
  3633. if(name == thisTarget->GetName() || name.empty())
  3634. {
  3635. continue;
  3636. }
  3637. // Support OLD behavior for CMP0003.
  3638. impl.WrongConfigLibraries.push_back(
  3639. cmLinkItem(name, thisTarget->FindTargetToLink(name)));
  3640. }
  3641. }
  3642. }
  3643. //----------------------------------------------------------------------------
  3644. void
  3645. cmTargetInternals::ComputeLinkImplementationLanguages(
  3646. cmTarget const* thisTarget,
  3647. const std::string& config,
  3648. OptionalLinkImplementation& impl) const
  3649. {
  3650. // This target needs runtime libraries for its source languages.
  3651. std::set<std::string> languages;
  3652. // Get languages used in our source files.
  3653. thisTarget->GetLanguages(languages, config);
  3654. // Copy the set of langauges to the link implementation.
  3655. impl.Languages.insert(impl.Languages.begin(),
  3656. languages.begin(), languages.end());
  3657. }
  3658. //----------------------------------------------------------------------------
  3659. cmTarget const* cmTarget::FindTargetToLink(std::string const& name) const
  3660. {
  3661. cmTarget const* tgt = this->Makefile->FindTargetToUse(name);
  3662. // Skip targets that will not really be linked. This is probably a
  3663. // name conflict between an external library and an executable
  3664. // within the project.
  3665. if(tgt && tgt->GetType() == cmTarget::EXECUTABLE &&
  3666. !tgt->IsExecutableWithExports())
  3667. {
  3668. tgt = 0;
  3669. }
  3670. if(tgt && tgt->GetType() == cmTarget::OBJECT_LIBRARY)
  3671. {
  3672. std::ostringstream e;
  3673. e << "Target \"" << this->GetName() << "\" links to "
  3674. "OBJECT library \"" << tgt->GetName() << "\" but this is not "
  3675. "allowed. "
  3676. "One may link only to STATIC or SHARED libraries, or to executables "
  3677. "with the ENABLE_EXPORTS property set.";
  3678. cmake* cm = this->Makefile->GetCMakeInstance();
  3679. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  3680. tgt = 0;
  3681. }
  3682. // Return the target found, if any.
  3683. return tgt;
  3684. }
  3685. //----------------------------------------------------------------------------
  3686. std::string cmTarget::CheckCMP0004(std::string const& item) const
  3687. {
  3688. // Strip whitespace off the library names because we used to do this
  3689. // in case variables were expanded at generate time. We no longer
  3690. // do the expansion but users link to libraries like " ${VAR} ".
  3691. std::string lib = item;
  3692. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  3693. if(pos != lib.npos)
  3694. {
  3695. lib = lib.substr(pos, lib.npos);
  3696. }
  3697. pos = lib.find_last_not_of(" \t\r\n");
  3698. if(pos != lib.npos)
  3699. {
  3700. lib = lib.substr(0, pos+1);
  3701. }
  3702. if(lib != item)
  3703. {
  3704. cmake* cm = this->Makefile->GetCMakeInstance();
  3705. switch(this->GetPolicyStatusCMP0004())
  3706. {
  3707. case cmPolicies::WARN:
  3708. {
  3709. std::ostringstream w;
  3710. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
  3711. << "Target \"" << this->GetName() << "\" links to item \""
  3712. << item << "\" which has leading or trailing whitespace.";
  3713. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  3714. this->GetBacktrace());
  3715. }
  3716. case cmPolicies::OLD:
  3717. break;
  3718. case cmPolicies::NEW:
  3719. {
  3720. std::ostringstream e;
  3721. e << "Target \"" << this->GetName() << "\" links to item \""
  3722. << item << "\" which has leading or trailing whitespace. "
  3723. << "This is now an error according to policy CMP0004.";
  3724. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  3725. }
  3726. break;
  3727. case cmPolicies::REQUIRED_IF_USED:
  3728. case cmPolicies::REQUIRED_ALWAYS:
  3729. {
  3730. std::ostringstream e;
  3731. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
  3732. << "Target \"" << this->GetName() << "\" links to item \""
  3733. << item << "\" which has leading or trailing whitespace.";
  3734. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  3735. }
  3736. break;
  3737. }
  3738. }
  3739. return lib;
  3740. }
  3741. //----------------------------------------------------------------------------
  3742. cmTargetInternalPointer::cmTargetInternalPointer()
  3743. {
  3744. this->Pointer = new cmTargetInternals;
  3745. }
  3746. //----------------------------------------------------------------------------
  3747. cmTargetInternalPointer
  3748. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  3749. {
  3750. // Ideally cmTarget instances should never be copied. However until
  3751. // we can make a sweep to remove that, this copy constructor avoids
  3752. // allowing the resources (Internals) to be copied.
  3753. this->Pointer = new cmTargetInternals(*r.Pointer);
  3754. }
  3755. //----------------------------------------------------------------------------
  3756. cmTargetInternalPointer::~cmTargetInternalPointer()
  3757. {
  3758. cmDeleteAll(this->Pointer->CompileFeaturesItems);
  3759. cmDeleteAll(this->Pointer->CompileDefinitionsItems);
  3760. cmDeleteAll(this->Pointer->SourceEntries);
  3761. delete this->Pointer;
  3762. }
  3763. //----------------------------------------------------------------------------
  3764. cmTargetInternalPointer&
  3765. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  3766. {
  3767. if(this == &r) { return *this; } // avoid warning on HP about self check
  3768. // Ideally cmTarget instances should never be copied. However until
  3769. // we can make a sweep to remove that, this copy constructor avoids
  3770. // allowing the resources (Internals) to be copied.
  3771. cmTargetInternals* oldPointer = this->Pointer;
  3772. this->Pointer = new cmTargetInternals(*r.Pointer);
  3773. delete oldPointer;
  3774. return *this;
  3775. }