cmTarget.cxx 115 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmTarget.h"
  4. #include <algorithm>
  5. #include <cassert>
  6. #include <iterator>
  7. #include <map>
  8. #include <set>
  9. #include <sstream>
  10. #include <unordered_map>
  11. #include <unordered_set>
  12. #include <cm/memory>
  13. #include <cm/string_view>
  14. #include <cmext/algorithm>
  15. #include <cmext/string_view>
  16. #include "cmsys/RegularExpression.hxx"
  17. #include "cmAlgorithms.h"
  18. #include "cmCustomCommand.h"
  19. #include "cmFileSet.h"
  20. #include "cmFindPackageStack.h"
  21. #include "cmGeneratorExpression.h"
  22. #include "cmGeneratorTarget.h"
  23. #include "cmGlobalGenerator.h"
  24. #include "cmList.h"
  25. #include "cmListFileCache.h"
  26. #include "cmMakefile.h"
  27. #include "cmMessageType.h"
  28. #include "cmProperty.h"
  29. #include "cmPropertyDefinition.h"
  30. #include "cmPropertyMap.h"
  31. #include "cmRange.h"
  32. #include "cmSourceFile.h"
  33. #include "cmSourceFileLocation.h"
  34. #include "cmSourceFileLocationKind.h"
  35. #include "cmState.h"
  36. #include "cmStateDirectory.h"
  37. #include "cmStateSnapshot.h"
  38. #include "cmSystemTools.h"
  39. #include "cmTargetPropertyComputer.h"
  40. #include "cmValue.h"
  41. #include "cmXcFramework.h"
  42. #include "cmake.h"
  43. template <>
  44. const std::string& cmTargetPropertyComputer::ComputeLocationForBuild<cmTarget>(
  45. cmTarget const* tgt)
  46. {
  47. static std::string loc;
  48. if (tgt->IsImported()) {
  49. loc = tgt->ImportedGetFullPath("", cmStateEnums::RuntimeBinaryArtifact);
  50. return loc;
  51. }
  52. cmGlobalGenerator* gg = tgt->GetGlobalGenerator();
  53. if (!gg->GetConfigureDoneCMP0026()) {
  54. gg->CreateGenerationObjects();
  55. }
  56. cmGeneratorTarget* gt = gg->FindGeneratorTarget(tgt->GetName());
  57. loc = gt->GetLocationForBuild();
  58. return loc;
  59. }
  60. template <>
  61. const std::string& cmTargetPropertyComputer::ComputeLocation<cmTarget>(
  62. cmTarget const* tgt, const std::string& config)
  63. {
  64. static std::string loc;
  65. if (tgt->IsImported()) {
  66. loc =
  67. tgt->ImportedGetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  68. return loc;
  69. }
  70. cmGlobalGenerator* gg = tgt->GetGlobalGenerator();
  71. if (!gg->GetConfigureDoneCMP0026()) {
  72. gg->CreateGenerationObjects();
  73. }
  74. cmGeneratorTarget* gt = gg->FindGeneratorTarget(tgt->GetName());
  75. loc = gt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  76. return loc;
  77. }
  78. template <>
  79. cmValue cmTargetPropertyComputer::GetSources<cmTarget>(cmTarget const* tgt,
  80. cmMakefile const& mf)
  81. {
  82. cmBTStringRange entries = tgt->GetSourceEntries();
  83. if (entries.empty()) {
  84. return nullptr;
  85. }
  86. std::ostringstream ss;
  87. const char* sep = "";
  88. for (auto const& entry : entries) {
  89. cmList files{ entry.Value };
  90. for (std::string const& file : files) {
  91. if (cmHasLiteralPrefix(file, "$<TARGET_OBJECTS:") &&
  92. file.back() == '>') {
  93. std::string objLibName = file.substr(17, file.size() - 18);
  94. if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
  95. ss << sep;
  96. sep = ";";
  97. ss << file;
  98. continue;
  99. }
  100. bool addContent = false;
  101. bool noMessage = true;
  102. std::ostringstream e;
  103. MessageType messageType = MessageType::AUTHOR_WARNING;
  104. switch (mf.GetPolicyStatus(cmPolicies::CMP0051)) {
  105. case cmPolicies::WARN:
  106. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
  107. noMessage = false;
  108. CM_FALLTHROUGH;
  109. case cmPolicies::OLD:
  110. break;
  111. case cmPolicies::NEW:
  112. addContent = true;
  113. break;
  114. }
  115. if (!noMessage) {
  116. e << "Target \"" << tgt->GetName()
  117. << "\" contains $<TARGET_OBJECTS> generator expression in its "
  118. "sources list. This content was not previously part of the "
  119. "SOURCES property when that property was read at configure "
  120. "time. Code reading that property needs to be adapted to "
  121. "ignore the generator expression using the string(GENEX_STRIP) "
  122. "command.";
  123. mf.IssueMessage(messageType, e.str());
  124. }
  125. if (addContent) {
  126. ss << sep;
  127. sep = ";";
  128. ss << file;
  129. }
  130. } else if (cmGeneratorExpression::Find(file) == std::string::npos) {
  131. ss << sep;
  132. sep = ";";
  133. ss << file;
  134. } else {
  135. cmSourceFile* sf = tgt->GetMakefile()->GetOrCreateSource(file);
  136. // Construct what is known about this source file location.
  137. cmSourceFileLocation const& location = sf->GetLocation();
  138. std::string sname = location.GetDirectory();
  139. if (!sname.empty()) {
  140. sname += "/";
  141. }
  142. sname += location.GetName();
  143. ss << sep;
  144. sep = ";";
  145. // Append this list entry.
  146. ss << sname;
  147. }
  148. }
  149. }
  150. static std::string srcs;
  151. srcs = ss.str();
  152. return cmValue(srcs);
  153. }
  154. namespace {
  155. struct FileSetEntries
  156. {
  157. FileSetEntries(cm::static_string_view propertyName)
  158. : PropertyName(propertyName)
  159. {
  160. }
  161. cm::static_string_view const PropertyName;
  162. std::vector<BT<std::string>> Entries;
  163. };
  164. struct FileSetType
  165. {
  166. FileSetType(cm::static_string_view typeName,
  167. cm::static_string_view defaultDirectoryProperty,
  168. cm::static_string_view defaultPathProperty,
  169. cm::static_string_view directoryPrefix,
  170. cm::static_string_view pathPrefix,
  171. cm::static_string_view typeDescription,
  172. cm::static_string_view defaultDescription,
  173. cm::static_string_view arbitraryDescription,
  174. FileSetEntries selfEntries, FileSetEntries interfaceEntries)
  175. : TypeName(typeName)
  176. , DefaultDirectoryProperty(defaultDirectoryProperty)
  177. , DefaultPathProperty(defaultPathProperty)
  178. , DirectoryPrefix(directoryPrefix)
  179. , PathPrefix(pathPrefix)
  180. , TypeDescription(typeDescription)
  181. , DefaultDescription(defaultDescription)
  182. , ArbitraryDescription(arbitraryDescription)
  183. , SelfEntries(std::move(selfEntries))
  184. , InterfaceEntries(std::move(interfaceEntries))
  185. {
  186. }
  187. cm::static_string_view const TypeName;
  188. cm::static_string_view const DefaultDirectoryProperty;
  189. cm::static_string_view const DefaultPathProperty;
  190. cm::static_string_view const DirectoryPrefix;
  191. cm::static_string_view const PathPrefix;
  192. cm::static_string_view const TypeDescription;
  193. cm::static_string_view const DefaultDescription;
  194. cm::static_string_view const ArbitraryDescription;
  195. FileSetEntries SelfEntries;
  196. FileSetEntries InterfaceEntries;
  197. enum class Action
  198. {
  199. Set,
  200. Append,
  201. };
  202. template <typename ValueType>
  203. bool WriteProperties(cmTarget* tgt, cmTargetInternals* impl,
  204. const std::string& prop, ValueType value,
  205. Action action);
  206. std::pair<bool, cmValue> ReadProperties(cmTarget const* tgt,
  207. cmTargetInternals const* impl,
  208. const std::string& prop) const;
  209. void AddFileSet(const std::string& name, cmFileSetVisibility vis,
  210. cmListFileBacktrace bt);
  211. };
  212. struct UsageRequirementProperty
  213. {
  214. enum class AppendEmpty
  215. {
  216. Yes,
  217. No,
  218. };
  219. UsageRequirementProperty(cm::static_string_view name,
  220. AppendEmpty appendEmpty = AppendEmpty::No)
  221. : Name(name)
  222. , AppendBehavior(appendEmpty)
  223. {
  224. }
  225. void CopyFromEntries(cmBTStringRange entries)
  226. {
  227. cm::append(this->Entries, entries);
  228. }
  229. enum class Action
  230. {
  231. Set,
  232. Prepend,
  233. Append,
  234. };
  235. template <typename ValueType>
  236. bool Write(cmTargetInternals const* impl,
  237. cm::optional<cmListFileBacktrace> const& bt,
  238. const std::string& prop, ValueType value, Action action);
  239. template <typename ValueType>
  240. void WriteDirect(cmTargetInternals const* impl,
  241. cm::optional<cmListFileBacktrace> const& bt,
  242. ValueType value, Action action);
  243. void WriteDirect(BT<std::string> value, Action action);
  244. std::pair<bool, cmValue> Read(const std::string& prop) const;
  245. cm::static_string_view const Name;
  246. AppendEmpty const AppendBehavior;
  247. std::vector<BT<std::string>> Entries;
  248. };
  249. struct TargetProperty
  250. {
  251. enum class InitCondition
  252. {
  253. // Always initialize the property.
  254. Always,
  255. // Never initialize the property.
  256. Never,
  257. // Only initialize if the target can compile sources.
  258. CanCompileSources,
  259. // Only apply to Xcode generators.
  260. NeedsXcode,
  261. // Only apply to Xcode generators on targets that can compile sources.
  262. NeedsXcodeAndCanCompileSources,
  263. // Needs to be a "normal" target (any non-global, non-utility target).
  264. NormalTarget,
  265. // Any non-imported target.
  266. NonImportedTarget,
  267. // Needs to be a "normal" target (any non-global, non-utility target) that
  268. // is not `IMPORTED`.
  269. NormalNonImportedTarget,
  270. // Needs to be a "normal" target with an artifact (no `INTERFACE`
  271. // libraries).
  272. TargetWithArtifact,
  273. // Needs to be a "normal" target with an artifact that is not an
  274. // executable.
  275. NonExecutableWithArtifact,
  276. // Needs to be a linkable library target (no `OBJECT` or `MODULE`
  277. // libraries).
  278. LinkableLibraryTarget,
  279. // Needs to be an executable.
  280. ExecutableTarget,
  281. // Needs to be a shared library (`SHARED`).
  282. SharedLibraryTarget,
  283. // Needs to be a target with meaningful symbol exports (`SHARED` or
  284. // `EXECUTABLE`).
  285. TargetWithSymbolExports,
  286. // Targets with "commands" associated with them. Basically everything
  287. // except global and `INTERFACE` targets.
  288. TargetWithCommands,
  289. };
  290. enum class Repetition
  291. {
  292. Once,
  293. PerConfig,
  294. PerConfigPrefix,
  295. };
  296. TargetProperty(cm::static_string_view name)
  297. : Name(name)
  298. {
  299. }
  300. TargetProperty(cm::static_string_view name, cm::static_string_view dflt,
  301. InitCondition init)
  302. : Name(name)
  303. , Default(dflt)
  304. , InitConditional(init)
  305. {
  306. }
  307. TargetProperty(cm::static_string_view name, InitCondition init)
  308. : Name(name)
  309. , InitConditional(init)
  310. {
  311. }
  312. TargetProperty(cm::static_string_view name, InitCondition init,
  313. Repetition repeat)
  314. : Name(name)
  315. , InitConditional(init)
  316. , Repeat(repeat)
  317. {
  318. }
  319. cm::static_string_view const Name;
  320. // Explicit initialization is needed for AppleClang in Xcode 8 and below
  321. // NOLINTNEXTLINE(readability-redundant-member-init)
  322. cm::optional<cm::static_string_view> const Default = {};
  323. InitCondition const InitConditional = InitCondition::Always;
  324. Repetition const Repeat = Repetition::Once;
  325. };
  326. #define IC TargetProperty::InitCondition
  327. #define R TargetProperty::Repetition
  328. /* clang-format off */
  329. #define COMMON_LANGUAGE_PROPERTIES(lang) \
  330. { #lang "_COMPILER_LAUNCHER"_s, IC::CanCompileSources }, \
  331. { #lang "_STANDARD"_s, IC::CanCompileSources }, \
  332. { #lang "_STANDARD_REQUIRED"_s, IC::CanCompileSources }, \
  333. { #lang "_EXTENSIONS"_s, IC::CanCompileSources }, \
  334. { #lang "_VISIBILITY_PRESET"_s, IC::CanCompileSources }
  335. /* clang-format on */
  336. TargetProperty const StaticTargetProperties[] = {
  337. /* clang-format off */
  338. // -- Debugger Properties
  339. { "DEBUGGER_WORKING_DIRECTORY"_s, IC::ExecutableTarget },
  340. // Compilation properties
  341. { "COMPILE_WARNING_AS_ERROR"_s, IC::CanCompileSources },
  342. { "INTERPROCEDURAL_OPTIMIZATION"_s, IC::CanCompileSources },
  343. { "INTERPROCEDURAL_OPTIMIZATION_"_s, IC::TargetWithArtifact, R::PerConfig },
  344. { "NO_SYSTEM_FROM_IMPORTED"_s, IC::CanCompileSources },
  345. // Set to `True` for `SHARED` and `MODULE` targets.
  346. { "POSITION_INDEPENDENT_CODE"_s, IC::CanCompileSources },
  347. { "VISIBILITY_INLINES_HIDDEN"_s, IC::CanCompileSources },
  348. // -- Features
  349. // ---- PCH
  350. { "DISABLE_PRECOMPILE_HEADERS"_s, IC::CanCompileSources },
  351. { "PCH_WARN_INVALID"_s, "ON"_s, IC::CanCompileSources },
  352. { "PCH_INSTANTIATE_TEMPLATES"_s, "ON"_s, IC::CanCompileSources },
  353. // -- Platforms
  354. // ---- Android
  355. { "ANDROID_API"_s, IC::CanCompileSources },
  356. { "ANDROID_API_MIN"_s, IC::CanCompileSources },
  357. { "ANDROID_ARCH"_s, IC::CanCompileSources },
  358. { "ANDROID_ASSETS_DIRECTORIES"_s, IC::CanCompileSources },
  359. { "ANDROID_JAVA_SOURCE_DIR"_s, IC::CanCompileSources },
  360. { "ANDROID_STL_TYPE"_s, IC::CanCompileSources },
  361. // ---- macOS
  362. { "OSX_ARCHITECTURES"_s, IC::CanCompileSources },
  363. // ---- Windows
  364. { "MSVC_DEBUG_INFORMATION_FORMAT"_s, IC::CanCompileSources },
  365. { "MSVC_RUNTIME_LIBRARY"_s, IC::CanCompileSources },
  366. { "VS_JUST_MY_CODE_DEBUGGING"_s, IC::CanCompileSources },
  367. { "VS_DEBUGGER_COMMAND"_s, IC::ExecutableTarget },
  368. { "VS_DEBUGGER_COMMAND_ARGUMENTS"_s, IC::ExecutableTarget },
  369. { "VS_DEBUGGER_ENVIRONMENT"_s, IC::ExecutableTarget },
  370. { "VS_DEBUGGER_WORKING_DIRECTORY"_s, IC::ExecutableTarget },
  371. { "VS_USE_DEBUG_LIBRARIES"_s, IC::NonImportedTarget },
  372. // ---- OpenWatcom
  373. { "WATCOM_RUNTIME_LIBRARY"_s, IC::CanCompileSources },
  374. // ---- AIX
  375. { "AIX_SHARED_LIBRARY_ARCHIVE"_s, IC::SharedLibraryTarget },
  376. // -- Language
  377. // ---- C
  378. COMMON_LANGUAGE_PROPERTIES(C),
  379. // ---- C++
  380. COMMON_LANGUAGE_PROPERTIES(CXX),
  381. { "CXX_MODULE_STD"_s, IC::CanCompileSources },
  382. // ---- CSharp
  383. { "DOTNET_SDK"_s, IC::NonImportedTarget },
  384. { "DOTNET_TARGET_FRAMEWORK"_s, IC::TargetWithCommands },
  385. { "DOTNET_TARGET_FRAMEWORK_VERSION"_s, IC::TargetWithCommands },
  386. // ---- CUDA
  387. COMMON_LANGUAGE_PROPERTIES(CUDA),
  388. { "CUDA_SEPARABLE_COMPILATION"_s, IC::CanCompileSources },
  389. { "CUDA_ARCHITECTURES"_s, IC::CanCompileSources },
  390. // ---- Fortran
  391. { "Fortran_FORMAT"_s, IC::CanCompileSources },
  392. { "Fortran_MODULE_DIRECTORY"_s, IC::CanCompileSources },
  393. { "Fortran_COMPILER_LAUNCHER"_s, IC::CanCompileSources },
  394. { "Fortran_PREPROCESS"_s, IC::CanCompileSources },
  395. { "Fortran_VISIBILITY_PRESET"_s, IC::CanCompileSources },
  396. // ---- HIP
  397. COMMON_LANGUAGE_PROPERTIES(HIP),
  398. { "HIP_ARCHITECTURES"_s, IC::CanCompileSources },
  399. // ---- ISPC
  400. { "ISPC_COMPILER_LAUNCHER"_s, IC::CanCompileSources },
  401. { "ISPC_HEADER_DIRECTORY"_s, IC::CanCompileSources },
  402. { "ISPC_HEADER_SUFFIX"_s, "_ispc.h"_s, IC::CanCompileSources },
  403. { "ISPC_INSTRUCTION_SETS"_s, IC::CanCompileSources },
  404. // ---- Objective C
  405. COMMON_LANGUAGE_PROPERTIES(OBJC),
  406. // ---- Objective C++
  407. COMMON_LANGUAGE_PROPERTIES(OBJCXX),
  408. // ---- Swift
  409. { "Swift_LANGUAGE_VERSION"_s, IC::CanCompileSources },
  410. { "Swift_MODULE_DIRECTORY"_s, IC::CanCompileSources },
  411. { "Swift_COMPILATION_MODE"_s, IC::CanCompileSources },
  412. // ---- moc
  413. { "AUTOMOC"_s, IC::CanCompileSources },
  414. { "AUTOMOC_COMPILER_PREDEFINES"_s, IC::CanCompileSources },
  415. { "AUTOMOC_MACRO_NAMES"_s, IC::CanCompileSources },
  416. { "AUTOMOC_MOC_OPTIONS"_s, IC::CanCompileSources },
  417. { "AUTOMOC_PATH_PREFIX"_s, IC::CanCompileSources },
  418. { "AUTOMOC_EXECUTABLE"_s, IC::CanCompileSources },
  419. // ---- uic
  420. { "AUTOUIC"_s, IC::CanCompileSources },
  421. { "AUTOUIC_OPTIONS"_s, IC::CanCompileSources },
  422. { "AUTOUIC_SEARCH_PATHS"_s, IC::CanCompileSources },
  423. { "AUTOUIC_EXECUTABLE"_s, IC::CanCompileSources },
  424. // ---- rcc
  425. { "AUTORCC"_s, IC::CanCompileSources },
  426. { "AUTORCC_OPTIONS"_s, IC::CanCompileSources },
  427. { "AUTORCC_EXECUTABLE"_s, IC::CanCompileSources },
  428. // Linking properties
  429. { "LINKER_TYPE"_s, IC::CanCompileSources },
  430. { "LINK_WARNING_AS_ERROR"_s, IC::CanCompileSources },
  431. { "ENABLE_EXPORTS"_s, IC::TargetWithSymbolExports },
  432. { "LINK_LIBRARIES_ONLY_TARGETS"_s, IC::NormalNonImportedTarget },
  433. { "LINK_LIBRARIES_STRATEGY"_s, IC::NormalNonImportedTarget },
  434. { "LINK_SEARCH_START_STATIC"_s, IC::CanCompileSources },
  435. { "LINK_SEARCH_END_STATIC"_s, IC::CanCompileSources },
  436. // Initialize per-configuration name postfix property from the variable only
  437. // for non-executable targets. This preserves compatibility with previous
  438. // CMake versions in which executables did not support this variable.
  439. // Projects may still specify the property directly.
  440. { "_POSTFIX"_s, IC::NonExecutableWithArtifact, R::PerConfigPrefix },
  441. // -- Dependent library lookup
  442. { "MACOSX_RPATH"_s, IC::CanCompileSources },
  443. // ---- Build
  444. { "BUILD_RPATH"_s, IC::CanCompileSources },
  445. { "BUILD_RPATH_USE_ORIGIN"_s, IC::CanCompileSources },
  446. { "SKIP_BUILD_RPATH"_s, "OFF"_s, IC::CanCompileSources },
  447. { "BUILD_WITH_INSTALL_RPATH"_s, "OFF"_s, IC::CanCompileSources },
  448. { "BUILD_WITH_INSTALL_NAME_DIR"_s, IC::CanCompileSources },
  449. // ---- Install
  450. { "INSTALL_NAME_DIR"_s, IC::CanCompileSources },
  451. { "INSTALL_REMOVE_ENVIRONMENT_RPATH"_s, IC::CanCompileSources },
  452. { "INSTALL_RPATH"_s, ""_s, IC::CanCompileSources },
  453. { "INSTALL_RPATH_USE_LINK_PATH"_s, "OFF"_s, IC::CanCompileSources },
  454. // -- Platforms
  455. // ---- AIX
  456. { "AIX_EXPORT_ALL_SYMBOLS"_s, IC::TargetWithSymbolExports },
  457. // ---- Android
  458. { "ANDROID_GUI"_s, IC::ExecutableTarget },
  459. { "ANDROID_JAR_DIRECTORIES"_s, IC::CanCompileSources },
  460. { "ANDROID_JAR_DEPENDENCIES"_s, IC::CanCompileSources },
  461. { "ANDROID_NATIVE_LIB_DIRECTORIES"_s, IC::CanCompileSources },
  462. { "ANDROID_NATIVE_LIB_DEPENDENCIES"_s, IC::CanCompileSources },
  463. { "ANDROID_PROGUARD"_s, IC::CanCompileSources },
  464. { "ANDROID_PROGUARD_CONFIG_PATH"_s, IC::CanCompileSources },
  465. { "ANDROID_SECURE_PROPS_PATH"_s, IC::CanCompileSources },
  466. // ---- iOS
  467. { "IOS_INSTALL_COMBINED"_s, IC::CanCompileSources },
  468. // ---- macOS
  469. { "FRAMEWORK_MULTI_CONFIG_POSTFIX_"_s, IC::LinkableLibraryTarget, R::PerConfig },
  470. // ---- Windows
  471. { "DLL_NAME_WITH_SOVERSION"_s, IC::SharedLibraryTarget },
  472. { "GNUtoMS"_s, IC::CanCompileSources },
  473. { "WIN32_EXECUTABLE"_s, IC::CanCompileSources },
  474. { "WINDOWS_EXPORT_ALL_SYMBOLS"_s, IC::TargetWithSymbolExports },
  475. // -- Languages
  476. // ---- C
  477. { "C_LINKER_LAUNCHER"_s, IC::CanCompileSources },
  478. // ---- C++
  479. { "CXX_LINKER_LAUNCHER"_s, IC::CanCompileSources },
  480. // ---- CUDA
  481. { "CUDA_RESOLVE_DEVICE_SYMBOLS"_s, IC::CanCompileSources },
  482. { "CUDA_RUNTIME_LIBRARY"_s, IC::CanCompileSources },
  483. // ---- HIP
  484. { "HIP_RUNTIME_LIBRARY"_s, IC::CanCompileSources },
  485. // ---- Objective C
  486. { "OBJC_LINKER_LAUNCHER"_s, IC::CanCompileSources },
  487. // ---- Objective C++
  488. { "OBJCXX_LINKER_LAUNCHER"_s, IC::CanCompileSources },
  489. // Static analysis
  490. // -- C
  491. { "C_CLANG_TIDY"_s, IC::CanCompileSources },
  492. { "C_CLANG_TIDY_EXPORT_FIXES_DIR"_s, IC::CanCompileSources },
  493. { "C_CPPLINT"_s, IC::CanCompileSources },
  494. { "C_CPPCHECK"_s, IC::CanCompileSources },
  495. { "C_INCLUDE_WHAT_YOU_USE"_s, IC::CanCompileSources },
  496. // -- C++
  497. { "CXX_CLANG_TIDY"_s, IC::CanCompileSources },
  498. { "CXX_CLANG_TIDY_EXPORT_FIXES_DIR"_s, IC::CanCompileSources },
  499. { "CXX_CPPLINT"_s, IC::CanCompileSources },
  500. { "CXX_CPPCHECK"_s, IC::CanCompileSources },
  501. { "CXX_INCLUDE_WHAT_YOU_USE"_s, IC::CanCompileSources },
  502. // -- Objective C
  503. { "OBJC_CLANG_TIDY"_s, IC::CanCompileSources },
  504. { "OBJC_CLANG_TIDY_EXPORT_FIXES_DIR"_s, IC::CanCompileSources },
  505. // -- Objective C++
  506. { "OBJCXX_CLANG_TIDY"_s, IC::CanCompileSources },
  507. { "OBJCXX_CLANG_TIDY_EXPORT_FIXES_DIR"_s, IC::CanCompileSources },
  508. // -- Linking
  509. { "LINK_WHAT_YOU_USE"_s, IC::CanCompileSources },
  510. // Build graph properties
  511. { "LINK_DEPENDS_NO_SHARED"_s, IC::CanCompileSources },
  512. { "UNITY_BUILD"_s, IC::CanCompileSources },
  513. { "UNITY_BUILD_UNIQUE_ID"_s, IC::CanCompileSources },
  514. { "UNITY_BUILD_BATCH_SIZE"_s, "8"_s, IC::CanCompileSources },
  515. { "UNITY_BUILD_MODE"_s, "BATCH"_s, IC::CanCompileSources },
  516. { "UNITY_BUILD_RELOCATABLE"_s, IC::CanCompileSources },
  517. { "OPTIMIZE_DEPENDENCIES"_s, IC::CanCompileSources },
  518. { "VERIFY_INTERFACE_HEADER_SETS"_s },
  519. // -- Android
  520. { "ANDROID_ANT_ADDITIONAL_OPTIONS"_s, IC::CanCompileSources },
  521. { "ANDROID_PROCESS_MAX"_s, IC::CanCompileSources },
  522. { "ANDROID_SKIP_ANT_STEP"_s, IC::CanCompileSources },
  523. // -- Autogen
  524. { "AUTOGEN_COMMAND_LINE_LENGTH_MAX"_s, IC::CanCompileSources },
  525. { "AUTOGEN_ORIGIN_DEPENDS"_s, IC::CanCompileSources },
  526. { "AUTOGEN_PARALLEL"_s, IC::CanCompileSources },
  527. { "AUTOGEN_USE_SYSTEM_INCLUDE"_s, IC::CanCompileSources },
  528. { "AUTOGEN_BETTER_GRAPH_MULTI_CONFIG"_s, IC::CanCompileSources },
  529. // -- moc
  530. { "AUTOMOC_DEPEND_FILTERS"_s, IC::CanCompileSources },
  531. // -- C++
  532. { "CXX_SCAN_FOR_MODULES"_s, IC::CanCompileSources },
  533. // -- Ninja
  534. { "JOB_POOL_COMPILE"_s, IC::CanCompileSources },
  535. { "JOB_POOL_LINK"_s, IC::CanCompileSources },
  536. { "JOB_POOL_PRECOMPILE_HEADER"_s, IC::CanCompileSources },
  537. // -- Visual Studio
  538. { "VS_NO_COMPILE_BATCHING"_s, IC::CanCompileSources },
  539. { "VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION"_s, IC::CanCompileSources},
  540. // Output location properties
  541. { "ARCHIVE_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
  542. { "ARCHIVE_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
  543. { "COMPILE_PDB_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
  544. { "COMPILE_PDB_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
  545. { "LIBRARY_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
  546. { "LIBRARY_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
  547. { "PDB_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
  548. { "PDB_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
  549. { "RUNTIME_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
  550. { "RUNTIME_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
  551. // macOS bundle properties
  552. { "FRAMEWORK"_s, IC::CanCompileSources },
  553. { "FRAMEWORK_MULTI_CONFIG_POSTFIX"_s, IC::CanCompileSources },
  554. { "MACOSX_BUNDLE"_s, IC::CanCompileSources },
  555. // Usage requirement properties
  556. { "LINK_INTERFACE_LIBRARIES"_s, IC::CanCompileSources },
  557. { "MAP_IMPORTED_CONFIG_"_s, IC::NormalTarget, R::PerConfig },
  558. { "EXPORT_FIND_PACKAGE_NAME"_s, IC::NormalTarget },
  559. // Metadata
  560. { "CROSSCOMPILING_EMULATOR"_s, IC::ExecutableTarget },
  561. { "EXPORT_BUILD_DATABASE"_s, IC::CanCompileSources },
  562. { "EXPORT_COMPILE_COMMANDS"_s, IC::CanCompileSources },
  563. { "FOLDER"_s },
  564. { "TEST_LAUNCHER"_s, IC::ExecutableTarget },
  565. // Xcode properties
  566. { "XCODE_GENERATE_SCHEME"_s, IC::NeedsXcode },
  567. #ifdef __APPLE__
  568. { "XCODE_SCHEME_ADDRESS_SANITIZER"_s, IC::NeedsXcodeAndCanCompileSources },
  569. { "XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN"_s, IC::NeedsXcodeAndCanCompileSources },
  570. { "XCODE_SCHEME_DEBUG_DOCUMENT_VERSIONING"_s, IC::NeedsXcodeAndCanCompileSources },
  571. { "XCODE_SCHEME_ENABLE_GPU_FRAME_CAPTURE_MODE"_s, IC::NeedsXcodeAndCanCompileSources },
  572. { "XCODE_SCHEME_THREAD_SANITIZER"_s, IC::NeedsXcodeAndCanCompileSources },
  573. { "XCODE_SCHEME_THREAD_SANITIZER_STOP"_s, IC::NeedsXcodeAndCanCompileSources },
  574. { "XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER"_s, IC::NeedsXcodeAndCanCompileSources },
  575. { "XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP"_s, IC::NeedsXcodeAndCanCompileSources },
  576. { "XCODE_SCHEME_LAUNCH_CONFIGURATION"_s, IC::NeedsXcodeAndCanCompileSources },
  577. { "XCODE_SCHEME_ENABLE_GPU_API_VALIDATION"_s, IC::NeedsXcodeAndCanCompileSources },
  578. { "XCODE_SCHEME_ENABLE_GPU_SHADER_VALIDATION"_s, IC::NeedsXcodeAndCanCompileSources },
  579. { "XCODE_SCHEME_WORKING_DIRECTORY"_s, IC::NeedsXcodeAndCanCompileSources },
  580. { "XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER"_s, IC::NeedsXcodeAndCanCompileSources },
  581. { "XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP"_s, IC::NeedsXcodeAndCanCompileSources },
  582. { "XCODE_SCHEME_MALLOC_SCRIBBLE"_s, IC::NeedsXcodeAndCanCompileSources },
  583. { "XCODE_SCHEME_MALLOC_GUARD_EDGES"_s, IC::NeedsXcodeAndCanCompileSources },
  584. { "XCODE_SCHEME_GUARD_MALLOC"_s, IC::NeedsXcodeAndCanCompileSources },
  585. { "XCODE_SCHEME_LAUNCH_MODE"_s, IC::NeedsXcodeAndCanCompileSources },
  586. { "XCODE_SCHEME_ZOMBIE_OBJECTS"_s, IC::NeedsXcodeAndCanCompileSources },
  587. { "XCODE_SCHEME_MALLOC_STACK"_s, IC::NeedsXcodeAndCanCompileSources },
  588. { "XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE"_s, IC::NeedsXcodeAndCanCompileSources },
  589. { "XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS"_s, IC::NeedsXcodeAndCanCompileSources },
  590. { "XCODE_SCHEME_ENVIRONMENT"_s, IC::NeedsXcodeAndCanCompileSources },
  591. { "XCODE_LINK_BUILD_PHASE_MODE"_s, "NONE"_s, IC::NeedsXcodeAndCanCompileSources },
  592. #endif
  593. /* clang-format on */
  594. };
  595. #undef COMMON_LANGUAGE_PROPERTIES
  596. #undef IC
  597. #undef R
  598. }
  599. class cmTargetInternals
  600. {
  601. public:
  602. cmStateEnums::TargetType TargetType;
  603. cmMakefile* Makefile;
  604. cmPolicies::PolicyMap PolicyMap;
  605. cmTarget const* TemplateTarget;
  606. std::string Name;
  607. std::string InstallPath;
  608. std::string RuntimeInstallPath;
  609. cmPropertyMap Properties;
  610. bool IsGeneratorProvided;
  611. bool HaveInstallRule;
  612. bool IsDLLPlatform;
  613. bool IsAIX;
  614. bool IsApple;
  615. bool IsAndroid;
  616. bool BuildInterfaceIncludesAppended;
  617. bool PerConfig;
  618. cmTarget::Visibility TargetVisibility;
  619. std::set<BT<std::pair<std::string, bool>>> Utilities;
  620. std::set<std::string> CodegenDependencies;
  621. std::vector<cmCustomCommand> PreBuildCommands;
  622. std::vector<cmCustomCommand> PreLinkCommands;
  623. std::vector<cmCustomCommand> PostBuildCommands;
  624. std::vector<cmInstallTargetGenerator*> InstallGenerators;
  625. std::set<std::string> SystemIncludeDirectories;
  626. cmTarget::LinkLibraryVectorType OriginalLinkLibraries;
  627. std::map<std::string, BTs<std::string>> LanguageStandardProperties;
  628. std::map<cmTargetExport const*, std::vector<std::string>>
  629. InstallIncludeDirectoriesEntries;
  630. std::vector<std::pair<cmTarget::TLLSignature, cmListFileContext>>
  631. TLLCommands;
  632. std::map<std::string, cmFileSet> FileSets;
  633. cmListFileBacktrace Backtrace;
  634. cmFindPackageStack FindPackageStack;
  635. UsageRequirementProperty IncludeDirectories;
  636. UsageRequirementProperty CompileOptions;
  637. UsageRequirementProperty CompileFeatures;
  638. UsageRequirementProperty CompileDefinitions;
  639. UsageRequirementProperty PrecompileHeaders;
  640. UsageRequirementProperty Sources;
  641. UsageRequirementProperty LinkOptions;
  642. UsageRequirementProperty LinkDirectories;
  643. UsageRequirementProperty LinkLibraries;
  644. UsageRequirementProperty InterfaceLinkLibraries;
  645. UsageRequirementProperty InterfaceLinkLibrariesDirect;
  646. UsageRequirementProperty InterfaceLinkLibrariesDirectExclude;
  647. UsageRequirementProperty ImportedCxxModulesIncludeDirectories;
  648. UsageRequirementProperty ImportedCxxModulesCompileDefinitions;
  649. UsageRequirementProperty ImportedCxxModulesCompileFeatures;
  650. UsageRequirementProperty ImportedCxxModulesCompileOptions;
  651. UsageRequirementProperty ImportedCxxModulesLinkLibraries;
  652. FileSetType HeadersFileSets;
  653. FileSetType CxxModulesFileSets;
  654. cmTargetInternals();
  655. bool IsImported() const;
  656. bool CheckImportedLibName(std::string const& prop,
  657. std::string const& value) const;
  658. std::string ProcessSourceItemCMP0049(const std::string& s) const;
  659. template <typename ValueType>
  660. void AddDirectoryToFileSet(cmTarget* self, std::string const& fileSetName,
  661. ValueType value, cm::string_view fileSetType,
  662. cm::string_view description,
  663. FileSetType::Action action);
  664. template <typename ValueType>
  665. void AddPathToFileSet(cmTarget* self, std::string const& fileSetName,
  666. ValueType value, cm::string_view fileSetType,
  667. cm::string_view description,
  668. FileSetType::Action action);
  669. cmValue GetFileSetDirectories(cmTarget const* self,
  670. std::string const& fileSetName,
  671. cm::string_view fileSetType) const;
  672. cmValue GetFileSetPaths(cmTarget const* self, std::string const& fileSetName,
  673. cm::string_view fileSetType) const;
  674. cmListFileBacktrace GetBacktrace(
  675. cm::optional<cmListFileBacktrace> const& bt) const
  676. {
  677. return bt ? *bt : this->Makefile->GetBacktrace();
  678. }
  679. };
  680. cmTargetInternals::cmTargetInternals()
  681. : IncludeDirectories("INCLUDE_DIRECTORIES"_s)
  682. , CompileOptions("COMPILE_OPTIONS"_s)
  683. , CompileFeatures("COMPILE_FEATURES"_s)
  684. , CompileDefinitions("COMPILE_DEFINITIONS"_s)
  685. , PrecompileHeaders("PRECOMPILE_HEADERS"_s)
  686. , Sources("SOURCES"_s, UsageRequirementProperty::AppendEmpty::Yes)
  687. , LinkOptions("LINK_OPTIONS"_s)
  688. , LinkDirectories("LINK_DIRECTORIES"_s)
  689. , LinkLibraries("LINK_LIBRARIES"_s)
  690. , InterfaceLinkLibraries("INTERFACE_LINK_LIBRARIES"_s)
  691. , InterfaceLinkLibrariesDirect("INTERFACE_LINK_LIBRARIES_DIRECT"_s)
  692. , InterfaceLinkLibrariesDirectExclude(
  693. "INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE"_s)
  694. , ImportedCxxModulesIncludeDirectories(
  695. "IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES"_s)
  696. , ImportedCxxModulesCompileDefinitions(
  697. "IMPORTED_CXX_MODULES_COMPILE_DEFINITIONS"_s)
  698. , ImportedCxxModulesCompileFeatures(
  699. "IMPORTED_CXX_MODULES_COMPILE_FEATURES"_s)
  700. , ImportedCxxModulesCompileOptions("IMPORTED_CXX_MODULES_COMPILE_OPTIONS"_s)
  701. , ImportedCxxModulesLinkLibraries("IMPORTED_CXX_MODULES_LINK_LIBRARIES"_s)
  702. , HeadersFileSets("HEADERS"_s, "HEADER_DIRS"_s, "HEADER_SET"_s,
  703. "HEADER_DIRS_"_s, "HEADER_SET_"_s, "Header"_s,
  704. "The default header set"_s, "Header set"_s,
  705. FileSetEntries("HEADER_SETS"_s),
  706. FileSetEntries("INTERFACE_HEADER_SETS"_s))
  707. , CxxModulesFileSets("CXX_MODULES"_s, "CXX_MODULE_DIRS"_s,
  708. "CXX_MODULE_SET"_s, "CXX_MODULE_DIRS_"_s,
  709. "CXX_MODULE_SET_"_s, "C++ module"_s,
  710. "The default C++ module set"_s, "C++ module set"_s,
  711. FileSetEntries("CXX_MODULE_SETS"_s),
  712. FileSetEntries("INTERFACE_CXX_MODULE_SETS"_s))
  713. {
  714. }
  715. template <typename ValueType>
  716. bool FileSetType::WriteProperties(cmTarget* tgt, cmTargetInternals* impl,
  717. const std::string& prop, ValueType value,
  718. Action action)
  719. {
  720. if (prop == this->DefaultDirectoryProperty) {
  721. impl->AddDirectoryToFileSet(tgt, std::string(this->TypeName), value,
  722. this->TypeName, this->DefaultDescription,
  723. action);
  724. return true;
  725. }
  726. if (prop == this->DefaultPathProperty) {
  727. impl->AddPathToFileSet(tgt, std::string(this->TypeName), value,
  728. this->TypeName, this->DefaultDescription, action);
  729. return true;
  730. }
  731. if (cmHasPrefix(prop, this->DirectoryPrefix)) {
  732. auto fileSetName = prop.substr(this->DirectoryPrefix.size());
  733. if (fileSetName.empty()) {
  734. impl->Makefile->IssueMessage(
  735. MessageType::FATAL_ERROR,
  736. cmStrCat(this->ArbitraryDescription, " name cannot be empty."));
  737. } else {
  738. impl->AddDirectoryToFileSet(
  739. tgt, fileSetName, value, this->TypeName,
  740. cmStrCat(this->ArbitraryDescription, " \"", fileSetName, "\""),
  741. action);
  742. }
  743. return true;
  744. }
  745. if (cmHasPrefix(prop, this->PathPrefix)) {
  746. auto fileSetName = prop.substr(this->PathPrefix.size());
  747. if (fileSetName.empty()) {
  748. impl->Makefile->IssueMessage(
  749. MessageType::FATAL_ERROR,
  750. cmStrCat(this->ArbitraryDescription, " name cannot be empty."));
  751. } else {
  752. impl->AddPathToFileSet(
  753. tgt, fileSetName, value, this->TypeName,
  754. cmStrCat(this->ArbitraryDescription, " \"", fileSetName, "\""),
  755. action);
  756. }
  757. return true;
  758. }
  759. return false;
  760. }
  761. std::pair<bool, cmValue> FileSetType::ReadProperties(
  762. cmTarget const* tgt, cmTargetInternals const* impl,
  763. const std::string& prop) const
  764. {
  765. bool did_read = false;
  766. cmValue value = nullptr;
  767. if (prop == this->DefaultDirectoryProperty) {
  768. value = impl->GetFileSetDirectories(tgt, std::string(this->TypeName),
  769. this->TypeName);
  770. did_read = true;
  771. } else if (prop == this->DefaultPathProperty) {
  772. value =
  773. impl->GetFileSetPaths(tgt, std::string(this->TypeName), this->TypeName);
  774. did_read = true;
  775. } else if (prop == this->SelfEntries.PropertyName) {
  776. static std::string output;
  777. output = cmList::to_string(this->SelfEntries.Entries);
  778. value = cmValue(output);
  779. did_read = true;
  780. } else if (prop == this->InterfaceEntries.PropertyName) {
  781. static std::string output;
  782. output = cmList::to_string(this->InterfaceEntries.Entries);
  783. value = cmValue(output);
  784. did_read = true;
  785. } else if (cmHasPrefix(prop, this->DirectoryPrefix)) {
  786. std::string fileSetName = prop.substr(this->DirectoryPrefix.size());
  787. if (!fileSetName.empty()) {
  788. value = impl->GetFileSetDirectories(tgt, fileSetName, this->TypeName);
  789. }
  790. did_read = true;
  791. } else if (cmHasPrefix(prop, this->PathPrefix)) {
  792. std::string fileSetName = prop.substr(this->PathPrefix.size());
  793. if (!fileSetName.empty()) {
  794. value = impl->GetFileSetPaths(tgt, fileSetName, this->TypeName);
  795. }
  796. did_read = true;
  797. }
  798. return { did_read, value };
  799. }
  800. void FileSetType::AddFileSet(const std::string& name, cmFileSetVisibility vis,
  801. cmListFileBacktrace bt)
  802. {
  803. if (cmFileSetVisibilityIsForSelf(vis)) {
  804. this->SelfEntries.Entries.emplace_back(name, bt);
  805. }
  806. if (cmFileSetVisibilityIsForInterface(vis)) {
  807. this->InterfaceEntries.Entries.emplace_back(name, std::move(bt));
  808. }
  809. }
  810. template <typename ValueType>
  811. bool UsageRequirementProperty::Write(
  812. cmTargetInternals const* impl, cm::optional<cmListFileBacktrace> const& bt,
  813. const std::string& prop, ValueType value, Action action)
  814. {
  815. if (prop == this->Name) {
  816. this->WriteDirect(impl, bt, value, action);
  817. return true;
  818. }
  819. return false;
  820. }
  821. template <typename ValueType>
  822. void UsageRequirementProperty::WriteDirect(
  823. cmTargetInternals const* impl, cm::optional<cmListFileBacktrace> const& bt,
  824. ValueType value, Action action)
  825. {
  826. if (action == Action::Set) {
  827. this->Entries.clear();
  828. }
  829. if (value) {
  830. cmListFileBacktrace lfbt = impl->GetBacktrace(bt);
  831. if (action == Action::Prepend) {
  832. this->Entries.emplace(this->Entries.begin(), value, lfbt);
  833. } else if (action == Action::Set || cmNonempty(value) ||
  834. this->AppendBehavior == AppendEmpty::Yes) {
  835. this->Entries.emplace_back(value, lfbt);
  836. }
  837. }
  838. }
  839. void UsageRequirementProperty::WriteDirect(BT<std::string> value,
  840. Action action)
  841. {
  842. if (action == Action::Set) {
  843. this->Entries.clear();
  844. }
  845. if (action == Action::Prepend) {
  846. this->Entries.emplace(this->Entries.begin(), std::move(value));
  847. } else {
  848. this->Entries.emplace_back(std::move(value));
  849. }
  850. }
  851. std::pair<bool, cmValue> UsageRequirementProperty::Read(
  852. const std::string& prop) const
  853. {
  854. bool did_read = false;
  855. cmValue value = nullptr;
  856. if (prop == this->Name) {
  857. if (!this->Entries.empty()) {
  858. // Storage to back the returned `cmValue`.
  859. static std::string output;
  860. output = cmList::to_string(this->Entries);
  861. value = cmValue(output);
  862. }
  863. did_read = true;
  864. }
  865. return { did_read, value };
  866. }
  867. cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
  868. Visibility vis, cmMakefile* mf, PerConfig perConfig)
  869. : impl(cm::make_unique<cmTargetInternals>())
  870. {
  871. assert(mf);
  872. this->impl->TargetType = type;
  873. this->impl->Makefile = mf;
  874. this->impl->Name = name;
  875. this->impl->TemplateTarget = nullptr;
  876. this->impl->IsGeneratorProvided = false;
  877. this->impl->HaveInstallRule = false;
  878. this->impl->IsDLLPlatform = false;
  879. this->impl->IsAIX = false;
  880. this->impl->IsApple = false;
  881. this->impl->IsAndroid = false;
  882. this->impl->TargetVisibility = vis;
  883. this->impl->BuildInterfaceIncludesAppended = false;
  884. this->impl->PerConfig = (perConfig == PerConfig::Yes);
  885. // Check whether this is a DLL platform.
  886. this->impl->IsDLLPlatform =
  887. !this->impl->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")
  888. .empty();
  889. // Check whether we are targeting AIX.
  890. {
  891. std::string const& systemName =
  892. this->impl->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME");
  893. this->impl->IsAIX = (systemName == "AIX" || systemName == "OS400");
  894. }
  895. // Check whether we are targeting Apple.
  896. this->impl->IsApple = this->impl->Makefile->IsOn("APPLE");
  897. // Check whether we are targeting an Android platform.
  898. this->impl->IsAndroid = (this->impl->Makefile->GetSafeDefinition(
  899. "CMAKE_SYSTEM_NAME") == "Android");
  900. // Save the backtrace of target construction.
  901. this->impl->Backtrace = this->impl->Makefile->GetBacktrace();
  902. if (this->impl->IsImported()) {
  903. this->impl->FindPackageStack = this->impl->Makefile->GetFindPackageStack();
  904. }
  905. if (this->IsNormal()) {
  906. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  907. // of the same directory property:
  908. this->impl->IncludeDirectories.CopyFromEntries(
  909. this->impl->Makefile->GetIncludeDirectoriesEntries());
  910. {
  911. auto const& sysInc = this->impl->Makefile->GetSystemIncludeDirectories();
  912. this->impl->SystemIncludeDirectories.insert(sysInc.begin(),
  913. sysInc.end());
  914. }
  915. this->impl->CompileOptions.CopyFromEntries(
  916. this->impl->Makefile->GetCompileOptionsEntries());
  917. this->impl->LinkOptions.CopyFromEntries(
  918. this->impl->Makefile->GetLinkOptionsEntries());
  919. this->impl->LinkDirectories.CopyFromEntries(
  920. this->impl->Makefile->GetLinkDirectoriesEntries());
  921. }
  922. // Record current policies for later use.
  923. this->impl->Makefile->RecordPolicies(this->impl->PolicyMap);
  924. if (this->impl->TargetType == cmStateEnums::INTERFACE_LIBRARY) {
  925. // This policy is checked in a few conditions. The properties relevant
  926. // to the policy are always ignored for cmStateEnums::INTERFACE_LIBRARY
  927. // targets,
  928. // so ensure that the conditions don't lead to nonsense.
  929. this->impl->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
  930. }
  931. std::set<TargetProperty::InitCondition> metConditions;
  932. metConditions.insert(TargetProperty::InitCondition::Always);
  933. if (this->CanCompileSources()) {
  934. metConditions.insert(TargetProperty::InitCondition::CanCompileSources);
  935. }
  936. if (this->GetGlobalGenerator()->IsXcode()) {
  937. metConditions.insert(TargetProperty::InitCondition::NeedsXcode);
  938. if (this->CanCompileSources()) {
  939. metConditions.insert(
  940. TargetProperty::InitCondition::NeedsXcodeAndCanCompileSources);
  941. }
  942. }
  943. if (!this->IsImported()) {
  944. metConditions.insert(TargetProperty::InitCondition::NonImportedTarget);
  945. }
  946. if (this->impl->TargetType != cmStateEnums::UTILITY &&
  947. this->impl->TargetType != cmStateEnums::GLOBAL_TARGET) {
  948. metConditions.insert(TargetProperty::InitCondition::NormalTarget);
  949. if (this->IsNormal()) {
  950. metConditions.insert(
  951. TargetProperty::InitCondition::NormalNonImportedTarget);
  952. }
  953. if (this->impl->TargetType != cmStateEnums::INTERFACE_LIBRARY) {
  954. metConditions.insert(TargetProperty::InitCondition::TargetWithArtifact);
  955. if (this->impl->TargetType != cmStateEnums::EXECUTABLE) {
  956. metConditions.insert(
  957. TargetProperty::InitCondition::NonExecutableWithArtifact);
  958. }
  959. }
  960. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
  961. this->impl->TargetType == cmStateEnums::STATIC_LIBRARY) {
  962. metConditions.insert(
  963. TargetProperty::InitCondition::LinkableLibraryTarget);
  964. }
  965. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY) {
  966. metConditions.insert(TargetProperty::InitCondition::SharedLibraryTarget);
  967. }
  968. }
  969. if (this->impl->TargetType == cmStateEnums::EXECUTABLE) {
  970. metConditions.insert(TargetProperty::InitCondition::ExecutableTarget);
  971. }
  972. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
  973. this->impl->TargetType == cmStateEnums::EXECUTABLE) {
  974. metConditions.insert(
  975. TargetProperty::InitCondition::TargetWithSymbolExports);
  976. }
  977. if (this->impl->TargetType <= cmStateEnums::GLOBAL_TARGET) {
  978. metConditions.insert(TargetProperty::InitCondition::TargetWithCommands);
  979. }
  980. std::vector<std::string> configNames =
  981. mf->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
  982. for (auto& config : configNames) {
  983. config = cmSystemTools::UpperCase(config);
  984. }
  985. std::string defKey;
  986. defKey.reserve(128);
  987. defKey += "CMAKE_";
  988. auto initProperty = [this, mf, &defKey](const std::string& property,
  989. const char* default_value) {
  990. // special init for ENABLE_EXPORTS
  991. // For SHARED_LIBRARY, only CMAKE_SHARED_LIBRARY_ENABLE_EXPORTS variable
  992. // is used
  993. // For EXECUTABLE, CMAKE_EXECUTABLE_ENABLE_EXPORTS or else
  994. // CMAKE_ENABLE_EXPORTS variables are used
  995. if (property == "ENABLE_EXPORTS"_s) {
  996. // Replace everything after "CMAKE_"
  997. defKey.replace(
  998. defKey.begin() + 6, defKey.end(),
  999. cmStrCat(this->impl->TargetType == cmStateEnums::EXECUTABLE
  1000. ? "EXECUTABLE"
  1001. : "SHARED_LIBRARY",
  1002. '_', property));
  1003. if (cmValue value = mf->GetDefinition(defKey)) {
  1004. this->SetProperty(property, value);
  1005. return;
  1006. }
  1007. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY) {
  1008. if (default_value) {
  1009. this->SetProperty(property, default_value);
  1010. }
  1011. return;
  1012. }
  1013. }
  1014. // Imported targets must set AIX_SHARED_LIBRARY_ARCHIVE explicitly.
  1015. if (this->IsImported() && property == "AIX_SHARED_LIBRARY_ARCHIVE"_s) {
  1016. return;
  1017. }
  1018. // Replace everything after "CMAKE_"
  1019. defKey.replace(defKey.begin() + 6, defKey.end(), property);
  1020. if (cmValue value = mf->GetDefinition(defKey)) {
  1021. this->SetProperty(property, value);
  1022. } else if (default_value) {
  1023. this->SetProperty(property, default_value);
  1024. }
  1025. };
  1026. std::string dflt_storage;
  1027. for (auto const& tp : StaticTargetProperties) {
  1028. // Ignore properties that we have not met the condition for.
  1029. if (!metConditions.count(tp.InitConditional)) {
  1030. continue;
  1031. }
  1032. const char* dflt = nullptr;
  1033. if (tp.Default) {
  1034. dflt_storage = std::string(*tp.Default);
  1035. dflt = dflt_storage.c_str();
  1036. }
  1037. if (tp.Repeat == TargetProperty::Repetition::Once) {
  1038. initProperty(std::string(tp.Name), dflt);
  1039. } else {
  1040. std::string propertyName;
  1041. for (auto const& configName : configNames) {
  1042. if (tp.Repeat == TargetProperty::Repetition::PerConfig) {
  1043. propertyName = cmStrCat(tp.Name, configName);
  1044. } else if (tp.Repeat == TargetProperty::Repetition::PerConfigPrefix) {
  1045. propertyName = cmStrCat(configName, tp.Name);
  1046. }
  1047. initProperty(propertyName, dflt);
  1048. }
  1049. }
  1050. }
  1051. // Clean up some property defaults.
  1052. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
  1053. this->impl->TargetType == cmStateEnums::MODULE_LIBRARY) {
  1054. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  1055. }
  1056. // check for "CMAKE_VS_GLOBALS" variable and set up target properties
  1057. // if any
  1058. cmValue globals = mf->GetDefinition("CMAKE_VS_GLOBALS");
  1059. if (globals) {
  1060. const std::string genName = mf->GetGlobalGenerator()->GetName();
  1061. if (cmHasLiteralPrefix(genName, "Visual Studio")) {
  1062. cmList props{ *globals };
  1063. const std::string vsGlobal = "VS_GLOBAL_";
  1064. for (const std::string& i : props) {
  1065. // split NAME=VALUE
  1066. const std::string::size_type assignment = i.find('=');
  1067. if (assignment != std::string::npos) {
  1068. const std::string propName = vsGlobal + i.substr(0, assignment);
  1069. const std::string propValue = i.substr(assignment + 1);
  1070. initProperty(propName, propValue.c_str());
  1071. }
  1072. }
  1073. }
  1074. }
  1075. if (!this->IsNormal() || mf->GetPropertyAsBool("SYSTEM")) {
  1076. this->SetProperty("SYSTEM", "ON");
  1077. }
  1078. for (auto const& prop : mf->GetState()->GetPropertyDefinitions().GetMap()) {
  1079. if (prop.first.second == cmProperty::TARGET &&
  1080. !prop.second.GetInitializeFromVariable().empty()) {
  1081. if (auto value =
  1082. mf->GetDefinition(prop.second.GetInitializeFromVariable())) {
  1083. this->SetProperty(prop.first.first, value);
  1084. }
  1085. }
  1086. }
  1087. }
  1088. cmTarget::cmTarget(cmTarget&&) noexcept = default;
  1089. cmTarget::~cmTarget() = default;
  1090. cmTarget& cmTarget::operator=(cmTarget&&) noexcept = default;
  1091. cmStateEnums::TargetType cmTarget::GetType() const
  1092. {
  1093. return this->impl->TargetType;
  1094. }
  1095. cmMakefile* cmTarget::GetMakefile() const
  1096. {
  1097. return this->impl->Makefile;
  1098. }
  1099. cmPolicies::PolicyMap const& cmTarget::GetPolicyMap() const
  1100. {
  1101. return this->impl->PolicyMap;
  1102. }
  1103. const std::string& cmTarget::GetName() const
  1104. {
  1105. return this->impl->Name;
  1106. }
  1107. const std::string& cmTarget::GetTemplateName() const
  1108. {
  1109. if (this->impl->TemplateTarget) {
  1110. return this->impl->TemplateTarget->GetTemplateName();
  1111. }
  1112. return this->impl->Name;
  1113. }
  1114. cmPolicies::PolicyStatus cmTarget::GetPolicyStatus(
  1115. cmPolicies::PolicyID policy) const
  1116. {
  1117. return this->impl->PolicyMap.Get(policy);
  1118. }
  1119. cmGlobalGenerator* cmTarget::GetGlobalGenerator() const
  1120. {
  1121. return this->impl->Makefile->GetGlobalGenerator();
  1122. }
  1123. BTs<std::string> const* cmTarget::GetLanguageStandardProperty(
  1124. const std::string& propertyName) const
  1125. {
  1126. auto entry = this->impl->LanguageStandardProperties.find(propertyName);
  1127. if (entry != this->impl->LanguageStandardProperties.end()) {
  1128. return &entry->second;
  1129. }
  1130. return nullptr;
  1131. }
  1132. void cmTarget::SetLanguageStandardProperty(std::string const& lang,
  1133. std::string const& value,
  1134. const std::string& feature)
  1135. {
  1136. cmListFileBacktrace featureBacktrace;
  1137. for (auto const& entry : this->impl->CompileFeatures.Entries) {
  1138. if (entry.Value == feature) {
  1139. featureBacktrace = entry.Backtrace;
  1140. break;
  1141. }
  1142. }
  1143. BTs<std::string>& languageStandardProperty =
  1144. this->impl->LanguageStandardProperties[cmStrCat(lang, "_STANDARD")];
  1145. if (languageStandardProperty.Value != value) {
  1146. languageStandardProperty.Value = value;
  1147. languageStandardProperty.Backtraces.clear();
  1148. }
  1149. languageStandardProperty.Backtraces.emplace_back(featureBacktrace);
  1150. }
  1151. void cmTarget::AddUtility(std::string const& name, bool cross,
  1152. cmMakefile const* mf)
  1153. {
  1154. this->impl->Utilities.insert(BT<std::pair<std::string, bool>>(
  1155. { name, cross }, mf ? mf->GetBacktrace() : cmListFileBacktrace()));
  1156. }
  1157. void cmTarget::AddUtility(BT<std::pair<std::string, bool>> util)
  1158. {
  1159. this->impl->Utilities.emplace(std::move(util));
  1160. }
  1161. void cmTarget::AddCodegenDependency(std::string const& name)
  1162. {
  1163. this->impl->CodegenDependencies.emplace(name);
  1164. }
  1165. std::set<std::string> const& cmTarget::GetCodegenDeps() const
  1166. {
  1167. return this->impl->CodegenDependencies;
  1168. }
  1169. std::set<BT<std::pair<std::string, bool>>> const& cmTarget::GetUtilities()
  1170. const
  1171. {
  1172. return this->impl->Utilities;
  1173. }
  1174. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  1175. {
  1176. return this->impl->Backtrace;
  1177. }
  1178. cmFindPackageStack const& cmTarget::GetFindPackageStack() const
  1179. {
  1180. return this->impl->FindPackageStack;
  1181. }
  1182. bool cmTarget::IsExecutableWithExports() const
  1183. {
  1184. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  1185. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  1186. }
  1187. bool cmTarget::IsSharedLibraryWithExports() const
  1188. {
  1189. return (this->GetType() == cmStateEnums::SHARED_LIBRARY &&
  1190. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  1191. }
  1192. bool cmTarget::IsFrameworkOnApple() const
  1193. {
  1194. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1195. this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  1196. this->IsApple() && this->GetPropertyAsBool("FRAMEWORK"));
  1197. }
  1198. bool cmTarget::IsArchivedAIXSharedLibrary() const
  1199. {
  1200. if (this->GetType() == cmStateEnums::SHARED_LIBRARY && this->IsAIX()) {
  1201. cmValue value = this->GetProperty("AIX_SHARED_LIBRARY_ARCHIVE");
  1202. if (!value.IsEmpty()) {
  1203. return value.IsOn();
  1204. }
  1205. if (this->IsImported()) {
  1206. return false;
  1207. }
  1208. switch (this->GetPolicyStatusCMP0182()) {
  1209. case cmPolicies::WARN:
  1210. case cmPolicies::OLD:
  1211. // The OLD behavior's default is to disable shared library archives.
  1212. break;
  1213. case cmPolicies::NEW:
  1214. // The NEW behavior's default is to enable shared library archives.
  1215. return true;
  1216. }
  1217. }
  1218. return false;
  1219. }
  1220. bool cmTarget::IsAppBundleOnApple() const
  1221. {
  1222. return (this->GetType() == cmStateEnums::EXECUTABLE && this->IsApple() &&
  1223. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  1224. }
  1225. bool cmTarget::IsAndroidGuiExecutable() const
  1226. {
  1227. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  1228. this->impl->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI"));
  1229. }
  1230. bool cmTarget::HasKnownObjectFileLocation(std::string* reason) const
  1231. {
  1232. return this->GetGlobalGenerator()->HasKnownObjectFileLocation(*this, reason);
  1233. }
  1234. std::vector<cmCustomCommand> const& cmTarget::GetPreBuildCommands() const
  1235. {
  1236. return this->impl->PreBuildCommands;
  1237. }
  1238. void cmTarget::AddPreBuildCommand(cmCustomCommand const& cmd)
  1239. {
  1240. this->impl->PreBuildCommands.push_back(cmd);
  1241. }
  1242. void cmTarget::AddPreBuildCommand(cmCustomCommand&& cmd)
  1243. {
  1244. this->impl->PreBuildCommands.push_back(std::move(cmd));
  1245. }
  1246. std::vector<cmCustomCommand> const& cmTarget::GetPreLinkCommands() const
  1247. {
  1248. return this->impl->PreLinkCommands;
  1249. }
  1250. void cmTarget::AddPreLinkCommand(cmCustomCommand const& cmd)
  1251. {
  1252. this->impl->PreLinkCommands.push_back(cmd);
  1253. }
  1254. void cmTarget::AddPreLinkCommand(cmCustomCommand&& cmd)
  1255. {
  1256. this->impl->PreLinkCommands.push_back(std::move(cmd));
  1257. }
  1258. std::vector<cmCustomCommand> const& cmTarget::GetPostBuildCommands() const
  1259. {
  1260. return this->impl->PostBuildCommands;
  1261. }
  1262. void cmTarget::AddPostBuildCommand(cmCustomCommand const& cmd)
  1263. {
  1264. this->impl->PostBuildCommands.push_back(cmd);
  1265. }
  1266. void cmTarget::AddPostBuildCommand(cmCustomCommand&& cmd)
  1267. {
  1268. this->impl->PostBuildCommands.push_back(std::move(cmd));
  1269. }
  1270. void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
  1271. {
  1272. if (!srcs.empty()) {
  1273. this->impl->Sources.WriteDirect(this->impl.get(), {},
  1274. cmValue(cmJoin(srcs, ";")),
  1275. UsageRequirementProperty::Action::Append);
  1276. }
  1277. }
  1278. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  1279. {
  1280. std::vector<std::string> srcFiles;
  1281. for (auto filename : srcs) {
  1282. if (!cmGeneratorExpression::StartsWithGeneratorExpression(filename)) {
  1283. if (!filename.empty()) {
  1284. filename = this->impl->ProcessSourceItemCMP0049(filename);
  1285. if (filename.empty()) {
  1286. return;
  1287. }
  1288. }
  1289. this->impl->Makefile->GetOrCreateSource(filename);
  1290. }
  1291. srcFiles.emplace_back(filename);
  1292. }
  1293. this->AddTracedSources(srcFiles);
  1294. }
  1295. std::string cmTargetInternals::ProcessSourceItemCMP0049(
  1296. const std::string& s) const
  1297. {
  1298. std::string src = s;
  1299. // For backwards compatibility replace variables in source names.
  1300. // This should eventually be removed.
  1301. this->Makefile->ExpandVariablesInString(src);
  1302. if (src != s) {
  1303. std::ostringstream e;
  1304. bool noMessage = false;
  1305. MessageType messageType = MessageType::AUTHOR_WARNING;
  1306. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0049)) {
  1307. case cmPolicies::WARN:
  1308. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0049) << "\n";
  1309. break;
  1310. case cmPolicies::OLD:
  1311. noMessage = true;
  1312. break;
  1313. case cmPolicies::NEW:
  1314. messageType = MessageType::FATAL_ERROR;
  1315. }
  1316. if (!noMessage) {
  1317. e << "Legacy variable expansion in source file \"" << s
  1318. << "\" expanded to \"" << src << "\" in target \"" << this->Name
  1319. << "\". This behavior will be removed in a "
  1320. "future version of CMake.";
  1321. this->Makefile->IssueMessage(messageType, e.str());
  1322. if (messageType == MessageType::FATAL_ERROR) {
  1323. return "";
  1324. }
  1325. }
  1326. }
  1327. return src;
  1328. }
  1329. std::string cmTarget::GetSourceCMP0049(const std::string& s)
  1330. {
  1331. return this->impl->ProcessSourceItemCMP0049(s);
  1332. }
  1333. struct CreateLocation
  1334. {
  1335. cmMakefile const* Makefile;
  1336. CreateLocation(cmMakefile const* mf)
  1337. : Makefile(mf)
  1338. {
  1339. }
  1340. cmSourceFileLocation operator()(const std::string& filename) const
  1341. {
  1342. return cmSourceFileLocation(this->Makefile, filename);
  1343. }
  1344. };
  1345. struct LocationMatcher
  1346. {
  1347. const cmSourceFileLocation& Needle;
  1348. LocationMatcher(const cmSourceFileLocation& needle)
  1349. : Needle(needle)
  1350. {
  1351. }
  1352. bool operator()(cmSourceFileLocation& loc)
  1353. {
  1354. return loc.Matches(this->Needle);
  1355. }
  1356. };
  1357. struct TargetPropertyEntryFinder
  1358. {
  1359. private:
  1360. const cmSourceFileLocation& Needle;
  1361. public:
  1362. TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
  1363. : Needle(needle)
  1364. {
  1365. }
  1366. bool operator()(BT<std::string> const& entry)
  1367. {
  1368. cmList files{ entry.Value };
  1369. std::vector<cmSourceFileLocation> locations;
  1370. locations.reserve(files.size());
  1371. std::transform(files.begin(), files.end(), std::back_inserter(locations),
  1372. CreateLocation(this->Needle.GetMakefile()));
  1373. return std::find_if(locations.begin(), locations.end(),
  1374. LocationMatcher(this->Needle)) != locations.end();
  1375. }
  1376. };
  1377. cmSourceFile* cmTarget::AddSource(const std::string& src, bool before)
  1378. {
  1379. cmSourceFileLocation sfl(this->impl->Makefile, src,
  1380. cmSourceFileLocationKind::Known);
  1381. auto const& sources = this->impl->Sources.Entries;
  1382. if (std::find_if(sources.begin(), sources.end(),
  1383. TargetPropertyEntryFinder(sfl)) == sources.end()) {
  1384. this->impl->Sources.WriteDirect(
  1385. this->impl.get(), {}, cmValue(src),
  1386. before ? UsageRequirementProperty::Action::Prepend
  1387. : UsageRequirementProperty::Action::Append);
  1388. }
  1389. if (cmGeneratorExpression::Find(src) != std::string::npos) {
  1390. return nullptr;
  1391. }
  1392. return this->impl->Makefile->GetOrCreateSource(
  1393. src, false, cmSourceFileLocationKind::Known);
  1394. }
  1395. void cmTarget::ClearDependencyInformation(cmMakefile& mf) const
  1396. {
  1397. std::string depname = cmStrCat(this->GetName(), "_LIB_DEPENDS");
  1398. mf.RemoveCacheDefinition(depname);
  1399. }
  1400. std::string cmTarget::GetDebugGeneratorExpressions(
  1401. const std::string& value, cmTargetLinkLibraryType llt) const
  1402. {
  1403. if (llt == GENERAL_LibraryType) {
  1404. return value;
  1405. }
  1406. // Get the list of configurations considered to be DEBUG.
  1407. std::vector<std::string> debugConfigs =
  1408. this->impl->Makefile->GetCMakeInstance()->GetDebugConfigs();
  1409. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  1410. if (debugConfigs.size() > 1) {
  1411. for (std::string const& conf : cmMakeRange(debugConfigs).advance(1)) {
  1412. configString += ",$<CONFIG:" + conf + ">";
  1413. }
  1414. configString = "$<OR:" + configString + ">";
  1415. }
  1416. if (llt == OPTIMIZED_LibraryType) {
  1417. configString = "$<NOT:" + configString + ">";
  1418. }
  1419. return "$<" + configString + ":" + value + ">";
  1420. }
  1421. static std::string targetNameGenex(const std::string& lib)
  1422. {
  1423. return "$<TARGET_NAME:" + lib + ">";
  1424. }
  1425. bool cmTarget::PushTLLCommandTrace(TLLSignature signature,
  1426. cmListFileContext const& lfc)
  1427. {
  1428. bool ret = true;
  1429. if (!this->impl->TLLCommands.empty()) {
  1430. if (this->impl->TLLCommands.back().first != signature) {
  1431. ret = false;
  1432. }
  1433. }
  1434. if (this->impl->TLLCommands.empty() ||
  1435. this->impl->TLLCommands.back().second != lfc) {
  1436. this->impl->TLLCommands.emplace_back(signature, lfc);
  1437. }
  1438. return ret;
  1439. }
  1440. void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const
  1441. {
  1442. const char* sigString =
  1443. (sig == cmTarget::KeywordTLLSignature ? "keyword" : "plain");
  1444. s << "The uses of the " << sigString << " signature are here:\n";
  1445. for (auto const& cmd : this->impl->TLLCommands) {
  1446. if (cmd.first == sig) {
  1447. cmListFileContext lfc = cmd.second;
  1448. lfc.FilePath = cmSystemTools::RelativeIfUnder(
  1449. this->impl->Makefile->GetState()->GetSourceDirectory(), lfc.FilePath);
  1450. s << " * " << lfc << '\n';
  1451. }
  1452. }
  1453. }
  1454. std::string const& cmTarget::GetInstallPath() const
  1455. {
  1456. return this->impl->InstallPath;
  1457. }
  1458. void cmTarget::SetInstallPath(std::string const& name)
  1459. {
  1460. this->impl->InstallPath = name;
  1461. }
  1462. std::string const& cmTarget::GetRuntimeInstallPath() const
  1463. {
  1464. return this->impl->RuntimeInstallPath;
  1465. }
  1466. void cmTarget::SetRuntimeInstallPath(std::string const& name)
  1467. {
  1468. this->impl->RuntimeInstallPath = name;
  1469. }
  1470. bool cmTarget::GetHaveInstallRule() const
  1471. {
  1472. return this->impl->HaveInstallRule;
  1473. }
  1474. void cmTarget::SetHaveInstallRule(bool hir)
  1475. {
  1476. this->impl->HaveInstallRule = hir;
  1477. }
  1478. void cmTarget::AddInstallGenerator(cmInstallTargetGenerator* g)
  1479. {
  1480. this->impl->InstallGenerators.emplace_back(g);
  1481. }
  1482. std::vector<cmInstallTargetGenerator*> const& cmTarget::GetInstallGenerators()
  1483. const
  1484. {
  1485. return this->impl->InstallGenerators;
  1486. }
  1487. bool cmTarget::GetIsGeneratorProvided() const
  1488. {
  1489. return this->impl->IsGeneratorProvided;
  1490. }
  1491. void cmTarget::SetIsGeneratorProvided(bool igp)
  1492. {
  1493. this->impl->IsGeneratorProvided = igp;
  1494. }
  1495. cmTarget::LinkLibraryVectorType const& cmTarget::GetOriginalLinkLibraries()
  1496. const
  1497. {
  1498. return this->impl->OriginalLinkLibraries;
  1499. }
  1500. void cmTarget::AddLinkLibrary(cmMakefile& mf, std::string const& lib,
  1501. cmTargetLinkLibraryType llt)
  1502. {
  1503. cmTarget* tgt = mf.FindTargetToUse(lib);
  1504. {
  1505. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  1506. const std::string libName =
  1507. (isNonImportedTarget && llt != GENERAL_LibraryType)
  1508. ? targetNameGenex(lib)
  1509. : lib;
  1510. this->AppendProperty("LINK_LIBRARIES",
  1511. this->GetDebugGeneratorExpressions(libName, llt),
  1512. mf.GetBacktrace());
  1513. }
  1514. if (cmGeneratorExpression::Find(lib) != std::string::npos ||
  1515. (tgt &&
  1516. (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
  1517. tgt->GetType() == cmStateEnums::OBJECT_LIBRARY)) ||
  1518. (this->impl->Name == lib)) {
  1519. return;
  1520. }
  1521. this->impl->OriginalLinkLibraries.emplace_back(lib, llt);
  1522. // Add the explicit dependency information for libraries. This is
  1523. // simply a set of libraries separated by ";". There should always
  1524. // be a trailing ";". These library names are not canonical, in that
  1525. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  1526. // We shouldn't remove duplicates here because external libraries
  1527. // may be purposefully duplicated to handle recursive dependencies,
  1528. // and we removing one instance will break the link line. Duplicates
  1529. // will be appropriately eliminated at emit time.
  1530. if (this->impl->TargetType >= cmStateEnums::STATIC_LIBRARY &&
  1531. this->impl->TargetType <= cmStateEnums::MODULE_LIBRARY &&
  1532. (this->GetPolicyStatusCMP0073() == cmPolicies::OLD ||
  1533. this->GetPolicyStatusCMP0073() == cmPolicies::WARN)) {
  1534. std::string targetEntry = cmStrCat(this->impl->Name, "_LIB_DEPENDS");
  1535. std::string dependencies;
  1536. cmValue old_val = mf.GetDefinition(targetEntry);
  1537. if (old_val) {
  1538. dependencies += *old_val;
  1539. }
  1540. switch (llt) {
  1541. case GENERAL_LibraryType:
  1542. dependencies += "general";
  1543. break;
  1544. case DEBUG_LibraryType:
  1545. dependencies += "debug";
  1546. break;
  1547. case OPTIMIZED_LibraryType:
  1548. dependencies += "optimized";
  1549. break;
  1550. }
  1551. dependencies += ";";
  1552. dependencies += lib;
  1553. dependencies += ";";
  1554. mf.AddCacheDefinition(targetEntry, dependencies,
  1555. "Dependencies for the target", cmStateEnums::STATIC);
  1556. }
  1557. }
  1558. void cmTarget::AddSystemIncludeDirectories(const std::set<std::string>& incs)
  1559. {
  1560. this->impl->SystemIncludeDirectories.insert(incs.begin(), incs.end());
  1561. }
  1562. std::set<std::string> const& cmTarget::GetSystemIncludeDirectories() const
  1563. {
  1564. return this->impl->SystemIncludeDirectories;
  1565. }
  1566. void cmTarget::AddInstallIncludeDirectories(cmTargetExport const& te,
  1567. cmStringRange const& incs)
  1568. {
  1569. std::copy(
  1570. incs.begin(), incs.end(),
  1571. std::back_inserter(this->impl->InstallIncludeDirectoriesEntries[&te]));
  1572. }
  1573. cmStringRange cmTarget::GetInstallIncludeDirectoriesEntries(
  1574. cmTargetExport const& te) const
  1575. {
  1576. auto i = this->impl->InstallIncludeDirectoriesEntries.find(&te);
  1577. if (i == this->impl->InstallIncludeDirectoriesEntries.end()) {
  1578. decltype(i->second) empty;
  1579. return cmMakeRange(empty);
  1580. }
  1581. return cmMakeRange(i->second);
  1582. }
  1583. cmBTStringRange cmTarget::GetIncludeDirectoriesEntries() const
  1584. {
  1585. return cmMakeRange(this->impl->IncludeDirectories.Entries);
  1586. }
  1587. cmBTStringRange cmTarget::GetCompileOptionsEntries() const
  1588. {
  1589. return cmMakeRange(this->impl->CompileOptions.Entries);
  1590. }
  1591. cmBTStringRange cmTarget::GetCompileFeaturesEntries() const
  1592. {
  1593. return cmMakeRange(this->impl->CompileFeatures.Entries);
  1594. }
  1595. cmBTStringRange cmTarget::GetCompileDefinitionsEntries() const
  1596. {
  1597. return cmMakeRange(this->impl->CompileDefinitions.Entries);
  1598. }
  1599. cmBTStringRange cmTarget::GetPrecompileHeadersEntries() const
  1600. {
  1601. return cmMakeRange(this->impl->PrecompileHeaders.Entries);
  1602. }
  1603. cmBTStringRange cmTarget::GetSourceEntries() const
  1604. {
  1605. return cmMakeRange(this->impl->Sources.Entries);
  1606. }
  1607. cmBTStringRange cmTarget::GetLinkOptionsEntries() const
  1608. {
  1609. return cmMakeRange(this->impl->LinkOptions.Entries);
  1610. }
  1611. cmBTStringRange cmTarget::GetLinkDirectoriesEntries() const
  1612. {
  1613. return cmMakeRange(this->impl->LinkDirectories.Entries);
  1614. }
  1615. cmBTStringRange cmTarget::GetLinkImplementationEntries() const
  1616. {
  1617. return cmMakeRange(this->impl->LinkLibraries.Entries);
  1618. }
  1619. cmBTStringRange cmTarget::GetLinkInterfaceEntries() const
  1620. {
  1621. return cmMakeRange(this->impl->InterfaceLinkLibraries.Entries);
  1622. }
  1623. cmBTStringRange cmTarget::GetLinkInterfaceDirectEntries() const
  1624. {
  1625. return cmMakeRange(this->impl->InterfaceLinkLibrariesDirect.Entries);
  1626. }
  1627. cmBTStringRange cmTarget::GetLinkInterfaceDirectExcludeEntries() const
  1628. {
  1629. return cmMakeRange(this->impl->InterfaceLinkLibrariesDirectExclude.Entries);
  1630. }
  1631. void cmTarget::CopyPolicyStatuses(cmTarget const* tgt)
  1632. {
  1633. // Normal targets cannot be the target of a copy.
  1634. assert(!this->IsNormal());
  1635. // Imported targets cannot be the target of a copy.
  1636. assert(!this->IsImported());
  1637. // Only imported targets can be the source of a copy.
  1638. assert(tgt->IsImported());
  1639. this->impl->PolicyMap = tgt->impl->PolicyMap;
  1640. this->impl->TemplateTarget = tgt;
  1641. }
  1642. void cmTarget::CopyImportedCxxModulesEntries(cmTarget const* tgt)
  1643. {
  1644. // Normal targets cannot be the target of a copy.
  1645. assert(!this->IsNormal());
  1646. // Imported targets cannot be the target of a copy.
  1647. assert(!this->IsImported());
  1648. // Only imported targets can be the source of a copy.
  1649. assert(tgt->IsImported());
  1650. this->impl->IncludeDirectories.Entries.clear();
  1651. this->impl->IncludeDirectories.CopyFromEntries(
  1652. cmMakeRange(tgt->impl->ImportedCxxModulesIncludeDirectories.Entries));
  1653. this->impl->CompileDefinitions.Entries.clear();
  1654. this->impl->CompileDefinitions.CopyFromEntries(
  1655. cmMakeRange(tgt->impl->ImportedCxxModulesCompileDefinitions.Entries));
  1656. this->impl->CompileFeatures.Entries.clear();
  1657. this->impl->CompileFeatures.CopyFromEntries(
  1658. cmMakeRange(tgt->impl->ImportedCxxModulesCompileFeatures.Entries));
  1659. this->impl->CompileOptions.Entries.clear();
  1660. this->impl->CompileOptions.CopyFromEntries(
  1661. cmMakeRange(tgt->impl->ImportedCxxModulesCompileOptions.Entries));
  1662. this->impl->LinkLibraries.Entries.clear();
  1663. this->impl->LinkLibraries.CopyFromEntries(
  1664. cmMakeRange(tgt->impl->ImportedCxxModulesLinkLibraries.Entries));
  1665. // Copy the C++ module fileset entries from `tgt`'s `INTERFACE` to this
  1666. // target's `PRIVATE`.
  1667. this->impl->CxxModulesFileSets.SelfEntries.Entries.clear();
  1668. this->impl->CxxModulesFileSets.SelfEntries.Entries =
  1669. tgt->impl->CxxModulesFileSets.InterfaceEntries.Entries;
  1670. }
  1671. void cmTarget::CopyImportedCxxModulesProperties(cmTarget const* tgt)
  1672. {
  1673. // Normal targets cannot be the target of a copy.
  1674. assert(!this->IsNormal());
  1675. // Imported targets cannot be the target of a copy.
  1676. assert(!this->IsImported());
  1677. // Only imported targets can be the source of a copy.
  1678. assert(tgt->IsImported());
  1679. // The list of properties that are relevant here include:
  1680. // - compilation-specific properties for any language or platform
  1681. // - compilation-specific properties for C++
  1682. // - build graph-specific properties that affect compilation
  1683. // - IDE metadata properties
  1684. // - static analysis properties
  1685. static const std::string propertiesToCopy[] = {
  1686. // Compilation properties
  1687. "DEFINE_SYMBOL",
  1688. "DEPRECATION",
  1689. "NO_SYSTEM_FROM_IMPORTED",
  1690. "POSITION_INDEPENDENT_CODE",
  1691. "VISIBILITY_INLINES_HIDDEN",
  1692. // -- Platforms
  1693. // ---- Android
  1694. "ANDROID_API",
  1695. "ANDROID_API_MIN",
  1696. "ANDROID_ARCH",
  1697. "ANDROID_STL_TYPE",
  1698. // ---- macOS
  1699. "OSX_ARCHITECTURES",
  1700. // ---- Windows
  1701. "MSVC_DEBUG_INFORMATION_FORMAT",
  1702. "MSVC_RUNTIME_LIBRARY",
  1703. "VS_PLATFORM_TOOLSET",
  1704. // ---- OpenWatcom
  1705. "WATCOM_RUNTIME_LIBRARY",
  1706. // -- Language
  1707. // ---- C++
  1708. "CXX_COMPILER_LAUNCHER",
  1709. "CXX_STANDARD",
  1710. "CXX_STANDARD_REQUIRED",
  1711. "CXX_EXTENSIONS",
  1712. "CXX_VISIBILITY_PRESET",
  1713. "CXX_MODULE_STD",
  1714. // Static analysis
  1715. "CXX_CLANG_TIDY",
  1716. "CXX_CLANG_TIDY_EXPORT_FIXES_DIR",
  1717. "CXX_CPPLINT",
  1718. "CXX_CPPCHECK",
  1719. "CXX_INCLUDE_WHAT_YOU_USE",
  1720. // Build graph properties
  1721. "EXCLUDE_FROM_ALL",
  1722. "EXCLUDE_FROM_DEFAULT_BUILD",
  1723. "OPTIMIZE_DEPENDENCIES",
  1724. // -- Ninja
  1725. "JOB_POOL_COMPILE",
  1726. // -- Visual Studio
  1727. "VS_NO_COMPILE_BATCHING",
  1728. "VS_PROJECT_IMPORT",
  1729. // Metadata
  1730. "EchoString",
  1731. "EXPORT_COMPILE_COMMANDS",
  1732. // Do *not* copy this property; it should be re-initialized at synthesis
  1733. // time from the `CMAKE_EXPORT_BUILD_DATABASE` variable as `IMPORTED`
  1734. // targets ignore the property initialization.
  1735. // "EXPORT_BUILD_DATABASE",
  1736. "FOLDER",
  1737. "LABELS",
  1738. "PROJECT_LABEL",
  1739. "SYSTEM",
  1740. };
  1741. auto copyProperty = [this, tgt](std::string const& prop) -> cmValue {
  1742. cmValue value = tgt->GetProperty(prop);
  1743. // Always set the property; it may have been explicitly unset.
  1744. this->SetProperty(prop, value);
  1745. return value;
  1746. };
  1747. for (auto const& prop : propertiesToCopy) {
  1748. copyProperty(prop);
  1749. }
  1750. static const cm::static_string_view perConfigPropertiesToCopy[] = {
  1751. "EXCLUDE_FROM_DEFAULT_BUILD_"_s,
  1752. "IMPORTED_CXX_MODULES_"_s,
  1753. "MAP_IMPORTED_CONFIG_"_s,
  1754. "OSX_ARCHITECTURES_"_s,
  1755. };
  1756. std::vector<std::string> configNames =
  1757. this->impl->Makefile->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
  1758. for (std::string const& configName : configNames) {
  1759. std::string configUpper = cmSystemTools::UpperCase(configName);
  1760. for (auto const& perConfigProp : perConfigPropertiesToCopy) {
  1761. copyProperty(cmStrCat(perConfigProp, configUpper));
  1762. }
  1763. }
  1764. if (this->GetGlobalGenerator()->IsXcode()) {
  1765. cmValue xcodeGenerateScheme = copyProperty("XCODE_GENERATE_SCHEME");
  1766. // TODO: Make sure these show up on the imported target in the first place
  1767. // XCODE_ATTRIBUTE_???
  1768. if (xcodeGenerateScheme.IsOn()) {
  1769. #ifdef __APPLE__
  1770. static const std::string xcodeSchemePropertiesToCopy[] = {
  1771. // FIXME: Do all of these apply? Do they matter?
  1772. "XCODE_SCHEME_ADDRESS_SANITIZER",
  1773. "XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN",
  1774. "XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER",
  1775. "XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS",
  1776. "XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE",
  1777. "XCODE_SCHEME_ENABLE_GPU_API_VALIDATION",
  1778. "XCODE_SCHEME_ENABLE_GPU_SHADER_VALIDATION",
  1779. "XCODE_SCHEME_GUARD_MALLOC",
  1780. "XCODE_SCHEME_LAUNCH_CONFIGURATION",
  1781. "XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP",
  1782. "XCODE_SCHEME_MALLOC_GUARD_EDGES",
  1783. "XCODE_SCHEME_MALLOC_SCRIBBLE",
  1784. "XCODE_SCHEME_MALLOC_STACK",
  1785. "XCODE_SCHEME_THREAD_SANITIZER",
  1786. "XCODE_SCHEME_THREAD_SANITIZER_STOP",
  1787. "XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER",
  1788. "XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP",
  1789. "XCODE_SCHEME_ZOMBIE_OBJECTS",
  1790. };
  1791. for (auto const& xcodeProperty : xcodeSchemePropertiesToCopy) {
  1792. copyProperty(xcodeProperty);
  1793. }
  1794. #endif
  1795. }
  1796. }
  1797. }
  1798. cmBTStringRange cmTarget::GetHeaderSetsEntries() const
  1799. {
  1800. return cmMakeRange(this->impl->HeadersFileSets.SelfEntries.Entries);
  1801. }
  1802. cmBTStringRange cmTarget::GetCxxModuleSetsEntries() const
  1803. {
  1804. return cmMakeRange(this->impl->CxxModulesFileSets.SelfEntries.Entries);
  1805. }
  1806. cmBTStringRange cmTarget::GetInterfaceHeaderSetsEntries() const
  1807. {
  1808. return cmMakeRange(this->impl->HeadersFileSets.InterfaceEntries.Entries);
  1809. }
  1810. cmBTStringRange cmTarget::GetInterfaceCxxModuleSetsEntries() const
  1811. {
  1812. return cmMakeRange(this->impl->CxxModulesFileSets.InterfaceEntries.Entries);
  1813. }
  1814. namespace {
  1815. #define MAKE_PROP(PROP) const std::string prop##PROP = #PROP
  1816. MAKE_PROP(C_STANDARD);
  1817. MAKE_PROP(CXX_STANDARD);
  1818. MAKE_PROP(CUDA_STANDARD);
  1819. MAKE_PROP(HIP_STANDARD);
  1820. MAKE_PROP(OBJC_STANDARD);
  1821. MAKE_PROP(OBJCXX_STANDARD);
  1822. MAKE_PROP(COMPILE_DEFINITIONS);
  1823. MAKE_PROP(COMPILE_FEATURES);
  1824. MAKE_PROP(COMPILE_OPTIONS);
  1825. MAKE_PROP(PRECOMPILE_HEADERS);
  1826. MAKE_PROP(PRECOMPILE_HEADERS_REUSE_FROM);
  1827. MAKE_PROP(CUDA_CUBIN_COMPILATION);
  1828. MAKE_PROP(CUDA_FATBIN_COMPILATION);
  1829. MAKE_PROP(CUDA_OPTIX_COMPILATION);
  1830. MAKE_PROP(CUDA_PTX_COMPILATION);
  1831. MAKE_PROP(IMPORTED);
  1832. MAKE_PROP(IMPORTED_GLOBAL);
  1833. MAKE_PROP(INCLUDE_DIRECTORIES);
  1834. MAKE_PROP(LINK_OPTIONS);
  1835. MAKE_PROP(IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES);
  1836. MAKE_PROP(IMPORTED_CXX_MODULES_COMPILE_DEFINITIONS);
  1837. MAKE_PROP(IMPORTED_CXX_MODULES_COMPILE_FEATURES);
  1838. MAKE_PROP(IMPORTED_CXX_MODULES_COMPILE_OPTIONS);
  1839. MAKE_PROP(IMPORTED_CXX_MODULES_LINK_LIBRARIES);
  1840. MAKE_PROP(LINK_DIRECTORIES);
  1841. MAKE_PROP(LINK_LIBRARIES);
  1842. MAKE_PROP(MANUALLY_ADDED_DEPENDENCIES);
  1843. MAKE_PROP(NAME);
  1844. MAKE_PROP(SOURCES);
  1845. MAKE_PROP(TYPE);
  1846. MAKE_PROP(BINARY_DIR);
  1847. MAKE_PROP(SOURCE_DIR);
  1848. MAKE_PROP(FALSE);
  1849. MAKE_PROP(TRUE);
  1850. MAKE_PROP(INTERFACE_LINK_LIBRARIES);
  1851. MAKE_PROP(INTERFACE_LINK_LIBRARIES_DIRECT);
  1852. MAKE_PROP(INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE);
  1853. #undef MAKE_PROP
  1854. }
  1855. namespace {
  1856. enum class ReadOnlyCondition
  1857. {
  1858. All,
  1859. Imported,
  1860. NonImported,
  1861. };
  1862. struct ReadOnlyProperty
  1863. {
  1864. ReadOnlyProperty(ReadOnlyCondition cond)
  1865. : Condition{ cond }
  1866. {
  1867. }
  1868. ReadOnlyProperty(ReadOnlyCondition cond, cmPolicies::PolicyID id)
  1869. : Condition{ cond }
  1870. , Policy{ id }
  1871. {
  1872. }
  1873. ReadOnlyCondition Condition;
  1874. cm::optional<cmPolicies::PolicyID> Policy;
  1875. std::string message(const std::string& prop, cmTarget* target) const
  1876. {
  1877. std::string msg;
  1878. if (this->Condition == ReadOnlyCondition::All) {
  1879. msg = " property is read-only for target(\"";
  1880. } else if (this->Condition == ReadOnlyCondition::Imported) {
  1881. msg = " property can't be set on imported targets(\"";
  1882. } else if (this->Condition == ReadOnlyCondition::NonImported) {
  1883. msg = " property can't be set on non-imported targets(\"";
  1884. }
  1885. return cmStrCat(prop, msg, target->GetName(), "\")\n");
  1886. }
  1887. bool isReadOnly(const std::string& prop, cmMakefile* context,
  1888. cmTarget* target) const
  1889. {
  1890. auto importedTarget = target->IsImported();
  1891. bool matchingCondition = true;
  1892. if ((!importedTarget && this->Condition == ReadOnlyCondition::Imported) ||
  1893. (importedTarget &&
  1894. this->Condition == ReadOnlyCondition::NonImported)) {
  1895. matchingCondition = false;
  1896. }
  1897. if (!matchingCondition) {
  1898. // Not read-only in this scenario
  1899. return false;
  1900. }
  1901. bool readOnly = true;
  1902. if (!this->Policy) {
  1903. // No policy associated, so is always read-only
  1904. context->IssueMessage(MessageType::FATAL_ERROR,
  1905. this->message(prop, target));
  1906. } else {
  1907. switch (target->GetPolicyStatus(*this->Policy)) {
  1908. case cmPolicies::WARN:
  1909. context->IssueMessage(
  1910. MessageType::AUTHOR_WARNING,
  1911. cmPolicies::GetPolicyWarning(cmPolicies::CMP0160) + "\n" +
  1912. this->message(prop, target));
  1913. CM_FALLTHROUGH;
  1914. case cmPolicies::OLD:
  1915. readOnly = false;
  1916. break;
  1917. case cmPolicies::NEW:
  1918. context->IssueMessage(MessageType::FATAL_ERROR,
  1919. this->message(prop, target));
  1920. break;
  1921. }
  1922. }
  1923. return readOnly;
  1924. }
  1925. };
  1926. bool IsSetableProperty(cmMakefile* context, cmTarget* target,
  1927. const std::string& prop)
  1928. {
  1929. using ROC = ReadOnlyCondition;
  1930. static std::unordered_map<std::string, ReadOnlyProperty> const readOnlyProps{
  1931. { "EXPORT_NAME", { ROC::Imported } },
  1932. { "HEADER_SETS", { ROC::All } },
  1933. { "IMPORTED_GLOBAL", { ROC::NonImported } },
  1934. { "INTERFACE_HEADER_SETS", { ROC::All } },
  1935. { "MANUALLY_ADDED_DEPENDENCIES", { ROC::All } },
  1936. { "NAME", { ROC::All } },
  1937. { "SOURCES", { ROC::Imported } },
  1938. { "TYPE", { ROC::All } },
  1939. { "ALIAS_GLOBAL", { ROC::All, cmPolicies::CMP0160 } },
  1940. { "BINARY_DIR", { ROC::All, cmPolicies::CMP0160 } },
  1941. { "CXX_MODULE_SETS", { ROC::All, cmPolicies::CMP0160 } },
  1942. { "IMPORTED", { ROC::All, cmPolicies::CMP0160 } },
  1943. { "INTERFACE_CXX_MODULE_SETS", { ROC::All, cmPolicies::CMP0160 } },
  1944. { "LOCATION", { ROC::All, cmPolicies::CMP0160 } },
  1945. { "LOCATION_CONFIG", { ROC::All, cmPolicies::CMP0160 } },
  1946. { "SOURCE_DIR", { ROC::All, cmPolicies::CMP0160 } }
  1947. };
  1948. auto it = readOnlyProps.find(prop);
  1949. if (it != readOnlyProps.end()) {
  1950. return !(it->second.isReadOnly(prop, context, target));
  1951. }
  1952. return true;
  1953. }
  1954. }
  1955. void cmTarget::SetProperty(const std::string& prop, cmValue value)
  1956. {
  1957. if (!IsSetableProperty(this->impl->Makefile, this, prop)) {
  1958. return;
  1959. }
  1960. UsageRequirementProperty* usageRequirements[] = {
  1961. &this->impl->IncludeDirectories,
  1962. &this->impl->CompileOptions,
  1963. &this->impl->CompileFeatures,
  1964. &this->impl->CompileDefinitions,
  1965. &this->impl->PrecompileHeaders,
  1966. &this->impl->Sources,
  1967. &this->impl->LinkOptions,
  1968. &this->impl->LinkDirectories,
  1969. &this->impl->LinkLibraries,
  1970. &this->impl->InterfaceLinkLibraries,
  1971. &this->impl->InterfaceLinkLibrariesDirect,
  1972. &this->impl->InterfaceLinkLibrariesDirectExclude,
  1973. &this->impl->ImportedCxxModulesIncludeDirectories,
  1974. &this->impl->ImportedCxxModulesCompileDefinitions,
  1975. &this->impl->ImportedCxxModulesCompileFeatures,
  1976. &this->impl->ImportedCxxModulesCompileOptions,
  1977. &this->impl->ImportedCxxModulesLinkLibraries,
  1978. };
  1979. for (auto* usageRequirement : usageRequirements) {
  1980. if (usageRequirement->Write(this->impl.get(), {}, prop, value,
  1981. UsageRequirementProperty::Action::Set)) {
  1982. return;
  1983. }
  1984. }
  1985. FileSetType* fileSetTypes[] = {
  1986. &this->impl->HeadersFileSets,
  1987. &this->impl->CxxModulesFileSets,
  1988. };
  1989. for (auto* fileSetType : fileSetTypes) {
  1990. if (fileSetType->WriteProperties(this, this->impl.get(), prop, value,
  1991. FileSetType::Action::Set)) {
  1992. return;
  1993. }
  1994. }
  1995. if (prop == propIMPORTED_GLOBAL) {
  1996. if (!value.IsOn()) {
  1997. std::ostringstream e;
  1998. e << "IMPORTED_GLOBAL property can't be set to FALSE on targets (\""
  1999. << this->impl->Name << "\")\n";
  2000. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  2001. return;
  2002. }
  2003. /* no need to change anything if value does not change */
  2004. if (!this->IsImportedGloballyVisible()) {
  2005. this->impl->TargetVisibility = Visibility::ImportedGlobally;
  2006. this->GetGlobalGenerator()->IndexTarget(this);
  2007. }
  2008. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME") &&
  2009. !this->impl->CheckImportedLibName(
  2010. prop,
  2011. value ? value
  2012. : std::string{})) { // NOLINT(bugprone-branch-clone)
  2013. /* error was reported by check method */
  2014. } else if (prop == propCUDA_CUBIN_COMPILATION ||
  2015. prop == propCUDA_FATBIN_COMPILATION ||
  2016. prop == propCUDA_OPTIX_COMPILATION ||
  2017. prop == propCUDA_PTX_COMPILATION) {
  2018. auto const& compiler =
  2019. this->impl->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID");
  2020. auto const& compilerVersion =
  2021. this->impl->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_VERSION");
  2022. if (this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  2023. auto e =
  2024. cmStrCat(prop, " property can only be applied to OBJECT targets(",
  2025. this->impl->Name, ")\n");
  2026. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e);
  2027. return;
  2028. }
  2029. const bool flag_found =
  2030. (prop == propCUDA_PTX_COMPILATION &&
  2031. this->impl->Makefile->GetDefinition("_CMAKE_CUDA_PTX_FLAG")) ||
  2032. (prop == propCUDA_CUBIN_COMPILATION &&
  2033. this->impl->Makefile->GetDefinition("_CMAKE_CUDA_CUBIN_FLAG")) ||
  2034. (prop == propCUDA_FATBIN_COMPILATION &&
  2035. this->impl->Makefile->GetDefinition("_CMAKE_CUDA_FATBIN_FLAG")) ||
  2036. (prop == propCUDA_OPTIX_COMPILATION &&
  2037. this->impl->Makefile->GetDefinition("_CMAKE_CUDA_OPTIX_FLAG"));
  2038. if (flag_found) {
  2039. this->impl->Properties.SetProperty(prop, value);
  2040. } else {
  2041. auto e = cmStrCat(prop, " property is not supported by ", compiler,
  2042. " compiler version ", compilerVersion, ".");
  2043. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e);
  2044. return;
  2045. }
  2046. } else if (prop == propPRECOMPILE_HEADERS_REUSE_FROM) {
  2047. if (this->GetProperty("PRECOMPILE_HEADERS")) {
  2048. std::ostringstream e;
  2049. e << "PRECOMPILE_HEADERS property is already set on target (\""
  2050. << this->impl->Name << "\")\n";
  2051. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  2052. return;
  2053. }
  2054. auto* reusedTarget = this->impl->Makefile->GetCMakeInstance()
  2055. ->GetGlobalGenerator()
  2056. ->FindTarget(value);
  2057. if (!reusedTarget) {
  2058. const std::string e(
  2059. "PRECOMPILE_HEADERS_REUSE_FROM set with non existing target");
  2060. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e);
  2061. return;
  2062. }
  2063. std::string reusedFrom = reusedTarget->GetSafeProperty(prop);
  2064. if (reusedFrom.empty()) {
  2065. reusedFrom = *value;
  2066. }
  2067. this->impl->Properties.SetProperty(prop, reusedFrom);
  2068. reusedTarget->SetProperty("COMPILE_PDB_NAME", reusedFrom);
  2069. reusedTarget->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY",
  2070. cmStrCat(reusedFrom, ".dir/"));
  2071. cmValue tmp = reusedTarget->GetProperty("COMPILE_PDB_NAME");
  2072. this->SetProperty("COMPILE_PDB_NAME", tmp);
  2073. this->AddUtility(reusedFrom, false, this->impl->Makefile);
  2074. } else if (prop == propC_STANDARD || prop == propCXX_STANDARD ||
  2075. prop == propCUDA_STANDARD || prop == propHIP_STANDARD ||
  2076. prop == propOBJC_STANDARD || prop == propOBJCXX_STANDARD) {
  2077. if (value) {
  2078. this->impl->LanguageStandardProperties[prop] =
  2079. BTs<std::string>(value, this->impl->Makefile->GetBacktrace());
  2080. } else {
  2081. this->impl->LanguageStandardProperties.erase(prop);
  2082. }
  2083. } else {
  2084. this->impl->Properties.SetProperty(prop, value);
  2085. }
  2086. }
  2087. void cmTarget::AppendProperty(const std::string& prop,
  2088. const std::string& value,
  2089. cm::optional<cmListFileBacktrace> const& bt,
  2090. bool asString)
  2091. {
  2092. if (!IsSetableProperty(this->impl->Makefile, this, prop)) {
  2093. return;
  2094. }
  2095. if (prop == "IMPORTED_GLOBAL") {
  2096. this->impl->Makefile->IssueMessage(
  2097. MessageType::FATAL_ERROR,
  2098. cmStrCat("IMPORTED_GLOBAL property can't be appended, only set on "
  2099. "imported targets (\"",
  2100. this->impl->Name, "\")\n"));
  2101. }
  2102. if (prop == propPRECOMPILE_HEADERS &&
  2103. this->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM")) {
  2104. this->impl->Makefile->IssueMessage(
  2105. MessageType::FATAL_ERROR,
  2106. cmStrCat(
  2107. "PRECOMPILE_HEADERS_REUSE_FROM property is already set on target (\"",
  2108. this->impl->Name, "\")\n"));
  2109. return;
  2110. }
  2111. UsageRequirementProperty* usageRequirements[] = {
  2112. &this->impl->IncludeDirectories,
  2113. &this->impl->CompileOptions,
  2114. &this->impl->CompileFeatures,
  2115. &this->impl->CompileDefinitions,
  2116. &this->impl->PrecompileHeaders,
  2117. &this->impl->Sources,
  2118. &this->impl->LinkOptions,
  2119. &this->impl->LinkDirectories,
  2120. &this->impl->LinkLibraries,
  2121. &this->impl->InterfaceLinkLibraries,
  2122. &this->impl->InterfaceLinkLibrariesDirect,
  2123. &this->impl->InterfaceLinkLibrariesDirectExclude,
  2124. &this->impl->ImportedCxxModulesIncludeDirectories,
  2125. &this->impl->ImportedCxxModulesCompileDefinitions,
  2126. &this->impl->ImportedCxxModulesCompileFeatures,
  2127. &this->impl->ImportedCxxModulesCompileOptions,
  2128. &this->impl->ImportedCxxModulesLinkLibraries,
  2129. };
  2130. for (auto* usageRequirement : usageRequirements) {
  2131. if (usageRequirement->Write(this->impl.get(), bt, prop, cmValue(value),
  2132. UsageRequirementProperty::Action::Append)) {
  2133. return;
  2134. }
  2135. }
  2136. FileSetType* fileSetTypes[] = {
  2137. &this->impl->HeadersFileSets,
  2138. &this->impl->CxxModulesFileSets,
  2139. };
  2140. for (auto* fileSetType : fileSetTypes) {
  2141. if (fileSetType->WriteProperties(this, this->impl.get(), prop, value,
  2142. FileSetType::Action::Append)) {
  2143. return;
  2144. }
  2145. }
  2146. if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) {
  2147. this->impl->Makefile->IssueMessage(
  2148. MessageType::FATAL_ERROR, prop + " property may not be APPENDed.");
  2149. } else if (prop == "C_STANDARD" || prop == "CXX_STANDARD" ||
  2150. prop == "CUDA_STANDARD" || prop == "HIP_STANDARD" ||
  2151. prop == "OBJC_STANDARD" || prop == "OBJCXX_STANDARD") {
  2152. this->impl->Makefile->IssueMessage(
  2153. MessageType::FATAL_ERROR, prop + " property may not be appended.");
  2154. } else {
  2155. this->impl->Properties.AppendProperty(prop, value, asString);
  2156. }
  2157. }
  2158. template <typename ValueType>
  2159. void cmTargetInternals::AddDirectoryToFileSet(cmTarget* self,
  2160. std::string const& fileSetName,
  2161. ValueType value,
  2162. cm::string_view fileSetType,
  2163. cm::string_view description,
  2164. FileSetType::Action action)
  2165. {
  2166. auto* fileSet = self->GetFileSet(fileSetName);
  2167. if (!fileSet) {
  2168. this->Makefile->IssueMessage(
  2169. MessageType::FATAL_ERROR,
  2170. cmStrCat(description, "has not yet been created."));
  2171. return;
  2172. }
  2173. if (fileSet->GetType() != fileSetType) {
  2174. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  2175. cmStrCat("File set \"", fileSetName,
  2176. "\" is not of type \"", fileSetType,
  2177. "\"."));
  2178. return;
  2179. }
  2180. if (action == FileSetType::Action::Set) {
  2181. fileSet->ClearDirectoryEntries();
  2182. }
  2183. if (cmNonempty(value)) {
  2184. fileSet->AddDirectoryEntry(
  2185. BT<std::string>(value, this->Makefile->GetBacktrace()));
  2186. }
  2187. }
  2188. template <typename ValueType>
  2189. void cmTargetInternals::AddPathToFileSet(cmTarget* self,
  2190. std::string const& fileSetName,
  2191. ValueType value,
  2192. cm::string_view fileSetType,
  2193. cm::string_view description,
  2194. FileSetType::Action action)
  2195. {
  2196. auto* fileSet = self->GetFileSet(fileSetName);
  2197. if (!fileSet) {
  2198. this->Makefile->IssueMessage(
  2199. MessageType::FATAL_ERROR,
  2200. cmStrCat(description, "has not yet been created."));
  2201. return;
  2202. }
  2203. if (fileSet->GetType() != fileSetType) {
  2204. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  2205. cmStrCat("File set \"", fileSetName,
  2206. "\" is not of type \"", fileSetType,
  2207. "\"."));
  2208. return;
  2209. }
  2210. if (action == FileSetType::Action::Set) {
  2211. fileSet->ClearFileEntries();
  2212. }
  2213. if (cmNonempty(value)) {
  2214. fileSet->AddFileEntry(
  2215. BT<std::string>(value, this->Makefile->GetBacktrace()));
  2216. }
  2217. }
  2218. cmValue cmTargetInternals::GetFileSetDirectories(
  2219. cmTarget const* self, std::string const& fileSetName,
  2220. cm::string_view fileSetType) const
  2221. {
  2222. auto const* fileSet = self->GetFileSet(fileSetName);
  2223. if (!fileSet) {
  2224. return nullptr;
  2225. }
  2226. if (fileSet->GetType() != fileSetType) {
  2227. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  2228. cmStrCat("File set \"", fileSetName,
  2229. "\" is not of type \"", fileSetType,
  2230. "\"."));
  2231. return nullptr;
  2232. }
  2233. static std::string output;
  2234. output = cmList::to_string(fileSet->GetDirectoryEntries());
  2235. return cmValue(output);
  2236. }
  2237. cmValue cmTargetInternals::GetFileSetPaths(cmTarget const* self,
  2238. std::string const& fileSetName,
  2239. cm::string_view fileSetType) const
  2240. {
  2241. auto const* fileSet = self->GetFileSet(fileSetName);
  2242. if (!fileSet) {
  2243. return nullptr;
  2244. }
  2245. if (fileSet->GetType() != fileSetType) {
  2246. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  2247. cmStrCat("File set \"", fileSetName,
  2248. "\" is not of type \"", fileSetType,
  2249. "\"."));
  2250. return nullptr;
  2251. }
  2252. static std::string output;
  2253. output = cmList::to_string(fileSet->GetFileEntries());
  2254. return cmValue(output);
  2255. }
  2256. void cmTarget::AppendBuildInterfaceIncludes()
  2257. {
  2258. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  2259. this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  2260. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  2261. this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  2262. !this->IsExecutableWithExports()) {
  2263. return;
  2264. }
  2265. if (this->impl->BuildInterfaceIncludesAppended) {
  2266. return;
  2267. }
  2268. this->impl->BuildInterfaceIncludesAppended = true;
  2269. if (this->impl->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE")) {
  2270. std::string dirs = this->impl->Makefile->GetCurrentBinaryDirectory();
  2271. if (!dirs.empty()) {
  2272. dirs += ';';
  2273. }
  2274. dirs += this->impl->Makefile->GetCurrentSourceDirectory();
  2275. if (!dirs.empty()) {
  2276. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  2277. ("$<BUILD_INTERFACE:" + dirs + ">"));
  2278. }
  2279. }
  2280. }
  2281. namespace {
  2282. bool CheckLinkLibraryPattern(UsageRequirementProperty const& usage,
  2283. cmake* context)
  2284. {
  2285. // Look for <LINK_LIBRARY:> and </LINK_LIBRARY:> internal tags
  2286. static cmsys::RegularExpression linkPattern(
  2287. "(^|;)(</?LINK_(LIBRARY|GROUP):[^;>]*>)(;|$)");
  2288. bool isValid = true;
  2289. for (const auto& item : usage.Entries) {
  2290. if (!linkPattern.find(item.Value)) {
  2291. continue;
  2292. }
  2293. isValid = false;
  2294. // Report an error.
  2295. context->IssueMessage(
  2296. MessageType::FATAL_ERROR,
  2297. cmStrCat(
  2298. "Property ", usage.Name, " contains the invalid item \"",
  2299. linkPattern.match(2), "\". The ", usage.Name,
  2300. " property may contain the generator-expression \"$<LINK_",
  2301. linkPattern.match(3),
  2302. ":...>\" which may be used to specify how the libraries are linked."),
  2303. item.Backtrace);
  2304. }
  2305. return isValid;
  2306. }
  2307. }
  2308. void cmTarget::FinalizeTargetConfiguration(
  2309. const cmBTStringRange& noConfigCompileDefinitions,
  2310. cm::optional<std::map<std::string, cmValue>>& perConfigCompileDefinitions)
  2311. {
  2312. if (this->GetType() == cmStateEnums::GLOBAL_TARGET) {
  2313. return;
  2314. }
  2315. if (!CheckLinkLibraryPattern(this->impl->LinkLibraries,
  2316. this->GetMakefile()->GetCMakeInstance()) ||
  2317. !CheckLinkLibraryPattern(this->impl->InterfaceLinkLibraries,
  2318. this->GetMakefile()->GetCMakeInstance()) ||
  2319. !CheckLinkLibraryPattern(this->impl->InterfaceLinkLibrariesDirect,
  2320. this->GetMakefile()->GetCMakeInstance())) {
  2321. return;
  2322. }
  2323. this->AppendBuildInterfaceIncludes();
  2324. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  2325. return;
  2326. }
  2327. for (auto const& def : noConfigCompileDefinitions) {
  2328. this->InsertCompileDefinition(def);
  2329. }
  2330. auto* mf = this->GetMakefile();
  2331. cmPolicies::PolicyStatus polSt = mf->GetPolicyStatus(cmPolicies::CMP0043);
  2332. if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) {
  2333. if (perConfigCompileDefinitions) {
  2334. for (auto const& it : *perConfigCompileDefinitions) {
  2335. if (cmValue val = it.second) {
  2336. this->AppendProperty(it.first, *val);
  2337. }
  2338. }
  2339. } else {
  2340. perConfigCompileDefinitions.emplace();
  2341. std::vector<std::string> configs =
  2342. mf->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
  2343. for (std::string const& c : configs) {
  2344. std::string defPropName =
  2345. cmStrCat("COMPILE_DEFINITIONS_", cmSystemTools::UpperCase(c));
  2346. cmValue val = mf->GetProperty(defPropName);
  2347. (*perConfigCompileDefinitions)[defPropName] = val;
  2348. if (val) {
  2349. this->AppendProperty(defPropName, *val);
  2350. }
  2351. }
  2352. }
  2353. }
  2354. }
  2355. void cmTarget::InsertInclude(BT<std::string> const& entry, bool before)
  2356. {
  2357. this->impl->IncludeDirectories.WriteDirect(
  2358. entry,
  2359. before ? UsageRequirementProperty::Action::Prepend
  2360. : UsageRequirementProperty::Action::Append);
  2361. }
  2362. void cmTarget::InsertCompileOption(BT<std::string> const& entry, bool before)
  2363. {
  2364. this->impl->CompileOptions.WriteDirect(
  2365. entry,
  2366. before ? UsageRequirementProperty::Action::Prepend
  2367. : UsageRequirementProperty::Action::Append);
  2368. }
  2369. void cmTarget::InsertCompileDefinition(BT<std::string> const& entry)
  2370. {
  2371. this->impl->CompileDefinitions.WriteDirect(
  2372. entry, UsageRequirementProperty::Action::Append);
  2373. }
  2374. void cmTarget::InsertLinkOption(BT<std::string> const& entry, bool before)
  2375. {
  2376. this->impl->LinkOptions.WriteDirect(
  2377. entry,
  2378. before ? UsageRequirementProperty::Action::Prepend
  2379. : UsageRequirementProperty::Action::Append);
  2380. }
  2381. void cmTarget::InsertLinkDirectory(BT<std::string> const& entry, bool before)
  2382. {
  2383. this->impl->LinkDirectories.WriteDirect(
  2384. entry,
  2385. before ? UsageRequirementProperty::Action::Prepend
  2386. : UsageRequirementProperty::Action::Append);
  2387. }
  2388. void cmTarget::InsertPrecompileHeader(BT<std::string> const& entry)
  2389. {
  2390. this->impl->PrecompileHeaders.WriteDirect(
  2391. entry, UsageRequirementProperty::Action::Append);
  2392. }
  2393. namespace {
  2394. void CheckLINK_INTERFACE_LIBRARIES(const std::string& prop,
  2395. const std::string& value,
  2396. cmMakefile* context, bool imported)
  2397. {
  2398. // Support imported and non-imported versions of the property.
  2399. const char* base = (imported ? "IMPORTED_LINK_INTERFACE_LIBRARIES"
  2400. : "LINK_INTERFACE_LIBRARIES");
  2401. // Look for link-type keywords in the value.
  2402. static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
  2403. if (keys.find(value)) {
  2404. // Report an error.
  2405. std::ostringstream e;
  2406. e << "Property " << prop << " may not contain link-type keyword \""
  2407. << keys.match(2) << "\". "
  2408. << "The " << base << " property has a per-configuration "
  2409. << "version called " << base << "_<CONFIG> which may be "
  2410. << "used to specify per-configuration rules.";
  2411. if (!imported) {
  2412. e << " "
  2413. << "Alternatively, an IMPORTED library may be created, configured "
  2414. << "with a per-configuration location, and then named in the "
  2415. << "property value. "
  2416. << "See the add_library command's IMPORTED mode for details."
  2417. << "\n"
  2418. << "If you have a list of libraries that already contains the "
  2419. << "keyword, use the target_link_libraries command with its "
  2420. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  2421. << "The command automatically recognizes link-type keywords and sets "
  2422. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  2423. << "properties accordingly.";
  2424. }
  2425. context->IssueMessage(MessageType::FATAL_ERROR, e.str());
  2426. }
  2427. }
  2428. void CheckINTERFACE_LINK_LIBRARIES(const std::string& value,
  2429. cmMakefile* context)
  2430. {
  2431. // Look for link-type keywords in the value.
  2432. static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
  2433. if (keys.find(value)) {
  2434. // Report an error.
  2435. std::ostringstream e;
  2436. e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
  2437. "keyword \""
  2438. << keys.match(2)
  2439. << "\". The INTERFACE_LINK_LIBRARIES "
  2440. "property may contain configuration-sensitive generator-expressions "
  2441. "which may be used to specify per-configuration rules.";
  2442. context->IssueMessage(MessageType::FATAL_ERROR, e.str());
  2443. }
  2444. }
  2445. void CheckIMPORTED_GLOBAL(const cmTarget* target, cmMakefile* context)
  2446. {
  2447. const auto& targets = context->GetOwnedImportedTargets();
  2448. auto it =
  2449. std::find_if(targets.begin(), targets.end(),
  2450. [&](const std::unique_ptr<cmTarget>& importTarget) -> bool {
  2451. return target == importTarget.get();
  2452. });
  2453. if (it == targets.end()) {
  2454. std::ostringstream e;
  2455. e << "Attempt to promote imported target \"" << target->GetName()
  2456. << "\" to global scope (by setting IMPORTED_GLOBAL) "
  2457. "which is not built in this directory.";
  2458. context->IssueMessage(MessageType::FATAL_ERROR, e.str());
  2459. }
  2460. }
  2461. }
  2462. void cmTarget::CheckProperty(const std::string& prop,
  2463. cmMakefile* context) const
  2464. {
  2465. // Certain properties need checking.
  2466. if (cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES")) {
  2467. if (cmValue value = this->GetProperty(prop)) {
  2468. CheckLINK_INTERFACE_LIBRARIES(prop, *value, context, false);
  2469. }
  2470. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES")) {
  2471. if (cmValue value = this->GetProperty(prop)) {
  2472. CheckLINK_INTERFACE_LIBRARIES(prop, *value, context, true);
  2473. }
  2474. } else if (prop == "INTERFACE_LINK_LIBRARIES") {
  2475. if (cmValue value = this->GetProperty(prop)) {
  2476. CheckINTERFACE_LINK_LIBRARIES(*value, context);
  2477. }
  2478. } else if (prop == "IMPORTED_GLOBAL") {
  2479. if (this->IsImported()) {
  2480. CheckIMPORTED_GLOBAL(this, context);
  2481. }
  2482. }
  2483. }
  2484. cmValue cmTarget::GetComputedProperty(const std::string& prop,
  2485. cmMakefile& mf) const
  2486. {
  2487. return cmTargetPropertyComputer::GetProperty(this, prop, mf);
  2488. }
  2489. cmValue cmTarget::GetProperty(const std::string& prop) const
  2490. {
  2491. static std::unordered_set<std::string> const specialProps{
  2492. propC_STANDARD,
  2493. propCXX_STANDARD,
  2494. propCUDA_STANDARD,
  2495. propHIP_STANDARD,
  2496. propOBJC_STANDARD,
  2497. propOBJCXX_STANDARD,
  2498. propLINK_LIBRARIES,
  2499. propTYPE,
  2500. propINCLUDE_DIRECTORIES,
  2501. propCOMPILE_FEATURES,
  2502. propCOMPILE_OPTIONS,
  2503. propCOMPILE_DEFINITIONS,
  2504. propPRECOMPILE_HEADERS,
  2505. propLINK_OPTIONS,
  2506. propLINK_DIRECTORIES,
  2507. propIMPORTED,
  2508. propIMPORTED_GLOBAL,
  2509. propMANUALLY_ADDED_DEPENDENCIES,
  2510. propNAME,
  2511. propBINARY_DIR,
  2512. propSOURCE_DIR,
  2513. propSOURCES,
  2514. propINTERFACE_LINK_LIBRARIES,
  2515. propINTERFACE_LINK_LIBRARIES_DIRECT,
  2516. propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE,
  2517. propIMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES,
  2518. propIMPORTED_CXX_MODULES_COMPILE_DEFINITIONS,
  2519. propIMPORTED_CXX_MODULES_COMPILE_FEATURES,
  2520. propIMPORTED_CXX_MODULES_COMPILE_OPTIONS,
  2521. propIMPORTED_CXX_MODULES_LINK_LIBRARIES,
  2522. };
  2523. if (specialProps.count(prop)) {
  2524. if (prop == propC_STANDARD || prop == propCXX_STANDARD ||
  2525. prop == propCUDA_STANDARD || prop == propHIP_STANDARD ||
  2526. prop == propOBJC_STANDARD || prop == propOBJCXX_STANDARD) {
  2527. auto propertyIter = this->impl->LanguageStandardProperties.find(prop);
  2528. if (propertyIter == this->impl->LanguageStandardProperties.end()) {
  2529. return nullptr;
  2530. }
  2531. return cmValue(propertyIter->second.Value);
  2532. }
  2533. UsageRequirementProperty const* usageRequirements[] = {
  2534. &this->impl->IncludeDirectories,
  2535. &this->impl->CompileOptions,
  2536. &this->impl->CompileFeatures,
  2537. &this->impl->CompileDefinitions,
  2538. &this->impl->PrecompileHeaders,
  2539. &this->impl->Sources,
  2540. &this->impl->LinkOptions,
  2541. &this->impl->LinkDirectories,
  2542. &this->impl->LinkLibraries,
  2543. &this->impl->InterfaceLinkLibraries,
  2544. &this->impl->InterfaceLinkLibrariesDirect,
  2545. &this->impl->InterfaceLinkLibrariesDirectExclude,
  2546. &this->impl->ImportedCxxModulesIncludeDirectories,
  2547. &this->impl->ImportedCxxModulesCompileDefinitions,
  2548. &this->impl->ImportedCxxModulesCompileFeatures,
  2549. &this->impl->ImportedCxxModulesCompileOptions,
  2550. &this->impl->ImportedCxxModulesLinkLibraries,
  2551. };
  2552. for (auto const* usageRequirement : usageRequirements) {
  2553. auto value = usageRequirement->Read(prop);
  2554. if (value.first) {
  2555. return value.second;
  2556. }
  2557. }
  2558. // the type property returns what type the target is
  2559. if (prop == propTYPE) {
  2560. return cmValue(cmState::GetTargetTypeName(this->GetType()));
  2561. }
  2562. if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
  2563. if (this->impl->Utilities.empty()) {
  2564. return nullptr;
  2565. }
  2566. static std::string output;
  2567. static std::vector<std::string> utilities;
  2568. utilities.resize(this->impl->Utilities.size());
  2569. std::transform(
  2570. this->impl->Utilities.cbegin(), this->impl->Utilities.cend(),
  2571. utilities.begin(),
  2572. [](const BT<std::pair<std::string, bool>>& item) -> std::string {
  2573. return item.Value.first;
  2574. });
  2575. output = cmList::to_string(utilities);
  2576. return cmValue(output);
  2577. }
  2578. if (prop == propIMPORTED) {
  2579. return this->IsImported() ? cmValue(propTRUE) : cmValue(propFALSE);
  2580. }
  2581. if (prop == propIMPORTED_GLOBAL) {
  2582. return this->IsImportedGloballyVisible() ? cmValue(propTRUE)
  2583. : cmValue(propFALSE);
  2584. }
  2585. if (prop == propNAME) {
  2586. return cmValue(this->GetName());
  2587. }
  2588. if (prop == propBINARY_DIR) {
  2589. return cmValue(this->impl->Makefile->GetStateSnapshot()
  2590. .GetDirectory()
  2591. .GetCurrentBinary());
  2592. }
  2593. if (prop == propSOURCE_DIR) {
  2594. return cmValue(this->impl->Makefile->GetStateSnapshot()
  2595. .GetDirectory()
  2596. .GetCurrentSource());
  2597. }
  2598. }
  2599. // Check fileset properties.
  2600. {
  2601. FileSetType* fileSetTypes[] = {
  2602. &this->impl->HeadersFileSets,
  2603. &this->impl->CxxModulesFileSets,
  2604. };
  2605. for (auto* fileSetType : fileSetTypes) {
  2606. auto value = fileSetType->ReadProperties(this, this->impl.get(), prop);
  2607. if (value.first) {
  2608. return value.second;
  2609. }
  2610. }
  2611. }
  2612. cmValue retVal = this->impl->Properties.GetPropertyValue(prop);
  2613. if (!retVal) {
  2614. const bool chain = this->impl->Makefile->GetState()->IsPropertyChained(
  2615. prop, cmProperty::TARGET);
  2616. if (chain) {
  2617. return this->impl->Makefile->GetStateSnapshot()
  2618. .GetDirectory()
  2619. .GetProperty(prop, chain);
  2620. }
  2621. return nullptr;
  2622. }
  2623. return retVal;
  2624. }
  2625. std::string const& cmTarget::GetSafeProperty(std::string const& prop) const
  2626. {
  2627. cmValue ret = this->GetProperty(prop);
  2628. if (ret) {
  2629. return *ret;
  2630. }
  2631. static std::string const s_empty;
  2632. return s_empty;
  2633. }
  2634. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  2635. {
  2636. return this->GetProperty(prop).IsOn();
  2637. }
  2638. cmPropertyMap const& cmTarget::GetProperties() const
  2639. {
  2640. return this->impl->Properties;
  2641. }
  2642. bool cmTarget::IsDLLPlatform() const
  2643. {
  2644. return this->impl->IsDLLPlatform;
  2645. }
  2646. bool cmTarget::IsAIX() const
  2647. {
  2648. return this->impl->IsAIX;
  2649. }
  2650. bool cmTarget::IsApple() const
  2651. {
  2652. return this->impl->IsApple;
  2653. }
  2654. bool cmTarget::IsNormal() const
  2655. {
  2656. switch (this->impl->TargetVisibility) {
  2657. case Visibility::Normal:
  2658. return true;
  2659. case Visibility::Generated:
  2660. case Visibility::Imported:
  2661. case Visibility::ImportedGlobally:
  2662. return false;
  2663. }
  2664. assert(false && "unknown visibility (IsNormal)");
  2665. return false;
  2666. }
  2667. bool cmTarget::IsSynthetic() const
  2668. {
  2669. switch (this->impl->TargetVisibility) {
  2670. case Visibility::Generated:
  2671. return true;
  2672. case Visibility::Normal:
  2673. case Visibility::Imported:
  2674. case Visibility::ImportedGlobally:
  2675. return false;
  2676. }
  2677. assert(false && "unknown visibility (IsSynthetic)");
  2678. return false;
  2679. }
  2680. bool cmTargetInternals::IsImported() const
  2681. {
  2682. switch (this->TargetVisibility) {
  2683. case cmTarget::Visibility::Imported:
  2684. case cmTarget::Visibility::ImportedGlobally:
  2685. return true;
  2686. case cmTarget::Visibility::Normal:
  2687. case cmTarget::Visibility::Generated:
  2688. return false;
  2689. }
  2690. assert(false && "unknown visibility (IsImported)");
  2691. return false;
  2692. }
  2693. bool cmTarget::IsImported() const
  2694. {
  2695. return this->impl->IsImported();
  2696. }
  2697. bool cmTarget::IsImportedGloballyVisible() const
  2698. {
  2699. switch (this->impl->TargetVisibility) {
  2700. case Visibility::ImportedGlobally:
  2701. return true;
  2702. case Visibility::Normal:
  2703. case Visibility::Generated:
  2704. case Visibility::Imported:
  2705. return false;
  2706. }
  2707. assert(false && "unknown visibility (IsImportedGloballyVisible)");
  2708. return false;
  2709. }
  2710. bool cmTarget::IsPerConfig() const
  2711. {
  2712. return this->impl->PerConfig;
  2713. }
  2714. bool cmTarget::IsRuntimeBinary() const
  2715. {
  2716. switch (this->GetType()) {
  2717. case cmStateEnums::EXECUTABLE:
  2718. case cmStateEnums::SHARED_LIBRARY:
  2719. case cmStateEnums::MODULE_LIBRARY:
  2720. return true;
  2721. case cmStateEnums::OBJECT_LIBRARY:
  2722. case cmStateEnums::STATIC_LIBRARY:
  2723. case cmStateEnums::UTILITY:
  2724. case cmStateEnums::INTERFACE_LIBRARY:
  2725. case cmStateEnums::GLOBAL_TARGET:
  2726. case cmStateEnums::UNKNOWN_LIBRARY:
  2727. break;
  2728. }
  2729. return false;
  2730. }
  2731. bool cmTarget::CanCompileSources() const
  2732. {
  2733. if (this->IsImported()) {
  2734. return false;
  2735. }
  2736. if (this->IsSynthetic()) {
  2737. return true;
  2738. }
  2739. switch (this->GetType()) {
  2740. case cmStateEnums::EXECUTABLE:
  2741. case cmStateEnums::STATIC_LIBRARY:
  2742. case cmStateEnums::SHARED_LIBRARY:
  2743. case cmStateEnums::MODULE_LIBRARY:
  2744. case cmStateEnums::OBJECT_LIBRARY:
  2745. return true;
  2746. case cmStateEnums::UTILITY:
  2747. case cmStateEnums::INTERFACE_LIBRARY:
  2748. case cmStateEnums::GLOBAL_TARGET:
  2749. case cmStateEnums::UNKNOWN_LIBRARY:
  2750. break;
  2751. }
  2752. return false;
  2753. }
  2754. const char* cmTarget::GetSuffixVariableInternal(
  2755. cmStateEnums::ArtifactType artifact) const
  2756. {
  2757. switch (this->GetType()) {
  2758. case cmStateEnums::STATIC_LIBRARY:
  2759. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  2760. case cmStateEnums::SHARED_LIBRARY:
  2761. switch (artifact) {
  2762. case cmStateEnums::RuntimeBinaryArtifact:
  2763. return this->IsArchivedAIXSharedLibrary()
  2764. ? "CMAKE_SHARED_LIBRARY_ARCHIVE_SUFFIX"
  2765. : "CMAKE_SHARED_LIBRARY_SUFFIX";
  2766. case cmStateEnums::ImportLibraryArtifact:
  2767. return this->IsApple() ? "CMAKE_APPLE_IMPORT_FILE_SUFFIX"
  2768. : "CMAKE_IMPORT_LIBRARY_SUFFIX";
  2769. }
  2770. break;
  2771. case cmStateEnums::MODULE_LIBRARY:
  2772. switch (artifact) {
  2773. case cmStateEnums::RuntimeBinaryArtifact:
  2774. return "CMAKE_SHARED_MODULE_SUFFIX";
  2775. case cmStateEnums::ImportLibraryArtifact:
  2776. return "CMAKE_IMPORT_LIBRARY_SUFFIX";
  2777. }
  2778. break;
  2779. case cmStateEnums::EXECUTABLE:
  2780. switch (artifact) {
  2781. case cmStateEnums::RuntimeBinaryArtifact:
  2782. // Android GUI application packages store the native
  2783. // binary as a shared library.
  2784. return (this->IsAndroidGuiExecutable()
  2785. ? "CMAKE_SHARED_LIBRARY_SUFFIX"
  2786. : "CMAKE_EXECUTABLE_SUFFIX");
  2787. case cmStateEnums::ImportLibraryArtifact:
  2788. return (this->impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_SUFFIX"
  2789. : "CMAKE_IMPORT_LIBRARY_SUFFIX");
  2790. }
  2791. break;
  2792. default:
  2793. break;
  2794. }
  2795. return "";
  2796. }
  2797. const char* cmTarget::GetPrefixVariableInternal(
  2798. cmStateEnums::ArtifactType artifact) const
  2799. {
  2800. switch (this->GetType()) {
  2801. case cmStateEnums::STATIC_LIBRARY:
  2802. return "CMAKE_STATIC_LIBRARY_PREFIX";
  2803. case cmStateEnums::SHARED_LIBRARY:
  2804. switch (artifact) {
  2805. case cmStateEnums::RuntimeBinaryArtifact:
  2806. return "CMAKE_SHARED_LIBRARY_PREFIX";
  2807. case cmStateEnums::ImportLibraryArtifact:
  2808. return this->IsApple() ? "CMAKE_APPLE_IMPORT_FILE_PREFIX"
  2809. : "CMAKE_IMPORT_LIBRARY_PREFIX";
  2810. }
  2811. break;
  2812. case cmStateEnums::MODULE_LIBRARY:
  2813. switch (artifact) {
  2814. case cmStateEnums::RuntimeBinaryArtifact:
  2815. return "CMAKE_SHARED_MODULE_PREFIX";
  2816. case cmStateEnums::ImportLibraryArtifact:
  2817. return "CMAKE_IMPORT_LIBRARY_PREFIX";
  2818. }
  2819. break;
  2820. case cmStateEnums::EXECUTABLE:
  2821. switch (artifact) {
  2822. case cmStateEnums::RuntimeBinaryArtifact:
  2823. // Android GUI application packages store the native
  2824. // binary as a shared library.
  2825. return (this->IsAndroidGuiExecutable()
  2826. ? "CMAKE_SHARED_LIBRARY_PREFIX"
  2827. : "");
  2828. case cmStateEnums::ImportLibraryArtifact:
  2829. return (this->impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_PREFIX"
  2830. : "CMAKE_IMPORT_LIBRARY_PREFIX");
  2831. }
  2832. break;
  2833. default:
  2834. break;
  2835. }
  2836. return "";
  2837. }
  2838. std::string cmTarget::ImportedGetFullPath(
  2839. const std::string& config, cmStateEnums::ArtifactType artifact) const
  2840. {
  2841. assert(this->IsImported());
  2842. // Lookup/compute/cache the import information for this
  2843. // configuration.
  2844. std::string desired_config = config;
  2845. if (config.empty()) {
  2846. desired_config = "NOCONFIG";
  2847. }
  2848. std::string result;
  2849. cmValue loc = nullptr;
  2850. cmValue imp = nullptr;
  2851. std::string suffix;
  2852. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  2853. this->GetMappedConfig(desired_config, loc, imp, suffix)) {
  2854. switch (artifact) {
  2855. case cmStateEnums::RuntimeBinaryArtifact:
  2856. if (loc) {
  2857. result = *loc;
  2858. } else if (imp) {
  2859. result = *imp;
  2860. } else {
  2861. std::string impProp = cmStrCat("IMPORTED_LOCATION", suffix);
  2862. if (cmValue config_location = this->GetProperty(impProp)) {
  2863. result = *config_location;
  2864. } else if (cmValue location =
  2865. this->GetProperty("IMPORTED_LOCATION")) {
  2866. result = *location;
  2867. }
  2868. if (result.empty() &&
  2869. (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2870. this->IsExecutableWithExports())) {
  2871. impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  2872. if (cmValue config_implib = this->GetProperty(impProp)) {
  2873. result = *config_implib;
  2874. } else if (cmValue implib = this->GetProperty("IMPORTED_IMPLIB")) {
  2875. result = *implib;
  2876. }
  2877. }
  2878. }
  2879. if (this->IsApple() &&
  2880. (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
  2881. this->impl->TargetType == cmStateEnums::STATIC_LIBRARY ||
  2882. this->impl->TargetType == cmStateEnums::UNKNOWN_LIBRARY) &&
  2883. cmSystemTools::IsPathToXcFramework(result)) {
  2884. auto plist = cmParseXcFrameworkPlist(result, *this->impl->Makefile,
  2885. this->impl->Backtrace);
  2886. if (!plist) {
  2887. return "";
  2888. }
  2889. auto const* library = plist->SelectSuitableLibrary(
  2890. *this->impl->Makefile, this->impl->Backtrace);
  2891. if (library) {
  2892. result = cmStrCat(result, '/', library->LibraryIdentifier, '/',
  2893. library->LibraryPath);
  2894. } else {
  2895. return "";
  2896. }
  2897. }
  2898. break;
  2899. case cmStateEnums::ImportLibraryArtifact:
  2900. if (imp) {
  2901. result = *imp;
  2902. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2903. this->IsExecutableWithExports()) {
  2904. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  2905. if (cmValue config_implib = this->GetProperty(impProp)) {
  2906. result = *config_implib;
  2907. } else if (cmValue implib = this->GetProperty("IMPORTED_IMPLIB")) {
  2908. result = *implib;
  2909. }
  2910. }
  2911. break;
  2912. }
  2913. }
  2914. if (result.empty()) {
  2915. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  2916. auto message = [&]() -> std::string {
  2917. std::string unset;
  2918. std::string configuration;
  2919. if (this->GetType() == cmStateEnums::SHARED_LIBRARY &&
  2920. artifact == cmStateEnums::RuntimeBinaryArtifact) {
  2921. unset = "IMPORTED_LOCATION or IMPORTED_IMPLIB";
  2922. } else if (artifact == cmStateEnums::RuntimeBinaryArtifact) {
  2923. unset = "IMPORTED_LOCATION";
  2924. } else if (artifact == cmStateEnums::ImportLibraryArtifact) {
  2925. unset = "IMPORTED_IMPLIB";
  2926. }
  2927. if (!config.empty()) {
  2928. configuration = cmStrCat(" configuration \"", config, "\"");
  2929. }
  2930. return cmStrCat(unset, " not set for imported target \"",
  2931. this->GetName(), "\"", configuration, ".");
  2932. };
  2933. switch (this->GetPolicyStatus(cmPolicies::CMP0111)) {
  2934. case cmPolicies::WARN:
  2935. this->impl->Makefile->IssueMessage(
  2936. MessageType::AUTHOR_WARNING,
  2937. cmPolicies::GetPolicyWarning(cmPolicies::CMP0111) + "\n" +
  2938. message());
  2939. CM_FALLTHROUGH;
  2940. case cmPolicies::OLD:
  2941. break;
  2942. default:
  2943. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  2944. message());
  2945. }
  2946. }
  2947. result = cmStrCat(this->GetName(), "-NOTFOUND");
  2948. }
  2949. return result;
  2950. }
  2951. const cmFileSet* cmTarget::GetFileSet(const std::string& name) const
  2952. {
  2953. auto it = this->impl->FileSets.find(name);
  2954. return it == this->impl->FileSets.end() ? nullptr : &it->second;
  2955. }
  2956. cmFileSet* cmTarget::GetFileSet(const std::string& name)
  2957. {
  2958. auto it = this->impl->FileSets.find(name);
  2959. return it == this->impl->FileSets.end() ? nullptr : &it->second;
  2960. }
  2961. std::pair<cmFileSet*, bool> cmTarget::GetOrCreateFileSet(
  2962. const std::string& name, const std::string& type, cmFileSetVisibility vis)
  2963. {
  2964. auto result = this->impl->FileSets.emplace(
  2965. name,
  2966. cmFileSet(*this->GetMakefile()->GetCMakeInstance(), name, type, vis));
  2967. if (result.second) {
  2968. auto bt = this->impl->Makefile->GetBacktrace();
  2969. if (type == this->impl->HeadersFileSets.TypeName) {
  2970. this->impl->HeadersFileSets.AddFileSet(name, vis, std::move(bt));
  2971. } else if (type == this->impl->CxxModulesFileSets.TypeName) {
  2972. this->impl->CxxModulesFileSets.AddFileSet(name, vis, std::move(bt));
  2973. }
  2974. }
  2975. return std::make_pair(&result.first->second, result.second);
  2976. }
  2977. std::string cmTarget::GetFileSetsPropertyName(const std::string& type)
  2978. {
  2979. if (type == "HEADERS") {
  2980. return "HEADER_SETS";
  2981. }
  2982. if (type == "CXX_MODULES") {
  2983. return "CXX_MODULE_SETS";
  2984. }
  2985. return "";
  2986. }
  2987. std::string cmTarget::GetInterfaceFileSetsPropertyName(const std::string& type)
  2988. {
  2989. if (type == "HEADERS") {
  2990. return "INTERFACE_HEADER_SETS";
  2991. }
  2992. if (type == "CXX_MODULES") {
  2993. return "INTERFACE_CXX_MODULE_SETS";
  2994. }
  2995. return "";
  2996. }
  2997. std::vector<std::string> cmTarget::GetAllFileSetNames() const
  2998. {
  2999. std::vector<std::string> result;
  3000. for (auto const& it : this->impl->FileSets) {
  3001. result.push_back(it.first);
  3002. }
  3003. return result;
  3004. }
  3005. std::vector<std::string> cmTarget::GetAllInterfaceFileSets() const
  3006. {
  3007. std::vector<std::string> result;
  3008. auto inserter = std::back_inserter(result);
  3009. auto appendEntries = [=](const std::vector<BT<std::string>>& entries) {
  3010. for (auto const& entry : entries) {
  3011. cmList expanded{ entry.Value };
  3012. std::copy(expanded.begin(), expanded.end(), inserter);
  3013. }
  3014. };
  3015. appendEntries(this->impl->HeadersFileSets.InterfaceEntries.Entries);
  3016. appendEntries(this->impl->CxxModulesFileSets.InterfaceEntries.Entries);
  3017. return result;
  3018. }
  3019. bool cmTarget::HasFileSets() const
  3020. {
  3021. return !this->impl->FileSets.empty();
  3022. }
  3023. bool cmTargetInternals::CheckImportedLibName(std::string const& prop,
  3024. std::string const& value) const
  3025. {
  3026. if (this->TargetType != cmStateEnums::INTERFACE_LIBRARY ||
  3027. !this->IsImported()) {
  3028. this->Makefile->IssueMessage(
  3029. MessageType::FATAL_ERROR,
  3030. prop +
  3031. " property may be set only on imported INTERFACE library targets.");
  3032. return false;
  3033. }
  3034. if (!value.empty()) {
  3035. if (value[0] == '-') {
  3036. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  3037. prop + " property value\n " + value +
  3038. "\nmay not start with '-'.");
  3039. return false;
  3040. }
  3041. std::string::size_type bad = value.find_first_of(":/\\;");
  3042. if (bad != std::string::npos) {
  3043. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  3044. prop + " property value\n " + value +
  3045. "\nmay not contain '" +
  3046. value.substr(bad, 1) + "'.");
  3047. return false;
  3048. }
  3049. }
  3050. return true;
  3051. }
  3052. bool cmTarget::GetMappedConfig(std::string const& desired_config, cmValue& loc,
  3053. cmValue& imp, std::string& suffix) const
  3054. {
  3055. std::string config_upper;
  3056. if (!desired_config.empty()) {
  3057. config_upper = cmSystemTools::UpperCase(desired_config);
  3058. }
  3059. std::string locPropBase;
  3060. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3061. locPropBase = "IMPORTED_LIBNAME";
  3062. } else if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  3063. locPropBase = "IMPORTED_OBJECTS";
  3064. } else {
  3065. locPropBase = "IMPORTED_LOCATION";
  3066. }
  3067. // Track the configuration-specific property suffix.
  3068. suffix = cmStrCat('_', config_upper);
  3069. cmList mappedConfigs;
  3070. {
  3071. std::string mapProp = cmStrCat("MAP_IMPORTED_CONFIG_", config_upper);
  3072. if (cmValue mapValue = this->GetProperty(mapProp)) {
  3073. mappedConfigs.assign(*mapValue, cmList::EmptyElements::Yes);
  3074. }
  3075. }
  3076. // If we needed to find one of the mapped configurations but did not
  3077. // There may be only IMPORTED_IMPLIB for a shared library or an executable
  3078. // with exports.
  3079. bool allowImp = (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  3080. this->IsExecutableWithExports()) ||
  3081. (this->IsAIX() && this->IsExecutableWithExports()) ||
  3082. (this->GetMakefile()->PlatformSupportsAppleTextStubs() &&
  3083. this->IsSharedLibraryWithExports());
  3084. // If a mapping was found, check its configurations.
  3085. for (auto mci = mappedConfigs.begin();
  3086. !loc && !imp && mci != mappedConfigs.end(); ++mci) {
  3087. // Look for this configuration.
  3088. if (mci->empty()) {
  3089. // An empty string in the mapping has a special meaning:
  3090. // look up the config-less properties.
  3091. loc = this->GetProperty(locPropBase);
  3092. if (allowImp) {
  3093. imp = this->GetProperty("IMPORTED_IMPLIB");
  3094. }
  3095. // If it was found, set the suffix.
  3096. if (loc || imp) {
  3097. suffix.clear();
  3098. }
  3099. } else {
  3100. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  3101. std::string locProp = cmStrCat(locPropBase, '_', mcUpper);
  3102. loc = this->GetProperty(locProp);
  3103. if (allowImp) {
  3104. std::string impProp = cmStrCat("IMPORTED_IMPLIB_", mcUpper);
  3105. imp = this->GetProperty(impProp);
  3106. }
  3107. // If it was found, use it for all properties below.
  3108. if (loc || imp) {
  3109. suffix = cmStrCat('_', mcUpper);
  3110. }
  3111. }
  3112. }
  3113. // If we needed to find one of the mapped configurations but did not
  3114. // then the target location is not found. The project does not want
  3115. // any other configuration.
  3116. if (!mappedConfigs.empty() && !loc && !imp) {
  3117. // Interface libraries are always available because their
  3118. // library name is optional so it is okay to leave loc empty.
  3119. return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
  3120. }
  3121. // If we have not yet found it then there are no mapped
  3122. // configurations. Look for an exact-match.
  3123. if (!loc && !imp) {
  3124. std::string locProp = cmStrCat(locPropBase, suffix);
  3125. loc = this->GetProperty(locProp);
  3126. if (allowImp) {
  3127. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  3128. imp = this->GetProperty(impProp);
  3129. }
  3130. }
  3131. // If we have not yet found it then there are no mapped
  3132. // configurations and no exact match.
  3133. if (!loc && !imp) {
  3134. // The suffix computed above is not useful.
  3135. suffix.clear();
  3136. // Look for a configuration-less location. This may be set by
  3137. // manually-written code.
  3138. loc = this->GetProperty(locPropBase);
  3139. if (allowImp) {
  3140. imp = this->GetProperty("IMPORTED_IMPLIB");
  3141. }
  3142. }
  3143. // If we have not yet found it then the project is willing to try
  3144. // any available configuration.
  3145. if (!loc && !imp) {
  3146. cmList availableConfigs;
  3147. if (cmValue iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS")) {
  3148. availableConfigs.assign(*iconfigs);
  3149. }
  3150. for (auto aci = availableConfigs.begin();
  3151. !loc && !imp && aci != availableConfigs.end(); ++aci) {
  3152. suffix = cmStrCat('_', cmSystemTools::UpperCase(*aci));
  3153. std::string locProp = cmStrCat(locPropBase, suffix);
  3154. loc = this->GetProperty(locProp);
  3155. if (allowImp) {
  3156. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  3157. imp = this->GetProperty(impProp);
  3158. }
  3159. }
  3160. }
  3161. // If we have not yet found it then the target location is not available.
  3162. if (!loc && !imp) {
  3163. // Interface libraries are always available because their
  3164. // library name is optional so it is okay to leave loc empty.
  3165. return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
  3166. }
  3167. return true;
  3168. }