cmTarget.cxx 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735
  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("DISABLE_PRECOMPILE_HEADERS");
  548. initProp("UNITY_BUILD");
  549. initProp("UNITY_BUILD_UNIQUE_ID");
  550. initProp("OPTIMIZE_DEPENDENCIES");
  551. initProp("EXPORT_COMPILE_COMMANDS");
  552. initProp("COMPILE_WARNING_AS_ERROR");
  553. initPropValue("UNITY_BUILD_BATCH_SIZE", "8");
  554. initPropValue("UNITY_BUILD_MODE", "BATCH");
  555. initPropValue("PCH_WARN_INVALID", "ON");
  556. initPropValue("PCH_INSTANTIATE_TEMPLATES", "ON");
  557. #ifdef __APPLE__
  558. if (this->GetGlobalGenerator()->IsXcode()) {
  559. initProp("XCODE_SCHEME_ADDRESS_SANITIZER");
  560. initProp("XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN");
  561. initProp("XCODE_SCHEME_DEBUG_DOCUMENT_VERSIONING");
  562. initProp("XCODE_SCHEME_ENABLE_GPU_FRAME_CAPTURE_MODE");
  563. initProp("XCODE_SCHEME_THREAD_SANITIZER");
  564. initProp("XCODE_SCHEME_THREAD_SANITIZER_STOP");
  565. initProp("XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER");
  566. initProp("XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP");
  567. initProp("XCODE_SCHEME_WORKING_DIRECTORY");
  568. initProp("XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER");
  569. initProp("XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP");
  570. initProp("XCODE_SCHEME_MALLOC_SCRIBBLE");
  571. initProp("XCODE_SCHEME_MALLOC_GUARD_EDGES");
  572. initProp("XCODE_SCHEME_GUARD_MALLOC");
  573. initProp("XCODE_SCHEME_ZOMBIE_OBJECTS");
  574. initProp("XCODE_SCHEME_MALLOC_STACK");
  575. initProp("XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE");
  576. initProp("XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS");
  577. initProp("XCODE_SCHEME_ENVIRONMENT");
  578. initPropValue("XCODE_LINK_BUILD_PHASE_MODE", "NONE");
  579. }
  580. #endif
  581. }
  582. initProp("FOLDER");
  583. initProp("VERIFY_HEADER_SETS");
  584. if (this->GetGlobalGenerator()->IsXcode()) {
  585. initProp("XCODE_GENERATE_SCHEME");
  586. }
  587. // Setup per-configuration property default values.
  588. if (this->GetType() != cmStateEnums::UTILITY &&
  589. this->GetType() != cmStateEnums::GLOBAL_TARGET) {
  590. static const auto configProps = {
  591. /* clang-format needs this comment to break after the opening brace */
  592. "ARCHIVE_OUTPUT_DIRECTORY_", "LIBRARY_OUTPUT_DIRECTORY_",
  593. "RUNTIME_OUTPUT_DIRECTORY_", "PDB_OUTPUT_DIRECTORY_",
  594. "COMPILE_PDB_OUTPUT_DIRECTORY_", "MAP_IMPORTED_CONFIG_",
  595. "INTERPROCEDURAL_OPTIMIZATION_"
  596. };
  597. // Collect the set of configuration types.
  598. std::vector<std::string> configNames =
  599. mf->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
  600. for (std::string const& configName : configNames) {
  601. std::string configUpper = cmSystemTools::UpperCase(configName);
  602. for (auto const& prop : configProps) {
  603. // Interface libraries have no output locations, so honor only
  604. // the configuration map.
  605. if (this->impl->TargetType == cmStateEnums::INTERFACE_LIBRARY &&
  606. strcmp(prop, "MAP_IMPORTED_CONFIG_") != 0) {
  607. continue;
  608. }
  609. std::string property = cmStrCat(prop, configUpper);
  610. initProp(property);
  611. }
  612. // Initialize per-configuration name postfix property from the
  613. // variable only for non-executable targets. This preserves
  614. // compatibility with previous CMake versions in which executables
  615. // did not support this variable. Projects may still specify the
  616. // property directly.
  617. if (this->impl->TargetType != cmStateEnums::EXECUTABLE &&
  618. this->impl->TargetType != cmStateEnums::INTERFACE_LIBRARY) {
  619. std::string property =
  620. cmStrCat(cmSystemTools::UpperCase(configName), "_POSTFIX");
  621. initProp(property);
  622. }
  623. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
  624. this->impl->TargetType == cmStateEnums::STATIC_LIBRARY) {
  625. std::string property = cmStrCat("FRAMEWORK_MULTI_CONFIG_POSTFIX_",
  626. cmSystemTools::UpperCase(configName));
  627. initProp(property);
  628. }
  629. }
  630. if (!this->IsImported()) {
  631. initProp("LINK_LIBRARIES_ONLY_TARGETS");
  632. }
  633. }
  634. // Save the backtrace of target construction.
  635. this->impl->Backtrace = this->impl->Makefile->GetBacktrace();
  636. if (!this->IsImported()) {
  637. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  638. // of the same directory property:
  639. cm::append(this->impl->IncludeDirectoriesEntries,
  640. this->impl->Makefile->GetIncludeDirectoriesEntries());
  641. {
  642. auto const& sysInc = this->impl->Makefile->GetSystemIncludeDirectories();
  643. this->impl->SystemIncludeDirectories.insert(sysInc.begin(),
  644. sysInc.end());
  645. }
  646. cm::append(this->impl->CompileOptionsEntries,
  647. this->impl->Makefile->GetCompileOptionsEntries());
  648. cm::append(this->impl->LinkOptionsEntries,
  649. this->impl->Makefile->GetLinkOptionsEntries());
  650. cm::append(this->impl->LinkDirectoriesEntries,
  651. this->impl->Makefile->GetLinkDirectoriesEntries());
  652. }
  653. if (this->impl->TargetType == cmStateEnums::EXECUTABLE) {
  654. initProp("ANDROID_GUI");
  655. initProp("CROSSCOMPILING_EMULATOR");
  656. initProp("ENABLE_EXPORTS");
  657. }
  658. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
  659. this->impl->TargetType == cmStateEnums::MODULE_LIBRARY) {
  660. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  661. } else if (this->CanCompileSources()) {
  662. initProp("POSITION_INDEPENDENT_CODE");
  663. }
  664. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
  665. this->impl->TargetType == cmStateEnums::EXECUTABLE) {
  666. initProp("AIX_EXPORT_ALL_SYMBOLS");
  667. initProp("WINDOWS_EXPORT_ALL_SYMBOLS");
  668. }
  669. // Record current policies for later use.
  670. this->impl->Makefile->RecordPolicies(this->impl->PolicyMap);
  671. if (this->impl->TargetType == cmStateEnums::INTERFACE_LIBRARY) {
  672. // This policy is checked in a few conditions. The properties relevant
  673. // to the policy are always ignored for cmStateEnums::INTERFACE_LIBRARY
  674. // targets,
  675. // so ensure that the conditions don't lead to nonsense.
  676. this->impl->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
  677. }
  678. if (!this->IsImported()) {
  679. initProp("DOTNET_SDK");
  680. }
  681. if (this->impl->TargetType <= cmStateEnums::GLOBAL_TARGET) {
  682. initProp("DOTNET_TARGET_FRAMEWORK");
  683. initProp("DOTNET_TARGET_FRAMEWORK_VERSION");
  684. }
  685. // check for "CMAKE_VS_GLOBALS" variable and set up target properties
  686. // if any
  687. cmValue globals = mf->GetDefinition("CMAKE_VS_GLOBALS");
  688. if (globals) {
  689. const std::string genName = mf->GetGlobalGenerator()->GetName();
  690. if (cmHasLiteralPrefix(genName, "Visual Studio")) {
  691. std::vector<std::string> props = cmExpandedList(*globals);
  692. const std::string vsGlobal = "VS_GLOBAL_";
  693. for (const std::string& i : props) {
  694. // split NAME=VALUE
  695. const std::string::size_type assignment = i.find('=');
  696. if (assignment != std::string::npos) {
  697. const std::string propName = vsGlobal + i.substr(0, assignment);
  698. const std::string propValue = i.substr(assignment + 1);
  699. initPropValue(propName, propValue.c_str());
  700. }
  701. }
  702. }
  703. }
  704. for (auto const& prop : mf->GetState()->GetPropertyDefinitions().GetMap()) {
  705. if (prop.first.second == cmProperty::TARGET &&
  706. !prop.second.GetInitializeFromVariable().empty()) {
  707. if (auto value =
  708. mf->GetDefinition(prop.second.GetInitializeFromVariable())) {
  709. this->SetProperty(prop.first.first, value);
  710. }
  711. }
  712. }
  713. }
  714. cmTarget::cmTarget(cmTarget&&) noexcept = default;
  715. cmTarget::~cmTarget() = default;
  716. cmTarget& cmTarget::operator=(cmTarget&&) noexcept = default;
  717. cmStateEnums::TargetType cmTarget::GetType() const
  718. {
  719. return this->impl->TargetType;
  720. }
  721. cmMakefile* cmTarget::GetMakefile() const
  722. {
  723. return this->impl->Makefile;
  724. }
  725. cmPolicies::PolicyMap const& cmTarget::GetPolicyMap() const
  726. {
  727. return this->impl->PolicyMap;
  728. }
  729. const std::string& cmTarget::GetName() const
  730. {
  731. return this->impl->Name;
  732. }
  733. cmPolicies::PolicyStatus cmTarget::GetPolicyStatus(
  734. cmPolicies::PolicyID policy) const
  735. {
  736. return this->impl->PolicyMap.Get(policy);
  737. }
  738. cmGlobalGenerator* cmTarget::GetGlobalGenerator() const
  739. {
  740. return this->impl->Makefile->GetGlobalGenerator();
  741. }
  742. BTs<std::string> const* cmTarget::GetLanguageStandardProperty(
  743. const std::string& propertyName) const
  744. {
  745. auto entry = this->impl->LanguageStandardProperties.find(propertyName);
  746. if (entry != this->impl->LanguageStandardProperties.end()) {
  747. return &entry->second;
  748. }
  749. return nullptr;
  750. }
  751. void cmTarget::SetLanguageStandardProperty(std::string const& lang,
  752. std::string const& value,
  753. const std::string& feature)
  754. {
  755. cmListFileBacktrace featureBacktrace;
  756. for (auto const& entry : this->impl->CompileFeaturesEntries) {
  757. if (entry.Value == feature) {
  758. featureBacktrace = entry.Backtrace;
  759. break;
  760. }
  761. }
  762. BTs<std::string>& languageStandardProperty =
  763. this->impl->LanguageStandardProperties[cmStrCat(lang, "_STANDARD")];
  764. if (languageStandardProperty.Value != value) {
  765. languageStandardProperty.Value = value;
  766. languageStandardProperty.Backtraces.clear();
  767. }
  768. languageStandardProperty.Backtraces.emplace_back(featureBacktrace);
  769. }
  770. void cmTarget::AddUtility(std::string const& name, bool cross, cmMakefile* mf)
  771. {
  772. this->impl->Utilities.insert(BT<std::pair<std::string, bool>>(
  773. { name, cross }, mf ? mf->GetBacktrace() : cmListFileBacktrace()));
  774. }
  775. void cmTarget::AddUtility(BT<std::pair<std::string, bool>> util)
  776. {
  777. this->impl->Utilities.emplace(std::move(util));
  778. }
  779. std::set<BT<std::pair<std::string, bool>>> const& cmTarget::GetUtilities()
  780. const
  781. {
  782. return this->impl->Utilities;
  783. }
  784. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  785. {
  786. return this->impl->Backtrace;
  787. }
  788. bool cmTarget::IsExecutableWithExports() const
  789. {
  790. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  791. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  792. }
  793. bool cmTarget::IsFrameworkOnApple() const
  794. {
  795. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  796. this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  797. this->impl->Makefile->IsOn("APPLE") &&
  798. this->GetPropertyAsBool("FRAMEWORK"));
  799. }
  800. bool cmTarget::IsAppBundleOnApple() const
  801. {
  802. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  803. this->impl->Makefile->IsOn("APPLE") &&
  804. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  805. }
  806. bool cmTarget::IsAndroidGuiExecutable() const
  807. {
  808. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  809. this->impl->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI"));
  810. }
  811. bool cmTarget::HasKnownObjectFileLocation(std::string* reason) const
  812. {
  813. return this->GetGlobalGenerator()->HasKnownObjectFileLocation(*this, reason);
  814. }
  815. std::vector<cmCustomCommand> const& cmTarget::GetPreBuildCommands() const
  816. {
  817. return this->impl->PreBuildCommands;
  818. }
  819. void cmTarget::AddPreBuildCommand(cmCustomCommand const& cmd)
  820. {
  821. this->impl->PreBuildCommands.push_back(cmd);
  822. }
  823. void cmTarget::AddPreBuildCommand(cmCustomCommand&& cmd)
  824. {
  825. this->impl->PreBuildCommands.push_back(std::move(cmd));
  826. }
  827. std::vector<cmCustomCommand> const& cmTarget::GetPreLinkCommands() const
  828. {
  829. return this->impl->PreLinkCommands;
  830. }
  831. void cmTarget::AddPreLinkCommand(cmCustomCommand const& cmd)
  832. {
  833. this->impl->PreLinkCommands.push_back(cmd);
  834. }
  835. void cmTarget::AddPreLinkCommand(cmCustomCommand&& cmd)
  836. {
  837. this->impl->PreLinkCommands.push_back(std::move(cmd));
  838. }
  839. std::vector<cmCustomCommand> const& cmTarget::GetPostBuildCommands() const
  840. {
  841. return this->impl->PostBuildCommands;
  842. }
  843. void cmTarget::AddPostBuildCommand(cmCustomCommand const& cmd)
  844. {
  845. this->impl->PostBuildCommands.push_back(cmd);
  846. }
  847. void cmTarget::AddPostBuildCommand(cmCustomCommand&& cmd)
  848. {
  849. this->impl->PostBuildCommands.push_back(std::move(cmd));
  850. }
  851. void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
  852. {
  853. if (!srcs.empty()) {
  854. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  855. this->impl->SourceEntries.emplace_back(cmJoin(srcs, ";"), lfbt);
  856. }
  857. }
  858. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  859. {
  860. std::string srcFiles;
  861. const char* sep = "";
  862. for (auto filename : srcs) {
  863. if (!cmGeneratorExpression::StartsWithGeneratorExpression(filename)) {
  864. if (!filename.empty()) {
  865. filename = this->impl->ProcessSourceItemCMP0049(filename);
  866. if (filename.empty()) {
  867. return;
  868. }
  869. }
  870. this->impl->Makefile->GetOrCreateSource(filename);
  871. }
  872. srcFiles += sep;
  873. srcFiles += filename;
  874. sep = ";";
  875. }
  876. if (!srcFiles.empty()) {
  877. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  878. this->impl->SourceEntries.emplace_back(std::move(srcFiles), lfbt);
  879. }
  880. }
  881. std::string cmTargetInternals::ProcessSourceItemCMP0049(
  882. const std::string& s) const
  883. {
  884. std::string src = s;
  885. // For backwards compatibility replace variables in source names.
  886. // This should eventually be removed.
  887. this->Makefile->ExpandVariablesInString(src);
  888. if (src != s) {
  889. std::ostringstream e;
  890. bool noMessage = false;
  891. MessageType messageType = MessageType::AUTHOR_WARNING;
  892. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0049)) {
  893. case cmPolicies::WARN:
  894. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0049) << "\n";
  895. break;
  896. case cmPolicies::OLD:
  897. noMessage = true;
  898. break;
  899. case cmPolicies::REQUIRED_ALWAYS:
  900. case cmPolicies::REQUIRED_IF_USED:
  901. case cmPolicies::NEW:
  902. messageType = MessageType::FATAL_ERROR;
  903. }
  904. if (!noMessage) {
  905. e << "Legacy variable expansion in source file \"" << s
  906. << "\" expanded to \"" << src << "\" in target \"" << this->Name
  907. << "\". This behavior will be removed in a "
  908. "future version of CMake.";
  909. this->Makefile->IssueMessage(messageType, e.str());
  910. if (messageType == MessageType::FATAL_ERROR) {
  911. return "";
  912. }
  913. }
  914. }
  915. return src;
  916. }
  917. std::string cmTarget::GetSourceCMP0049(const std::string& s)
  918. {
  919. return this->impl->ProcessSourceItemCMP0049(s);
  920. }
  921. struct CreateLocation
  922. {
  923. cmMakefile const* Makefile;
  924. CreateLocation(cmMakefile const* mf)
  925. : Makefile(mf)
  926. {
  927. }
  928. cmSourceFileLocation operator()(const std::string& filename) const
  929. {
  930. return cmSourceFileLocation(this->Makefile, filename);
  931. }
  932. };
  933. struct LocationMatcher
  934. {
  935. const cmSourceFileLocation& Needle;
  936. LocationMatcher(const cmSourceFileLocation& needle)
  937. : Needle(needle)
  938. {
  939. }
  940. bool operator()(cmSourceFileLocation& loc)
  941. {
  942. return loc.Matches(this->Needle);
  943. }
  944. };
  945. struct TargetPropertyEntryFinder
  946. {
  947. private:
  948. const cmSourceFileLocation& Needle;
  949. public:
  950. TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
  951. : Needle(needle)
  952. {
  953. }
  954. bool operator()(BT<std::string> const& entry)
  955. {
  956. std::vector<std::string> files = cmExpandedList(entry.Value);
  957. std::vector<cmSourceFileLocation> locations;
  958. locations.reserve(files.size());
  959. std::transform(files.begin(), files.end(), std::back_inserter(locations),
  960. CreateLocation(this->Needle.GetMakefile()));
  961. return std::find_if(locations.begin(), locations.end(),
  962. LocationMatcher(this->Needle)) != locations.end();
  963. }
  964. };
  965. cmSourceFile* cmTarget::AddSource(const std::string& src, bool before)
  966. {
  967. cmSourceFileLocation sfl(this->impl->Makefile, src,
  968. cmSourceFileLocationKind::Known);
  969. if (std::find_if(
  970. this->impl->SourceEntries.begin(), this->impl->SourceEntries.end(),
  971. TargetPropertyEntryFinder(sfl)) == this->impl->SourceEntries.end()) {
  972. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  973. this->impl->SourceEntries.insert(before ? this->impl->SourceEntries.begin()
  974. : this->impl->SourceEntries.end(),
  975. BT<std::string>(src, lfbt));
  976. }
  977. if (cmGeneratorExpression::Find(src) != std::string::npos) {
  978. return nullptr;
  979. }
  980. return this->impl->Makefile->GetOrCreateSource(
  981. src, false, cmSourceFileLocationKind::Known);
  982. }
  983. void cmTarget::ClearDependencyInformation(cmMakefile& mf) const
  984. {
  985. std::string depname = cmStrCat(this->GetName(), "_LIB_DEPENDS");
  986. mf.RemoveCacheDefinition(depname);
  987. }
  988. std::string cmTarget::GetDebugGeneratorExpressions(
  989. const std::string& value, cmTargetLinkLibraryType llt) const
  990. {
  991. if (llt == GENERAL_LibraryType) {
  992. return value;
  993. }
  994. // Get the list of configurations considered to be DEBUG.
  995. std::vector<std::string> debugConfigs =
  996. this->impl->Makefile->GetCMakeInstance()->GetDebugConfigs();
  997. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  998. if (debugConfigs.size() > 1) {
  999. for (std::string const& conf : cmMakeRange(debugConfigs).advance(1)) {
  1000. configString += ",$<CONFIG:" + conf + ">";
  1001. }
  1002. configString = "$<OR:" + configString + ">";
  1003. }
  1004. if (llt == OPTIMIZED_LibraryType) {
  1005. configString = "$<NOT:" + configString + ">";
  1006. }
  1007. return "$<" + configString + ":" + value + ">";
  1008. }
  1009. static std::string targetNameGenex(const std::string& lib)
  1010. {
  1011. return "$<TARGET_NAME:" + lib + ">";
  1012. }
  1013. bool cmTarget::PushTLLCommandTrace(TLLSignature signature,
  1014. cmListFileContext const& lfc)
  1015. {
  1016. bool ret = true;
  1017. if (!this->impl->TLLCommands.empty()) {
  1018. if (this->impl->TLLCommands.back().first != signature) {
  1019. ret = false;
  1020. }
  1021. }
  1022. if (this->impl->TLLCommands.empty() ||
  1023. this->impl->TLLCommands.back().second != lfc) {
  1024. this->impl->TLLCommands.emplace_back(signature, lfc);
  1025. }
  1026. return ret;
  1027. }
  1028. void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const
  1029. {
  1030. const char* sigString =
  1031. (sig == cmTarget::KeywordTLLSignature ? "keyword" : "plain");
  1032. s << "The uses of the " << sigString << " signature are here:\n";
  1033. for (auto const& cmd : this->impl->TLLCommands) {
  1034. if (cmd.first == sig) {
  1035. cmListFileContext lfc = cmd.second;
  1036. lfc.FilePath = cmSystemTools::RelativeIfUnder(
  1037. this->impl->Makefile->GetState()->GetSourceDirectory(), lfc.FilePath);
  1038. s << " * " << lfc << '\n';
  1039. }
  1040. }
  1041. }
  1042. std::string const& cmTarget::GetInstallPath() const
  1043. {
  1044. return this->impl->InstallPath;
  1045. }
  1046. void cmTarget::SetInstallPath(std::string const& name)
  1047. {
  1048. this->impl->InstallPath = name;
  1049. }
  1050. std::string const& cmTarget::GetRuntimeInstallPath() const
  1051. {
  1052. return this->impl->RuntimeInstallPath;
  1053. }
  1054. void cmTarget::SetRuntimeInstallPath(std::string const& name)
  1055. {
  1056. this->impl->RuntimeInstallPath = name;
  1057. }
  1058. bool cmTarget::GetHaveInstallRule() const
  1059. {
  1060. return this->impl->HaveInstallRule;
  1061. }
  1062. void cmTarget::SetHaveInstallRule(bool hir)
  1063. {
  1064. this->impl->HaveInstallRule = hir;
  1065. }
  1066. void cmTarget::AddInstallGenerator(cmInstallTargetGenerator* g)
  1067. {
  1068. this->impl->InstallGenerators.emplace_back(g);
  1069. }
  1070. std::vector<cmInstallTargetGenerator*> const& cmTarget::GetInstallGenerators()
  1071. const
  1072. {
  1073. return this->impl->InstallGenerators;
  1074. }
  1075. bool cmTarget::GetIsGeneratorProvided() const
  1076. {
  1077. return this->impl->IsGeneratorProvided;
  1078. }
  1079. void cmTarget::SetIsGeneratorProvided(bool igp)
  1080. {
  1081. this->impl->IsGeneratorProvided = igp;
  1082. }
  1083. cmTarget::LinkLibraryVectorType const& cmTarget::GetOriginalLinkLibraries()
  1084. const
  1085. {
  1086. return this->impl->OriginalLinkLibraries;
  1087. }
  1088. void cmTarget::AddLinkLibrary(cmMakefile& mf, std::string const& lib,
  1089. cmTargetLinkLibraryType llt)
  1090. {
  1091. cmTarget* tgt = mf.FindTargetToUse(lib);
  1092. {
  1093. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  1094. const std::string libName =
  1095. (isNonImportedTarget && llt != GENERAL_LibraryType)
  1096. ? targetNameGenex(lib)
  1097. : lib;
  1098. this->AppendProperty("LINK_LIBRARIES",
  1099. this->GetDebugGeneratorExpressions(libName, llt));
  1100. }
  1101. if (cmGeneratorExpression::Find(lib) != std::string::npos ||
  1102. (tgt &&
  1103. (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
  1104. tgt->GetType() == cmStateEnums::OBJECT_LIBRARY)) ||
  1105. (this->impl->Name == lib)) {
  1106. return;
  1107. }
  1108. this->impl->OriginalLinkLibraries.emplace_back(lib, llt);
  1109. // Add the explicit dependency information for libraries. This is
  1110. // simply a set of libraries separated by ";". There should always
  1111. // be a trailing ";". These library names are not canonical, in that
  1112. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  1113. // We shouldn't remove duplicates here because external libraries
  1114. // may be purposefully duplicated to handle recursive dependencies,
  1115. // and we removing one instance will break the link line. Duplicates
  1116. // will be appropriately eliminated at emit time.
  1117. if (this->impl->TargetType >= cmStateEnums::STATIC_LIBRARY &&
  1118. this->impl->TargetType <= cmStateEnums::MODULE_LIBRARY &&
  1119. (this->GetPolicyStatusCMP0073() == cmPolicies::OLD ||
  1120. this->GetPolicyStatusCMP0073() == cmPolicies::WARN)) {
  1121. std::string targetEntry = cmStrCat(this->impl->Name, "_LIB_DEPENDS");
  1122. std::string dependencies;
  1123. cmValue old_val = mf.GetDefinition(targetEntry);
  1124. if (old_val) {
  1125. dependencies += *old_val;
  1126. }
  1127. switch (llt) {
  1128. case GENERAL_LibraryType:
  1129. dependencies += "general";
  1130. break;
  1131. case DEBUG_LibraryType:
  1132. dependencies += "debug";
  1133. break;
  1134. case OPTIMIZED_LibraryType:
  1135. dependencies += "optimized";
  1136. break;
  1137. }
  1138. dependencies += ";";
  1139. dependencies += lib;
  1140. dependencies += ";";
  1141. mf.AddCacheDefinition(targetEntry, dependencies,
  1142. "Dependencies for the target", cmStateEnums::STATIC);
  1143. }
  1144. }
  1145. void cmTarget::AddSystemIncludeDirectories(const std::set<std::string>& incs)
  1146. {
  1147. this->impl->SystemIncludeDirectories.insert(incs.begin(), incs.end());
  1148. }
  1149. std::set<std::string> const& cmTarget::GetSystemIncludeDirectories() const
  1150. {
  1151. return this->impl->SystemIncludeDirectories;
  1152. }
  1153. void cmTarget::AddInstallIncludeDirectories(cmTargetExport const& te,
  1154. cmStringRange const& incs)
  1155. {
  1156. std::copy(
  1157. incs.begin(), incs.end(),
  1158. std::back_inserter(this->impl->InstallIncludeDirectoriesEntries[&te]));
  1159. }
  1160. cmStringRange cmTarget::GetInstallIncludeDirectoriesEntries(
  1161. cmTargetExport const& te) const
  1162. {
  1163. auto i = this->impl->InstallIncludeDirectoriesEntries.find(&te);
  1164. if (i == this->impl->InstallIncludeDirectoriesEntries.end()) {
  1165. decltype(i->second) empty;
  1166. return cmMakeRange(empty);
  1167. }
  1168. return cmMakeRange(i->second);
  1169. }
  1170. cmBTStringRange cmTarget::GetIncludeDirectoriesEntries() const
  1171. {
  1172. return cmMakeRange(this->impl->IncludeDirectoriesEntries);
  1173. }
  1174. cmBTStringRange cmTarget::GetCompileOptionsEntries() const
  1175. {
  1176. return cmMakeRange(this->impl->CompileOptionsEntries);
  1177. }
  1178. cmBTStringRange cmTarget::GetCompileFeaturesEntries() const
  1179. {
  1180. return cmMakeRange(this->impl->CompileFeaturesEntries);
  1181. }
  1182. cmBTStringRange cmTarget::GetCompileDefinitionsEntries() const
  1183. {
  1184. return cmMakeRange(this->impl->CompileDefinitionsEntries);
  1185. }
  1186. cmBTStringRange cmTarget::GetPrecompileHeadersEntries() const
  1187. {
  1188. return cmMakeRange(this->impl->PrecompileHeadersEntries);
  1189. }
  1190. cmBTStringRange cmTarget::GetSourceEntries() const
  1191. {
  1192. return cmMakeRange(this->impl->SourceEntries);
  1193. }
  1194. cmBTStringRange cmTarget::GetLinkOptionsEntries() const
  1195. {
  1196. return cmMakeRange(this->impl->LinkOptionsEntries);
  1197. }
  1198. cmBTStringRange cmTarget::GetLinkDirectoriesEntries() const
  1199. {
  1200. return cmMakeRange(this->impl->LinkDirectoriesEntries);
  1201. }
  1202. cmBTStringRange cmTarget::GetLinkImplementationEntries() const
  1203. {
  1204. return cmMakeRange(this->impl->LinkImplementationPropertyEntries);
  1205. }
  1206. cmBTStringRange cmTarget::GetLinkInterfaceEntries() const
  1207. {
  1208. return cmMakeRange(this->impl->LinkInterfacePropertyEntries);
  1209. }
  1210. cmBTStringRange cmTarget::GetLinkInterfaceDirectEntries() const
  1211. {
  1212. return cmMakeRange(this->impl->LinkInterfaceDirectPropertyEntries);
  1213. }
  1214. cmBTStringRange cmTarget::GetLinkInterfaceDirectExcludeEntries() const
  1215. {
  1216. return cmMakeRange(this->impl->LinkInterfaceDirectExcludePropertyEntries);
  1217. }
  1218. cmBTStringRange cmTarget::GetHeaderSetsEntries() const
  1219. {
  1220. return cmMakeRange(this->impl->HeadersFileSets.SelfEntries.Entries);
  1221. }
  1222. cmBTStringRange cmTarget::GetInterfaceHeaderSetsEntries() const
  1223. {
  1224. return cmMakeRange(this->impl->HeadersFileSets.InterfaceEntries.Entries);
  1225. }
  1226. namespace {
  1227. #define MAKE_PROP(PROP) const std::string prop##PROP = #PROP
  1228. MAKE_PROP(C_STANDARD);
  1229. MAKE_PROP(CXX_STANDARD);
  1230. MAKE_PROP(CUDA_STANDARD);
  1231. MAKE_PROP(HIP_STANDARD);
  1232. MAKE_PROP(OBJC_STANDARD);
  1233. MAKE_PROP(OBJCXX_STANDARD);
  1234. MAKE_PROP(COMPILE_DEFINITIONS);
  1235. MAKE_PROP(COMPILE_FEATURES);
  1236. MAKE_PROP(COMPILE_OPTIONS);
  1237. MAKE_PROP(PRECOMPILE_HEADERS);
  1238. MAKE_PROP(PRECOMPILE_HEADERS_REUSE_FROM);
  1239. MAKE_PROP(CUDA_PTX_COMPILATION);
  1240. MAKE_PROP(EXPORT_NAME);
  1241. MAKE_PROP(IMPORTED);
  1242. MAKE_PROP(IMPORTED_GLOBAL);
  1243. MAKE_PROP(INCLUDE_DIRECTORIES);
  1244. MAKE_PROP(LINK_OPTIONS);
  1245. MAKE_PROP(LINK_DIRECTORIES);
  1246. MAKE_PROP(LINK_LIBRARIES);
  1247. MAKE_PROP(MANUALLY_ADDED_DEPENDENCIES);
  1248. MAKE_PROP(NAME);
  1249. MAKE_PROP(SOURCES);
  1250. MAKE_PROP(TYPE);
  1251. MAKE_PROP(BINARY_DIR);
  1252. MAKE_PROP(SOURCE_DIR);
  1253. MAKE_PROP(FALSE);
  1254. MAKE_PROP(TRUE);
  1255. MAKE_PROP(INTERFACE_LINK_LIBRARIES);
  1256. MAKE_PROP(INTERFACE_LINK_LIBRARIES_DIRECT);
  1257. MAKE_PROP(INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE);
  1258. #undef MAKE_PROP
  1259. }
  1260. namespace {
  1261. // to workaround bug on GCC/AIX
  1262. // Define a template to force conversion to std::string
  1263. template <typename ValueType>
  1264. std::string ConvertToString(ValueType value);
  1265. template <>
  1266. std::string ConvertToString<const char*>(const char* value)
  1267. {
  1268. return std::string(value);
  1269. }
  1270. template <>
  1271. std::string ConvertToString<cmValue>(cmValue value)
  1272. {
  1273. return std::string(*value);
  1274. }
  1275. template <typename ValueType>
  1276. bool StringIsEmpty(ValueType const& value);
  1277. template <>
  1278. bool StringIsEmpty<const char*>(const char* const& value)
  1279. {
  1280. return cmValue::IsEmpty(value);
  1281. }
  1282. template <>
  1283. bool StringIsEmpty<cmValue>(cmValue const& value)
  1284. {
  1285. return value.IsEmpty();
  1286. }
  1287. template <>
  1288. bool StringIsEmpty<std::string>(std::string const& value)
  1289. {
  1290. return value.empty();
  1291. }
  1292. }
  1293. template <typename ValueType>
  1294. void cmTarget::StoreProperty(const std::string& prop, ValueType value)
  1295. {
  1296. if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
  1297. this->impl->Makefile->IssueMessage(
  1298. MessageType::FATAL_ERROR,
  1299. "MANUALLY_ADDED_DEPENDENCIES property is read-only\n");
  1300. return;
  1301. }
  1302. if (prop == propNAME) {
  1303. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1304. "NAME property is read-only\n");
  1305. return;
  1306. }
  1307. if (prop == propTYPE) {
  1308. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1309. "TYPE property is read-only\n");
  1310. return;
  1311. }
  1312. if (prop == propEXPORT_NAME && this->IsImported()) {
  1313. std::ostringstream e;
  1314. e << "EXPORT_NAME property can't be set on imported targets (\""
  1315. << this->impl->Name << "\")\n";
  1316. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1317. return;
  1318. }
  1319. if (prop == propSOURCES && this->IsImported()) {
  1320. std::ostringstream e;
  1321. e << "SOURCES property can't be set on imported targets (\""
  1322. << this->impl->Name << "\")\n";
  1323. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1324. return;
  1325. }
  1326. if (prop == propIMPORTED_GLOBAL && !this->IsImported()) {
  1327. std::ostringstream e;
  1328. e << "IMPORTED_GLOBAL property can't be set on non-imported targets (\""
  1329. << this->impl->Name << "\")\n";
  1330. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1331. return;
  1332. }
  1333. if (prop == propINCLUDE_DIRECTORIES) {
  1334. this->impl->IncludeDirectoriesEntries.clear();
  1335. if (value) {
  1336. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1337. this->impl->IncludeDirectoriesEntries.emplace_back(value, lfbt);
  1338. }
  1339. } else if (prop == propCOMPILE_OPTIONS) {
  1340. this->impl->CompileOptionsEntries.clear();
  1341. if (value) {
  1342. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1343. this->impl->CompileOptionsEntries.emplace_back(value, lfbt);
  1344. }
  1345. } else if (prop == propCOMPILE_FEATURES) {
  1346. this->impl->CompileFeaturesEntries.clear();
  1347. if (value) {
  1348. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1349. this->impl->CompileFeaturesEntries.emplace_back(value, lfbt);
  1350. }
  1351. } else if (prop == propCOMPILE_DEFINITIONS) {
  1352. this->impl->CompileDefinitionsEntries.clear();
  1353. if (value) {
  1354. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1355. this->impl->CompileDefinitionsEntries.emplace_back(value, lfbt);
  1356. }
  1357. } else if (prop == propLINK_OPTIONS) {
  1358. this->impl->LinkOptionsEntries.clear();
  1359. if (value) {
  1360. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1361. this->impl->LinkOptionsEntries.emplace_back(value, lfbt);
  1362. }
  1363. } else if (prop == propLINK_DIRECTORIES) {
  1364. this->impl->LinkDirectoriesEntries.clear();
  1365. if (value) {
  1366. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1367. this->impl->LinkDirectoriesEntries.emplace_back(value, lfbt);
  1368. }
  1369. } else if (prop == propPRECOMPILE_HEADERS) {
  1370. this->impl->PrecompileHeadersEntries.clear();
  1371. if (value) {
  1372. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1373. this->impl->PrecompileHeadersEntries.emplace_back(value, lfbt);
  1374. }
  1375. } else if (prop == propLINK_LIBRARIES) {
  1376. this->impl->LinkImplementationPropertyEntries.clear();
  1377. if (value) {
  1378. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1379. this->impl->LinkImplementationPropertyEntries.emplace_back(value, lfbt);
  1380. }
  1381. } else if (prop == propINTERFACE_LINK_LIBRARIES) {
  1382. this->impl->LinkInterfacePropertyEntries.clear();
  1383. if (value) {
  1384. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1385. this->impl->LinkInterfacePropertyEntries.emplace_back(value, lfbt);
  1386. }
  1387. } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) {
  1388. this->impl->LinkInterfaceDirectPropertyEntries.clear();
  1389. if (value) {
  1390. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1391. this->impl->LinkInterfaceDirectPropertyEntries.emplace_back(value, lfbt);
  1392. }
  1393. } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) {
  1394. this->impl->LinkInterfaceDirectExcludePropertyEntries.clear();
  1395. if (value) {
  1396. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1397. this->impl->LinkInterfaceDirectExcludePropertyEntries.emplace_back(value,
  1398. lfbt);
  1399. }
  1400. } else if (prop == propSOURCES) {
  1401. this->impl->SourceEntries.clear();
  1402. if (value) {
  1403. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1404. this->impl->SourceEntries.emplace_back(value, lfbt);
  1405. }
  1406. } else if (prop == propIMPORTED_GLOBAL) {
  1407. if (!cmIsOn(value)) {
  1408. std::ostringstream e;
  1409. e << "IMPORTED_GLOBAL property can't be set to FALSE on targets (\""
  1410. << this->impl->Name << "\")\n";
  1411. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1412. return;
  1413. }
  1414. /* no need to change anything if value does not change */
  1415. if (!this->impl->ImportedGloballyVisible) {
  1416. this->impl->ImportedGloballyVisible = true;
  1417. this->GetGlobalGenerator()->IndexTarget(this);
  1418. }
  1419. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME") &&
  1420. !this->impl->CheckImportedLibName(
  1421. prop,
  1422. value ? value
  1423. : std::string{})) { // NOLINT(bugprone-branch-clone)
  1424. /* error was reported by check method */
  1425. } else if (prop == propCUDA_PTX_COMPILATION &&
  1426. this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  1427. std::ostringstream e;
  1428. e << "CUDA_PTX_COMPILATION property can only be applied to OBJECT "
  1429. "targets (\""
  1430. << this->impl->Name << "\")\n";
  1431. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1432. return;
  1433. } else if (prop == propPRECOMPILE_HEADERS_REUSE_FROM) {
  1434. if (this->GetProperty("PRECOMPILE_HEADERS")) {
  1435. std::ostringstream e;
  1436. e << "PRECOMPILE_HEADERS property is already set on target (\""
  1437. << this->impl->Name << "\")\n";
  1438. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1439. return;
  1440. }
  1441. auto* reusedTarget = this->impl->Makefile->GetCMakeInstance()
  1442. ->GetGlobalGenerator()
  1443. ->FindTarget(value);
  1444. if (!reusedTarget) {
  1445. const std::string e(
  1446. "PRECOMPILE_HEADERS_REUSE_FROM set with non existing target");
  1447. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e);
  1448. return;
  1449. }
  1450. std::string reusedFrom = reusedTarget->GetSafeProperty(prop);
  1451. if (reusedFrom.empty()) {
  1452. reusedFrom = ConvertToString(value);
  1453. }
  1454. this->impl->Properties.SetProperty(prop, reusedFrom);
  1455. reusedTarget->SetProperty("COMPILE_PDB_NAME", reusedFrom);
  1456. reusedTarget->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY",
  1457. cmStrCat(reusedFrom, ".dir/"));
  1458. cmValue tmp = reusedTarget->GetProperty("COMPILE_PDB_NAME");
  1459. this->SetProperty("COMPILE_PDB_NAME", tmp);
  1460. this->AddUtility(reusedFrom, false, this->impl->Makefile);
  1461. } else if (prop == propC_STANDARD || prop == propCXX_STANDARD ||
  1462. prop == propCUDA_STANDARD || prop == propHIP_STANDARD ||
  1463. prop == propOBJC_STANDARD || prop == propOBJCXX_STANDARD) {
  1464. if (value) {
  1465. this->impl->LanguageStandardProperties[prop] =
  1466. BTs<std::string>(value, this->impl->Makefile->GetBacktrace());
  1467. } else {
  1468. this->impl->LanguageStandardProperties.erase(prop);
  1469. }
  1470. } else if (this->impl->HeadersFileSets.WriteProperties(
  1471. this, this->impl.get(), prop, value, true)) {
  1472. /* Handled in the `if` condition. */
  1473. } else {
  1474. this->impl->Properties.SetProperty(prop, value);
  1475. }
  1476. }
  1477. void cmTarget::AppendProperty(const std::string& prop,
  1478. const std::string& value, bool asString)
  1479. {
  1480. if (prop == "NAME") {
  1481. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1482. "NAME property is read-only\n");
  1483. return;
  1484. }
  1485. if (prop == "EXPORT_NAME" && this->IsImported()) {
  1486. std::ostringstream e;
  1487. e << "EXPORT_NAME property can't be set on imported targets (\""
  1488. << this->impl->Name << "\")\n";
  1489. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1490. return;
  1491. }
  1492. if (prop == "SOURCES" && this->IsImported()) {
  1493. std::ostringstream e;
  1494. e << "SOURCES property can't be set on imported targets (\""
  1495. << this->impl->Name << "\")\n";
  1496. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1497. return;
  1498. }
  1499. if (prop == "IMPORTED_GLOBAL") {
  1500. std::ostringstream e;
  1501. e << "IMPORTED_GLOBAL property can't be appended, only set on imported "
  1502. "targets (\""
  1503. << this->impl->Name << "\")\n";
  1504. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1505. return;
  1506. }
  1507. if (prop == "INCLUDE_DIRECTORIES") {
  1508. if (!value.empty()) {
  1509. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1510. this->impl->IncludeDirectoriesEntries.emplace_back(value, lfbt);
  1511. }
  1512. } else if (prop == "COMPILE_OPTIONS") {
  1513. if (!value.empty()) {
  1514. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1515. this->impl->CompileOptionsEntries.emplace_back(value, lfbt);
  1516. }
  1517. } else if (prop == "COMPILE_FEATURES") {
  1518. if (!value.empty()) {
  1519. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1520. this->impl->CompileFeaturesEntries.emplace_back(value, lfbt);
  1521. }
  1522. } else if (prop == "COMPILE_DEFINITIONS") {
  1523. if (!value.empty()) {
  1524. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1525. this->impl->CompileDefinitionsEntries.emplace_back(value, lfbt);
  1526. }
  1527. } else if (prop == "LINK_OPTIONS") {
  1528. if (!value.empty()) {
  1529. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1530. this->impl->LinkOptionsEntries.emplace_back(value, lfbt);
  1531. }
  1532. } else if (prop == "LINK_DIRECTORIES") {
  1533. if (!value.empty()) {
  1534. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1535. this->impl->LinkDirectoriesEntries.emplace_back(value, lfbt);
  1536. }
  1537. } else if (prop == "PRECOMPILE_HEADERS") {
  1538. if (this->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM")) {
  1539. std::ostringstream e;
  1540. e << "PRECOMPILE_HEADERS_REUSE_FROM property is already set on target "
  1541. "(\""
  1542. << this->impl->Name << "\")\n";
  1543. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1544. return;
  1545. }
  1546. if (!value.empty()) {
  1547. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1548. this->impl->PrecompileHeadersEntries.emplace_back(value, lfbt);
  1549. }
  1550. } else if (prop == "LINK_LIBRARIES") {
  1551. if (!value.empty()) {
  1552. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1553. this->impl->LinkImplementationPropertyEntries.emplace_back(value, lfbt);
  1554. }
  1555. } else if (prop == propINTERFACE_LINK_LIBRARIES) {
  1556. if (!value.empty()) {
  1557. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1558. this->impl->LinkInterfacePropertyEntries.emplace_back(value, lfbt);
  1559. }
  1560. } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) {
  1561. if (!value.empty()) {
  1562. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1563. this->impl->LinkInterfaceDirectPropertyEntries.emplace_back(value, lfbt);
  1564. }
  1565. } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) {
  1566. if (!value.empty()) {
  1567. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1568. this->impl->LinkInterfaceDirectExcludePropertyEntries.emplace_back(value,
  1569. lfbt);
  1570. }
  1571. } else if (prop == "SOURCES") {
  1572. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1573. this->impl->SourceEntries.emplace_back(value, lfbt);
  1574. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) {
  1575. this->impl->Makefile->IssueMessage(
  1576. MessageType::FATAL_ERROR, prop + " property may not be APPENDed.");
  1577. } else if (prop == "C_STANDARD" || prop == "CXX_STANDARD" ||
  1578. prop == "CUDA_STANDARD" || prop == "HIP_STANDARD" ||
  1579. prop == "OBJC_STANDARD" || prop == "OBJCXX_STANDARD") {
  1580. this->impl->Makefile->IssueMessage(
  1581. MessageType::FATAL_ERROR, prop + " property may not be appended.");
  1582. } else if (this->impl->HeadersFileSets.WriteProperties(
  1583. this, this->impl.get(), prop, value, false)) {
  1584. /* Handled in the `if` condition. */
  1585. } else {
  1586. this->impl->Properties.AppendProperty(prop, value, asString);
  1587. }
  1588. }
  1589. void cmTarget::SetProperty(const std::string& prop, const char* value)
  1590. {
  1591. this->StoreProperty(prop, value);
  1592. }
  1593. void cmTarget::SetProperty(const std::string& prop, cmValue value)
  1594. {
  1595. this->StoreProperty(prop, value);
  1596. }
  1597. template <typename ValueType>
  1598. void cmTargetInternals::AddDirectoryToFileSet(
  1599. cmTarget* self, std::string const& fileSetName, ValueType value,
  1600. cm::string_view fileSetType, cm::string_view description, bool clear)
  1601. {
  1602. auto* fileSet = self->GetFileSet(fileSetName);
  1603. if (!fileSet) {
  1604. this->Makefile->IssueMessage(
  1605. MessageType::FATAL_ERROR,
  1606. cmStrCat(description, "has not yet been created."));
  1607. return;
  1608. }
  1609. if (fileSet->GetType() != fileSetType) {
  1610. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1611. cmStrCat("File set \"", fileSetName,
  1612. "\" is not of type \"", fileSetType,
  1613. "\"."));
  1614. return;
  1615. }
  1616. if (clear) {
  1617. fileSet->ClearDirectoryEntries();
  1618. }
  1619. if (!StringIsEmpty(value)) {
  1620. fileSet->AddDirectoryEntry(
  1621. BT<std::string>(value, this->Makefile->GetBacktrace()));
  1622. }
  1623. }
  1624. template <typename ValueType>
  1625. void cmTargetInternals::AddPathToFileSet(
  1626. cmTarget* self, std::string const& fileSetName, ValueType value,
  1627. cm::string_view fileSetType, cm::string_view description, bool clear)
  1628. {
  1629. auto* fileSet = self->GetFileSet(fileSetName);
  1630. if (!fileSet) {
  1631. this->Makefile->IssueMessage(
  1632. MessageType::FATAL_ERROR,
  1633. cmStrCat(description, "has not yet been created."));
  1634. return;
  1635. }
  1636. if (fileSet->GetType() != fileSetType) {
  1637. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1638. cmStrCat("File set \"", fileSetName,
  1639. "\" is not of type \"", fileSetType,
  1640. "\"."));
  1641. return;
  1642. }
  1643. if (clear) {
  1644. fileSet->ClearFileEntries();
  1645. }
  1646. if (!StringIsEmpty(value)) {
  1647. fileSet->AddFileEntry(
  1648. BT<std::string>(value, this->Makefile->GetBacktrace()));
  1649. }
  1650. }
  1651. cmValue cmTargetInternals::GetFileSetDirectories(
  1652. cmTarget const* self, std::string const& fileSetName,
  1653. cm::string_view fileSetType) const
  1654. {
  1655. auto const* fileSet = self->GetFileSet(fileSetName);
  1656. if (!fileSet) {
  1657. return nullptr;
  1658. }
  1659. if (fileSet->GetType() != fileSetType) {
  1660. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1661. cmStrCat("File set \"", fileSetName,
  1662. "\" is not of type \"", fileSetType,
  1663. "\"."));
  1664. return nullptr;
  1665. }
  1666. static std::string output;
  1667. output = cmJoin(fileSet->GetDirectoryEntries(), ";"_s);
  1668. return cmValue(output);
  1669. }
  1670. cmValue cmTargetInternals::GetFileSetPaths(cmTarget const* self,
  1671. std::string const& fileSetName,
  1672. cm::string_view fileSetType) const
  1673. {
  1674. auto const* fileSet = self->GetFileSet(fileSetName);
  1675. if (!fileSet) {
  1676. return nullptr;
  1677. }
  1678. if (fileSet->GetType() != fileSetType) {
  1679. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1680. cmStrCat("File set \"", fileSetName,
  1681. "\" is not of type \"", fileSetType,
  1682. "\"."));
  1683. return nullptr;
  1684. }
  1685. static std::string output;
  1686. output = cmJoin(fileSet->GetFileEntries(), ";"_s);
  1687. return cmValue(output);
  1688. }
  1689. void cmTarget::AppendBuildInterfaceIncludes()
  1690. {
  1691. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1692. this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  1693. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  1694. this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  1695. !this->IsExecutableWithExports()) {
  1696. return;
  1697. }
  1698. if (this->impl->BuildInterfaceIncludesAppended) {
  1699. return;
  1700. }
  1701. this->impl->BuildInterfaceIncludesAppended = true;
  1702. if (this->impl->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE")) {
  1703. std::string dirs = this->impl->Makefile->GetCurrentBinaryDirectory();
  1704. if (!dirs.empty()) {
  1705. dirs += ';';
  1706. }
  1707. dirs += this->impl->Makefile->GetCurrentSourceDirectory();
  1708. if (!dirs.empty()) {
  1709. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  1710. ("$<BUILD_INTERFACE:" + dirs + ">"));
  1711. }
  1712. }
  1713. }
  1714. void cmTarget::InsertInclude(BT<std::string> const& entry, bool before)
  1715. {
  1716. auto position = before ? this->impl->IncludeDirectoriesEntries.begin()
  1717. : this->impl->IncludeDirectoriesEntries.end();
  1718. this->impl->IncludeDirectoriesEntries.insert(position, entry);
  1719. }
  1720. void cmTarget::InsertCompileOption(BT<std::string> const& entry, bool before)
  1721. {
  1722. auto position = before ? this->impl->CompileOptionsEntries.begin()
  1723. : this->impl->CompileOptionsEntries.end();
  1724. this->impl->CompileOptionsEntries.insert(position, entry);
  1725. }
  1726. void cmTarget::InsertCompileDefinition(BT<std::string> const& entry)
  1727. {
  1728. this->impl->CompileDefinitionsEntries.push_back(entry);
  1729. }
  1730. void cmTarget::InsertLinkOption(BT<std::string> const& entry, bool before)
  1731. {
  1732. auto position = before ? this->impl->LinkOptionsEntries.begin()
  1733. : this->impl->LinkOptionsEntries.end();
  1734. this->impl->LinkOptionsEntries.insert(position, entry);
  1735. }
  1736. void cmTarget::InsertLinkDirectory(BT<std::string> const& entry, bool before)
  1737. {
  1738. auto position = before ? this->impl->LinkDirectoriesEntries.begin()
  1739. : this->impl->LinkDirectoriesEntries.end();
  1740. this->impl->LinkDirectoriesEntries.insert(position, entry);
  1741. }
  1742. void cmTarget::InsertPrecompileHeader(BT<std::string> const& entry)
  1743. {
  1744. this->impl->PrecompileHeadersEntries.push_back(entry);
  1745. }
  1746. namespace {
  1747. void CheckLinkLibraryPattern(const std::string& property,
  1748. const std::string& value, cmMakefile* context)
  1749. {
  1750. // Look for <LINK_LIBRARY:> and </LINK_LIBRARY:> internal tags
  1751. static cmsys::RegularExpression linkPattern(
  1752. "(^|;)(</?LINK_(LIBRARY|GROUP):[^;>]*>)(;|$)");
  1753. if (!linkPattern.find(value)) {
  1754. return;
  1755. }
  1756. // Report an error.
  1757. context->IssueMessage(
  1758. MessageType::FATAL_ERROR,
  1759. cmStrCat(
  1760. "Property ", property, " contains the invalid item \"",
  1761. linkPattern.match(2), "\". The ", property,
  1762. " property may contain the generator-expression \"$<LINK_",
  1763. linkPattern.match(3),
  1764. ":...>\" which may be used to specify how the libraries are linked."));
  1765. }
  1766. void CheckLINK_INTERFACE_LIBRARIES(const std::string& prop,
  1767. const std::string& value,
  1768. cmMakefile* context, bool imported)
  1769. {
  1770. // Support imported and non-imported versions of the property.
  1771. const char* base = (imported ? "IMPORTED_LINK_INTERFACE_LIBRARIES"
  1772. : "LINK_INTERFACE_LIBRARIES");
  1773. // Look for link-type keywords in the value.
  1774. static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
  1775. if (keys.find(value)) {
  1776. // Report an error.
  1777. std::ostringstream e;
  1778. e << "Property " << prop << " may not contain link-type keyword \""
  1779. << keys.match(2) << "\". "
  1780. << "The " << base << " property has a per-configuration "
  1781. << "version called " << base << "_<CONFIG> which may be "
  1782. << "used to specify per-configuration rules.";
  1783. if (!imported) {
  1784. e << " "
  1785. << "Alternatively, an IMPORTED library may be created, configured "
  1786. << "with a per-configuration location, and then named in the "
  1787. << "property value. "
  1788. << "See the add_library command's IMPORTED mode for details."
  1789. << "\n"
  1790. << "If you have a list of libraries that already contains the "
  1791. << "keyword, use the target_link_libraries command with its "
  1792. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  1793. << "The command automatically recognizes link-type keywords and sets "
  1794. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  1795. << "properties accordingly.";
  1796. }
  1797. context->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1798. }
  1799. CheckLinkLibraryPattern(base, value, context);
  1800. }
  1801. void CheckLINK_LIBRARIES(const std::string& value, cmMakefile* context)
  1802. {
  1803. CheckLinkLibraryPattern("LINK_LIBRARIES", value, context);
  1804. }
  1805. void CheckINTERFACE_LINK_LIBRARIES(const std::string& value,
  1806. cmMakefile* context)
  1807. {
  1808. // Look for link-type keywords in the value.
  1809. static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
  1810. if (keys.find(value)) {
  1811. // Report an error.
  1812. std::ostringstream e;
  1813. e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
  1814. "keyword \""
  1815. << keys.match(2)
  1816. << "\". The INTERFACE_LINK_LIBRARIES "
  1817. "property may contain configuration-sensitive generator-expressions "
  1818. "which may be used to specify per-configuration rules.";
  1819. context->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1820. }
  1821. CheckLinkLibraryPattern("INTERFACE_LINK_LIBRARIES", value, context);
  1822. }
  1823. void CheckIMPORTED_GLOBAL(const cmTarget* target, cmMakefile* context)
  1824. {
  1825. const auto& targets = context->GetOwnedImportedTargets();
  1826. auto it =
  1827. std::find_if(targets.begin(), targets.end(),
  1828. [&](const std::unique_ptr<cmTarget>& importTarget) -> bool {
  1829. return target == importTarget.get();
  1830. });
  1831. if (it == targets.end()) {
  1832. std::ostringstream e;
  1833. e << "Attempt to promote imported target \"" << target->GetName()
  1834. << "\" to global scope (by setting IMPORTED_GLOBAL) "
  1835. "which is not built in this directory.";
  1836. context->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1837. }
  1838. }
  1839. }
  1840. void cmTarget::CheckProperty(const std::string& prop,
  1841. cmMakefile* context) const
  1842. {
  1843. // Certain properties need checking.
  1844. if (cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES")) {
  1845. if (cmValue value = this->GetProperty(prop)) {
  1846. CheckLINK_INTERFACE_LIBRARIES(prop, *value, context, false);
  1847. }
  1848. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES")) {
  1849. if (cmValue value = this->GetProperty(prop)) {
  1850. CheckLINK_INTERFACE_LIBRARIES(prop, *value, context, true);
  1851. }
  1852. } else if (prop == "LINK_LIBRARIES") {
  1853. if (cmValue value = this->GetProperty(prop)) {
  1854. CheckLINK_LIBRARIES(*value, context);
  1855. }
  1856. } else if (prop == "INTERFACE_LINK_LIBRARIES") {
  1857. if (cmValue value = this->GetProperty(prop)) {
  1858. CheckINTERFACE_LINK_LIBRARIES(*value, context);
  1859. }
  1860. } else if (prop == "IMPORTED_GLOBAL") {
  1861. if (this->IsImported()) {
  1862. CheckIMPORTED_GLOBAL(this, context);
  1863. }
  1864. }
  1865. }
  1866. cmValue cmTarget::GetComputedProperty(const std::string& prop,
  1867. cmMakefile& mf) const
  1868. {
  1869. return cmTargetPropertyComputer::GetProperty(this, prop, mf);
  1870. }
  1871. cmValue cmTarget::GetProperty(const std::string& prop) const
  1872. {
  1873. static std::unordered_set<std::string> const specialProps{
  1874. propC_STANDARD,
  1875. propCXX_STANDARD,
  1876. propCUDA_STANDARD,
  1877. propOBJC_STANDARD,
  1878. propOBJCXX_STANDARD,
  1879. propLINK_LIBRARIES,
  1880. propTYPE,
  1881. propINCLUDE_DIRECTORIES,
  1882. propCOMPILE_FEATURES,
  1883. propCOMPILE_OPTIONS,
  1884. propCOMPILE_DEFINITIONS,
  1885. propPRECOMPILE_HEADERS,
  1886. propLINK_OPTIONS,
  1887. propLINK_DIRECTORIES,
  1888. propIMPORTED,
  1889. propIMPORTED_GLOBAL,
  1890. propMANUALLY_ADDED_DEPENDENCIES,
  1891. propNAME,
  1892. propBINARY_DIR,
  1893. propSOURCE_DIR,
  1894. propSOURCES,
  1895. propINTERFACE_LINK_LIBRARIES,
  1896. propINTERFACE_LINK_LIBRARIES_DIRECT,
  1897. propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE,
  1898. };
  1899. if (specialProps.count(prop)) {
  1900. if (prop == propC_STANDARD || prop == propCXX_STANDARD ||
  1901. prop == propCUDA_STANDARD || prop == propOBJC_STANDARD ||
  1902. prop == propOBJCXX_STANDARD) {
  1903. auto propertyIter = this->impl->LanguageStandardProperties.find(prop);
  1904. if (propertyIter == this->impl->LanguageStandardProperties.end()) {
  1905. return nullptr;
  1906. }
  1907. return cmValue(propertyIter->second.Value);
  1908. }
  1909. if (prop == propLINK_LIBRARIES) {
  1910. if (this->impl->LinkImplementationPropertyEntries.empty()) {
  1911. return nullptr;
  1912. }
  1913. static std::string output;
  1914. output = cmJoin(this->impl->LinkImplementationPropertyEntries, ";");
  1915. return cmValue(output);
  1916. }
  1917. if (prop == propINTERFACE_LINK_LIBRARIES) {
  1918. if (this->impl->LinkInterfacePropertyEntries.empty()) {
  1919. return nullptr;
  1920. }
  1921. static std::string output;
  1922. output = cmJoin(this->impl->LinkInterfacePropertyEntries, ";");
  1923. return cmValue(output);
  1924. }
  1925. if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) {
  1926. if (this->impl->LinkInterfaceDirectPropertyEntries.empty()) {
  1927. return nullptr;
  1928. }
  1929. static std::string output;
  1930. output = cmJoin(this->impl->LinkInterfaceDirectPropertyEntries, ";");
  1931. return cmValue(output);
  1932. }
  1933. if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) {
  1934. if (this->impl->LinkInterfaceDirectExcludePropertyEntries.empty()) {
  1935. return nullptr;
  1936. }
  1937. static std::string output;
  1938. output =
  1939. cmJoin(this->impl->LinkInterfaceDirectExcludePropertyEntries, ";");
  1940. return cmValue(output);
  1941. }
  1942. // the type property returns what type the target is
  1943. if (prop == propTYPE) {
  1944. return cmValue(cmState::GetTargetTypeName(this->GetType()));
  1945. }
  1946. if (prop == propINCLUDE_DIRECTORIES) {
  1947. if (this->impl->IncludeDirectoriesEntries.empty()) {
  1948. return nullptr;
  1949. }
  1950. static std::string output;
  1951. output = cmJoin(this->impl->IncludeDirectoriesEntries, ";");
  1952. return cmValue(output);
  1953. }
  1954. if (prop == propCOMPILE_FEATURES) {
  1955. if (this->impl->CompileFeaturesEntries.empty()) {
  1956. return nullptr;
  1957. }
  1958. static std::string output;
  1959. output = cmJoin(this->impl->CompileFeaturesEntries, ";");
  1960. return cmValue(output);
  1961. }
  1962. if (prop == propCOMPILE_OPTIONS) {
  1963. if (this->impl->CompileOptionsEntries.empty()) {
  1964. return nullptr;
  1965. }
  1966. static std::string output;
  1967. output = cmJoin(this->impl->CompileOptionsEntries, ";");
  1968. return cmValue(output);
  1969. }
  1970. if (prop == propCOMPILE_DEFINITIONS) {
  1971. if (this->impl->CompileDefinitionsEntries.empty()) {
  1972. return nullptr;
  1973. }
  1974. static std::string output;
  1975. output = cmJoin(this->impl->CompileDefinitionsEntries, ";");
  1976. return cmValue(output);
  1977. }
  1978. if (prop == propLINK_OPTIONS) {
  1979. if (this->impl->LinkOptionsEntries.empty()) {
  1980. return nullptr;
  1981. }
  1982. static std::string output;
  1983. output = cmJoin(this->impl->LinkOptionsEntries, ";");
  1984. return cmValue(output);
  1985. }
  1986. if (prop == propLINK_DIRECTORIES) {
  1987. if (this->impl->LinkDirectoriesEntries.empty()) {
  1988. return nullptr;
  1989. }
  1990. static std::string output;
  1991. output = cmJoin(this->impl->LinkDirectoriesEntries, ";");
  1992. return cmValue(output);
  1993. }
  1994. if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
  1995. if (this->impl->Utilities.empty()) {
  1996. return nullptr;
  1997. }
  1998. static std::string output;
  1999. static std::vector<std::string> utilities;
  2000. utilities.resize(this->impl->Utilities.size());
  2001. std::transform(
  2002. this->impl->Utilities.cbegin(), this->impl->Utilities.cend(),
  2003. utilities.begin(),
  2004. [](const BT<std::pair<std::string, bool>>& item) -> std::string {
  2005. return item.Value.first;
  2006. });
  2007. output = cmJoin(utilities, ";");
  2008. return cmValue(output);
  2009. }
  2010. if (prop == propPRECOMPILE_HEADERS) {
  2011. if (this->impl->PrecompileHeadersEntries.empty()) {
  2012. return nullptr;
  2013. }
  2014. static std::string output;
  2015. output = cmJoin(this->impl->PrecompileHeadersEntries, ";");
  2016. return cmValue(output);
  2017. }
  2018. if (prop == propIMPORTED) {
  2019. return this->IsImported() ? cmValue(propTRUE) : cmValue(propFALSE);
  2020. }
  2021. if (prop == propIMPORTED_GLOBAL) {
  2022. return this->IsImportedGloballyVisible() ? cmValue(propTRUE)
  2023. : cmValue(propFALSE);
  2024. }
  2025. if (prop == propNAME) {
  2026. return cmValue(this->GetName());
  2027. }
  2028. if (prop == propBINARY_DIR) {
  2029. return cmValue(this->impl->Makefile->GetStateSnapshot()
  2030. .GetDirectory()
  2031. .GetCurrentBinary());
  2032. }
  2033. if (prop == propSOURCE_DIR) {
  2034. return cmValue(this->impl->Makefile->GetStateSnapshot()
  2035. .GetDirectory()
  2036. .GetCurrentSource());
  2037. }
  2038. }
  2039. // Check fileset properties.
  2040. {
  2041. auto headers =
  2042. this->impl->HeadersFileSets.ReadProperties(this, this->impl.get(), prop);
  2043. if (headers.first) {
  2044. return headers.second;
  2045. }
  2046. }
  2047. cmValue retVal = this->impl->Properties.GetPropertyValue(prop);
  2048. if (!retVal) {
  2049. const bool chain = this->impl->Makefile->GetState()->IsPropertyChained(
  2050. prop, cmProperty::TARGET);
  2051. if (chain) {
  2052. return this->impl->Makefile->GetStateSnapshot()
  2053. .GetDirectory()
  2054. .GetProperty(prop, chain);
  2055. }
  2056. return nullptr;
  2057. }
  2058. return retVal;
  2059. }
  2060. std::string const& cmTarget::GetSafeProperty(std::string const& prop) const
  2061. {
  2062. cmValue ret = this->GetProperty(prop);
  2063. if (ret) {
  2064. return *ret;
  2065. }
  2066. static std::string const s_empty;
  2067. return s_empty;
  2068. }
  2069. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  2070. {
  2071. return cmIsOn(this->GetProperty(prop));
  2072. }
  2073. cmPropertyMap const& cmTarget::GetProperties() const
  2074. {
  2075. return this->impl->Properties;
  2076. }
  2077. bool cmTarget::IsDLLPlatform() const
  2078. {
  2079. return this->impl->IsDLLPlatform;
  2080. }
  2081. bool cmTarget::IsAIX() const
  2082. {
  2083. return this->impl->IsAIX;
  2084. }
  2085. bool cmTarget::IsImported() const
  2086. {
  2087. return this->impl->IsImportedTarget;
  2088. }
  2089. bool cmTarget::IsImportedGloballyVisible() const
  2090. {
  2091. return this->impl->ImportedGloballyVisible;
  2092. }
  2093. bool cmTarget::IsPerConfig() const
  2094. {
  2095. return this->impl->PerConfig;
  2096. }
  2097. bool cmTarget::CanCompileSources() const
  2098. {
  2099. if (this->IsImported()) {
  2100. return false;
  2101. }
  2102. switch (this->GetType()) {
  2103. case cmStateEnums::EXECUTABLE:
  2104. case cmStateEnums::STATIC_LIBRARY:
  2105. case cmStateEnums::SHARED_LIBRARY:
  2106. case cmStateEnums::MODULE_LIBRARY:
  2107. case cmStateEnums::OBJECT_LIBRARY:
  2108. return true;
  2109. case cmStateEnums::UTILITY:
  2110. case cmStateEnums::INTERFACE_LIBRARY:
  2111. case cmStateEnums::GLOBAL_TARGET:
  2112. case cmStateEnums::UNKNOWN_LIBRARY:
  2113. break;
  2114. }
  2115. return false;
  2116. }
  2117. const char* cmTarget::GetSuffixVariableInternal(
  2118. cmStateEnums::ArtifactType artifact) const
  2119. {
  2120. switch (this->GetType()) {
  2121. case cmStateEnums::STATIC_LIBRARY:
  2122. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  2123. case cmStateEnums::SHARED_LIBRARY:
  2124. switch (artifact) {
  2125. case cmStateEnums::RuntimeBinaryArtifact:
  2126. return "CMAKE_SHARED_LIBRARY_SUFFIX";
  2127. case cmStateEnums::ImportLibraryArtifact:
  2128. return "CMAKE_IMPORT_LIBRARY_SUFFIX";
  2129. }
  2130. break;
  2131. case cmStateEnums::MODULE_LIBRARY:
  2132. switch (artifact) {
  2133. case cmStateEnums::RuntimeBinaryArtifact:
  2134. return "CMAKE_SHARED_MODULE_SUFFIX";
  2135. case cmStateEnums::ImportLibraryArtifact:
  2136. return "CMAKE_IMPORT_LIBRARY_SUFFIX";
  2137. }
  2138. break;
  2139. case cmStateEnums::EXECUTABLE:
  2140. switch (artifact) {
  2141. case cmStateEnums::RuntimeBinaryArtifact:
  2142. // Android GUI application packages store the native
  2143. // binary as a shared library.
  2144. return (this->IsAndroidGuiExecutable()
  2145. ? "CMAKE_SHARED_LIBRARY_SUFFIX"
  2146. : "CMAKE_EXECUTABLE_SUFFIX");
  2147. case cmStateEnums::ImportLibraryArtifact:
  2148. return (this->impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_SUFFIX"
  2149. : "CMAKE_IMPORT_LIBRARY_SUFFIX");
  2150. }
  2151. break;
  2152. default:
  2153. break;
  2154. }
  2155. return "";
  2156. }
  2157. const char* cmTarget::GetPrefixVariableInternal(
  2158. cmStateEnums::ArtifactType artifact) const
  2159. {
  2160. switch (this->GetType()) {
  2161. case cmStateEnums::STATIC_LIBRARY:
  2162. return "CMAKE_STATIC_LIBRARY_PREFIX";
  2163. case cmStateEnums::SHARED_LIBRARY:
  2164. switch (artifact) {
  2165. case cmStateEnums::RuntimeBinaryArtifact:
  2166. return "CMAKE_SHARED_LIBRARY_PREFIX";
  2167. case cmStateEnums::ImportLibraryArtifact:
  2168. return "CMAKE_IMPORT_LIBRARY_PREFIX";
  2169. }
  2170. break;
  2171. case cmStateEnums::MODULE_LIBRARY:
  2172. switch (artifact) {
  2173. case cmStateEnums::RuntimeBinaryArtifact:
  2174. return "CMAKE_SHARED_MODULE_PREFIX";
  2175. case cmStateEnums::ImportLibraryArtifact:
  2176. return "CMAKE_IMPORT_LIBRARY_PREFIX";
  2177. }
  2178. break;
  2179. case cmStateEnums::EXECUTABLE:
  2180. switch (artifact) {
  2181. case cmStateEnums::RuntimeBinaryArtifact:
  2182. // Android GUI application packages store the native
  2183. // binary as a shared library.
  2184. return (this->IsAndroidGuiExecutable()
  2185. ? "CMAKE_SHARED_LIBRARY_PREFIX"
  2186. : "");
  2187. case cmStateEnums::ImportLibraryArtifact:
  2188. return (this->impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_PREFIX"
  2189. : "CMAKE_IMPORT_LIBRARY_PREFIX");
  2190. }
  2191. break;
  2192. default:
  2193. break;
  2194. }
  2195. return "";
  2196. }
  2197. std::string cmTarget::ImportedGetFullPath(
  2198. const std::string& config, cmStateEnums::ArtifactType artifact) const
  2199. {
  2200. assert(this->IsImported());
  2201. // Lookup/compute/cache the import information for this
  2202. // configuration.
  2203. std::string desired_config = config;
  2204. if (config.empty()) {
  2205. desired_config = "NOCONFIG";
  2206. }
  2207. std::string result;
  2208. cmValue loc = nullptr;
  2209. cmValue imp = nullptr;
  2210. std::string suffix;
  2211. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  2212. this->GetMappedConfig(desired_config, loc, imp, suffix)) {
  2213. switch (artifact) {
  2214. case cmStateEnums::RuntimeBinaryArtifact:
  2215. if (loc) {
  2216. result = *loc;
  2217. } else {
  2218. std::string impProp = cmStrCat("IMPORTED_LOCATION", suffix);
  2219. if (cmValue config_location = this->GetProperty(impProp)) {
  2220. result = *config_location;
  2221. } else if (cmValue location =
  2222. this->GetProperty("IMPORTED_LOCATION")) {
  2223. result = *location;
  2224. }
  2225. }
  2226. break;
  2227. case cmStateEnums::ImportLibraryArtifact:
  2228. if (imp) {
  2229. result = *imp;
  2230. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2231. this->IsExecutableWithExports()) {
  2232. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  2233. if (cmValue config_implib = this->GetProperty(impProp)) {
  2234. result = *config_implib;
  2235. } else if (cmValue implib = this->GetProperty("IMPORTED_IMPLIB")) {
  2236. result = *implib;
  2237. }
  2238. }
  2239. break;
  2240. }
  2241. }
  2242. if (result.empty()) {
  2243. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  2244. auto message = [&]() -> std::string {
  2245. std::string unset;
  2246. std::string configuration;
  2247. if (artifact == cmStateEnums::RuntimeBinaryArtifact) {
  2248. unset = "IMPORTED_LOCATION";
  2249. } else if (artifact == cmStateEnums::ImportLibraryArtifact) {
  2250. unset = "IMPORTED_IMPLIB";
  2251. }
  2252. if (!config.empty()) {
  2253. configuration = cmStrCat(" configuration \"", config, "\"");
  2254. }
  2255. return cmStrCat(unset, " not set for imported target \"",
  2256. this->GetName(), "\"", configuration, ".");
  2257. };
  2258. switch (this->GetPolicyStatus(cmPolicies::CMP0111)) {
  2259. case cmPolicies::WARN:
  2260. this->impl->Makefile->IssueMessage(
  2261. MessageType::AUTHOR_WARNING,
  2262. cmPolicies::GetPolicyWarning(cmPolicies::CMP0111) + "\n" +
  2263. message());
  2264. CM_FALLTHROUGH;
  2265. case cmPolicies::OLD:
  2266. break;
  2267. default:
  2268. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  2269. message());
  2270. }
  2271. }
  2272. result = cmStrCat(this->GetName(), "-NOTFOUND");
  2273. }
  2274. return result;
  2275. }
  2276. const cmFileSet* cmTarget::GetFileSet(const std::string& name) const
  2277. {
  2278. auto it = this->impl->FileSets.find(name);
  2279. return it == this->impl->FileSets.end() ? nullptr : &it->second;
  2280. }
  2281. cmFileSet* cmTarget::GetFileSet(const std::string& name)
  2282. {
  2283. auto it = this->impl->FileSets.find(name);
  2284. return it == this->impl->FileSets.end() ? nullptr : &it->second;
  2285. }
  2286. std::pair<cmFileSet*, bool> cmTarget::GetOrCreateFileSet(
  2287. const std::string& name, const std::string& type, cmFileSetVisibility vis)
  2288. {
  2289. auto result = this->impl->FileSets.emplace(
  2290. std::make_pair(name, cmFileSet(name, type, vis)));
  2291. if (result.second) {
  2292. auto bt = this->impl->Makefile->GetBacktrace();
  2293. if (type == this->impl->HeadersFileSets.TypeName) {
  2294. this->impl->HeadersFileSets.AddFileSet(name, vis, std::move(bt));
  2295. }
  2296. }
  2297. return std::make_pair(&result.first->second, result.second);
  2298. }
  2299. std::string cmTarget::GetFileSetsPropertyName(const std::string& type)
  2300. {
  2301. if (type == "HEADERS") {
  2302. return "HEADER_SETS";
  2303. }
  2304. return "";
  2305. }
  2306. std::string cmTarget::GetInterfaceFileSetsPropertyName(const std::string& type)
  2307. {
  2308. if (type == "HEADERS") {
  2309. return "INTERFACE_HEADER_SETS";
  2310. }
  2311. return "";
  2312. }
  2313. std::vector<std::string> cmTarget::GetAllFileSetNames() const
  2314. {
  2315. std::vector<std::string> result;
  2316. for (auto const& it : this->impl->FileSets) {
  2317. result.push_back(it.first);
  2318. }
  2319. return result;
  2320. }
  2321. std::vector<std::string> cmTarget::GetAllInterfaceFileSets() const
  2322. {
  2323. std::vector<std::string> result;
  2324. auto inserter = std::back_inserter(result);
  2325. auto appendEntries = [=](const std::vector<BT<std::string>>& entries) {
  2326. for (auto const& entry : entries) {
  2327. auto expanded = cmExpandedList(entry.Value);
  2328. std::copy(expanded.begin(), expanded.end(), inserter);
  2329. }
  2330. };
  2331. appendEntries(this->impl->HeadersFileSets.InterfaceEntries.Entries);
  2332. return result;
  2333. }
  2334. bool cmTargetInternals::CheckImportedLibName(std::string const& prop,
  2335. std::string const& value) const
  2336. {
  2337. if (this->TargetType != cmStateEnums::INTERFACE_LIBRARY ||
  2338. !this->IsImportedTarget) {
  2339. this->Makefile->IssueMessage(
  2340. MessageType::FATAL_ERROR,
  2341. prop +
  2342. " property may be set only on imported INTERFACE library targets.");
  2343. return false;
  2344. }
  2345. if (!value.empty()) {
  2346. if (value[0] == '-') {
  2347. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  2348. prop + " property value\n " + value +
  2349. "\nmay not start with '-'.");
  2350. return false;
  2351. }
  2352. std::string::size_type bad = value.find_first_of(":/\\;");
  2353. if (bad != std::string::npos) {
  2354. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  2355. prop + " property value\n " + value +
  2356. "\nmay not contain '" +
  2357. value.substr(bad, 1) + "'.");
  2358. return false;
  2359. }
  2360. }
  2361. return true;
  2362. }
  2363. bool cmTarget::GetMappedConfig(std::string const& desired_config, cmValue& loc,
  2364. cmValue& imp, std::string& suffix) const
  2365. {
  2366. std::string config_upper;
  2367. if (!desired_config.empty()) {
  2368. config_upper = cmSystemTools::UpperCase(desired_config);
  2369. }
  2370. std::string locPropBase;
  2371. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  2372. locPropBase = "IMPORTED_LIBNAME";
  2373. } else if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  2374. locPropBase = "IMPORTED_OBJECTS";
  2375. } else {
  2376. locPropBase = "IMPORTED_LOCATION";
  2377. }
  2378. // Track the configuration-specific property suffix.
  2379. suffix = cmStrCat('_', config_upper);
  2380. std::vector<std::string> mappedConfigs;
  2381. {
  2382. std::string mapProp = cmStrCat("MAP_IMPORTED_CONFIG_", config_upper);
  2383. if (cmValue mapValue = this->GetProperty(mapProp)) {
  2384. cmExpandList(*mapValue, mappedConfigs, true);
  2385. }
  2386. }
  2387. // If we needed to find one of the mapped configurations but did not
  2388. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  2389. // library or an executable with exports.
  2390. bool allowImp = (this->IsDLLPlatform() &&
  2391. (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2392. this->IsExecutableWithExports())) ||
  2393. (this->IsAIX() && this->IsExecutableWithExports());
  2394. // If a mapping was found, check its configurations.
  2395. for (auto mci = mappedConfigs.begin();
  2396. !loc && !imp && mci != mappedConfigs.end(); ++mci) {
  2397. // Look for this configuration.
  2398. if (mci->empty()) {
  2399. // An empty string in the mapping has a special meaning:
  2400. // look up the config-less properties.
  2401. loc = this->GetProperty(locPropBase);
  2402. if (allowImp) {
  2403. imp = this->GetProperty("IMPORTED_IMPLIB");
  2404. }
  2405. // If it was found, set the suffix.
  2406. if (loc || imp) {
  2407. suffix.clear();
  2408. }
  2409. } else {
  2410. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  2411. std::string locProp = cmStrCat(locPropBase, '_', mcUpper);
  2412. loc = this->GetProperty(locProp);
  2413. if (allowImp) {
  2414. std::string impProp = cmStrCat("IMPORTED_IMPLIB_", mcUpper);
  2415. imp = this->GetProperty(impProp);
  2416. }
  2417. // If it was found, use it for all properties below.
  2418. if (loc || imp) {
  2419. suffix = cmStrCat('_', mcUpper);
  2420. }
  2421. }
  2422. }
  2423. // If we needed to find one of the mapped configurations but did not
  2424. // then the target location is not found. The project does not want
  2425. // any other configuration.
  2426. if (!mappedConfigs.empty() && !loc && !imp) {
  2427. // Interface libraries are always available because their
  2428. // library name is optional so it is okay to leave loc empty.
  2429. return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
  2430. }
  2431. // If we have not yet found it then there are no mapped
  2432. // configurations. Look for an exact-match.
  2433. if (!loc && !imp) {
  2434. std::string locProp = cmStrCat(locPropBase, suffix);
  2435. loc = this->GetProperty(locProp);
  2436. if (allowImp) {
  2437. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  2438. imp = this->GetProperty(impProp);
  2439. }
  2440. }
  2441. // If we have not yet found it then there are no mapped
  2442. // configurations and no exact match.
  2443. if (!loc && !imp) {
  2444. // The suffix computed above is not useful.
  2445. suffix.clear();
  2446. // Look for a configuration-less location. This may be set by
  2447. // manually-written code.
  2448. loc = this->GetProperty(locPropBase);
  2449. if (allowImp) {
  2450. imp = this->GetProperty("IMPORTED_IMPLIB");
  2451. }
  2452. }
  2453. // If we have not yet found it then the project is willing to try
  2454. // any available configuration.
  2455. if (!loc && !imp) {
  2456. std::vector<std::string> availableConfigs;
  2457. if (cmValue iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS")) {
  2458. cmExpandList(*iconfigs, availableConfigs);
  2459. }
  2460. for (auto aci = availableConfigs.begin();
  2461. !loc && !imp && aci != availableConfigs.end(); ++aci) {
  2462. suffix = cmStrCat('_', cmSystemTools::UpperCase(*aci));
  2463. std::string locProp = cmStrCat(locPropBase, suffix);
  2464. loc = this->GetProperty(locProp);
  2465. if (allowImp) {
  2466. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  2467. imp = this->GetProperty(impProp);
  2468. }
  2469. }
  2470. }
  2471. // If we have not yet found it then the target location is not available.
  2472. if (!loc && !imp) {
  2473. // Interface libraries are always available because their
  2474. // library name is optional so it is okay to leave loc empty.
  2475. return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
  2476. }
  2477. return true;
  2478. }