cmTarget.cxx 81 KB

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