cmTarget.cxx 121 KB

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