cmTarget.cxx 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736
  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 <cstring>
  7. #include <initializer_list>
  8. #include <iterator>
  9. #include <map>
  10. #include <set>
  11. #include <sstream>
  12. #include <unordered_set>
  13. #include <cm/memory>
  14. #include <cm/string_view>
  15. #include <cmext/algorithm>
  16. #include <cmext/string_view>
  17. #include "cmsys/RegularExpression.hxx"
  18. #include "cmAlgorithms.h"
  19. #include "cmCustomCommand.h"
  20. #include "cmFileSet.h"
  21. #include "cmGeneratorExpression.h"
  22. #include "cmGeneratorTarget.h"
  23. #include "cmGlobalGenerator.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 "cmake.h"
  41. template <>
  42. const std::string& cmTargetPropertyComputer::ComputeLocationForBuild<cmTarget>(
  43. cmTarget const* tgt)
  44. {
  45. static std::string loc;
  46. if (tgt->IsImported()) {
  47. loc = tgt->ImportedGetFullPath("", cmStateEnums::RuntimeBinaryArtifact);
  48. return loc;
  49. }
  50. cmGlobalGenerator* gg = tgt->GetGlobalGenerator();
  51. if (!gg->GetConfigureDoneCMP0026()) {
  52. gg->CreateGenerationObjects();
  53. }
  54. cmGeneratorTarget* gt = gg->FindGeneratorTarget(tgt->GetName());
  55. loc = gt->GetLocationForBuild();
  56. return loc;
  57. }
  58. template <>
  59. const std::string& cmTargetPropertyComputer::ComputeLocation<cmTarget>(
  60. cmTarget const* tgt, const std::string& config)
  61. {
  62. static std::string loc;
  63. if (tgt->IsImported()) {
  64. loc =
  65. tgt->ImportedGetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  66. return loc;
  67. }
  68. cmGlobalGenerator* gg = tgt->GetGlobalGenerator();
  69. if (!gg->GetConfigureDoneCMP0026()) {
  70. gg->CreateGenerationObjects();
  71. }
  72. cmGeneratorTarget* gt = gg->FindGeneratorTarget(tgt->GetName());
  73. loc = gt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  74. return loc;
  75. }
  76. template <>
  77. cmValue cmTargetPropertyComputer::GetSources<cmTarget>(cmTarget const* tgt,
  78. cmMakefile const& mf)
  79. {
  80. cmBTStringRange entries = tgt->GetSourceEntries();
  81. if (entries.empty()) {
  82. return nullptr;
  83. }
  84. std::ostringstream ss;
  85. const char* sep = "";
  86. for (auto const& entry : entries) {
  87. std::vector<std::string> files = cmExpandedList(entry.Value);
  88. for (std::string const& file : files) {
  89. if (cmHasLiteralPrefix(file, "$<TARGET_OBJECTS:") &&
  90. file.back() == '>') {
  91. std::string objLibName = file.substr(17, file.size() - 18);
  92. if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
  93. ss << sep;
  94. sep = ";";
  95. ss << file;
  96. continue;
  97. }
  98. bool addContent = false;
  99. bool noMessage = true;
  100. std::ostringstream e;
  101. MessageType messageType = MessageType::AUTHOR_WARNING;
  102. switch (mf.GetPolicyStatus(cmPolicies::CMP0051)) {
  103. case cmPolicies::WARN:
  104. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
  105. noMessage = false;
  106. CM_FALLTHROUGH;
  107. case cmPolicies::OLD:
  108. break;
  109. case cmPolicies::REQUIRED_ALWAYS:
  110. case cmPolicies::REQUIRED_IF_USED:
  111. case cmPolicies::NEW:
  112. addContent = true;
  113. break;
  114. }
  115. if (!noMessage) {
  116. e << "Target \"" << tgt->GetName()
  117. << "\" contains $<TARGET_OBJECTS> generator expression in its "
  118. "sources list. This content was not previously part of the "
  119. "SOURCES property when that property was read at configure "
  120. "time. Code reading that property needs to be adapted to "
  121. "ignore the generator expression using the string(GENEX_STRIP) "
  122. "command.";
  123. mf.IssueMessage(messageType, e.str());
  124. }
  125. if (addContent) {
  126. ss << sep;
  127. sep = ";";
  128. ss << file;
  129. }
  130. } else if (cmGeneratorExpression::Find(file) == std::string::npos) {
  131. ss << sep;
  132. sep = ";";
  133. ss << file;
  134. } else {
  135. cmSourceFile* sf = tgt->GetMakefile()->GetOrCreateSource(file);
  136. // Construct what is known about this source file location.
  137. cmSourceFileLocation const& location = sf->GetLocation();
  138. std::string sname = location.GetDirectory();
  139. if (!sname.empty()) {
  140. sname += "/";
  141. }
  142. sname += location.GetName();
  143. ss << sep;
  144. sep = ";";
  145. // Append this list entry.
  146. ss << sname;
  147. }
  148. }
  149. }
  150. static std::string srcs;
  151. srcs = ss.str();
  152. return cmValue(srcs);
  153. }
  154. namespace {
  155. struct FileSetEntries
  156. {
  157. FileSetEntries(cm::static_string_view propertyName)
  158. : PropertyName(propertyName)
  159. {
  160. }
  161. cm::static_string_view const PropertyName;
  162. std::vector<BT<std::string>> Entries;
  163. };
  164. struct FileSetType
  165. {
  166. FileSetType(cm::static_string_view typeName,
  167. cm::static_string_view defaultDirectoryProperty,
  168. cm::static_string_view defaultPathProperty,
  169. cm::static_string_view directoryPrefix,
  170. cm::static_string_view pathPrefix,
  171. cm::static_string_view typeDescription,
  172. cm::static_string_view defaultDescription,
  173. cm::static_string_view arbitraryDescription,
  174. FileSetEntries selfEntries, FileSetEntries interfaceEntries)
  175. : TypeName(typeName)
  176. , DefaultDirectoryProperty(defaultDirectoryProperty)
  177. , DefaultPathProperty(defaultPathProperty)
  178. , DirectoryPrefix(directoryPrefix)
  179. , PathPrefix(pathPrefix)
  180. , TypeDescription(typeDescription)
  181. , DefaultDescription(defaultDescription)
  182. , ArbitraryDescription(arbitraryDescription)
  183. , SelfEntries(std::move(selfEntries))
  184. , InterfaceEntries(std::move(interfaceEntries))
  185. {
  186. }
  187. cm::static_string_view const TypeName;
  188. cm::static_string_view const DefaultDirectoryProperty;
  189. cm::static_string_view const DefaultPathProperty;
  190. cm::static_string_view const DirectoryPrefix;
  191. cm::static_string_view const PathPrefix;
  192. cm::static_string_view const TypeDescription;
  193. cm::static_string_view const DefaultDescription;
  194. cm::static_string_view const ArbitraryDescription;
  195. FileSetEntries SelfEntries;
  196. FileSetEntries InterfaceEntries;
  197. template <typename ValueType>
  198. bool WriteProperties(cmTarget* tgt, cmTargetInternals* impl,
  199. const std::string& prop, ValueType value, bool clear);
  200. std::pair<bool, cmValue> ReadProperties(cmTarget const* tgt,
  201. cmTargetInternals const* impl,
  202. const std::string& prop) const;
  203. void AddFileSet(const std::string& name, cmFileSetVisibility vis,
  204. cmListFileBacktrace bt);
  205. };
  206. }
  207. class cmTargetInternals
  208. {
  209. public:
  210. cmStateEnums::TargetType TargetType;
  211. cmMakefile* Makefile;
  212. cmPolicies::PolicyMap PolicyMap;
  213. std::string Name;
  214. std::string InstallPath;
  215. std::string RuntimeInstallPath;
  216. cmPropertyMap Properties;
  217. bool IsGeneratorProvided;
  218. bool HaveInstallRule;
  219. bool IsDLLPlatform;
  220. bool IsAIX;
  221. bool IsAndroid;
  222. bool IsImportedTarget;
  223. bool ImportedGloballyVisible;
  224. bool BuildInterfaceIncludesAppended;
  225. bool PerConfig;
  226. std::set<BT<std::pair<std::string, bool>>> Utilities;
  227. std::vector<cmCustomCommand> PreBuildCommands;
  228. std::vector<cmCustomCommand> PreLinkCommands;
  229. std::vector<cmCustomCommand> PostBuildCommands;
  230. std::vector<cmInstallTargetGenerator*> InstallGenerators;
  231. std::set<std::string> SystemIncludeDirectories;
  232. cmTarget::LinkLibraryVectorType OriginalLinkLibraries;
  233. std::map<std::string, BTs<std::string>> LanguageStandardProperties;
  234. std::vector<BT<std::string>> IncludeDirectoriesEntries;
  235. std::map<cmTargetExport const*, std::vector<std::string>>
  236. InstallIncludeDirectoriesEntries;
  237. std::vector<BT<std::string>> CompileOptionsEntries;
  238. std::vector<BT<std::string>> CompileFeaturesEntries;
  239. std::vector<BT<std::string>> CompileDefinitionsEntries;
  240. std::vector<BT<std::string>> PrecompileHeadersEntries;
  241. std::vector<BT<std::string>> SourceEntries;
  242. std::vector<BT<std::string>> LinkOptionsEntries;
  243. std::vector<BT<std::string>> LinkDirectoriesEntries;
  244. std::vector<BT<std::string>> LinkImplementationPropertyEntries;
  245. std::vector<BT<std::string>> LinkInterfacePropertyEntries;
  246. std::vector<BT<std::string>> LinkInterfaceDirectPropertyEntries;
  247. std::vector<BT<std::string>> LinkInterfaceDirectExcludePropertyEntries;
  248. std::vector<std::pair<cmTarget::TLLSignature, cmListFileContext>>
  249. TLLCommands;
  250. std::map<std::string, cmFileSet> FileSets;
  251. cmListFileBacktrace Backtrace;
  252. FileSetType HeadersFileSets;
  253. cmTargetInternals();
  254. bool CheckImportedLibName(std::string const& prop,
  255. std::string const& value) const;
  256. std::string ProcessSourceItemCMP0049(const std::string& s) const;
  257. template <typename ValueType>
  258. void AddDirectoryToFileSet(cmTarget* self, std::string const& fileSetName,
  259. ValueType value, cm::string_view fileSetType,
  260. cm::string_view description, bool clear);
  261. template <typename ValueType>
  262. void AddPathToFileSet(cmTarget* self, std::string const& fileSetName,
  263. ValueType value, cm::string_view fileSetType,
  264. cm::string_view description, bool clear);
  265. cmValue GetFileSetDirectories(cmTarget const* self,
  266. std::string const& fileSetName,
  267. cm::string_view fileSetType) const;
  268. cmValue GetFileSetPaths(cmTarget const* self, std::string const& fileSetName,
  269. cm::string_view fileSetType) const;
  270. };
  271. cmTargetInternals::cmTargetInternals()
  272. : HeadersFileSets("HEADERS"_s, "HEADER_DIRS"_s, "HEADER_SET"_s,
  273. "HEADER_DIRS_"_s, "HEADER_SET_"_s, "Header"_s,
  274. "The default header set"_s, "Header set"_s,
  275. FileSetEntries("HEADER_SETS"_s),
  276. FileSetEntries("INTERFACE_HEADER_SETS"_s))
  277. {
  278. }
  279. template <typename ValueType>
  280. bool FileSetType::WriteProperties(cmTarget* tgt, cmTargetInternals* impl,
  281. const std::string& prop, ValueType value,
  282. bool clear)
  283. {
  284. if (prop == this->DefaultDirectoryProperty) {
  285. impl->AddDirectoryToFileSet(tgt, std::string(this->TypeName), value,
  286. this->TypeName, this->DefaultDescription,
  287. clear);
  288. return true;
  289. }
  290. if (prop == this->DefaultPathProperty) {
  291. impl->AddPathToFileSet(tgt, std::string(this->TypeName), value,
  292. this->TypeName, this->DefaultDescription, clear);
  293. return true;
  294. }
  295. if (cmHasPrefix(prop, this->DirectoryPrefix)) {
  296. auto fileSetName = prop.substr(this->DirectoryPrefix.size());
  297. if (fileSetName.empty()) {
  298. impl->Makefile->IssueMessage(
  299. MessageType::FATAL_ERROR,
  300. cmStrCat(this->ArbitraryDescription, " name cannot be empty."));
  301. } else {
  302. impl->AddDirectoryToFileSet(
  303. tgt, fileSetName, value, this->TypeName,
  304. cmStrCat(this->ArbitraryDescription, " \"", fileSetName, "\""), clear);
  305. }
  306. return true;
  307. }
  308. if (cmHasPrefix(prop, this->PathPrefix)) {
  309. auto fileSetName = prop.substr(this->PathPrefix.size());
  310. if (fileSetName.empty()) {
  311. impl->Makefile->IssueMessage(
  312. MessageType::FATAL_ERROR,
  313. cmStrCat(this->ArbitraryDescription, " name cannot be empty."));
  314. } else {
  315. impl->AddPathToFileSet(
  316. tgt, fileSetName, value, this->TypeName,
  317. cmStrCat(this->ArbitraryDescription, " \"", fileSetName, "\""), clear);
  318. }
  319. return true;
  320. }
  321. if (prop == this->SelfEntries.PropertyName) {
  322. impl->Makefile->IssueMessage(
  323. MessageType::FATAL_ERROR,
  324. cmStrCat(this->SelfEntries.PropertyName, " property is read-only\n"));
  325. return true;
  326. }
  327. if (prop == this->InterfaceEntries.PropertyName) {
  328. impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  329. cmStrCat(this->InterfaceEntries.PropertyName,
  330. " property is read-only\n"));
  331. return true;
  332. }
  333. return false;
  334. }
  335. std::pair<bool, cmValue> FileSetType::ReadProperties(
  336. cmTarget const* tgt, cmTargetInternals const* impl,
  337. const std::string& prop) const
  338. {
  339. bool did_read = false;
  340. cmValue value = nullptr;
  341. if (prop == this->DefaultDirectoryProperty) {
  342. value = impl->GetFileSetDirectories(tgt, std::string(this->TypeName),
  343. this->TypeName);
  344. did_read = true;
  345. } else if (prop == this->DefaultPathProperty) {
  346. value =
  347. impl->GetFileSetPaths(tgt, std::string(this->TypeName), this->TypeName);
  348. did_read = true;
  349. } else if (prop == this->SelfEntries.PropertyName) {
  350. static std::string output;
  351. output = cmJoin(this->SelfEntries.Entries, ";"_s);
  352. value = cmValue(output);
  353. did_read = true;
  354. } else if (prop == this->InterfaceEntries.PropertyName) {
  355. static std::string output;
  356. output = cmJoin(this->InterfaceEntries.Entries, ";"_s);
  357. value = cmValue(output);
  358. did_read = true;
  359. } else if (cmHasPrefix(prop, this->DirectoryPrefix)) {
  360. std::string fileSetName = prop.substr(this->DirectoryPrefix.size());
  361. if (!fileSetName.empty()) {
  362. value = impl->GetFileSetDirectories(tgt, fileSetName, this->TypeName);
  363. }
  364. did_read = true;
  365. } else if (cmHasPrefix(prop, this->PathPrefix)) {
  366. std::string fileSetName = prop.substr(this->PathPrefix.size());
  367. if (!fileSetName.empty()) {
  368. value = impl->GetFileSetPaths(tgt, fileSetName, this->TypeName);
  369. }
  370. did_read = true;
  371. }
  372. return { did_read, value };
  373. }
  374. void FileSetType::AddFileSet(const std::string& name, cmFileSetVisibility vis,
  375. cmListFileBacktrace bt)
  376. {
  377. if (cmFileSetVisibilityIsForSelf(vis)) {
  378. this->SelfEntries.Entries.emplace_back(name, bt);
  379. }
  380. if (cmFileSetVisibilityIsForInterface(vis)) {
  381. this->InterfaceEntries.Entries.emplace_back(name, std::move(bt));
  382. }
  383. }
  384. namespace {
  385. #define SETUP_COMMON_LANGUAGE_PROPERTIES(lang) \
  386. initProp(#lang "_COMPILER_LAUNCHER"); \
  387. initProp(#lang "_STANDARD"); \
  388. initProp(#lang "_STANDARD_REQUIRED"); \
  389. initProp(#lang "_EXTENSIONS"); \
  390. initProp(#lang "_VISIBILITY_PRESET")
  391. }
  392. cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
  393. Visibility vis, cmMakefile* mf, PerConfig perConfig)
  394. : impl(cm::make_unique<cmTargetInternals>())
  395. {
  396. assert(mf);
  397. this->impl->TargetType = type;
  398. this->impl->Makefile = mf;
  399. this->impl->Name = name;
  400. this->impl->IsGeneratorProvided = false;
  401. this->impl->HaveInstallRule = false;
  402. this->impl->IsDLLPlatform = false;
  403. this->impl->IsAIX = false;
  404. this->impl->IsAndroid = false;
  405. this->impl->IsImportedTarget =
  406. (vis == VisibilityImported || vis == VisibilityImportedGlobally);
  407. this->impl->ImportedGloballyVisible = vis == VisibilityImportedGlobally;
  408. this->impl->BuildInterfaceIncludesAppended = false;
  409. this->impl->PerConfig = (perConfig == PerConfig::Yes);
  410. // Check whether this is a DLL platform.
  411. this->impl->IsDLLPlatform =
  412. !this->impl->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")
  413. .empty();
  414. // Check whether we are targeting AIX.
  415. {
  416. std::string const& systemName =
  417. this->impl->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME");
  418. this->impl->IsAIX = (systemName == "AIX" || systemName == "OS400");
  419. }
  420. // Check whether we are targeting an Android platform.
  421. this->impl->IsAndroid = (this->impl->Makefile->GetSafeDefinition(
  422. "CMAKE_SYSTEM_NAME") == "Android");
  423. std::string defKey;
  424. defKey.reserve(128);
  425. defKey += "CMAKE_";
  426. auto initProp = [this, mf, &defKey](const std::string& property) {
  427. // Replace everything after "CMAKE_"
  428. defKey.replace(defKey.begin() + 6, defKey.end(), property);
  429. if (cmValue value = mf->GetDefinition(defKey)) {
  430. this->SetProperty(property, value);
  431. }
  432. };
  433. auto initPropValue = [this, mf, &defKey](const std::string& property,
  434. const char* default_value) {
  435. // Replace everything after "CMAKE_"
  436. defKey.replace(defKey.begin() + 6, defKey.end(), property);
  437. if (cmValue value = mf->GetDefinition(defKey)) {
  438. this->SetProperty(property, value);
  439. } else if (default_value) {
  440. this->SetProperty(property, default_value);
  441. }
  442. };
  443. // Setup default property values.
  444. if (this->CanCompileSources()) {
  445. SETUP_COMMON_LANGUAGE_PROPERTIES(C);
  446. SETUP_COMMON_LANGUAGE_PROPERTIES(OBJC);
  447. SETUP_COMMON_LANGUAGE_PROPERTIES(CXX);
  448. SETUP_COMMON_LANGUAGE_PROPERTIES(OBJCXX);
  449. SETUP_COMMON_LANGUAGE_PROPERTIES(CUDA);
  450. SETUP_COMMON_LANGUAGE_PROPERTIES(HIP);
  451. initProp("ANDROID_API");
  452. initProp("ANDROID_API_MIN");
  453. initProp("ANDROID_ARCH");
  454. initProp("ANDROID_STL_TYPE");
  455. initProp("ANDROID_SKIP_ANT_STEP");
  456. initProp("ANDROID_PROCESS_MAX");
  457. initProp("ANDROID_PROGUARD");
  458. initProp("ANDROID_PROGUARD_CONFIG_PATH");
  459. initProp("ANDROID_SECURE_PROPS_PATH");
  460. initProp("ANDROID_NATIVE_LIB_DIRECTORIES");
  461. initProp("ANDROID_NATIVE_LIB_DEPENDENCIES");
  462. initProp("ANDROID_JAVA_SOURCE_DIR");
  463. initProp("ANDROID_JAR_DIRECTORIES");
  464. initProp("ANDROID_JAR_DEPENDENCIES");
  465. initProp("ANDROID_ASSETS_DIRECTORIES");
  466. initProp("ANDROID_ANT_ADDITIONAL_OPTIONS");
  467. initProp("BUILD_RPATH");
  468. initProp("BUILD_RPATH_USE_ORIGIN");
  469. initProp("INSTALL_NAME_DIR");
  470. initProp("INSTALL_REMOVE_ENVIRONMENT_RPATH");
  471. initPropValue("INSTALL_RPATH", "");
  472. initPropValue("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  473. initProp("INTERPROCEDURAL_OPTIMIZATION");
  474. initPropValue("SKIP_BUILD_RPATH", "OFF");
  475. initPropValue("BUILD_WITH_INSTALL_RPATH", "OFF");
  476. initProp("ARCHIVE_OUTPUT_DIRECTORY");
  477. initProp("LIBRARY_OUTPUT_DIRECTORY");
  478. initProp("RUNTIME_OUTPUT_DIRECTORY");
  479. initProp("PDB_OUTPUT_DIRECTORY");
  480. initProp("COMPILE_PDB_OUTPUT_DIRECTORY");
  481. initProp("FRAMEWORK");
  482. initProp("FRAMEWORK_MULTI_CONFIG_POSTFIX");
  483. initProp("Fortran_FORMAT");
  484. initProp("Fortran_MODULE_DIRECTORY");
  485. initProp("Fortran_COMPILER_LAUNCHER");
  486. initProp("Fortran_PREPROCESS");
  487. initProp("Fortran_VISIBILITY_PRESET");
  488. initProp("GNUtoMS");
  489. initProp("OSX_ARCHITECTURES");
  490. initProp("IOS_INSTALL_COMBINED");
  491. initProp("AUTOMOC");
  492. initProp("AUTOUIC");
  493. initProp("AUTORCC");
  494. initProp("AUTOGEN_ORIGIN_DEPENDS");
  495. initProp("AUTOGEN_PARALLEL");
  496. initProp("AUTOMOC_COMPILER_PREDEFINES");
  497. initProp("AUTOMOC_DEPEND_FILTERS");
  498. initProp("AUTOMOC_MACRO_NAMES");
  499. initProp("AUTOMOC_MOC_OPTIONS");
  500. initProp("AUTOUIC_OPTIONS");
  501. initProp("AUTOMOC_PATH_PREFIX");
  502. initProp("AUTOUIC_SEARCH_PATHS");
  503. initProp("AUTORCC_OPTIONS");
  504. initProp("LINK_DEPENDS_NO_SHARED");
  505. initProp("LINK_INTERFACE_LIBRARIES");
  506. initProp("MSVC_RUNTIME_LIBRARY");
  507. initProp("WATCOM_RUNTIME_LIBRARY");
  508. initProp("WIN32_EXECUTABLE");
  509. initProp("MACOSX_BUNDLE");
  510. initProp("MACOSX_RPATH");
  511. initProp("NO_SYSTEM_FROM_IMPORTED");
  512. initProp("BUILD_WITH_INSTALL_NAME_DIR");
  513. initProp("C_CLANG_TIDY");
  514. initProp("C_CPPLINT");
  515. initProp("C_CPPCHECK");
  516. initProp("C_INCLUDE_WHAT_YOU_USE");
  517. initProp("C_LINKER_LAUNCHER");
  518. initProp("LINK_WHAT_YOU_USE");
  519. initProp("CXX_CLANG_TIDY");
  520. initProp("CXX_CPPLINT");
  521. initProp("CXX_CPPCHECK");
  522. initProp("CXX_INCLUDE_WHAT_YOU_USE");
  523. initProp("CXX_LINKER_LAUNCHER");
  524. initProp("CUDA_SEPARABLE_COMPILATION");
  525. initProp("CUDA_RESOLVE_DEVICE_SYMBOLS");
  526. initProp("CUDA_RUNTIME_LIBRARY");
  527. initProp("CUDA_ARCHITECTURES");
  528. initProp("HIP_RUNTIME_LIBRARY");
  529. initProp("HIP_ARCHITECTURES");
  530. initProp("VISIBILITY_INLINES_HIDDEN");
  531. initProp("JOB_POOL_COMPILE");
  532. initProp("JOB_POOL_LINK");
  533. initProp("JOB_POOL_PRECOMPILE_HEADER");
  534. initProp("ISPC_COMPILER_LAUNCHER");
  535. initProp("ISPC_HEADER_DIRECTORY");
  536. initPropValue("ISPC_HEADER_SUFFIX", "_ispc.h");
  537. initProp("ISPC_INSTRUCTION_SETS");
  538. initProp("LINK_SEARCH_START_STATIC");
  539. initProp("LINK_SEARCH_END_STATIC");
  540. initProp("OBJC_CLANG_TIDY");
  541. initProp("OBJC_LINKER_LAUNCHER");
  542. initProp("OBJCXX_CLANG_TIDY");
  543. initProp("OBJCXX_LINKER_LAUNCHER");
  544. initProp("Swift_LANGUAGE_VERSION");
  545. initProp("Swift_MODULE_DIRECTORY");
  546. initProp("VS_JUST_MY_CODE_DEBUGGING");
  547. initProp("VS_NO_COMPILE_BATCHING");
  548. initProp("DISABLE_PRECOMPILE_HEADERS");
  549. initProp("UNITY_BUILD");
  550. initProp("UNITY_BUILD_UNIQUE_ID");
  551. initProp("OPTIMIZE_DEPENDENCIES");
  552. initProp("EXPORT_COMPILE_COMMANDS");
  553. initProp("COMPILE_WARNING_AS_ERROR");
  554. initPropValue("UNITY_BUILD_BATCH_SIZE", "8");
  555. initPropValue("UNITY_BUILD_MODE", "BATCH");
  556. initPropValue("PCH_WARN_INVALID", "ON");
  557. initPropValue("PCH_INSTANTIATE_TEMPLATES", "ON");
  558. #ifdef __APPLE__
  559. if (this->GetGlobalGenerator()->IsXcode()) {
  560. initProp("XCODE_SCHEME_ADDRESS_SANITIZER");
  561. initProp("XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN");
  562. initProp("XCODE_SCHEME_DEBUG_DOCUMENT_VERSIONING");
  563. initProp("XCODE_SCHEME_ENABLE_GPU_FRAME_CAPTURE_MODE");
  564. initProp("XCODE_SCHEME_THREAD_SANITIZER");
  565. initProp("XCODE_SCHEME_THREAD_SANITIZER_STOP");
  566. initProp("XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER");
  567. initProp("XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP");
  568. initProp("XCODE_SCHEME_WORKING_DIRECTORY");
  569. initProp("XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER");
  570. initProp("XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP");
  571. initProp("XCODE_SCHEME_MALLOC_SCRIBBLE");
  572. initProp("XCODE_SCHEME_MALLOC_GUARD_EDGES");
  573. initProp("XCODE_SCHEME_GUARD_MALLOC");
  574. initProp("XCODE_SCHEME_ZOMBIE_OBJECTS");
  575. initProp("XCODE_SCHEME_MALLOC_STACK");
  576. initProp("XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE");
  577. initProp("XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS");
  578. initProp("XCODE_SCHEME_ENVIRONMENT");
  579. initPropValue("XCODE_LINK_BUILD_PHASE_MODE", "NONE");
  580. }
  581. #endif
  582. }
  583. initProp("FOLDER");
  584. initProp("VERIFY_INTERFACE_HEADER_SETS");
  585. if (this->GetGlobalGenerator()->IsXcode()) {
  586. initProp("XCODE_GENERATE_SCHEME");
  587. }
  588. // Setup per-configuration property default values.
  589. if (this->GetType() != cmStateEnums::UTILITY &&
  590. this->GetType() != cmStateEnums::GLOBAL_TARGET) {
  591. static const auto configProps = {
  592. /* clang-format needs this comment to break after the opening brace */
  593. "ARCHIVE_OUTPUT_DIRECTORY_", "LIBRARY_OUTPUT_DIRECTORY_",
  594. "RUNTIME_OUTPUT_DIRECTORY_", "PDB_OUTPUT_DIRECTORY_",
  595. "COMPILE_PDB_OUTPUT_DIRECTORY_", "MAP_IMPORTED_CONFIG_",
  596. "INTERPROCEDURAL_OPTIMIZATION_"
  597. };
  598. // Collect the set of configuration types.
  599. std::vector<std::string> configNames =
  600. mf->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
  601. for (std::string const& configName : configNames) {
  602. std::string configUpper = cmSystemTools::UpperCase(configName);
  603. for (auto const& prop : configProps) {
  604. // Interface libraries have no output locations, so honor only
  605. // the configuration map.
  606. if (this->impl->TargetType == cmStateEnums::INTERFACE_LIBRARY &&
  607. strcmp(prop, "MAP_IMPORTED_CONFIG_") != 0) {
  608. continue;
  609. }
  610. std::string property = cmStrCat(prop, configUpper);
  611. initProp(property);
  612. }
  613. // Initialize per-configuration name postfix property from the
  614. // variable only for non-executable targets. This preserves
  615. // compatibility with previous CMake versions in which executables
  616. // did not support this variable. Projects may still specify the
  617. // property directly.
  618. if (this->impl->TargetType != cmStateEnums::EXECUTABLE &&
  619. this->impl->TargetType != cmStateEnums::INTERFACE_LIBRARY) {
  620. std::string property =
  621. cmStrCat(cmSystemTools::UpperCase(configName), "_POSTFIX");
  622. initProp(property);
  623. }
  624. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
  625. this->impl->TargetType == cmStateEnums::STATIC_LIBRARY) {
  626. std::string property = cmStrCat("FRAMEWORK_MULTI_CONFIG_POSTFIX_",
  627. cmSystemTools::UpperCase(configName));
  628. initProp(property);
  629. }
  630. }
  631. if (!this->IsImported()) {
  632. initProp("LINK_LIBRARIES_ONLY_TARGETS");
  633. }
  634. }
  635. // Save the backtrace of target construction.
  636. this->impl->Backtrace = this->impl->Makefile->GetBacktrace();
  637. if (!this->IsImported()) {
  638. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  639. // of the same directory property:
  640. cm::append(this->impl->IncludeDirectoriesEntries,
  641. this->impl->Makefile->GetIncludeDirectoriesEntries());
  642. {
  643. auto const& sysInc = this->impl->Makefile->GetSystemIncludeDirectories();
  644. this->impl->SystemIncludeDirectories.insert(sysInc.begin(),
  645. sysInc.end());
  646. }
  647. cm::append(this->impl->CompileOptionsEntries,
  648. this->impl->Makefile->GetCompileOptionsEntries());
  649. cm::append(this->impl->LinkOptionsEntries,
  650. this->impl->Makefile->GetLinkOptionsEntries());
  651. cm::append(this->impl->LinkDirectoriesEntries,
  652. this->impl->Makefile->GetLinkDirectoriesEntries());
  653. }
  654. if (this->impl->TargetType == cmStateEnums::EXECUTABLE) {
  655. initProp("ANDROID_GUI");
  656. initProp("CROSSCOMPILING_EMULATOR");
  657. initProp("ENABLE_EXPORTS");
  658. }
  659. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
  660. this->impl->TargetType == cmStateEnums::MODULE_LIBRARY) {
  661. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  662. } else if (this->CanCompileSources()) {
  663. initProp("POSITION_INDEPENDENT_CODE");
  664. }
  665. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
  666. this->impl->TargetType == cmStateEnums::EXECUTABLE) {
  667. initProp("AIX_EXPORT_ALL_SYMBOLS");
  668. initProp("WINDOWS_EXPORT_ALL_SYMBOLS");
  669. }
  670. // Record current policies for later use.
  671. this->impl->Makefile->RecordPolicies(this->impl->PolicyMap);
  672. if (this->impl->TargetType == cmStateEnums::INTERFACE_LIBRARY) {
  673. // This policy is checked in a few conditions. The properties relevant
  674. // to the policy are always ignored for cmStateEnums::INTERFACE_LIBRARY
  675. // targets,
  676. // so ensure that the conditions don't lead to nonsense.
  677. this->impl->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
  678. }
  679. if (!this->IsImported()) {
  680. initProp("DOTNET_SDK");
  681. }
  682. if (this->impl->TargetType <= cmStateEnums::GLOBAL_TARGET) {
  683. initProp("DOTNET_TARGET_FRAMEWORK");
  684. initProp("DOTNET_TARGET_FRAMEWORK_VERSION");
  685. }
  686. // check for "CMAKE_VS_GLOBALS" variable and set up target properties
  687. // if any
  688. cmValue globals = mf->GetDefinition("CMAKE_VS_GLOBALS");
  689. if (globals) {
  690. const std::string genName = mf->GetGlobalGenerator()->GetName();
  691. if (cmHasLiteralPrefix(genName, "Visual Studio")) {
  692. std::vector<std::string> props = cmExpandedList(*globals);
  693. const std::string vsGlobal = "VS_GLOBAL_";
  694. for (const std::string& i : props) {
  695. // split NAME=VALUE
  696. const std::string::size_type assignment = i.find('=');
  697. if (assignment != std::string::npos) {
  698. const std::string propName = vsGlobal + i.substr(0, assignment);
  699. const std::string propValue = i.substr(assignment + 1);
  700. initPropValue(propName, propValue.c_str());
  701. }
  702. }
  703. }
  704. }
  705. for (auto const& prop : mf->GetState()->GetPropertyDefinitions().GetMap()) {
  706. if (prop.first.second == cmProperty::TARGET &&
  707. !prop.second.GetInitializeFromVariable().empty()) {
  708. if (auto value =
  709. mf->GetDefinition(prop.second.GetInitializeFromVariable())) {
  710. this->SetProperty(prop.first.first, value);
  711. }
  712. }
  713. }
  714. }
  715. cmTarget::cmTarget(cmTarget&&) noexcept = default;
  716. cmTarget::~cmTarget() = default;
  717. cmTarget& cmTarget::operator=(cmTarget&&) noexcept = default;
  718. cmStateEnums::TargetType cmTarget::GetType() const
  719. {
  720. return this->impl->TargetType;
  721. }
  722. cmMakefile* cmTarget::GetMakefile() const
  723. {
  724. return this->impl->Makefile;
  725. }
  726. cmPolicies::PolicyMap const& cmTarget::GetPolicyMap() const
  727. {
  728. return this->impl->PolicyMap;
  729. }
  730. const std::string& cmTarget::GetName() const
  731. {
  732. return this->impl->Name;
  733. }
  734. cmPolicies::PolicyStatus cmTarget::GetPolicyStatus(
  735. cmPolicies::PolicyID policy) const
  736. {
  737. return this->impl->PolicyMap.Get(policy);
  738. }
  739. cmGlobalGenerator* cmTarget::GetGlobalGenerator() const
  740. {
  741. return this->impl->Makefile->GetGlobalGenerator();
  742. }
  743. BTs<std::string> const* cmTarget::GetLanguageStandardProperty(
  744. const std::string& propertyName) const
  745. {
  746. auto entry = this->impl->LanguageStandardProperties.find(propertyName);
  747. if (entry != this->impl->LanguageStandardProperties.end()) {
  748. return &entry->second;
  749. }
  750. return nullptr;
  751. }
  752. void cmTarget::SetLanguageStandardProperty(std::string const& lang,
  753. std::string const& value,
  754. const std::string& feature)
  755. {
  756. cmListFileBacktrace featureBacktrace;
  757. for (auto const& entry : this->impl->CompileFeaturesEntries) {
  758. if (entry.Value == feature) {
  759. featureBacktrace = entry.Backtrace;
  760. break;
  761. }
  762. }
  763. BTs<std::string>& languageStandardProperty =
  764. this->impl->LanguageStandardProperties[cmStrCat(lang, "_STANDARD")];
  765. if (languageStandardProperty.Value != value) {
  766. languageStandardProperty.Value = value;
  767. languageStandardProperty.Backtraces.clear();
  768. }
  769. languageStandardProperty.Backtraces.emplace_back(featureBacktrace);
  770. }
  771. void cmTarget::AddUtility(std::string const& name, bool cross, cmMakefile* mf)
  772. {
  773. this->impl->Utilities.insert(BT<std::pair<std::string, bool>>(
  774. { name, cross }, mf ? mf->GetBacktrace() : cmListFileBacktrace()));
  775. }
  776. void cmTarget::AddUtility(BT<std::pair<std::string, bool>> util)
  777. {
  778. this->impl->Utilities.emplace(std::move(util));
  779. }
  780. std::set<BT<std::pair<std::string, bool>>> const& cmTarget::GetUtilities()
  781. const
  782. {
  783. return this->impl->Utilities;
  784. }
  785. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  786. {
  787. return this->impl->Backtrace;
  788. }
  789. bool cmTarget::IsExecutableWithExports() const
  790. {
  791. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  792. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  793. }
  794. bool cmTarget::IsFrameworkOnApple() const
  795. {
  796. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  797. this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  798. this->impl->Makefile->IsOn("APPLE") &&
  799. this->GetPropertyAsBool("FRAMEWORK"));
  800. }
  801. bool cmTarget::IsAppBundleOnApple() const
  802. {
  803. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  804. this->impl->Makefile->IsOn("APPLE") &&
  805. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  806. }
  807. bool cmTarget::IsAndroidGuiExecutable() const
  808. {
  809. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  810. this->impl->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI"));
  811. }
  812. bool cmTarget::HasKnownObjectFileLocation(std::string* reason) const
  813. {
  814. return this->GetGlobalGenerator()->HasKnownObjectFileLocation(*this, reason);
  815. }
  816. std::vector<cmCustomCommand> const& cmTarget::GetPreBuildCommands() const
  817. {
  818. return this->impl->PreBuildCommands;
  819. }
  820. void cmTarget::AddPreBuildCommand(cmCustomCommand const& cmd)
  821. {
  822. this->impl->PreBuildCommands.push_back(cmd);
  823. }
  824. void cmTarget::AddPreBuildCommand(cmCustomCommand&& cmd)
  825. {
  826. this->impl->PreBuildCommands.push_back(std::move(cmd));
  827. }
  828. std::vector<cmCustomCommand> const& cmTarget::GetPreLinkCommands() const
  829. {
  830. return this->impl->PreLinkCommands;
  831. }
  832. void cmTarget::AddPreLinkCommand(cmCustomCommand const& cmd)
  833. {
  834. this->impl->PreLinkCommands.push_back(cmd);
  835. }
  836. void cmTarget::AddPreLinkCommand(cmCustomCommand&& cmd)
  837. {
  838. this->impl->PreLinkCommands.push_back(std::move(cmd));
  839. }
  840. std::vector<cmCustomCommand> const& cmTarget::GetPostBuildCommands() const
  841. {
  842. return this->impl->PostBuildCommands;
  843. }
  844. void cmTarget::AddPostBuildCommand(cmCustomCommand const& cmd)
  845. {
  846. this->impl->PostBuildCommands.push_back(cmd);
  847. }
  848. void cmTarget::AddPostBuildCommand(cmCustomCommand&& cmd)
  849. {
  850. this->impl->PostBuildCommands.push_back(std::move(cmd));
  851. }
  852. void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
  853. {
  854. if (!srcs.empty()) {
  855. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  856. this->impl->SourceEntries.emplace_back(cmJoin(srcs, ";"), lfbt);
  857. }
  858. }
  859. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  860. {
  861. std::string srcFiles;
  862. const char* sep = "";
  863. for (auto filename : srcs) {
  864. if (!cmGeneratorExpression::StartsWithGeneratorExpression(filename)) {
  865. if (!filename.empty()) {
  866. filename = this->impl->ProcessSourceItemCMP0049(filename);
  867. if (filename.empty()) {
  868. return;
  869. }
  870. }
  871. this->impl->Makefile->GetOrCreateSource(filename);
  872. }
  873. srcFiles += sep;
  874. srcFiles += filename;
  875. sep = ";";
  876. }
  877. if (!srcFiles.empty()) {
  878. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  879. this->impl->SourceEntries.emplace_back(std::move(srcFiles), lfbt);
  880. }
  881. }
  882. std::string cmTargetInternals::ProcessSourceItemCMP0049(
  883. const std::string& s) const
  884. {
  885. std::string src = s;
  886. // For backwards compatibility replace variables in source names.
  887. // This should eventually be removed.
  888. this->Makefile->ExpandVariablesInString(src);
  889. if (src != s) {
  890. std::ostringstream e;
  891. bool noMessage = false;
  892. MessageType messageType = MessageType::AUTHOR_WARNING;
  893. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0049)) {
  894. case cmPolicies::WARN:
  895. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0049) << "\n";
  896. break;
  897. case cmPolicies::OLD:
  898. noMessage = true;
  899. break;
  900. case cmPolicies::REQUIRED_ALWAYS:
  901. case cmPolicies::REQUIRED_IF_USED:
  902. case cmPolicies::NEW:
  903. messageType = MessageType::FATAL_ERROR;
  904. }
  905. if (!noMessage) {
  906. e << "Legacy variable expansion in source file \"" << s
  907. << "\" expanded to \"" << src << "\" in target \"" << this->Name
  908. << "\". This behavior will be removed in a "
  909. "future version of CMake.";
  910. this->Makefile->IssueMessage(messageType, e.str());
  911. if (messageType == MessageType::FATAL_ERROR) {
  912. return "";
  913. }
  914. }
  915. }
  916. return src;
  917. }
  918. std::string cmTarget::GetSourceCMP0049(const std::string& s)
  919. {
  920. return this->impl->ProcessSourceItemCMP0049(s);
  921. }
  922. struct CreateLocation
  923. {
  924. cmMakefile const* Makefile;
  925. CreateLocation(cmMakefile const* mf)
  926. : Makefile(mf)
  927. {
  928. }
  929. cmSourceFileLocation operator()(const std::string& filename) const
  930. {
  931. return cmSourceFileLocation(this->Makefile, filename);
  932. }
  933. };
  934. struct LocationMatcher
  935. {
  936. const cmSourceFileLocation& Needle;
  937. LocationMatcher(const cmSourceFileLocation& needle)
  938. : Needle(needle)
  939. {
  940. }
  941. bool operator()(cmSourceFileLocation& loc)
  942. {
  943. return loc.Matches(this->Needle);
  944. }
  945. };
  946. struct TargetPropertyEntryFinder
  947. {
  948. private:
  949. const cmSourceFileLocation& Needle;
  950. public:
  951. TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
  952. : Needle(needle)
  953. {
  954. }
  955. bool operator()(BT<std::string> const& entry)
  956. {
  957. std::vector<std::string> files = cmExpandedList(entry.Value);
  958. std::vector<cmSourceFileLocation> locations;
  959. locations.reserve(files.size());
  960. std::transform(files.begin(), files.end(), std::back_inserter(locations),
  961. CreateLocation(this->Needle.GetMakefile()));
  962. return std::find_if(locations.begin(), locations.end(),
  963. LocationMatcher(this->Needle)) != locations.end();
  964. }
  965. };
  966. cmSourceFile* cmTarget::AddSource(const std::string& src, bool before)
  967. {
  968. cmSourceFileLocation sfl(this->impl->Makefile, src,
  969. cmSourceFileLocationKind::Known);
  970. if (std::find_if(
  971. this->impl->SourceEntries.begin(), this->impl->SourceEntries.end(),
  972. TargetPropertyEntryFinder(sfl)) == this->impl->SourceEntries.end()) {
  973. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  974. this->impl->SourceEntries.insert(before ? this->impl->SourceEntries.begin()
  975. : this->impl->SourceEntries.end(),
  976. BT<std::string>(src, lfbt));
  977. }
  978. if (cmGeneratorExpression::Find(src) != std::string::npos) {
  979. return nullptr;
  980. }
  981. return this->impl->Makefile->GetOrCreateSource(
  982. src, false, cmSourceFileLocationKind::Known);
  983. }
  984. void cmTarget::ClearDependencyInformation(cmMakefile& mf) const
  985. {
  986. std::string depname = cmStrCat(this->GetName(), "_LIB_DEPENDS");
  987. mf.RemoveCacheDefinition(depname);
  988. }
  989. std::string cmTarget::GetDebugGeneratorExpressions(
  990. const std::string& value, cmTargetLinkLibraryType llt) const
  991. {
  992. if (llt == GENERAL_LibraryType) {
  993. return value;
  994. }
  995. // Get the list of configurations considered to be DEBUG.
  996. std::vector<std::string> debugConfigs =
  997. this->impl->Makefile->GetCMakeInstance()->GetDebugConfigs();
  998. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  999. if (debugConfigs.size() > 1) {
  1000. for (std::string const& conf : cmMakeRange(debugConfigs).advance(1)) {
  1001. configString += ",$<CONFIG:" + conf + ">";
  1002. }
  1003. configString = "$<OR:" + configString + ">";
  1004. }
  1005. if (llt == OPTIMIZED_LibraryType) {
  1006. configString = "$<NOT:" + configString + ">";
  1007. }
  1008. return "$<" + configString + ":" + value + ">";
  1009. }
  1010. static std::string targetNameGenex(const std::string& lib)
  1011. {
  1012. return "$<TARGET_NAME:" + lib + ">";
  1013. }
  1014. bool cmTarget::PushTLLCommandTrace(TLLSignature signature,
  1015. cmListFileContext const& lfc)
  1016. {
  1017. bool ret = true;
  1018. if (!this->impl->TLLCommands.empty()) {
  1019. if (this->impl->TLLCommands.back().first != signature) {
  1020. ret = false;
  1021. }
  1022. }
  1023. if (this->impl->TLLCommands.empty() ||
  1024. this->impl->TLLCommands.back().second != lfc) {
  1025. this->impl->TLLCommands.emplace_back(signature, lfc);
  1026. }
  1027. return ret;
  1028. }
  1029. void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const
  1030. {
  1031. const char* sigString =
  1032. (sig == cmTarget::KeywordTLLSignature ? "keyword" : "plain");
  1033. s << "The uses of the " << sigString << " signature are here:\n";
  1034. for (auto const& cmd : this->impl->TLLCommands) {
  1035. if (cmd.first == sig) {
  1036. cmListFileContext lfc = cmd.second;
  1037. lfc.FilePath = cmSystemTools::RelativeIfUnder(
  1038. this->impl->Makefile->GetState()->GetSourceDirectory(), lfc.FilePath);
  1039. s << " * " << lfc << '\n';
  1040. }
  1041. }
  1042. }
  1043. std::string const& cmTarget::GetInstallPath() const
  1044. {
  1045. return this->impl->InstallPath;
  1046. }
  1047. void cmTarget::SetInstallPath(std::string const& name)
  1048. {
  1049. this->impl->InstallPath = name;
  1050. }
  1051. std::string const& cmTarget::GetRuntimeInstallPath() const
  1052. {
  1053. return this->impl->RuntimeInstallPath;
  1054. }
  1055. void cmTarget::SetRuntimeInstallPath(std::string const& name)
  1056. {
  1057. this->impl->RuntimeInstallPath = name;
  1058. }
  1059. bool cmTarget::GetHaveInstallRule() const
  1060. {
  1061. return this->impl->HaveInstallRule;
  1062. }
  1063. void cmTarget::SetHaveInstallRule(bool hir)
  1064. {
  1065. this->impl->HaveInstallRule = hir;
  1066. }
  1067. void cmTarget::AddInstallGenerator(cmInstallTargetGenerator* g)
  1068. {
  1069. this->impl->InstallGenerators.emplace_back(g);
  1070. }
  1071. std::vector<cmInstallTargetGenerator*> const& cmTarget::GetInstallGenerators()
  1072. const
  1073. {
  1074. return this->impl->InstallGenerators;
  1075. }
  1076. bool cmTarget::GetIsGeneratorProvided() const
  1077. {
  1078. return this->impl->IsGeneratorProvided;
  1079. }
  1080. void cmTarget::SetIsGeneratorProvided(bool igp)
  1081. {
  1082. this->impl->IsGeneratorProvided = igp;
  1083. }
  1084. cmTarget::LinkLibraryVectorType const& cmTarget::GetOriginalLinkLibraries()
  1085. const
  1086. {
  1087. return this->impl->OriginalLinkLibraries;
  1088. }
  1089. void cmTarget::AddLinkLibrary(cmMakefile& mf, std::string const& lib,
  1090. cmTargetLinkLibraryType llt)
  1091. {
  1092. cmTarget* tgt = mf.FindTargetToUse(lib);
  1093. {
  1094. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  1095. const std::string libName =
  1096. (isNonImportedTarget && llt != GENERAL_LibraryType)
  1097. ? targetNameGenex(lib)
  1098. : lib;
  1099. this->AppendProperty("LINK_LIBRARIES",
  1100. this->GetDebugGeneratorExpressions(libName, llt));
  1101. }
  1102. if (cmGeneratorExpression::Find(lib) != std::string::npos ||
  1103. (tgt &&
  1104. (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
  1105. tgt->GetType() == cmStateEnums::OBJECT_LIBRARY)) ||
  1106. (this->impl->Name == lib)) {
  1107. return;
  1108. }
  1109. this->impl->OriginalLinkLibraries.emplace_back(lib, llt);
  1110. // Add the explicit dependency information for libraries. This is
  1111. // simply a set of libraries separated by ";". There should always
  1112. // be a trailing ";". These library names are not canonical, in that
  1113. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  1114. // We shouldn't remove duplicates here because external libraries
  1115. // may be purposefully duplicated to handle recursive dependencies,
  1116. // and we removing one instance will break the link line. Duplicates
  1117. // will be appropriately eliminated at emit time.
  1118. if (this->impl->TargetType >= cmStateEnums::STATIC_LIBRARY &&
  1119. this->impl->TargetType <= cmStateEnums::MODULE_LIBRARY &&
  1120. (this->GetPolicyStatusCMP0073() == cmPolicies::OLD ||
  1121. this->GetPolicyStatusCMP0073() == cmPolicies::WARN)) {
  1122. std::string targetEntry = cmStrCat(this->impl->Name, "_LIB_DEPENDS");
  1123. std::string dependencies;
  1124. cmValue old_val = mf.GetDefinition(targetEntry);
  1125. if (old_val) {
  1126. dependencies += *old_val;
  1127. }
  1128. switch (llt) {
  1129. case GENERAL_LibraryType:
  1130. dependencies += "general";
  1131. break;
  1132. case DEBUG_LibraryType:
  1133. dependencies += "debug";
  1134. break;
  1135. case OPTIMIZED_LibraryType:
  1136. dependencies += "optimized";
  1137. break;
  1138. }
  1139. dependencies += ";";
  1140. dependencies += lib;
  1141. dependencies += ";";
  1142. mf.AddCacheDefinition(targetEntry, dependencies,
  1143. "Dependencies for the target", cmStateEnums::STATIC);
  1144. }
  1145. }
  1146. void cmTarget::AddSystemIncludeDirectories(const std::set<std::string>& incs)
  1147. {
  1148. this->impl->SystemIncludeDirectories.insert(incs.begin(), incs.end());
  1149. }
  1150. std::set<std::string> const& cmTarget::GetSystemIncludeDirectories() const
  1151. {
  1152. return this->impl->SystemIncludeDirectories;
  1153. }
  1154. void cmTarget::AddInstallIncludeDirectories(cmTargetExport const& te,
  1155. cmStringRange const& incs)
  1156. {
  1157. std::copy(
  1158. incs.begin(), incs.end(),
  1159. std::back_inserter(this->impl->InstallIncludeDirectoriesEntries[&te]));
  1160. }
  1161. cmStringRange cmTarget::GetInstallIncludeDirectoriesEntries(
  1162. cmTargetExport const& te) const
  1163. {
  1164. auto i = this->impl->InstallIncludeDirectoriesEntries.find(&te);
  1165. if (i == this->impl->InstallIncludeDirectoriesEntries.end()) {
  1166. decltype(i->second) empty;
  1167. return cmMakeRange(empty);
  1168. }
  1169. return cmMakeRange(i->second);
  1170. }
  1171. cmBTStringRange cmTarget::GetIncludeDirectoriesEntries() const
  1172. {
  1173. return cmMakeRange(this->impl->IncludeDirectoriesEntries);
  1174. }
  1175. cmBTStringRange cmTarget::GetCompileOptionsEntries() const
  1176. {
  1177. return cmMakeRange(this->impl->CompileOptionsEntries);
  1178. }
  1179. cmBTStringRange cmTarget::GetCompileFeaturesEntries() const
  1180. {
  1181. return cmMakeRange(this->impl->CompileFeaturesEntries);
  1182. }
  1183. cmBTStringRange cmTarget::GetCompileDefinitionsEntries() const
  1184. {
  1185. return cmMakeRange(this->impl->CompileDefinitionsEntries);
  1186. }
  1187. cmBTStringRange cmTarget::GetPrecompileHeadersEntries() const
  1188. {
  1189. return cmMakeRange(this->impl->PrecompileHeadersEntries);
  1190. }
  1191. cmBTStringRange cmTarget::GetSourceEntries() const
  1192. {
  1193. return cmMakeRange(this->impl->SourceEntries);
  1194. }
  1195. cmBTStringRange cmTarget::GetLinkOptionsEntries() const
  1196. {
  1197. return cmMakeRange(this->impl->LinkOptionsEntries);
  1198. }
  1199. cmBTStringRange cmTarget::GetLinkDirectoriesEntries() const
  1200. {
  1201. return cmMakeRange(this->impl->LinkDirectoriesEntries);
  1202. }
  1203. cmBTStringRange cmTarget::GetLinkImplementationEntries() const
  1204. {
  1205. return cmMakeRange(this->impl->LinkImplementationPropertyEntries);
  1206. }
  1207. cmBTStringRange cmTarget::GetLinkInterfaceEntries() const
  1208. {
  1209. return cmMakeRange(this->impl->LinkInterfacePropertyEntries);
  1210. }
  1211. cmBTStringRange cmTarget::GetLinkInterfaceDirectEntries() const
  1212. {
  1213. return cmMakeRange(this->impl->LinkInterfaceDirectPropertyEntries);
  1214. }
  1215. cmBTStringRange cmTarget::GetLinkInterfaceDirectExcludeEntries() const
  1216. {
  1217. return cmMakeRange(this->impl->LinkInterfaceDirectExcludePropertyEntries);
  1218. }
  1219. cmBTStringRange cmTarget::GetHeaderSetsEntries() const
  1220. {
  1221. return cmMakeRange(this->impl->HeadersFileSets.SelfEntries.Entries);
  1222. }
  1223. cmBTStringRange cmTarget::GetInterfaceHeaderSetsEntries() const
  1224. {
  1225. return cmMakeRange(this->impl->HeadersFileSets.InterfaceEntries.Entries);
  1226. }
  1227. namespace {
  1228. #define MAKE_PROP(PROP) const std::string prop##PROP = #PROP
  1229. MAKE_PROP(C_STANDARD);
  1230. MAKE_PROP(CXX_STANDARD);
  1231. MAKE_PROP(CUDA_STANDARD);
  1232. MAKE_PROP(HIP_STANDARD);
  1233. MAKE_PROP(OBJC_STANDARD);
  1234. MAKE_PROP(OBJCXX_STANDARD);
  1235. MAKE_PROP(COMPILE_DEFINITIONS);
  1236. MAKE_PROP(COMPILE_FEATURES);
  1237. MAKE_PROP(COMPILE_OPTIONS);
  1238. MAKE_PROP(PRECOMPILE_HEADERS);
  1239. MAKE_PROP(PRECOMPILE_HEADERS_REUSE_FROM);
  1240. MAKE_PROP(CUDA_PTX_COMPILATION);
  1241. MAKE_PROP(EXPORT_NAME);
  1242. MAKE_PROP(IMPORTED);
  1243. MAKE_PROP(IMPORTED_GLOBAL);
  1244. MAKE_PROP(INCLUDE_DIRECTORIES);
  1245. MAKE_PROP(LINK_OPTIONS);
  1246. MAKE_PROP(LINK_DIRECTORIES);
  1247. MAKE_PROP(LINK_LIBRARIES);
  1248. MAKE_PROP(MANUALLY_ADDED_DEPENDENCIES);
  1249. MAKE_PROP(NAME);
  1250. MAKE_PROP(SOURCES);
  1251. MAKE_PROP(TYPE);
  1252. MAKE_PROP(BINARY_DIR);
  1253. MAKE_PROP(SOURCE_DIR);
  1254. MAKE_PROP(FALSE);
  1255. MAKE_PROP(TRUE);
  1256. MAKE_PROP(INTERFACE_LINK_LIBRARIES);
  1257. MAKE_PROP(INTERFACE_LINK_LIBRARIES_DIRECT);
  1258. MAKE_PROP(INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE);
  1259. #undef MAKE_PROP
  1260. }
  1261. namespace {
  1262. // to workaround bug on GCC/AIX
  1263. // Define a template to force conversion to std::string
  1264. template <typename ValueType>
  1265. std::string ConvertToString(ValueType value);
  1266. template <>
  1267. std::string ConvertToString<const char*>(const char* value)
  1268. {
  1269. return std::string(value);
  1270. }
  1271. template <>
  1272. std::string ConvertToString<cmValue>(cmValue value)
  1273. {
  1274. return std::string(*value);
  1275. }
  1276. template <typename ValueType>
  1277. bool StringIsEmpty(ValueType const& value);
  1278. template <>
  1279. bool StringIsEmpty<const char*>(const char* const& value)
  1280. {
  1281. return cmValue::IsEmpty(value);
  1282. }
  1283. template <>
  1284. bool StringIsEmpty<cmValue>(cmValue const& value)
  1285. {
  1286. return value.IsEmpty();
  1287. }
  1288. template <>
  1289. bool StringIsEmpty<std::string>(std::string const& value)
  1290. {
  1291. return value.empty();
  1292. }
  1293. }
  1294. template <typename ValueType>
  1295. void cmTarget::StoreProperty(const std::string& prop, ValueType value)
  1296. {
  1297. if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
  1298. this->impl->Makefile->IssueMessage(
  1299. MessageType::FATAL_ERROR,
  1300. "MANUALLY_ADDED_DEPENDENCIES property is read-only\n");
  1301. return;
  1302. }
  1303. if (prop == propNAME) {
  1304. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1305. "NAME property is read-only\n");
  1306. return;
  1307. }
  1308. if (prop == propTYPE) {
  1309. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1310. "TYPE property is read-only\n");
  1311. return;
  1312. }
  1313. if (prop == propEXPORT_NAME && this->IsImported()) {
  1314. std::ostringstream e;
  1315. e << "EXPORT_NAME property can't be set on imported targets (\""
  1316. << this->impl->Name << "\")\n";
  1317. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1318. return;
  1319. }
  1320. if (prop == propSOURCES && this->IsImported()) {
  1321. std::ostringstream e;
  1322. e << "SOURCES property can't be set on imported targets (\""
  1323. << this->impl->Name << "\")\n";
  1324. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1325. return;
  1326. }
  1327. if (prop == propIMPORTED_GLOBAL && !this->IsImported()) {
  1328. std::ostringstream e;
  1329. e << "IMPORTED_GLOBAL property can't be set on non-imported targets (\""
  1330. << this->impl->Name << "\")\n";
  1331. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1332. return;
  1333. }
  1334. if (prop == propINCLUDE_DIRECTORIES) {
  1335. this->impl->IncludeDirectoriesEntries.clear();
  1336. if (value) {
  1337. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1338. this->impl->IncludeDirectoriesEntries.emplace_back(value, lfbt);
  1339. }
  1340. } else if (prop == propCOMPILE_OPTIONS) {
  1341. this->impl->CompileOptionsEntries.clear();
  1342. if (value) {
  1343. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1344. this->impl->CompileOptionsEntries.emplace_back(value, lfbt);
  1345. }
  1346. } else if (prop == propCOMPILE_FEATURES) {
  1347. this->impl->CompileFeaturesEntries.clear();
  1348. if (value) {
  1349. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1350. this->impl->CompileFeaturesEntries.emplace_back(value, lfbt);
  1351. }
  1352. } else if (prop == propCOMPILE_DEFINITIONS) {
  1353. this->impl->CompileDefinitionsEntries.clear();
  1354. if (value) {
  1355. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1356. this->impl->CompileDefinitionsEntries.emplace_back(value, lfbt);
  1357. }
  1358. } else if (prop == propLINK_OPTIONS) {
  1359. this->impl->LinkOptionsEntries.clear();
  1360. if (value) {
  1361. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1362. this->impl->LinkOptionsEntries.emplace_back(value, lfbt);
  1363. }
  1364. } else if (prop == propLINK_DIRECTORIES) {
  1365. this->impl->LinkDirectoriesEntries.clear();
  1366. if (value) {
  1367. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1368. this->impl->LinkDirectoriesEntries.emplace_back(value, lfbt);
  1369. }
  1370. } else if (prop == propPRECOMPILE_HEADERS) {
  1371. this->impl->PrecompileHeadersEntries.clear();
  1372. if (value) {
  1373. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1374. this->impl->PrecompileHeadersEntries.emplace_back(value, lfbt);
  1375. }
  1376. } else if (prop == propLINK_LIBRARIES) {
  1377. this->impl->LinkImplementationPropertyEntries.clear();
  1378. if (value) {
  1379. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1380. this->impl->LinkImplementationPropertyEntries.emplace_back(value, lfbt);
  1381. }
  1382. } else if (prop == propINTERFACE_LINK_LIBRARIES) {
  1383. this->impl->LinkInterfacePropertyEntries.clear();
  1384. if (value) {
  1385. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1386. this->impl->LinkInterfacePropertyEntries.emplace_back(value, lfbt);
  1387. }
  1388. } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) {
  1389. this->impl->LinkInterfaceDirectPropertyEntries.clear();
  1390. if (value) {
  1391. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1392. this->impl->LinkInterfaceDirectPropertyEntries.emplace_back(value, lfbt);
  1393. }
  1394. } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) {
  1395. this->impl->LinkInterfaceDirectExcludePropertyEntries.clear();
  1396. if (value) {
  1397. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1398. this->impl->LinkInterfaceDirectExcludePropertyEntries.emplace_back(value,
  1399. lfbt);
  1400. }
  1401. } else if (prop == propSOURCES) {
  1402. this->impl->SourceEntries.clear();
  1403. if (value) {
  1404. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1405. this->impl->SourceEntries.emplace_back(value, lfbt);
  1406. }
  1407. } else if (prop == propIMPORTED_GLOBAL) {
  1408. if (!cmIsOn(value)) {
  1409. std::ostringstream e;
  1410. e << "IMPORTED_GLOBAL property can't be set to FALSE on targets (\""
  1411. << this->impl->Name << "\")\n";
  1412. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1413. return;
  1414. }
  1415. /* no need to change anything if value does not change */
  1416. if (!this->impl->ImportedGloballyVisible) {
  1417. this->impl->ImportedGloballyVisible = true;
  1418. this->GetGlobalGenerator()->IndexTarget(this);
  1419. }
  1420. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME") &&
  1421. !this->impl->CheckImportedLibName(
  1422. prop,
  1423. value ? value
  1424. : std::string{})) { // NOLINT(bugprone-branch-clone)
  1425. /* error was reported by check method */
  1426. } else if (prop == propCUDA_PTX_COMPILATION &&
  1427. this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  1428. std::ostringstream e;
  1429. e << "CUDA_PTX_COMPILATION property can only be applied to OBJECT "
  1430. "targets (\""
  1431. << this->impl->Name << "\")\n";
  1432. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1433. return;
  1434. } else if (prop == propPRECOMPILE_HEADERS_REUSE_FROM) {
  1435. if (this->GetProperty("PRECOMPILE_HEADERS")) {
  1436. std::ostringstream e;
  1437. e << "PRECOMPILE_HEADERS property is already set on target (\""
  1438. << this->impl->Name << "\")\n";
  1439. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1440. return;
  1441. }
  1442. auto* reusedTarget = this->impl->Makefile->GetCMakeInstance()
  1443. ->GetGlobalGenerator()
  1444. ->FindTarget(value);
  1445. if (!reusedTarget) {
  1446. const std::string e(
  1447. "PRECOMPILE_HEADERS_REUSE_FROM set with non existing target");
  1448. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e);
  1449. return;
  1450. }
  1451. std::string reusedFrom = reusedTarget->GetSafeProperty(prop);
  1452. if (reusedFrom.empty()) {
  1453. reusedFrom = ConvertToString(value);
  1454. }
  1455. this->impl->Properties.SetProperty(prop, reusedFrom);
  1456. reusedTarget->SetProperty("COMPILE_PDB_NAME", reusedFrom);
  1457. reusedTarget->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY",
  1458. cmStrCat(reusedFrom, ".dir/"));
  1459. cmValue tmp = reusedTarget->GetProperty("COMPILE_PDB_NAME");
  1460. this->SetProperty("COMPILE_PDB_NAME", tmp);
  1461. this->AddUtility(reusedFrom, false, this->impl->Makefile);
  1462. } else if (prop == propC_STANDARD || prop == propCXX_STANDARD ||
  1463. prop == propCUDA_STANDARD || prop == propHIP_STANDARD ||
  1464. prop == propOBJC_STANDARD || prop == propOBJCXX_STANDARD) {
  1465. if (value) {
  1466. this->impl->LanguageStandardProperties[prop] =
  1467. BTs<std::string>(value, this->impl->Makefile->GetBacktrace());
  1468. } else {
  1469. this->impl->LanguageStandardProperties.erase(prop);
  1470. }
  1471. } else if (this->impl->HeadersFileSets.WriteProperties(
  1472. this, this->impl.get(), prop, value, true)) {
  1473. /* Handled in the `if` condition. */
  1474. } else {
  1475. this->impl->Properties.SetProperty(prop, value);
  1476. }
  1477. }
  1478. void cmTarget::AppendProperty(const std::string& prop,
  1479. const std::string& value, bool asString)
  1480. {
  1481. if (prop == "NAME") {
  1482. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1483. "NAME property is read-only\n");
  1484. return;
  1485. }
  1486. if (prop == "EXPORT_NAME" && this->IsImported()) {
  1487. std::ostringstream e;
  1488. e << "EXPORT_NAME property can't be set on imported targets (\""
  1489. << this->impl->Name << "\")\n";
  1490. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1491. return;
  1492. }
  1493. if (prop == "SOURCES" && this->IsImported()) {
  1494. std::ostringstream e;
  1495. e << "SOURCES property can't be set on imported targets (\""
  1496. << this->impl->Name << "\")\n";
  1497. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1498. return;
  1499. }
  1500. if (prop == "IMPORTED_GLOBAL") {
  1501. std::ostringstream e;
  1502. e << "IMPORTED_GLOBAL property can't be appended, only set on imported "
  1503. "targets (\""
  1504. << this->impl->Name << "\")\n";
  1505. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1506. return;
  1507. }
  1508. if (prop == "INCLUDE_DIRECTORIES") {
  1509. if (!value.empty()) {
  1510. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1511. this->impl->IncludeDirectoriesEntries.emplace_back(value, lfbt);
  1512. }
  1513. } else if (prop == "COMPILE_OPTIONS") {
  1514. if (!value.empty()) {
  1515. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1516. this->impl->CompileOptionsEntries.emplace_back(value, lfbt);
  1517. }
  1518. } else if (prop == "COMPILE_FEATURES") {
  1519. if (!value.empty()) {
  1520. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1521. this->impl->CompileFeaturesEntries.emplace_back(value, lfbt);
  1522. }
  1523. } else if (prop == "COMPILE_DEFINITIONS") {
  1524. if (!value.empty()) {
  1525. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1526. this->impl->CompileDefinitionsEntries.emplace_back(value, lfbt);
  1527. }
  1528. } else if (prop == "LINK_OPTIONS") {
  1529. if (!value.empty()) {
  1530. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1531. this->impl->LinkOptionsEntries.emplace_back(value, lfbt);
  1532. }
  1533. } else if (prop == "LINK_DIRECTORIES") {
  1534. if (!value.empty()) {
  1535. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1536. this->impl->LinkDirectoriesEntries.emplace_back(value, lfbt);
  1537. }
  1538. } else if (prop == "PRECOMPILE_HEADERS") {
  1539. if (this->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM")) {
  1540. std::ostringstream e;
  1541. e << "PRECOMPILE_HEADERS_REUSE_FROM property is already set on target "
  1542. "(\""
  1543. << this->impl->Name << "\")\n";
  1544. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1545. return;
  1546. }
  1547. if (!value.empty()) {
  1548. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1549. this->impl->PrecompileHeadersEntries.emplace_back(value, lfbt);
  1550. }
  1551. } else if (prop == "LINK_LIBRARIES") {
  1552. if (!value.empty()) {
  1553. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1554. this->impl->LinkImplementationPropertyEntries.emplace_back(value, lfbt);
  1555. }
  1556. } else if (prop == propINTERFACE_LINK_LIBRARIES) {
  1557. if (!value.empty()) {
  1558. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1559. this->impl->LinkInterfacePropertyEntries.emplace_back(value, lfbt);
  1560. }
  1561. } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) {
  1562. if (!value.empty()) {
  1563. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1564. this->impl->LinkInterfaceDirectPropertyEntries.emplace_back(value, lfbt);
  1565. }
  1566. } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) {
  1567. if (!value.empty()) {
  1568. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1569. this->impl->LinkInterfaceDirectExcludePropertyEntries.emplace_back(value,
  1570. lfbt);
  1571. }
  1572. } else if (prop == "SOURCES") {
  1573. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1574. this->impl->SourceEntries.emplace_back(value, lfbt);
  1575. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) {
  1576. this->impl->Makefile->IssueMessage(
  1577. MessageType::FATAL_ERROR, prop + " property may not be APPENDed.");
  1578. } else if (prop == "C_STANDARD" || prop == "CXX_STANDARD" ||
  1579. prop == "CUDA_STANDARD" || prop == "HIP_STANDARD" ||
  1580. prop == "OBJC_STANDARD" || prop == "OBJCXX_STANDARD") {
  1581. this->impl->Makefile->IssueMessage(
  1582. MessageType::FATAL_ERROR, prop + " property may not be appended.");
  1583. } else if (this->impl->HeadersFileSets.WriteProperties(
  1584. this, this->impl.get(), prop, value, false)) {
  1585. /* Handled in the `if` condition. */
  1586. } else {
  1587. this->impl->Properties.AppendProperty(prop, value, asString);
  1588. }
  1589. }
  1590. void cmTarget::SetProperty(const std::string& prop, const char* value)
  1591. {
  1592. this->StoreProperty(prop, value);
  1593. }
  1594. void cmTarget::SetProperty(const std::string& prop, cmValue value)
  1595. {
  1596. this->StoreProperty(prop, value);
  1597. }
  1598. template <typename ValueType>
  1599. void cmTargetInternals::AddDirectoryToFileSet(
  1600. cmTarget* self, std::string const& fileSetName, ValueType value,
  1601. cm::string_view fileSetType, cm::string_view description, bool clear)
  1602. {
  1603. auto* fileSet = self->GetFileSet(fileSetName);
  1604. if (!fileSet) {
  1605. this->Makefile->IssueMessage(
  1606. MessageType::FATAL_ERROR,
  1607. cmStrCat(description, "has not yet been created."));
  1608. return;
  1609. }
  1610. if (fileSet->GetType() != fileSetType) {
  1611. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1612. cmStrCat("File set \"", fileSetName,
  1613. "\" is not of type \"", fileSetType,
  1614. "\"."));
  1615. return;
  1616. }
  1617. if (clear) {
  1618. fileSet->ClearDirectoryEntries();
  1619. }
  1620. if (!StringIsEmpty(value)) {
  1621. fileSet->AddDirectoryEntry(
  1622. BT<std::string>(value, this->Makefile->GetBacktrace()));
  1623. }
  1624. }
  1625. template <typename ValueType>
  1626. void cmTargetInternals::AddPathToFileSet(
  1627. cmTarget* self, std::string const& fileSetName, ValueType value,
  1628. cm::string_view fileSetType, cm::string_view description, bool clear)
  1629. {
  1630. auto* fileSet = self->GetFileSet(fileSetName);
  1631. if (!fileSet) {
  1632. this->Makefile->IssueMessage(
  1633. MessageType::FATAL_ERROR,
  1634. cmStrCat(description, "has not yet been created."));
  1635. return;
  1636. }
  1637. if (fileSet->GetType() != fileSetType) {
  1638. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1639. cmStrCat("File set \"", fileSetName,
  1640. "\" is not of type \"", fileSetType,
  1641. "\"."));
  1642. return;
  1643. }
  1644. if (clear) {
  1645. fileSet->ClearFileEntries();
  1646. }
  1647. if (!StringIsEmpty(value)) {
  1648. fileSet->AddFileEntry(
  1649. BT<std::string>(value, this->Makefile->GetBacktrace()));
  1650. }
  1651. }
  1652. cmValue cmTargetInternals::GetFileSetDirectories(
  1653. cmTarget const* self, std::string const& fileSetName,
  1654. cm::string_view fileSetType) const
  1655. {
  1656. auto const* fileSet = self->GetFileSet(fileSetName);
  1657. if (!fileSet) {
  1658. return nullptr;
  1659. }
  1660. if (fileSet->GetType() != fileSetType) {
  1661. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1662. cmStrCat("File set \"", fileSetName,
  1663. "\" is not of type \"", fileSetType,
  1664. "\"."));
  1665. return nullptr;
  1666. }
  1667. static std::string output;
  1668. output = cmJoin(fileSet->GetDirectoryEntries(), ";"_s);
  1669. return cmValue(output);
  1670. }
  1671. cmValue cmTargetInternals::GetFileSetPaths(cmTarget const* self,
  1672. std::string const& fileSetName,
  1673. cm::string_view fileSetType) const
  1674. {
  1675. auto const* fileSet = self->GetFileSet(fileSetName);
  1676. if (!fileSet) {
  1677. return nullptr;
  1678. }
  1679. if (fileSet->GetType() != fileSetType) {
  1680. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1681. cmStrCat("File set \"", fileSetName,
  1682. "\" is not of type \"", fileSetType,
  1683. "\"."));
  1684. return nullptr;
  1685. }
  1686. static std::string output;
  1687. output = cmJoin(fileSet->GetFileEntries(), ";"_s);
  1688. return cmValue(output);
  1689. }
  1690. void cmTarget::AppendBuildInterfaceIncludes()
  1691. {
  1692. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1693. this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  1694. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  1695. this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  1696. !this->IsExecutableWithExports()) {
  1697. return;
  1698. }
  1699. if (this->impl->BuildInterfaceIncludesAppended) {
  1700. return;
  1701. }
  1702. this->impl->BuildInterfaceIncludesAppended = true;
  1703. if (this->impl->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE")) {
  1704. std::string dirs = this->impl->Makefile->GetCurrentBinaryDirectory();
  1705. if (!dirs.empty()) {
  1706. dirs += ';';
  1707. }
  1708. dirs += this->impl->Makefile->GetCurrentSourceDirectory();
  1709. if (!dirs.empty()) {
  1710. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  1711. ("$<BUILD_INTERFACE:" + dirs + ">"));
  1712. }
  1713. }
  1714. }
  1715. void cmTarget::InsertInclude(BT<std::string> const& entry, bool before)
  1716. {
  1717. auto position = before ? this->impl->IncludeDirectoriesEntries.begin()
  1718. : this->impl->IncludeDirectoriesEntries.end();
  1719. this->impl->IncludeDirectoriesEntries.insert(position, entry);
  1720. }
  1721. void cmTarget::InsertCompileOption(BT<std::string> const& entry, bool before)
  1722. {
  1723. auto position = before ? this->impl->CompileOptionsEntries.begin()
  1724. : this->impl->CompileOptionsEntries.end();
  1725. this->impl->CompileOptionsEntries.insert(position, entry);
  1726. }
  1727. void cmTarget::InsertCompileDefinition(BT<std::string> const& entry)
  1728. {
  1729. this->impl->CompileDefinitionsEntries.push_back(entry);
  1730. }
  1731. void cmTarget::InsertLinkOption(BT<std::string> const& entry, bool before)
  1732. {
  1733. auto position = before ? this->impl->LinkOptionsEntries.begin()
  1734. : this->impl->LinkOptionsEntries.end();
  1735. this->impl->LinkOptionsEntries.insert(position, entry);
  1736. }
  1737. void cmTarget::InsertLinkDirectory(BT<std::string> const& entry, bool before)
  1738. {
  1739. auto position = before ? this->impl->LinkDirectoriesEntries.begin()
  1740. : this->impl->LinkDirectoriesEntries.end();
  1741. this->impl->LinkDirectoriesEntries.insert(position, entry);
  1742. }
  1743. void cmTarget::InsertPrecompileHeader(BT<std::string> const& entry)
  1744. {
  1745. this->impl->PrecompileHeadersEntries.push_back(entry);
  1746. }
  1747. namespace {
  1748. void CheckLinkLibraryPattern(const std::string& property,
  1749. const std::string& value, cmMakefile* context)
  1750. {
  1751. // Look for <LINK_LIBRARY:> and </LINK_LIBRARY:> internal tags
  1752. static cmsys::RegularExpression linkPattern(
  1753. "(^|;)(</?LINK_(LIBRARY|GROUP):[^;>]*>)(;|$)");
  1754. if (!linkPattern.find(value)) {
  1755. return;
  1756. }
  1757. // Report an error.
  1758. context->IssueMessage(
  1759. MessageType::FATAL_ERROR,
  1760. cmStrCat(
  1761. "Property ", property, " contains the invalid item \"",
  1762. linkPattern.match(2), "\". The ", property,
  1763. " property may contain the generator-expression \"$<LINK_",
  1764. linkPattern.match(3),
  1765. ":...>\" which may be used to specify how the libraries are linked."));
  1766. }
  1767. void CheckLINK_INTERFACE_LIBRARIES(const std::string& prop,
  1768. const std::string& value,
  1769. cmMakefile* context, bool imported)
  1770. {
  1771. // Support imported and non-imported versions of the property.
  1772. const char* base = (imported ? "IMPORTED_LINK_INTERFACE_LIBRARIES"
  1773. : "LINK_INTERFACE_LIBRARIES");
  1774. // Look for link-type keywords in the value.
  1775. static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
  1776. if (keys.find(value)) {
  1777. // Report an error.
  1778. std::ostringstream e;
  1779. e << "Property " << prop << " may not contain link-type keyword \""
  1780. << keys.match(2) << "\". "
  1781. << "The " << base << " property has a per-configuration "
  1782. << "version called " << base << "_<CONFIG> which may be "
  1783. << "used to specify per-configuration rules.";
  1784. if (!imported) {
  1785. e << " "
  1786. << "Alternatively, an IMPORTED library may be created, configured "
  1787. << "with a per-configuration location, and then named in the "
  1788. << "property value. "
  1789. << "See the add_library command's IMPORTED mode for details."
  1790. << "\n"
  1791. << "If you have a list of libraries that already contains the "
  1792. << "keyword, use the target_link_libraries command with its "
  1793. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  1794. << "The command automatically recognizes link-type keywords and sets "
  1795. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  1796. << "properties accordingly.";
  1797. }
  1798. context->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1799. }
  1800. CheckLinkLibraryPattern(base, value, context);
  1801. }
  1802. void CheckLINK_LIBRARIES(const std::string& value, cmMakefile* context)
  1803. {
  1804. CheckLinkLibraryPattern("LINK_LIBRARIES", value, context);
  1805. }
  1806. void CheckINTERFACE_LINK_LIBRARIES(const std::string& value,
  1807. cmMakefile* context)
  1808. {
  1809. // Look for link-type keywords in the value.
  1810. static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
  1811. if (keys.find(value)) {
  1812. // Report an error.
  1813. std::ostringstream e;
  1814. e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
  1815. "keyword \""
  1816. << keys.match(2)
  1817. << "\". The INTERFACE_LINK_LIBRARIES "
  1818. "property may contain configuration-sensitive generator-expressions "
  1819. "which may be used to specify per-configuration rules.";
  1820. context->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1821. }
  1822. CheckLinkLibraryPattern("INTERFACE_LINK_LIBRARIES", value, context);
  1823. }
  1824. void CheckIMPORTED_GLOBAL(const cmTarget* target, cmMakefile* context)
  1825. {
  1826. const auto& targets = context->GetOwnedImportedTargets();
  1827. auto it =
  1828. std::find_if(targets.begin(), targets.end(),
  1829. [&](const std::unique_ptr<cmTarget>& importTarget) -> bool {
  1830. return target == importTarget.get();
  1831. });
  1832. if (it == targets.end()) {
  1833. std::ostringstream e;
  1834. e << "Attempt to promote imported target \"" << target->GetName()
  1835. << "\" to global scope (by setting IMPORTED_GLOBAL) "
  1836. "which is not built in this directory.";
  1837. context->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1838. }
  1839. }
  1840. }
  1841. void cmTarget::CheckProperty(const std::string& prop,
  1842. cmMakefile* context) const
  1843. {
  1844. // Certain properties need checking.
  1845. if (cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES")) {
  1846. if (cmValue value = this->GetProperty(prop)) {
  1847. CheckLINK_INTERFACE_LIBRARIES(prop, *value, context, false);
  1848. }
  1849. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES")) {
  1850. if (cmValue value = this->GetProperty(prop)) {
  1851. CheckLINK_INTERFACE_LIBRARIES(prop, *value, context, true);
  1852. }
  1853. } else if (prop == "LINK_LIBRARIES") {
  1854. if (cmValue value = this->GetProperty(prop)) {
  1855. CheckLINK_LIBRARIES(*value, context);
  1856. }
  1857. } else if (prop == "INTERFACE_LINK_LIBRARIES") {
  1858. if (cmValue value = this->GetProperty(prop)) {
  1859. CheckINTERFACE_LINK_LIBRARIES(*value, context);
  1860. }
  1861. } else if (prop == "IMPORTED_GLOBAL") {
  1862. if (this->IsImported()) {
  1863. CheckIMPORTED_GLOBAL(this, context);
  1864. }
  1865. }
  1866. }
  1867. cmValue cmTarget::GetComputedProperty(const std::string& prop,
  1868. cmMakefile& mf) const
  1869. {
  1870. return cmTargetPropertyComputer::GetProperty(this, prop, mf);
  1871. }
  1872. cmValue cmTarget::GetProperty(const std::string& prop) const
  1873. {
  1874. static std::unordered_set<std::string> const specialProps{
  1875. propC_STANDARD,
  1876. propCXX_STANDARD,
  1877. propCUDA_STANDARD,
  1878. propOBJC_STANDARD,
  1879. propOBJCXX_STANDARD,
  1880. propLINK_LIBRARIES,
  1881. propTYPE,
  1882. propINCLUDE_DIRECTORIES,
  1883. propCOMPILE_FEATURES,
  1884. propCOMPILE_OPTIONS,
  1885. propCOMPILE_DEFINITIONS,
  1886. propPRECOMPILE_HEADERS,
  1887. propLINK_OPTIONS,
  1888. propLINK_DIRECTORIES,
  1889. propIMPORTED,
  1890. propIMPORTED_GLOBAL,
  1891. propMANUALLY_ADDED_DEPENDENCIES,
  1892. propNAME,
  1893. propBINARY_DIR,
  1894. propSOURCE_DIR,
  1895. propSOURCES,
  1896. propINTERFACE_LINK_LIBRARIES,
  1897. propINTERFACE_LINK_LIBRARIES_DIRECT,
  1898. propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE,
  1899. };
  1900. if (specialProps.count(prop)) {
  1901. if (prop == propC_STANDARD || prop == propCXX_STANDARD ||
  1902. prop == propCUDA_STANDARD || prop == propOBJC_STANDARD ||
  1903. prop == propOBJCXX_STANDARD) {
  1904. auto propertyIter = this->impl->LanguageStandardProperties.find(prop);
  1905. if (propertyIter == this->impl->LanguageStandardProperties.end()) {
  1906. return nullptr;
  1907. }
  1908. return cmValue(propertyIter->second.Value);
  1909. }
  1910. if (prop == propLINK_LIBRARIES) {
  1911. if (this->impl->LinkImplementationPropertyEntries.empty()) {
  1912. return nullptr;
  1913. }
  1914. static std::string output;
  1915. output = cmJoin(this->impl->LinkImplementationPropertyEntries, ";");
  1916. return cmValue(output);
  1917. }
  1918. if (prop == propINTERFACE_LINK_LIBRARIES) {
  1919. if (this->impl->LinkInterfacePropertyEntries.empty()) {
  1920. return nullptr;
  1921. }
  1922. static std::string output;
  1923. output = cmJoin(this->impl->LinkInterfacePropertyEntries, ";");
  1924. return cmValue(output);
  1925. }
  1926. if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) {
  1927. if (this->impl->LinkInterfaceDirectPropertyEntries.empty()) {
  1928. return nullptr;
  1929. }
  1930. static std::string output;
  1931. output = cmJoin(this->impl->LinkInterfaceDirectPropertyEntries, ";");
  1932. return cmValue(output);
  1933. }
  1934. if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) {
  1935. if (this->impl->LinkInterfaceDirectExcludePropertyEntries.empty()) {
  1936. return nullptr;
  1937. }
  1938. static std::string output;
  1939. output =
  1940. cmJoin(this->impl->LinkInterfaceDirectExcludePropertyEntries, ";");
  1941. return cmValue(output);
  1942. }
  1943. // the type property returns what type the target is
  1944. if (prop == propTYPE) {
  1945. return cmValue(cmState::GetTargetTypeName(this->GetType()));
  1946. }
  1947. if (prop == propINCLUDE_DIRECTORIES) {
  1948. if (this->impl->IncludeDirectoriesEntries.empty()) {
  1949. return nullptr;
  1950. }
  1951. static std::string output;
  1952. output = cmJoin(this->impl->IncludeDirectoriesEntries, ";");
  1953. return cmValue(output);
  1954. }
  1955. if (prop == propCOMPILE_FEATURES) {
  1956. if (this->impl->CompileFeaturesEntries.empty()) {
  1957. return nullptr;
  1958. }
  1959. static std::string output;
  1960. output = cmJoin(this->impl->CompileFeaturesEntries, ";");
  1961. return cmValue(output);
  1962. }
  1963. if (prop == propCOMPILE_OPTIONS) {
  1964. if (this->impl->CompileOptionsEntries.empty()) {
  1965. return nullptr;
  1966. }
  1967. static std::string output;
  1968. output = cmJoin(this->impl->CompileOptionsEntries, ";");
  1969. return cmValue(output);
  1970. }
  1971. if (prop == propCOMPILE_DEFINITIONS) {
  1972. if (this->impl->CompileDefinitionsEntries.empty()) {
  1973. return nullptr;
  1974. }
  1975. static std::string output;
  1976. output = cmJoin(this->impl->CompileDefinitionsEntries, ";");
  1977. return cmValue(output);
  1978. }
  1979. if (prop == propLINK_OPTIONS) {
  1980. if (this->impl->LinkOptionsEntries.empty()) {
  1981. return nullptr;
  1982. }
  1983. static std::string output;
  1984. output = cmJoin(this->impl->LinkOptionsEntries, ";");
  1985. return cmValue(output);
  1986. }
  1987. if (prop == propLINK_DIRECTORIES) {
  1988. if (this->impl->LinkDirectoriesEntries.empty()) {
  1989. return nullptr;
  1990. }
  1991. static std::string output;
  1992. output = cmJoin(this->impl->LinkDirectoriesEntries, ";");
  1993. return cmValue(output);
  1994. }
  1995. if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
  1996. if (this->impl->Utilities.empty()) {
  1997. return nullptr;
  1998. }
  1999. static std::string output;
  2000. static std::vector<std::string> utilities;
  2001. utilities.resize(this->impl->Utilities.size());
  2002. std::transform(
  2003. this->impl->Utilities.cbegin(), this->impl->Utilities.cend(),
  2004. utilities.begin(),
  2005. [](const BT<std::pair<std::string, bool>>& item) -> std::string {
  2006. return item.Value.first;
  2007. });
  2008. output = cmJoin(utilities, ";");
  2009. return cmValue(output);
  2010. }
  2011. if (prop == propPRECOMPILE_HEADERS) {
  2012. if (this->impl->PrecompileHeadersEntries.empty()) {
  2013. return nullptr;
  2014. }
  2015. static std::string output;
  2016. output = cmJoin(this->impl->PrecompileHeadersEntries, ";");
  2017. return cmValue(output);
  2018. }
  2019. if (prop == propIMPORTED) {
  2020. return this->IsImported() ? cmValue(propTRUE) : cmValue(propFALSE);
  2021. }
  2022. if (prop == propIMPORTED_GLOBAL) {
  2023. return this->IsImportedGloballyVisible() ? cmValue(propTRUE)
  2024. : cmValue(propFALSE);
  2025. }
  2026. if (prop == propNAME) {
  2027. return cmValue(this->GetName());
  2028. }
  2029. if (prop == propBINARY_DIR) {
  2030. return cmValue(this->impl->Makefile->GetStateSnapshot()
  2031. .GetDirectory()
  2032. .GetCurrentBinary());
  2033. }
  2034. if (prop == propSOURCE_DIR) {
  2035. return cmValue(this->impl->Makefile->GetStateSnapshot()
  2036. .GetDirectory()
  2037. .GetCurrentSource());
  2038. }
  2039. }
  2040. // Check fileset properties.
  2041. {
  2042. auto headers =
  2043. this->impl->HeadersFileSets.ReadProperties(this, this->impl.get(), prop);
  2044. if (headers.first) {
  2045. return headers.second;
  2046. }
  2047. }
  2048. cmValue retVal = this->impl->Properties.GetPropertyValue(prop);
  2049. if (!retVal) {
  2050. const bool chain = this->impl->Makefile->GetState()->IsPropertyChained(
  2051. prop, cmProperty::TARGET);
  2052. if (chain) {
  2053. return this->impl->Makefile->GetStateSnapshot()
  2054. .GetDirectory()
  2055. .GetProperty(prop, chain);
  2056. }
  2057. return nullptr;
  2058. }
  2059. return retVal;
  2060. }
  2061. std::string const& cmTarget::GetSafeProperty(std::string const& prop) const
  2062. {
  2063. cmValue ret = this->GetProperty(prop);
  2064. if (ret) {
  2065. return *ret;
  2066. }
  2067. static std::string const s_empty;
  2068. return s_empty;
  2069. }
  2070. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  2071. {
  2072. return cmIsOn(this->GetProperty(prop));
  2073. }
  2074. cmPropertyMap const& cmTarget::GetProperties() const
  2075. {
  2076. return this->impl->Properties;
  2077. }
  2078. bool cmTarget::IsDLLPlatform() const
  2079. {
  2080. return this->impl->IsDLLPlatform;
  2081. }
  2082. bool cmTarget::IsAIX() const
  2083. {
  2084. return this->impl->IsAIX;
  2085. }
  2086. bool cmTarget::IsImported() const
  2087. {
  2088. return this->impl->IsImportedTarget;
  2089. }
  2090. bool cmTarget::IsImportedGloballyVisible() const
  2091. {
  2092. return this->impl->ImportedGloballyVisible;
  2093. }
  2094. bool cmTarget::IsPerConfig() const
  2095. {
  2096. return this->impl->PerConfig;
  2097. }
  2098. bool cmTarget::CanCompileSources() const
  2099. {
  2100. if (this->IsImported()) {
  2101. return false;
  2102. }
  2103. switch (this->GetType()) {
  2104. case cmStateEnums::EXECUTABLE:
  2105. case cmStateEnums::STATIC_LIBRARY:
  2106. case cmStateEnums::SHARED_LIBRARY:
  2107. case cmStateEnums::MODULE_LIBRARY:
  2108. case cmStateEnums::OBJECT_LIBRARY:
  2109. return true;
  2110. case cmStateEnums::UTILITY:
  2111. case cmStateEnums::INTERFACE_LIBRARY:
  2112. case cmStateEnums::GLOBAL_TARGET:
  2113. case cmStateEnums::UNKNOWN_LIBRARY:
  2114. break;
  2115. }
  2116. return false;
  2117. }
  2118. const char* cmTarget::GetSuffixVariableInternal(
  2119. cmStateEnums::ArtifactType artifact) const
  2120. {
  2121. switch (this->GetType()) {
  2122. case cmStateEnums::STATIC_LIBRARY:
  2123. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  2124. case cmStateEnums::SHARED_LIBRARY:
  2125. switch (artifact) {
  2126. case cmStateEnums::RuntimeBinaryArtifact:
  2127. return "CMAKE_SHARED_LIBRARY_SUFFIX";
  2128. case cmStateEnums::ImportLibraryArtifact:
  2129. return "CMAKE_IMPORT_LIBRARY_SUFFIX";
  2130. }
  2131. break;
  2132. case cmStateEnums::MODULE_LIBRARY:
  2133. switch (artifact) {
  2134. case cmStateEnums::RuntimeBinaryArtifact:
  2135. return "CMAKE_SHARED_MODULE_SUFFIX";
  2136. case cmStateEnums::ImportLibraryArtifact:
  2137. return "CMAKE_IMPORT_LIBRARY_SUFFIX";
  2138. }
  2139. break;
  2140. case cmStateEnums::EXECUTABLE:
  2141. switch (artifact) {
  2142. case cmStateEnums::RuntimeBinaryArtifact:
  2143. // Android GUI application packages store the native
  2144. // binary as a shared library.
  2145. return (this->IsAndroidGuiExecutable()
  2146. ? "CMAKE_SHARED_LIBRARY_SUFFIX"
  2147. : "CMAKE_EXECUTABLE_SUFFIX");
  2148. case cmStateEnums::ImportLibraryArtifact:
  2149. return (this->impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_SUFFIX"
  2150. : "CMAKE_IMPORT_LIBRARY_SUFFIX");
  2151. }
  2152. break;
  2153. default:
  2154. break;
  2155. }
  2156. return "";
  2157. }
  2158. const char* cmTarget::GetPrefixVariableInternal(
  2159. cmStateEnums::ArtifactType artifact) const
  2160. {
  2161. switch (this->GetType()) {
  2162. case cmStateEnums::STATIC_LIBRARY:
  2163. return "CMAKE_STATIC_LIBRARY_PREFIX";
  2164. case cmStateEnums::SHARED_LIBRARY:
  2165. switch (artifact) {
  2166. case cmStateEnums::RuntimeBinaryArtifact:
  2167. return "CMAKE_SHARED_LIBRARY_PREFIX";
  2168. case cmStateEnums::ImportLibraryArtifact:
  2169. return "CMAKE_IMPORT_LIBRARY_PREFIX";
  2170. }
  2171. break;
  2172. case cmStateEnums::MODULE_LIBRARY:
  2173. switch (artifact) {
  2174. case cmStateEnums::RuntimeBinaryArtifact:
  2175. return "CMAKE_SHARED_MODULE_PREFIX";
  2176. case cmStateEnums::ImportLibraryArtifact:
  2177. return "CMAKE_IMPORT_LIBRARY_PREFIX";
  2178. }
  2179. break;
  2180. case cmStateEnums::EXECUTABLE:
  2181. switch (artifact) {
  2182. case cmStateEnums::RuntimeBinaryArtifact:
  2183. // Android GUI application packages store the native
  2184. // binary as a shared library.
  2185. return (this->IsAndroidGuiExecutable()
  2186. ? "CMAKE_SHARED_LIBRARY_PREFIX"
  2187. : "");
  2188. case cmStateEnums::ImportLibraryArtifact:
  2189. return (this->impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_PREFIX"
  2190. : "CMAKE_IMPORT_LIBRARY_PREFIX");
  2191. }
  2192. break;
  2193. default:
  2194. break;
  2195. }
  2196. return "";
  2197. }
  2198. std::string cmTarget::ImportedGetFullPath(
  2199. const std::string& config, cmStateEnums::ArtifactType artifact) const
  2200. {
  2201. assert(this->IsImported());
  2202. // Lookup/compute/cache the import information for this
  2203. // configuration.
  2204. std::string desired_config = config;
  2205. if (config.empty()) {
  2206. desired_config = "NOCONFIG";
  2207. }
  2208. std::string result;
  2209. cmValue loc = nullptr;
  2210. cmValue imp = nullptr;
  2211. std::string suffix;
  2212. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  2213. this->GetMappedConfig(desired_config, loc, imp, suffix)) {
  2214. switch (artifact) {
  2215. case cmStateEnums::RuntimeBinaryArtifact:
  2216. if (loc) {
  2217. result = *loc;
  2218. } else {
  2219. std::string impProp = cmStrCat("IMPORTED_LOCATION", suffix);
  2220. if (cmValue config_location = this->GetProperty(impProp)) {
  2221. result = *config_location;
  2222. } else if (cmValue location =
  2223. this->GetProperty("IMPORTED_LOCATION")) {
  2224. result = *location;
  2225. }
  2226. }
  2227. break;
  2228. case cmStateEnums::ImportLibraryArtifact:
  2229. if (imp) {
  2230. result = *imp;
  2231. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2232. this->IsExecutableWithExports()) {
  2233. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  2234. if (cmValue config_implib = this->GetProperty(impProp)) {
  2235. result = *config_implib;
  2236. } else if (cmValue implib = this->GetProperty("IMPORTED_IMPLIB")) {
  2237. result = *implib;
  2238. }
  2239. }
  2240. break;
  2241. }
  2242. }
  2243. if (result.empty()) {
  2244. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  2245. auto message = [&]() -> std::string {
  2246. std::string unset;
  2247. std::string configuration;
  2248. if (artifact == cmStateEnums::RuntimeBinaryArtifact) {
  2249. unset = "IMPORTED_LOCATION";
  2250. } else if (artifact == cmStateEnums::ImportLibraryArtifact) {
  2251. unset = "IMPORTED_IMPLIB";
  2252. }
  2253. if (!config.empty()) {
  2254. configuration = cmStrCat(" configuration \"", config, "\"");
  2255. }
  2256. return cmStrCat(unset, " not set for imported target \"",
  2257. this->GetName(), "\"", configuration, ".");
  2258. };
  2259. switch (this->GetPolicyStatus(cmPolicies::CMP0111)) {
  2260. case cmPolicies::WARN:
  2261. this->impl->Makefile->IssueMessage(
  2262. MessageType::AUTHOR_WARNING,
  2263. cmPolicies::GetPolicyWarning(cmPolicies::CMP0111) + "\n" +
  2264. message());
  2265. CM_FALLTHROUGH;
  2266. case cmPolicies::OLD:
  2267. break;
  2268. default:
  2269. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  2270. message());
  2271. }
  2272. }
  2273. result = cmStrCat(this->GetName(), "-NOTFOUND");
  2274. }
  2275. return result;
  2276. }
  2277. const cmFileSet* cmTarget::GetFileSet(const std::string& name) const
  2278. {
  2279. auto it = this->impl->FileSets.find(name);
  2280. return it == this->impl->FileSets.end() ? nullptr : &it->second;
  2281. }
  2282. cmFileSet* cmTarget::GetFileSet(const std::string& name)
  2283. {
  2284. auto it = this->impl->FileSets.find(name);
  2285. return it == this->impl->FileSets.end() ? nullptr : &it->second;
  2286. }
  2287. std::pair<cmFileSet*, bool> cmTarget::GetOrCreateFileSet(
  2288. const std::string& name, const std::string& type, cmFileSetVisibility vis)
  2289. {
  2290. auto result = this->impl->FileSets.emplace(
  2291. std::make_pair(name, cmFileSet(name, type, vis)));
  2292. if (result.second) {
  2293. auto bt = this->impl->Makefile->GetBacktrace();
  2294. if (type == this->impl->HeadersFileSets.TypeName) {
  2295. this->impl->HeadersFileSets.AddFileSet(name, vis, std::move(bt));
  2296. }
  2297. }
  2298. return std::make_pair(&result.first->second, result.second);
  2299. }
  2300. std::string cmTarget::GetFileSetsPropertyName(const std::string& type)
  2301. {
  2302. if (type == "HEADERS") {
  2303. return "HEADER_SETS";
  2304. }
  2305. return "";
  2306. }
  2307. std::string cmTarget::GetInterfaceFileSetsPropertyName(const std::string& type)
  2308. {
  2309. if (type == "HEADERS") {
  2310. return "INTERFACE_HEADER_SETS";
  2311. }
  2312. return "";
  2313. }
  2314. std::vector<std::string> cmTarget::GetAllFileSetNames() const
  2315. {
  2316. std::vector<std::string> result;
  2317. for (auto const& it : this->impl->FileSets) {
  2318. result.push_back(it.first);
  2319. }
  2320. return result;
  2321. }
  2322. std::vector<std::string> cmTarget::GetAllInterfaceFileSets() const
  2323. {
  2324. std::vector<std::string> result;
  2325. auto inserter = std::back_inserter(result);
  2326. auto appendEntries = [=](const std::vector<BT<std::string>>& entries) {
  2327. for (auto const& entry : entries) {
  2328. auto expanded = cmExpandedList(entry.Value);
  2329. std::copy(expanded.begin(), expanded.end(), inserter);
  2330. }
  2331. };
  2332. appendEntries(this->impl->HeadersFileSets.InterfaceEntries.Entries);
  2333. return result;
  2334. }
  2335. bool cmTargetInternals::CheckImportedLibName(std::string const& prop,
  2336. std::string const& value) const
  2337. {
  2338. if (this->TargetType != cmStateEnums::INTERFACE_LIBRARY ||
  2339. !this->IsImportedTarget) {
  2340. this->Makefile->IssueMessage(
  2341. MessageType::FATAL_ERROR,
  2342. prop +
  2343. " property may be set only on imported INTERFACE library targets.");
  2344. return false;
  2345. }
  2346. if (!value.empty()) {
  2347. if (value[0] == '-') {
  2348. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  2349. prop + " property value\n " + value +
  2350. "\nmay not start with '-'.");
  2351. return false;
  2352. }
  2353. std::string::size_type bad = value.find_first_of(":/\\;");
  2354. if (bad != std::string::npos) {
  2355. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  2356. prop + " property value\n " + value +
  2357. "\nmay not contain '" +
  2358. value.substr(bad, 1) + "'.");
  2359. return false;
  2360. }
  2361. }
  2362. return true;
  2363. }
  2364. bool cmTarget::GetMappedConfig(std::string const& desired_config, cmValue& loc,
  2365. cmValue& imp, std::string& suffix) const
  2366. {
  2367. std::string config_upper;
  2368. if (!desired_config.empty()) {
  2369. config_upper = cmSystemTools::UpperCase(desired_config);
  2370. }
  2371. std::string locPropBase;
  2372. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  2373. locPropBase = "IMPORTED_LIBNAME";
  2374. } else if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  2375. locPropBase = "IMPORTED_OBJECTS";
  2376. } else {
  2377. locPropBase = "IMPORTED_LOCATION";
  2378. }
  2379. // Track the configuration-specific property suffix.
  2380. suffix = cmStrCat('_', config_upper);
  2381. std::vector<std::string> mappedConfigs;
  2382. {
  2383. std::string mapProp = cmStrCat("MAP_IMPORTED_CONFIG_", config_upper);
  2384. if (cmValue mapValue = this->GetProperty(mapProp)) {
  2385. cmExpandList(*mapValue, mappedConfigs, true);
  2386. }
  2387. }
  2388. // If we needed to find one of the mapped configurations but did not
  2389. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  2390. // library or an executable with exports.
  2391. bool allowImp = (this->IsDLLPlatform() &&
  2392. (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2393. this->IsExecutableWithExports())) ||
  2394. (this->IsAIX() && this->IsExecutableWithExports());
  2395. // If a mapping was found, check its configurations.
  2396. for (auto mci = mappedConfigs.begin();
  2397. !loc && !imp && mci != mappedConfigs.end(); ++mci) {
  2398. // Look for this configuration.
  2399. if (mci->empty()) {
  2400. // An empty string in the mapping has a special meaning:
  2401. // look up the config-less properties.
  2402. loc = this->GetProperty(locPropBase);
  2403. if (allowImp) {
  2404. imp = this->GetProperty("IMPORTED_IMPLIB");
  2405. }
  2406. // If it was found, set the suffix.
  2407. if (loc || imp) {
  2408. suffix.clear();
  2409. }
  2410. } else {
  2411. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  2412. std::string locProp = cmStrCat(locPropBase, '_', mcUpper);
  2413. loc = this->GetProperty(locProp);
  2414. if (allowImp) {
  2415. std::string impProp = cmStrCat("IMPORTED_IMPLIB_", mcUpper);
  2416. imp = this->GetProperty(impProp);
  2417. }
  2418. // If it was found, use it for all properties below.
  2419. if (loc || imp) {
  2420. suffix = cmStrCat('_', mcUpper);
  2421. }
  2422. }
  2423. }
  2424. // If we needed to find one of the mapped configurations but did not
  2425. // then the target location is not found. The project does not want
  2426. // any other configuration.
  2427. if (!mappedConfigs.empty() && !loc && !imp) {
  2428. // Interface libraries are always available because their
  2429. // library name is optional so it is okay to leave loc empty.
  2430. return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
  2431. }
  2432. // If we have not yet found it then there are no mapped
  2433. // configurations. Look for an exact-match.
  2434. if (!loc && !imp) {
  2435. std::string locProp = cmStrCat(locPropBase, suffix);
  2436. loc = this->GetProperty(locProp);
  2437. if (allowImp) {
  2438. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  2439. imp = this->GetProperty(impProp);
  2440. }
  2441. }
  2442. // If we have not yet found it then there are no mapped
  2443. // configurations and no exact match.
  2444. if (!loc && !imp) {
  2445. // The suffix computed above is not useful.
  2446. suffix.clear();
  2447. // Look for a configuration-less location. This may be set by
  2448. // manually-written code.
  2449. loc = this->GetProperty(locPropBase);
  2450. if (allowImp) {
  2451. imp = this->GetProperty("IMPORTED_IMPLIB");
  2452. }
  2453. }
  2454. // If we have not yet found it then the project is willing to try
  2455. // any available configuration.
  2456. if (!loc && !imp) {
  2457. std::vector<std::string> availableConfigs;
  2458. if (cmValue iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS")) {
  2459. cmExpandList(*iconfigs, availableConfigs);
  2460. }
  2461. for (auto aci = availableConfigs.begin();
  2462. !loc && !imp && aci != availableConfigs.end(); ++aci) {
  2463. suffix = cmStrCat('_', cmSystemTools::UpperCase(*aci));
  2464. std::string locProp = cmStrCat(locPropBase, suffix);
  2465. loc = this->GetProperty(locProp);
  2466. if (allowImp) {
  2467. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  2468. imp = this->GetProperty(impProp);
  2469. }
  2470. }
  2471. }
  2472. // If we have not yet found it then the target location is not available.
  2473. if (!loc && !imp) {
  2474. // Interface libraries are always available because their
  2475. // library name is optional so it is okay to leave loc empty.
  2476. return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
  2477. }
  2478. return true;
  2479. }