cmTarget.cxx 95 KB

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