cmTarget.cxx 125 KB

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