cmTarget.cxx 82 KB

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