cmTarget.cxx 121 KB

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