cmTarget.cxx 111 KB

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