cmTarget.cxx 111 KB

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