cmTarget.cxx 114 KB

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