cmTarget.cxx 137 KB

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