cmTarget.cxx 125 KB

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