cmTarget.cxx 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293
  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 "cmsys/RegularExpression.hxx"
  16. #include "cmAlgorithms.h"
  17. #include "cmCustomCommand.h"
  18. #include "cmGeneratorExpression.h"
  19. #include "cmGeneratorTarget.h"
  20. #include "cmGlobalGenerator.h"
  21. #include "cmListFileCache.h"
  22. #include "cmMakefile.h"
  23. #include "cmMessageType.h"
  24. #include "cmMessenger.h"
  25. #include "cmProperty.h"
  26. #include "cmPropertyMap.h"
  27. #include "cmRange.h"
  28. #include "cmSourceFile.h"
  29. #include "cmSourceFileLocation.h"
  30. #include "cmSourceFileLocationKind.h"
  31. #include "cmState.h"
  32. #include "cmStateDirectory.h"
  33. #include "cmStateSnapshot.h"
  34. #include "cmSystemTools.h"
  35. #include "cmTargetPropertyComputer.h"
  36. #include "cmake.h"
  37. template <>
  38. const std::string& cmTargetPropertyComputer::ComputeLocationForBuild<cmTarget>(
  39. cmTarget const* tgt)
  40. {
  41. static std::string loc;
  42. if (tgt->IsImported()) {
  43. loc = tgt->ImportedGetFullPath("", cmStateEnums::RuntimeBinaryArtifact);
  44. return loc;
  45. }
  46. cmGlobalGenerator* gg = tgt->GetGlobalGenerator();
  47. if (!gg->GetConfigureDoneCMP0026()) {
  48. gg->CreateGenerationObjects();
  49. }
  50. cmGeneratorTarget* gt = gg->FindGeneratorTarget(tgt->GetName());
  51. loc = gt->GetLocationForBuild();
  52. return loc;
  53. }
  54. template <>
  55. const std::string& cmTargetPropertyComputer::ComputeLocation<cmTarget>(
  56. cmTarget const* tgt, const std::string& config)
  57. {
  58. static std::string loc;
  59. if (tgt->IsImported()) {
  60. loc =
  61. tgt->ImportedGetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  62. return loc;
  63. }
  64. cmGlobalGenerator* gg = tgt->GetGlobalGenerator();
  65. if (!gg->GetConfigureDoneCMP0026()) {
  66. gg->CreateGenerationObjects();
  67. }
  68. cmGeneratorTarget* gt = gg->FindGeneratorTarget(tgt->GetName());
  69. loc = gt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  70. return loc;
  71. }
  72. template <>
  73. cmProp cmTargetPropertyComputer::GetSources<cmTarget>(
  74. cmTarget const* tgt, cmMessenger* messenger,
  75. cmListFileBacktrace const& context)
  76. {
  77. cmStringRange entries = tgt->GetSourceEntries();
  78. if (entries.empty()) {
  79. return nullptr;
  80. }
  81. std::ostringstream ss;
  82. const char* sep = "";
  83. for (std::string const& entry : entries) {
  84. std::vector<std::string> files = cmExpandedList(entry);
  85. for (std::string const& file : files) {
  86. if (cmHasLiteralPrefix(file, "$<TARGET_OBJECTS:") &&
  87. file.back() == '>') {
  88. std::string objLibName = file.substr(17, file.size() - 18);
  89. if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
  90. ss << sep;
  91. sep = ";";
  92. ss << file;
  93. continue;
  94. }
  95. bool addContent = false;
  96. bool noMessage = true;
  97. std::ostringstream e;
  98. MessageType messageType = MessageType::AUTHOR_WARNING;
  99. switch (context.GetBottom().GetPolicy(cmPolicies::CMP0051)) {
  100. case cmPolicies::WARN:
  101. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
  102. noMessage = false;
  103. case cmPolicies::OLD:
  104. break;
  105. case cmPolicies::REQUIRED_ALWAYS:
  106. case cmPolicies::REQUIRED_IF_USED:
  107. case cmPolicies::NEW:
  108. addContent = true;
  109. }
  110. if (!noMessage) {
  111. e << "Target \"" << tgt->GetName()
  112. << "\" contains $<TARGET_OBJECTS> generator expression in its "
  113. "sources list. This content was not previously part of the "
  114. "SOURCES property when that property was read at configure "
  115. "time. Code reading that property needs to be adapted to "
  116. "ignore the generator expression using the string(GENEX_STRIP) "
  117. "command.";
  118. messenger->IssueMessage(messageType, e.str(), context);
  119. }
  120. if (addContent) {
  121. ss << sep;
  122. sep = ";";
  123. ss << file;
  124. }
  125. } else if (cmGeneratorExpression::Find(file) == std::string::npos) {
  126. ss << sep;
  127. sep = ";";
  128. ss << file;
  129. } else {
  130. cmSourceFile* sf = tgt->GetMakefile()->GetOrCreateSource(file);
  131. // Construct what is known about this source file location.
  132. cmSourceFileLocation const& location = sf->GetLocation();
  133. std::string sname = location.GetDirectory();
  134. if (!sname.empty()) {
  135. sname += "/";
  136. }
  137. sname += location.GetName();
  138. ss << sep;
  139. sep = ";";
  140. // Append this list entry.
  141. ss << sname;
  142. }
  143. }
  144. }
  145. static std::string srcs;
  146. srcs = ss.str();
  147. return cmProp(srcs);
  148. }
  149. class cmTargetInternals
  150. {
  151. public:
  152. cmStateEnums::TargetType TargetType;
  153. cmMakefile* Makefile;
  154. cmPolicies::PolicyMap PolicyMap;
  155. std::string Name;
  156. std::string InstallPath;
  157. std::string RuntimeInstallPath;
  158. cmPropertyMap Properties;
  159. bool IsGeneratorProvided;
  160. bool HaveInstallRule;
  161. bool IsDLLPlatform;
  162. bool IsAIX;
  163. bool IsAndroid;
  164. bool IsImportedTarget;
  165. bool ImportedGloballyVisible;
  166. bool BuildInterfaceIncludesAppended;
  167. bool PerConfig;
  168. std::set<BT<std::pair<std::string, bool>>> Utilities;
  169. std::vector<cmCustomCommand> PreBuildCommands;
  170. std::vector<cmCustomCommand> PreLinkCommands;
  171. std::vector<cmCustomCommand> PostBuildCommands;
  172. std::vector<cmInstallTargetGenerator*> InstallGenerators;
  173. std::set<std::string> SystemIncludeDirectories;
  174. cmTarget::LinkLibraryVectorType OriginalLinkLibraries;
  175. std::map<std::string, BTs<std::string>> LanguageStandardProperties;
  176. std::vector<std::string> IncludeDirectoriesEntries;
  177. std::vector<cmListFileBacktrace> IncludeDirectoriesBacktraces;
  178. std::vector<std::string> InstallIncludeDirectoriesEntries;
  179. std::vector<std::string> CompileOptionsEntries;
  180. std::vector<cmListFileBacktrace> CompileOptionsBacktraces;
  181. std::vector<std::string> CompileFeaturesEntries;
  182. std::vector<cmListFileBacktrace> CompileFeaturesBacktraces;
  183. std::vector<std::string> CompileDefinitionsEntries;
  184. std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces;
  185. std::vector<std::string> PrecompileHeadersEntries;
  186. std::vector<cmListFileBacktrace> PrecompileHeadersBacktraces;
  187. std::vector<std::string> SourceEntries;
  188. std::vector<cmListFileBacktrace> SourceBacktraces;
  189. std::vector<std::string> LinkOptionsEntries;
  190. std::vector<cmListFileBacktrace> LinkOptionsBacktraces;
  191. std::vector<std::string> LinkDirectoriesEntries;
  192. std::vector<cmListFileBacktrace> LinkDirectoriesBacktraces;
  193. std::vector<std::string> LinkImplementationPropertyEntries;
  194. std::vector<cmListFileBacktrace> LinkImplementationPropertyBacktraces;
  195. std::vector<std::pair<cmTarget::TLLSignature, cmListFileContext>>
  196. TLLCommands;
  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 (cmProp 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 (cmProp 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_THREAD_SANITIZER");
  379. initProp("XCODE_SCHEME_THREAD_SANITIZER_STOP");
  380. initProp("XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER");
  381. initProp("XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP");
  382. initProp("XCODE_SCHEME_WORKING_DIRECTORY");
  383. initProp("XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER");
  384. initProp("XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP");
  385. initProp("XCODE_SCHEME_MALLOC_SCRIBBLE");
  386. initProp("XCODE_SCHEME_MALLOC_GUARD_EDGES");
  387. initProp("XCODE_SCHEME_GUARD_MALLOC");
  388. initProp("XCODE_SCHEME_ZOMBIE_OBJECTS");
  389. initProp("XCODE_SCHEME_MALLOC_STACK");
  390. initProp("XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE");
  391. initProp("XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS");
  392. initProp("XCODE_SCHEME_ENVIRONMENT");
  393. initPropValue("XCODE_LINK_BUILD_PHASE_MODE", "NONE");
  394. }
  395. #endif
  396. }
  397. initProp("FOLDER");
  398. if (this->GetGlobalGenerator()->IsXcode()) {
  399. initProp("XCODE_GENERATE_SCHEME");
  400. }
  401. // Setup per-configuration property default values.
  402. if (this->GetType() != cmStateEnums::UTILITY &&
  403. this->GetType() != cmStateEnums::GLOBAL_TARGET) {
  404. static const auto configProps = {
  405. /* clang-format needs this comment to break after the opening brace */
  406. "ARCHIVE_OUTPUT_DIRECTORY_", "LIBRARY_OUTPUT_DIRECTORY_",
  407. "RUNTIME_OUTPUT_DIRECTORY_", "PDB_OUTPUT_DIRECTORY_",
  408. "COMPILE_PDB_OUTPUT_DIRECTORY_", "MAP_IMPORTED_CONFIG_",
  409. "INTERPROCEDURAL_OPTIMIZATION_"
  410. };
  411. // Collect the set of configuration types.
  412. std::vector<std::string> configNames =
  413. mf->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
  414. for (std::string const& configName : configNames) {
  415. std::string configUpper = cmSystemTools::UpperCase(configName);
  416. for (auto const& prop : configProps) {
  417. // Interface libraries have no output locations, so honor only
  418. // the configuration map.
  419. if (this->impl->TargetType == cmStateEnums::INTERFACE_LIBRARY &&
  420. strcmp(prop, "MAP_IMPORTED_CONFIG_") != 0) {
  421. continue;
  422. }
  423. std::string property = cmStrCat(prop, configUpper);
  424. initProp(property);
  425. }
  426. // Initialize per-configuration name postfix property from the
  427. // variable only for non-executable targets. This preserves
  428. // compatibility with previous CMake versions in which executables
  429. // did not support this variable. Projects may still specify the
  430. // property directly.
  431. if (this->impl->TargetType != cmStateEnums::EXECUTABLE &&
  432. this->impl->TargetType != cmStateEnums::INTERFACE_LIBRARY) {
  433. std::string property =
  434. cmStrCat(cmSystemTools::UpperCase(configName), "_POSTFIX");
  435. initProp(property);
  436. }
  437. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
  438. this->impl->TargetType == cmStateEnums::STATIC_LIBRARY) {
  439. std::string property = cmStrCat("FRAMEWORK_MULTI_CONFIG_POSTFIX_",
  440. cmSystemTools::UpperCase(configName));
  441. initProp(property);
  442. }
  443. }
  444. }
  445. // Save the backtrace of target construction.
  446. this->impl->Backtrace = this->impl->Makefile->GetBacktrace();
  447. if (!this->IsImported()) {
  448. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  449. // of the same directory property:
  450. cm::append(this->impl->IncludeDirectoriesEntries,
  451. this->impl->Makefile->GetIncludeDirectoriesEntries());
  452. cm::append(this->impl->IncludeDirectoriesBacktraces,
  453. this->impl->Makefile->GetIncludeDirectoriesBacktraces());
  454. {
  455. auto const& sysInc = this->impl->Makefile->GetSystemIncludeDirectories();
  456. this->impl->SystemIncludeDirectories.insert(sysInc.begin(),
  457. sysInc.end());
  458. }
  459. cm::append(this->impl->CompileOptionsEntries,
  460. this->impl->Makefile->GetCompileOptionsEntries());
  461. cm::append(this->impl->CompileOptionsBacktraces,
  462. this->impl->Makefile->GetCompileOptionsBacktraces());
  463. cm::append(this->impl->LinkOptionsEntries,
  464. this->impl->Makefile->GetLinkOptionsEntries());
  465. cm::append(this->impl->LinkOptionsBacktraces,
  466. this->impl->Makefile->GetLinkOptionsBacktraces());
  467. cm::append(this->impl->LinkDirectoriesEntries,
  468. this->impl->Makefile->GetLinkDirectoriesEntries());
  469. cm::append(this->impl->LinkDirectoriesBacktraces,
  470. this->impl->Makefile->GetLinkDirectoriesBacktraces());
  471. }
  472. if (this->impl->TargetType == cmStateEnums::EXECUTABLE) {
  473. initProp("ANDROID_GUI");
  474. initProp("CROSSCOMPILING_EMULATOR");
  475. initProp("ENABLE_EXPORTS");
  476. }
  477. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
  478. this->impl->TargetType == cmStateEnums::MODULE_LIBRARY) {
  479. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  480. } else if (this->CanCompileSources()) {
  481. initProp("POSITION_INDEPENDENT_CODE");
  482. }
  483. if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
  484. this->impl->TargetType == cmStateEnums::EXECUTABLE) {
  485. initProp("AIX_EXPORT_ALL_SYMBOLS");
  486. initProp("WINDOWS_EXPORT_ALL_SYMBOLS");
  487. }
  488. // Record current policies for later use.
  489. this->impl->Makefile->RecordPolicies(this->impl->PolicyMap);
  490. if (this->impl->TargetType == cmStateEnums::INTERFACE_LIBRARY) {
  491. // This policy is checked in a few conditions. The properties relevant
  492. // to the policy are always ignored for cmStateEnums::INTERFACE_LIBRARY
  493. // targets,
  494. // so ensure that the conditions don't lead to nonsense.
  495. this->impl->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
  496. }
  497. if (this->impl->TargetType <= cmStateEnums::GLOBAL_TARGET) {
  498. initProp("DOTNET_TARGET_FRAMEWORK");
  499. initProp("DOTNET_TARGET_FRAMEWORK_VERSION");
  500. }
  501. // check for "CMAKE_VS_GLOBALS" variable and set up target properties
  502. // if any
  503. cmProp globals = mf->GetDefinition("CMAKE_VS_GLOBALS");
  504. if (globals) {
  505. const std::string genName = mf->GetGlobalGenerator()->GetName();
  506. if (cmHasLiteralPrefix(genName, "Visual Studio")) {
  507. std::vector<std::string> props = cmExpandedList(*globals);
  508. const std::string vsGlobal = "VS_GLOBAL_";
  509. for (const std::string& i : props) {
  510. // split NAME=VALUE
  511. const std::string::size_type assignment = i.find('=');
  512. if (assignment != std::string::npos) {
  513. const std::string propName = vsGlobal + i.substr(0, assignment);
  514. const std::string propValue = i.substr(assignment + 1);
  515. initPropValue(propName, propValue.c_str());
  516. }
  517. }
  518. }
  519. }
  520. }
  521. cmTarget::cmTarget(cmTarget&&) noexcept = default;
  522. cmTarget::~cmTarget() = default;
  523. cmTarget& cmTarget::operator=(cmTarget&&) noexcept = default;
  524. cmStateEnums::TargetType cmTarget::GetType() const
  525. {
  526. return this->impl->TargetType;
  527. }
  528. cmMakefile* cmTarget::GetMakefile() const
  529. {
  530. return this->impl->Makefile;
  531. }
  532. cmPolicies::PolicyMap const& cmTarget::GetPolicyMap() const
  533. {
  534. return this->impl->PolicyMap;
  535. }
  536. const std::string& cmTarget::GetName() const
  537. {
  538. return this->impl->Name;
  539. }
  540. cmPolicies::PolicyStatus cmTarget::GetPolicyStatus(
  541. cmPolicies::PolicyID policy) const
  542. {
  543. return this->impl->PolicyMap.Get(policy);
  544. }
  545. cmGlobalGenerator* cmTarget::GetGlobalGenerator() const
  546. {
  547. return this->impl->Makefile->GetGlobalGenerator();
  548. }
  549. BTs<std::string> const* cmTarget::GetLanguageStandardProperty(
  550. const std::string& propertyName) const
  551. {
  552. auto entry = this->impl->LanguageStandardProperties.find(propertyName);
  553. if (entry != this->impl->LanguageStandardProperties.end()) {
  554. return &entry->second;
  555. }
  556. return nullptr;
  557. }
  558. void cmTarget::SetLanguageStandardProperty(std::string const& lang,
  559. std::string const& value,
  560. const std::string& feature)
  561. {
  562. cmListFileBacktrace featureBacktrace;
  563. for (size_t i = 0; i < this->impl->CompileFeaturesEntries.size(); i++) {
  564. if (this->impl->CompileFeaturesEntries[i] == feature) {
  565. if (i < this->impl->CompileFeaturesBacktraces.size()) {
  566. featureBacktrace = this->impl->CompileFeaturesBacktraces[i];
  567. }
  568. break;
  569. }
  570. }
  571. BTs<std::string>& languageStandardProperty =
  572. this->impl->LanguageStandardProperties[cmStrCat(lang, "_STANDARD")];
  573. if (languageStandardProperty.Value != value) {
  574. languageStandardProperty.Value = value;
  575. languageStandardProperty.Backtraces.clear();
  576. }
  577. languageStandardProperty.Backtraces.emplace_back(featureBacktrace);
  578. }
  579. void cmTarget::AddUtility(std::string const& name, bool cross, cmMakefile* mf)
  580. {
  581. this->impl->Utilities.insert(BT<std::pair<std::string, bool>>(
  582. { name, cross }, mf ? mf->GetBacktrace() : cmListFileBacktrace()));
  583. }
  584. void cmTarget::AddUtility(BT<std::pair<std::string, bool>> util)
  585. {
  586. this->impl->Utilities.emplace(std::move(util));
  587. }
  588. std::set<BT<std::pair<std::string, bool>>> const& cmTarget::GetUtilities()
  589. const
  590. {
  591. return this->impl->Utilities;
  592. }
  593. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  594. {
  595. return this->impl->Backtrace;
  596. }
  597. bool cmTarget::IsExecutableWithExports() const
  598. {
  599. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  600. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  601. }
  602. bool cmTarget::IsFrameworkOnApple() const
  603. {
  604. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  605. this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  606. this->impl->Makefile->IsOn("APPLE") &&
  607. this->GetPropertyAsBool("FRAMEWORK"));
  608. }
  609. bool cmTarget::IsAppBundleOnApple() const
  610. {
  611. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  612. this->impl->Makefile->IsOn("APPLE") &&
  613. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  614. }
  615. bool cmTarget::IsAndroidGuiExecutable() const
  616. {
  617. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  618. this->impl->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI"));
  619. }
  620. std::vector<cmCustomCommand> const& cmTarget::GetPreBuildCommands() const
  621. {
  622. return this->impl->PreBuildCommands;
  623. }
  624. void cmTarget::AddPreBuildCommand(cmCustomCommand const& cmd)
  625. {
  626. this->impl->PreBuildCommands.push_back(cmd);
  627. }
  628. void cmTarget::AddPreBuildCommand(cmCustomCommand&& cmd)
  629. {
  630. this->impl->PreBuildCommands.push_back(std::move(cmd));
  631. }
  632. std::vector<cmCustomCommand> const& cmTarget::GetPreLinkCommands() const
  633. {
  634. return this->impl->PreLinkCommands;
  635. }
  636. void cmTarget::AddPreLinkCommand(cmCustomCommand const& cmd)
  637. {
  638. this->impl->PreLinkCommands.push_back(cmd);
  639. }
  640. void cmTarget::AddPreLinkCommand(cmCustomCommand&& cmd)
  641. {
  642. this->impl->PreLinkCommands.push_back(std::move(cmd));
  643. }
  644. std::vector<cmCustomCommand> const& cmTarget::GetPostBuildCommands() const
  645. {
  646. return this->impl->PostBuildCommands;
  647. }
  648. void cmTarget::AddPostBuildCommand(cmCustomCommand const& cmd)
  649. {
  650. this->impl->PostBuildCommands.push_back(cmd);
  651. }
  652. void cmTarget::AddPostBuildCommand(cmCustomCommand&& cmd)
  653. {
  654. this->impl->PostBuildCommands.push_back(std::move(cmd));
  655. }
  656. void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
  657. {
  658. if (!srcs.empty()) {
  659. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  660. this->impl->SourceEntries.push_back(cmJoin(srcs, ";"));
  661. this->impl->SourceBacktraces.push_back(lfbt);
  662. }
  663. }
  664. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  665. {
  666. std::string srcFiles;
  667. const char* sep = "";
  668. for (auto filename : srcs) {
  669. if (!cmGeneratorExpression::StartsWithGeneratorExpression(filename)) {
  670. if (!filename.empty()) {
  671. filename = this->impl->ProcessSourceItemCMP0049(filename);
  672. if (filename.empty()) {
  673. return;
  674. }
  675. }
  676. this->impl->Makefile->GetOrCreateSource(filename);
  677. }
  678. srcFiles += sep;
  679. srcFiles += filename;
  680. sep = ";";
  681. }
  682. if (!srcFiles.empty()) {
  683. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  684. this->impl->SourceEntries.push_back(std::move(srcFiles));
  685. this->impl->SourceBacktraces.push_back(lfbt);
  686. }
  687. }
  688. std::string cmTargetInternals::ProcessSourceItemCMP0049(
  689. const std::string& s) const
  690. {
  691. std::string src = s;
  692. // For backwards compatibility replace variables in source names.
  693. // This should eventually be removed.
  694. this->Makefile->ExpandVariablesInString(src);
  695. if (src != s) {
  696. std::ostringstream e;
  697. bool noMessage = false;
  698. MessageType messageType = MessageType::AUTHOR_WARNING;
  699. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0049)) {
  700. case cmPolicies::WARN:
  701. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0049) << "\n";
  702. break;
  703. case cmPolicies::OLD:
  704. noMessage = true;
  705. break;
  706. case cmPolicies::REQUIRED_ALWAYS:
  707. case cmPolicies::REQUIRED_IF_USED:
  708. case cmPolicies::NEW:
  709. messageType = MessageType::FATAL_ERROR;
  710. }
  711. if (!noMessage) {
  712. e << "Legacy variable expansion in source file \"" << s
  713. << "\" expanded to \"" << src << "\" in target \"" << this->Name
  714. << "\". This behavior will be removed in a "
  715. "future version of CMake.";
  716. this->Makefile->IssueMessage(messageType, e.str());
  717. if (messageType == MessageType::FATAL_ERROR) {
  718. return "";
  719. }
  720. }
  721. }
  722. return src;
  723. }
  724. std::string cmTarget::GetSourceCMP0049(const std::string& s)
  725. {
  726. return this->impl->ProcessSourceItemCMP0049(s);
  727. }
  728. struct CreateLocation
  729. {
  730. cmMakefile const* Makefile;
  731. CreateLocation(cmMakefile const* mf)
  732. : Makefile(mf)
  733. {
  734. }
  735. cmSourceFileLocation operator()(const std::string& filename) const
  736. {
  737. return cmSourceFileLocation(this->Makefile, filename);
  738. }
  739. };
  740. struct LocationMatcher
  741. {
  742. const cmSourceFileLocation& Needle;
  743. LocationMatcher(const cmSourceFileLocation& needle)
  744. : Needle(needle)
  745. {
  746. }
  747. bool operator()(cmSourceFileLocation& loc)
  748. {
  749. return loc.Matches(this->Needle);
  750. }
  751. };
  752. struct TargetPropertyEntryFinder
  753. {
  754. private:
  755. const cmSourceFileLocation& Needle;
  756. public:
  757. TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
  758. : Needle(needle)
  759. {
  760. }
  761. bool operator()(std::string const& entry)
  762. {
  763. std::vector<std::string> files = cmExpandedList(entry);
  764. std::vector<cmSourceFileLocation> locations;
  765. locations.reserve(files.size());
  766. std::transform(files.begin(), files.end(), std::back_inserter(locations),
  767. CreateLocation(this->Needle.GetMakefile()));
  768. return std::find_if(locations.begin(), locations.end(),
  769. LocationMatcher(this->Needle)) != locations.end();
  770. }
  771. };
  772. cmSourceFile* cmTarget::AddSource(const std::string& src, bool before)
  773. {
  774. cmSourceFileLocation sfl(this->impl->Makefile, src,
  775. cmSourceFileLocationKind::Known);
  776. if (std::find_if(
  777. this->impl->SourceEntries.begin(), this->impl->SourceEntries.end(),
  778. TargetPropertyEntryFinder(sfl)) == this->impl->SourceEntries.end()) {
  779. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  780. this->impl->SourceEntries.insert(before ? this->impl->SourceEntries.begin()
  781. : this->impl->SourceEntries.end(),
  782. src);
  783. this->impl->SourceBacktraces.insert(
  784. before ? this->impl->SourceBacktraces.begin()
  785. : this->impl->SourceBacktraces.end(),
  786. 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. cmProp 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(cmStringRange const& incs)
  965. {
  966. std::copy(incs.begin(), incs.end(),
  967. std::back_inserter(this->impl->InstallIncludeDirectoriesEntries));
  968. }
  969. cmStringRange cmTarget::GetInstallIncludeDirectoriesEntries() const
  970. {
  971. return cmMakeRange(this->impl->InstallIncludeDirectoriesEntries);
  972. }
  973. cmStringRange cmTarget::GetIncludeDirectoriesEntries() const
  974. {
  975. return cmMakeRange(this->impl->IncludeDirectoriesEntries);
  976. }
  977. cmBacktraceRange cmTarget::GetIncludeDirectoriesBacktraces() const
  978. {
  979. return cmMakeRange(this->impl->IncludeDirectoriesBacktraces);
  980. }
  981. cmStringRange cmTarget::GetCompileOptionsEntries() const
  982. {
  983. return cmMakeRange(this->impl->CompileOptionsEntries);
  984. }
  985. cmBacktraceRange cmTarget::GetCompileOptionsBacktraces() const
  986. {
  987. return cmMakeRange(this->impl->CompileOptionsBacktraces);
  988. }
  989. cmStringRange cmTarget::GetCompileFeaturesEntries() const
  990. {
  991. return cmMakeRange(this->impl->CompileFeaturesEntries);
  992. }
  993. cmBacktraceRange cmTarget::GetCompileFeaturesBacktraces() const
  994. {
  995. return cmMakeRange(this->impl->CompileFeaturesBacktraces);
  996. }
  997. cmStringRange cmTarget::GetCompileDefinitionsEntries() const
  998. {
  999. return cmMakeRange(this->impl->CompileDefinitionsEntries);
  1000. }
  1001. cmBacktraceRange cmTarget::GetCompileDefinitionsBacktraces() const
  1002. {
  1003. return cmMakeRange(this->impl->CompileDefinitionsBacktraces);
  1004. }
  1005. cmStringRange cmTarget::GetPrecompileHeadersEntries() const
  1006. {
  1007. return cmMakeRange(this->impl->PrecompileHeadersEntries);
  1008. }
  1009. cmBacktraceRange cmTarget::GetPrecompileHeadersBacktraces() const
  1010. {
  1011. return cmMakeRange(this->impl->PrecompileHeadersBacktraces);
  1012. }
  1013. cmStringRange cmTarget::GetSourceEntries() const
  1014. {
  1015. return cmMakeRange(this->impl->SourceEntries);
  1016. }
  1017. cmBacktraceRange cmTarget::GetSourceBacktraces() const
  1018. {
  1019. return cmMakeRange(this->impl->SourceBacktraces);
  1020. }
  1021. cmStringRange cmTarget::GetLinkOptionsEntries() const
  1022. {
  1023. return cmMakeRange(this->impl->LinkOptionsEntries);
  1024. }
  1025. cmBacktraceRange cmTarget::GetLinkOptionsBacktraces() const
  1026. {
  1027. return cmMakeRange(this->impl->LinkOptionsBacktraces);
  1028. }
  1029. cmStringRange cmTarget::GetLinkDirectoriesEntries() const
  1030. {
  1031. return cmMakeRange(this->impl->LinkDirectoriesEntries);
  1032. }
  1033. cmBacktraceRange cmTarget::GetLinkDirectoriesBacktraces() const
  1034. {
  1035. return cmMakeRange(this->impl->LinkDirectoriesBacktraces);
  1036. }
  1037. cmStringRange cmTarget::GetLinkImplementationEntries() const
  1038. {
  1039. return cmMakeRange(this->impl->LinkImplementationPropertyEntries);
  1040. }
  1041. cmBacktraceRange cmTarget::GetLinkImplementationBacktraces() const
  1042. {
  1043. return cmMakeRange(this->impl->LinkImplementationPropertyBacktraces);
  1044. }
  1045. namespace {
  1046. #define MAKE_PROP(PROP) const std::string prop##PROP = #PROP
  1047. MAKE_PROP(C_STANDARD);
  1048. MAKE_PROP(CXX_STANDARD);
  1049. MAKE_PROP(CUDA_STANDARD);
  1050. MAKE_PROP(HIP_STANDARD);
  1051. MAKE_PROP(OBJC_STANDARD);
  1052. MAKE_PROP(OBJCXX_STANDARD);
  1053. MAKE_PROP(COMPILE_DEFINITIONS);
  1054. MAKE_PROP(COMPILE_FEATURES);
  1055. MAKE_PROP(COMPILE_OPTIONS);
  1056. MAKE_PROP(PRECOMPILE_HEADERS);
  1057. MAKE_PROP(PRECOMPILE_HEADERS_REUSE_FROM);
  1058. MAKE_PROP(CUDA_PTX_COMPILATION);
  1059. MAKE_PROP(EXPORT_NAME);
  1060. MAKE_PROP(IMPORTED);
  1061. MAKE_PROP(IMPORTED_GLOBAL);
  1062. MAKE_PROP(INCLUDE_DIRECTORIES);
  1063. MAKE_PROP(LINK_OPTIONS);
  1064. MAKE_PROP(LINK_DIRECTORIES);
  1065. MAKE_PROP(LINK_LIBRARIES);
  1066. MAKE_PROP(MANUALLY_ADDED_DEPENDENCIES);
  1067. MAKE_PROP(NAME);
  1068. MAKE_PROP(SOURCES);
  1069. MAKE_PROP(TYPE);
  1070. MAKE_PROP(BINARY_DIR);
  1071. MAKE_PROP(SOURCE_DIR);
  1072. MAKE_PROP(FALSE);
  1073. MAKE_PROP(TRUE);
  1074. #undef MAKE_PROP
  1075. }
  1076. namespace {
  1077. // to workaround bug on GCC/AIX
  1078. // Define a template to force conversion to std::string
  1079. template <typename ValueType>
  1080. std::string ConvertToString(ValueType value);
  1081. template <>
  1082. std::string ConvertToString<const char*>(const char* value)
  1083. {
  1084. return std::string(value);
  1085. }
  1086. template <>
  1087. std::string ConvertToString<cmProp>(cmProp value)
  1088. {
  1089. return std::string(*value);
  1090. }
  1091. }
  1092. template <typename ValueType>
  1093. void cmTarget::StoreProperty(const std::string& prop, ValueType value)
  1094. {
  1095. if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
  1096. this->impl->Makefile->IssueMessage(
  1097. MessageType::FATAL_ERROR,
  1098. "MANUALLY_ADDED_DEPENDENCIES property is read-only\n");
  1099. return;
  1100. }
  1101. if (prop == propNAME) {
  1102. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1103. "NAME property is read-only\n");
  1104. return;
  1105. }
  1106. if (prop == propTYPE) {
  1107. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1108. "TYPE property is read-only\n");
  1109. return;
  1110. }
  1111. if (prop == propEXPORT_NAME && this->IsImported()) {
  1112. std::ostringstream e;
  1113. e << "EXPORT_NAME property can't be set on imported targets (\""
  1114. << this->impl->Name << "\")\n";
  1115. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1116. return;
  1117. }
  1118. if (prop == propSOURCES && this->IsImported()) {
  1119. std::ostringstream e;
  1120. e << "SOURCES property can't be set on imported targets (\""
  1121. << this->impl->Name << "\")\n";
  1122. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1123. return;
  1124. }
  1125. if (prop == propIMPORTED_GLOBAL && !this->IsImported()) {
  1126. std::ostringstream e;
  1127. e << "IMPORTED_GLOBAL property can't be set on non-imported targets (\""
  1128. << this->impl->Name << "\")\n";
  1129. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1130. return;
  1131. }
  1132. if (prop == propINCLUDE_DIRECTORIES) {
  1133. this->impl->IncludeDirectoriesEntries.clear();
  1134. this->impl->IncludeDirectoriesBacktraces.clear();
  1135. if (value) {
  1136. this->impl->IncludeDirectoriesEntries.emplace_back(value);
  1137. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1138. this->impl->IncludeDirectoriesBacktraces.push_back(lfbt);
  1139. }
  1140. } else if (prop == propCOMPILE_OPTIONS) {
  1141. this->impl->CompileOptionsEntries.clear();
  1142. this->impl->CompileOptionsBacktraces.clear();
  1143. if (value) {
  1144. this->impl->CompileOptionsEntries.emplace_back(value);
  1145. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1146. this->impl->CompileOptionsBacktraces.push_back(lfbt);
  1147. }
  1148. } else if (prop == propCOMPILE_FEATURES) {
  1149. this->impl->CompileFeaturesEntries.clear();
  1150. this->impl->CompileFeaturesBacktraces.clear();
  1151. if (value) {
  1152. this->impl->CompileFeaturesEntries.emplace_back(value);
  1153. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1154. this->impl->CompileFeaturesBacktraces.push_back(lfbt);
  1155. }
  1156. } else if (prop == propCOMPILE_DEFINITIONS) {
  1157. this->impl->CompileDefinitionsEntries.clear();
  1158. this->impl->CompileDefinitionsBacktraces.clear();
  1159. if (value) {
  1160. this->impl->CompileDefinitionsEntries.emplace_back(value);
  1161. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1162. this->impl->CompileDefinitionsBacktraces.push_back(lfbt);
  1163. }
  1164. } else if (prop == propLINK_OPTIONS) {
  1165. this->impl->LinkOptionsEntries.clear();
  1166. this->impl->LinkOptionsBacktraces.clear();
  1167. if (value) {
  1168. this->impl->LinkOptionsEntries.emplace_back(value);
  1169. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1170. this->impl->LinkOptionsBacktraces.push_back(lfbt);
  1171. }
  1172. } else if (prop == propLINK_DIRECTORIES) {
  1173. this->impl->LinkDirectoriesEntries.clear();
  1174. this->impl->LinkDirectoriesBacktraces.clear();
  1175. if (value) {
  1176. this->impl->LinkDirectoriesEntries.emplace_back(value);
  1177. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1178. this->impl->LinkDirectoriesBacktraces.push_back(lfbt);
  1179. }
  1180. } else if (prop == propPRECOMPILE_HEADERS) {
  1181. this->impl->PrecompileHeadersEntries.clear();
  1182. this->impl->PrecompileHeadersBacktraces.clear();
  1183. if (value) {
  1184. this->impl->PrecompileHeadersEntries.emplace_back(value);
  1185. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1186. this->impl->PrecompileHeadersBacktraces.push_back(lfbt);
  1187. }
  1188. } else if (prop == propLINK_LIBRARIES) {
  1189. this->impl->LinkImplementationPropertyEntries.clear();
  1190. this->impl->LinkImplementationPropertyBacktraces.clear();
  1191. if (value) {
  1192. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1193. this->impl->LinkImplementationPropertyEntries.emplace_back(value);
  1194. this->impl->LinkImplementationPropertyBacktraces.push_back(lfbt);
  1195. }
  1196. } else if (prop == propSOURCES) {
  1197. this->impl->SourceEntries.clear();
  1198. this->impl->SourceBacktraces.clear();
  1199. if (value) {
  1200. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1201. this->impl->SourceEntries.emplace_back(value);
  1202. this->impl->SourceBacktraces.push_back(lfbt);
  1203. }
  1204. } else if (prop == propIMPORTED_GLOBAL) {
  1205. if (!cmIsOn(value)) {
  1206. std::ostringstream e;
  1207. e << "IMPORTED_GLOBAL property can't be set to FALSE on targets (\""
  1208. << this->impl->Name << "\")\n";
  1209. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1210. return;
  1211. }
  1212. /* no need to change anything if value does not change */
  1213. if (!this->impl->ImportedGloballyVisible) {
  1214. this->impl->ImportedGloballyVisible = true;
  1215. this->GetGlobalGenerator()->IndexTarget(this);
  1216. }
  1217. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME") &&
  1218. !this->impl->CheckImportedLibName(
  1219. prop, value ? value : std::string{})) {
  1220. /* error was reported by check method */
  1221. } else if (prop == propCUDA_PTX_COMPILATION &&
  1222. this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  1223. std::ostringstream e;
  1224. e << "CUDA_PTX_COMPILATION property can only be applied to OBJECT "
  1225. "targets (\""
  1226. << this->impl->Name << "\")\n";
  1227. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1228. return;
  1229. } else if (prop == propPRECOMPILE_HEADERS_REUSE_FROM) {
  1230. if (this->GetProperty("PRECOMPILE_HEADERS")) {
  1231. std::ostringstream e;
  1232. e << "PRECOMPILE_HEADERS property is already set on target (\""
  1233. << this->impl->Name << "\")\n";
  1234. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1235. return;
  1236. }
  1237. auto* reusedTarget = this->impl->Makefile->GetCMakeInstance()
  1238. ->GetGlobalGenerator()
  1239. ->FindTarget(value);
  1240. if (!reusedTarget) {
  1241. const std::string e(
  1242. "PRECOMPILE_HEADERS_REUSE_FROM set with non existing target");
  1243. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e);
  1244. return;
  1245. }
  1246. std::string reusedFrom = reusedTarget->GetSafeProperty(prop);
  1247. if (reusedFrom.empty()) {
  1248. reusedFrom = ConvertToString(value);
  1249. }
  1250. this->impl->Properties.SetProperty(prop, reusedFrom);
  1251. reusedTarget->SetProperty("COMPILE_PDB_NAME", reusedFrom);
  1252. reusedTarget->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY",
  1253. cmStrCat(reusedFrom, ".dir/"));
  1254. cmProp tmp = reusedTarget->GetProperty("COMPILE_PDB_NAME");
  1255. this->SetProperty("COMPILE_PDB_NAME", tmp);
  1256. this->AddUtility(reusedFrom, false, this->impl->Makefile);
  1257. } else if (prop == propC_STANDARD || prop == propCXX_STANDARD ||
  1258. prop == propCUDA_STANDARD || prop == propHIP_STANDARD ||
  1259. prop == propOBJC_STANDARD || prop == propOBJCXX_STANDARD) {
  1260. if (value) {
  1261. this->impl->LanguageStandardProperties[prop] =
  1262. BTs<std::string>(value, this->impl->Makefile->GetBacktrace());
  1263. } else {
  1264. this->impl->LanguageStandardProperties.erase(prop);
  1265. }
  1266. } else {
  1267. this->impl->Properties.SetProperty(prop, value);
  1268. }
  1269. }
  1270. void cmTarget::AppendProperty(const std::string& prop,
  1271. const std::string& value, bool asString)
  1272. {
  1273. if (prop == "NAME") {
  1274. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1275. "NAME property is read-only\n");
  1276. return;
  1277. }
  1278. if (prop == "EXPORT_NAME" && this->IsImported()) {
  1279. std::ostringstream e;
  1280. e << "EXPORT_NAME property can't be set on imported targets (\""
  1281. << this->impl->Name << "\")\n";
  1282. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1283. return;
  1284. }
  1285. if (prop == "SOURCES" && this->IsImported()) {
  1286. std::ostringstream e;
  1287. e << "SOURCES property can't be set on imported targets (\""
  1288. << this->impl->Name << "\")\n";
  1289. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1290. return;
  1291. }
  1292. if (prop == "IMPORTED_GLOBAL") {
  1293. std::ostringstream e;
  1294. e << "IMPORTED_GLOBAL property can't be appended, only set on imported "
  1295. "targets (\""
  1296. << this->impl->Name << "\")\n";
  1297. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1298. return;
  1299. }
  1300. if (prop == "INCLUDE_DIRECTORIES") {
  1301. if (!value.empty()) {
  1302. this->impl->IncludeDirectoriesEntries.emplace_back(value);
  1303. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1304. this->impl->IncludeDirectoriesBacktraces.push_back(lfbt);
  1305. }
  1306. } else if (prop == "COMPILE_OPTIONS") {
  1307. if (!value.empty()) {
  1308. this->impl->CompileOptionsEntries.emplace_back(value);
  1309. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1310. this->impl->CompileOptionsBacktraces.push_back(lfbt);
  1311. }
  1312. } else if (prop == "COMPILE_FEATURES") {
  1313. if (!value.empty()) {
  1314. this->impl->CompileFeaturesEntries.emplace_back(value);
  1315. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1316. this->impl->CompileFeaturesBacktraces.push_back(lfbt);
  1317. }
  1318. } else if (prop == "COMPILE_DEFINITIONS") {
  1319. if (!value.empty()) {
  1320. this->impl->CompileDefinitionsEntries.emplace_back(value);
  1321. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1322. this->impl->CompileDefinitionsBacktraces.push_back(lfbt);
  1323. }
  1324. } else if (prop == "LINK_OPTIONS") {
  1325. if (!value.empty()) {
  1326. this->impl->LinkOptionsEntries.emplace_back(value);
  1327. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1328. this->impl->LinkOptionsBacktraces.push_back(lfbt);
  1329. }
  1330. } else if (prop == "LINK_DIRECTORIES") {
  1331. if (!value.empty()) {
  1332. this->impl->LinkDirectoriesEntries.emplace_back(value);
  1333. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1334. this->impl->LinkDirectoriesBacktraces.push_back(lfbt);
  1335. }
  1336. } else if (prop == "PRECOMPILE_HEADERS") {
  1337. if (this->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM")) {
  1338. std::ostringstream e;
  1339. e << "PRECOMPILE_HEADERS_REUSE_FROM property is already set on target "
  1340. "(\""
  1341. << this->impl->Name << "\")\n";
  1342. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1343. return;
  1344. }
  1345. if (!value.empty()) {
  1346. this->impl->PrecompileHeadersEntries.emplace_back(value);
  1347. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1348. this->impl->PrecompileHeadersBacktraces.push_back(lfbt);
  1349. }
  1350. } else if (prop == "LINK_LIBRARIES") {
  1351. if (!value.empty()) {
  1352. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1353. this->impl->LinkImplementationPropertyEntries.emplace_back(value);
  1354. this->impl->LinkImplementationPropertyBacktraces.push_back(lfbt);
  1355. }
  1356. } else if (prop == "SOURCES") {
  1357. cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace();
  1358. this->impl->SourceEntries.emplace_back(value);
  1359. this->impl->SourceBacktraces.push_back(lfbt);
  1360. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) {
  1361. this->impl->Makefile->IssueMessage(
  1362. MessageType::FATAL_ERROR, prop + " property may not be APPENDed.");
  1363. } else if (prop == "C_STANDARD" || prop == "CXX_STANDARD" ||
  1364. prop == "CUDA_STANDARD" || prop == "HIP_STANDARD" ||
  1365. prop == "OBJC_STANDARD" || prop == "OBJCXX_STANDARD") {
  1366. this->impl->Makefile->IssueMessage(
  1367. MessageType::FATAL_ERROR, prop + " property may not be appended.");
  1368. } else {
  1369. this->impl->Properties.AppendProperty(prop, value, asString);
  1370. }
  1371. }
  1372. void cmTarget::SetProperty(const std::string& prop, const char* value)
  1373. {
  1374. this->StoreProperty(prop, value);
  1375. }
  1376. void cmTarget::SetProperty(const std::string& prop, cmProp value)
  1377. {
  1378. this->StoreProperty(prop, value);
  1379. }
  1380. void cmTarget::AppendBuildInterfaceIncludes()
  1381. {
  1382. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1383. this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  1384. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  1385. this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  1386. !this->IsExecutableWithExports()) {
  1387. return;
  1388. }
  1389. if (this->impl->BuildInterfaceIncludesAppended) {
  1390. return;
  1391. }
  1392. this->impl->BuildInterfaceIncludesAppended = true;
  1393. if (this->impl->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE")) {
  1394. std::string dirs = this->impl->Makefile->GetCurrentBinaryDirectory();
  1395. if (!dirs.empty()) {
  1396. dirs += ';';
  1397. }
  1398. dirs += this->impl->Makefile->GetCurrentSourceDirectory();
  1399. if (!dirs.empty()) {
  1400. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  1401. ("$<BUILD_INTERFACE:" + dirs + ">"));
  1402. }
  1403. }
  1404. }
  1405. void cmTarget::InsertInclude(std::string const& entry,
  1406. cmListFileBacktrace const& bt, bool before)
  1407. {
  1408. auto position = before ? this->impl->IncludeDirectoriesEntries.begin()
  1409. : this->impl->IncludeDirectoriesEntries.end();
  1410. auto btPosition = before ? this->impl->IncludeDirectoriesBacktraces.begin()
  1411. : this->impl->IncludeDirectoriesBacktraces.end();
  1412. this->impl->IncludeDirectoriesEntries.insert(position, entry);
  1413. this->impl->IncludeDirectoriesBacktraces.insert(btPosition, bt);
  1414. }
  1415. void cmTarget::InsertCompileOption(std::string const& entry,
  1416. cmListFileBacktrace const& bt, bool before)
  1417. {
  1418. auto position = before ? this->impl->CompileOptionsEntries.begin()
  1419. : this->impl->CompileOptionsEntries.end();
  1420. auto btPosition = before ? this->impl->CompileOptionsBacktraces.begin()
  1421. : this->impl->CompileOptionsBacktraces.end();
  1422. this->impl->CompileOptionsEntries.insert(position, entry);
  1423. this->impl->CompileOptionsBacktraces.insert(btPosition, bt);
  1424. }
  1425. void cmTarget::InsertCompileDefinition(std::string const& entry,
  1426. cmListFileBacktrace const& bt)
  1427. {
  1428. this->impl->CompileDefinitionsEntries.push_back(entry);
  1429. this->impl->CompileDefinitionsBacktraces.push_back(bt);
  1430. }
  1431. void cmTarget::InsertLinkOption(std::string const& entry,
  1432. cmListFileBacktrace const& bt, bool before)
  1433. {
  1434. auto position = before ? this->impl->LinkOptionsEntries.begin()
  1435. : this->impl->LinkOptionsEntries.end();
  1436. auto btPosition = before ? this->impl->LinkOptionsBacktraces.begin()
  1437. : this->impl->LinkOptionsBacktraces.end();
  1438. this->impl->LinkOptionsEntries.insert(position, entry);
  1439. this->impl->LinkOptionsBacktraces.insert(btPosition, bt);
  1440. }
  1441. void cmTarget::InsertLinkDirectory(std::string const& entry,
  1442. cmListFileBacktrace const& bt, bool before)
  1443. {
  1444. auto position = before ? this->impl->LinkDirectoriesEntries.begin()
  1445. : this->impl->LinkDirectoriesEntries.end();
  1446. auto btPosition = before ? this->impl->LinkDirectoriesBacktraces.begin()
  1447. : this->impl->LinkDirectoriesBacktraces.end();
  1448. this->impl->LinkDirectoriesEntries.insert(position, entry);
  1449. this->impl->LinkDirectoriesBacktraces.insert(btPosition, bt);
  1450. }
  1451. void cmTarget::InsertPrecompileHeader(std::string const& entry,
  1452. cmListFileBacktrace const& bt)
  1453. {
  1454. this->impl->PrecompileHeadersEntries.push_back(entry);
  1455. this->impl->PrecompileHeadersBacktraces.push_back(bt);
  1456. }
  1457. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(const std::string& prop,
  1458. const std::string& value,
  1459. cmMakefile* context,
  1460. bool imported)
  1461. {
  1462. // Look for link-type keywords in the value.
  1463. static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
  1464. if (!keys.find(value)) {
  1465. return;
  1466. }
  1467. // Support imported and non-imported versions of the property.
  1468. const char* base = (imported ? "IMPORTED_LINK_INTERFACE_LIBRARIES"
  1469. : "LINK_INTERFACE_LIBRARIES");
  1470. // Report an error.
  1471. std::ostringstream e;
  1472. e << "Property " << prop << " may not contain link-type keyword \""
  1473. << keys.match(2) << "\". "
  1474. << "The " << base << " property has a per-configuration "
  1475. << "version called " << base << "_<CONFIG> which may be "
  1476. << "used to specify per-configuration rules.";
  1477. if (!imported) {
  1478. e << " "
  1479. << "Alternatively, an IMPORTED library may be created, configured "
  1480. << "with a per-configuration location, and then named in the "
  1481. << "property value. "
  1482. << "See the add_library command's IMPORTED mode for details."
  1483. << "\n"
  1484. << "If you have a list of libraries that already contains the "
  1485. << "keyword, use the target_link_libraries command with its "
  1486. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  1487. << "The command automatically recognizes link-type keywords and sets "
  1488. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  1489. << "properties accordingly.";
  1490. }
  1491. context->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1492. }
  1493. static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const std::string& value,
  1494. cmMakefile* context)
  1495. {
  1496. // Look for link-type keywords in the value.
  1497. static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
  1498. if (!keys.find(value)) {
  1499. return;
  1500. }
  1501. // Report an error.
  1502. std::ostringstream e;
  1503. e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
  1504. "keyword \""
  1505. << keys.match(2)
  1506. << "\". The INTERFACE_LINK_LIBRARIES "
  1507. "property may contain configuration-sensitive generator-expressions "
  1508. "which may be used to specify per-configuration rules.";
  1509. context->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1510. }
  1511. static void cmTargetCheckIMPORTED_GLOBAL(const cmTarget* target,
  1512. cmMakefile* context)
  1513. {
  1514. const auto& targets = context->GetOwnedImportedTargets();
  1515. auto it =
  1516. std::find_if(targets.begin(), targets.end(),
  1517. [&](const std::unique_ptr<cmTarget>& importTarget) -> bool {
  1518. return target == importTarget.get();
  1519. });
  1520. if (it == targets.end()) {
  1521. std::ostringstream e;
  1522. e << "Attempt to promote imported target \"" << target->GetName()
  1523. << "\" to global scope (by setting IMPORTED_GLOBAL) "
  1524. "which is not built in this directory.";
  1525. context->IssueMessage(MessageType::FATAL_ERROR, e.str());
  1526. }
  1527. }
  1528. void cmTarget::CheckProperty(const std::string& prop,
  1529. cmMakefile* context) const
  1530. {
  1531. // Certain properties need checking.
  1532. if (cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES")) {
  1533. if (cmProp value = this->GetProperty(prop)) {
  1534. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, *value, context, false);
  1535. }
  1536. }
  1537. if (cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES")) {
  1538. if (cmProp value = this->GetProperty(prop)) {
  1539. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, *value, context, true);
  1540. }
  1541. }
  1542. if (prop == "INTERFACE_LINK_LIBRARIES") {
  1543. if (cmProp value = this->GetProperty(prop)) {
  1544. cmTargetCheckINTERFACE_LINK_LIBRARIES(*value, context);
  1545. }
  1546. }
  1547. if (prop == "IMPORTED_GLOBAL") {
  1548. if (this->IsImported()) {
  1549. cmTargetCheckIMPORTED_GLOBAL(this, context);
  1550. }
  1551. }
  1552. }
  1553. cmProp cmTarget::GetComputedProperty(const std::string& prop,
  1554. cmMessenger* messenger,
  1555. cmListFileBacktrace const& context) const
  1556. {
  1557. return cmTargetPropertyComputer::GetProperty(this, prop, messenger, context);
  1558. }
  1559. cmProp cmTarget::GetProperty(const std::string& prop) const
  1560. {
  1561. static std::unordered_set<std::string> const specialProps{
  1562. propC_STANDARD,
  1563. propCXX_STANDARD,
  1564. propCUDA_STANDARD,
  1565. propOBJC_STANDARD,
  1566. propOBJCXX_STANDARD,
  1567. propLINK_LIBRARIES,
  1568. propTYPE,
  1569. propINCLUDE_DIRECTORIES,
  1570. propCOMPILE_FEATURES,
  1571. propCOMPILE_OPTIONS,
  1572. propCOMPILE_DEFINITIONS,
  1573. propPRECOMPILE_HEADERS,
  1574. propLINK_OPTIONS,
  1575. propLINK_DIRECTORIES,
  1576. propIMPORTED,
  1577. propIMPORTED_GLOBAL,
  1578. propMANUALLY_ADDED_DEPENDENCIES,
  1579. propNAME,
  1580. propBINARY_DIR,
  1581. propSOURCE_DIR,
  1582. propSOURCES
  1583. };
  1584. if (specialProps.count(prop)) {
  1585. if (prop == propC_STANDARD || prop == propCXX_STANDARD ||
  1586. prop == propCUDA_STANDARD || prop == propOBJC_STANDARD ||
  1587. prop == propOBJCXX_STANDARD) {
  1588. auto propertyIter = this->impl->LanguageStandardProperties.find(prop);
  1589. if (propertyIter == this->impl->LanguageStandardProperties.end()) {
  1590. return nullptr;
  1591. }
  1592. return cmProp(propertyIter->second.Value);
  1593. }
  1594. if (prop == propLINK_LIBRARIES) {
  1595. if (this->impl->LinkImplementationPropertyEntries.empty()) {
  1596. return nullptr;
  1597. }
  1598. static std::string output;
  1599. output = cmJoin(this->impl->LinkImplementationPropertyEntries, ";");
  1600. return cmProp(output);
  1601. }
  1602. // the type property returns what type the target is
  1603. if (prop == propTYPE) {
  1604. return cmProp(cmState::GetTargetTypeName(this->GetType()));
  1605. }
  1606. if (prop == propINCLUDE_DIRECTORIES) {
  1607. if (this->impl->IncludeDirectoriesEntries.empty()) {
  1608. return nullptr;
  1609. }
  1610. static std::string output;
  1611. output = cmJoin(this->impl->IncludeDirectoriesEntries, ";");
  1612. return cmProp(output);
  1613. }
  1614. if (prop == propCOMPILE_FEATURES) {
  1615. if (this->impl->CompileFeaturesEntries.empty()) {
  1616. return nullptr;
  1617. }
  1618. static std::string output;
  1619. output = cmJoin(this->impl->CompileFeaturesEntries, ";");
  1620. return cmProp(output);
  1621. }
  1622. if (prop == propCOMPILE_OPTIONS) {
  1623. if (this->impl->CompileOptionsEntries.empty()) {
  1624. return nullptr;
  1625. }
  1626. static std::string output;
  1627. output = cmJoin(this->impl->CompileOptionsEntries, ";");
  1628. return cmProp(output);
  1629. }
  1630. if (prop == propCOMPILE_DEFINITIONS) {
  1631. if (this->impl->CompileDefinitionsEntries.empty()) {
  1632. return nullptr;
  1633. }
  1634. static std::string output;
  1635. output = cmJoin(this->impl->CompileDefinitionsEntries, ";");
  1636. return cmProp(output);
  1637. }
  1638. if (prop == propLINK_OPTIONS) {
  1639. if (this->impl->LinkOptionsEntries.empty()) {
  1640. return nullptr;
  1641. }
  1642. static std::string output;
  1643. output = cmJoin(this->impl->LinkOptionsEntries, ";");
  1644. return cmProp(output);
  1645. }
  1646. if (prop == propLINK_DIRECTORIES) {
  1647. if (this->impl->LinkDirectoriesEntries.empty()) {
  1648. return nullptr;
  1649. }
  1650. static std::string output;
  1651. output = cmJoin(this->impl->LinkDirectoriesEntries, ";");
  1652. return cmProp(output);
  1653. }
  1654. if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
  1655. if (this->impl->Utilities.empty()) {
  1656. return nullptr;
  1657. }
  1658. static std::string output;
  1659. static std::vector<std::string> utilities;
  1660. utilities.resize(this->impl->Utilities.size());
  1661. std::transform(
  1662. this->impl->Utilities.cbegin(), this->impl->Utilities.cend(),
  1663. utilities.begin(),
  1664. [](const BT<std::pair<std::string, bool>>& item) -> std::string {
  1665. return item.Value.first;
  1666. });
  1667. output = cmJoin(utilities, ";");
  1668. return cmProp(output);
  1669. }
  1670. if (prop == propPRECOMPILE_HEADERS) {
  1671. if (this->impl->PrecompileHeadersEntries.empty()) {
  1672. return nullptr;
  1673. }
  1674. static std::string output;
  1675. output = cmJoin(this->impl->PrecompileHeadersEntries, ";");
  1676. return cmProp(output);
  1677. }
  1678. if (prop == propIMPORTED) {
  1679. return this->IsImported() ? cmProp(propTRUE) : cmProp(propFALSE);
  1680. }
  1681. if (prop == propIMPORTED_GLOBAL) {
  1682. return this->IsImportedGloballyVisible() ? cmProp(propTRUE)
  1683. : cmProp(propFALSE);
  1684. }
  1685. if (prop == propNAME) {
  1686. return cmProp(this->GetName());
  1687. }
  1688. if (prop == propBINARY_DIR) {
  1689. return cmProp(this->impl->Makefile->GetStateSnapshot()
  1690. .GetDirectory()
  1691. .GetCurrentBinary());
  1692. }
  1693. if (prop == propSOURCE_DIR) {
  1694. return cmProp(this->impl->Makefile->GetStateSnapshot()
  1695. .GetDirectory()
  1696. .GetCurrentSource());
  1697. }
  1698. }
  1699. cmProp retVal = this->impl->Properties.GetPropertyValue(prop);
  1700. if (!retVal) {
  1701. const bool chain = this->impl->Makefile->GetState()->IsPropertyChained(
  1702. prop, cmProperty::TARGET);
  1703. if (chain) {
  1704. return this->impl->Makefile->GetStateSnapshot()
  1705. .GetDirectory()
  1706. .GetProperty(prop, chain);
  1707. }
  1708. return nullptr;
  1709. }
  1710. return retVal;
  1711. }
  1712. std::string const& cmTarget::GetSafeProperty(std::string const& prop) const
  1713. {
  1714. cmProp ret = this->GetProperty(prop);
  1715. if (ret) {
  1716. return *ret;
  1717. }
  1718. static std::string const s_empty;
  1719. return s_empty;
  1720. }
  1721. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  1722. {
  1723. return cmIsOn(this->GetProperty(prop));
  1724. }
  1725. cmPropertyMap const& cmTarget::GetProperties() const
  1726. {
  1727. return this->impl->Properties;
  1728. }
  1729. bool cmTarget::IsDLLPlatform() const
  1730. {
  1731. return this->impl->IsDLLPlatform;
  1732. }
  1733. bool cmTarget::IsAIX() const
  1734. {
  1735. return this->impl->IsAIX;
  1736. }
  1737. bool cmTarget::IsImported() const
  1738. {
  1739. return this->impl->IsImportedTarget;
  1740. }
  1741. bool cmTarget::IsImportedGloballyVisible() const
  1742. {
  1743. return this->impl->ImportedGloballyVisible;
  1744. }
  1745. bool cmTarget::IsPerConfig() const
  1746. {
  1747. return this->impl->PerConfig;
  1748. }
  1749. bool cmTarget::CanCompileSources() const
  1750. {
  1751. if (this->IsImported()) {
  1752. return false;
  1753. }
  1754. switch (this->GetType()) {
  1755. case cmStateEnums::EXECUTABLE:
  1756. case cmStateEnums::STATIC_LIBRARY:
  1757. case cmStateEnums::SHARED_LIBRARY:
  1758. case cmStateEnums::MODULE_LIBRARY:
  1759. case cmStateEnums::OBJECT_LIBRARY:
  1760. return true;
  1761. case cmStateEnums::UTILITY:
  1762. case cmStateEnums::INTERFACE_LIBRARY:
  1763. case cmStateEnums::GLOBAL_TARGET:
  1764. case cmStateEnums::UNKNOWN_LIBRARY:
  1765. break;
  1766. }
  1767. return false;
  1768. }
  1769. const char* cmTarget::GetSuffixVariableInternal(
  1770. cmStateEnums::ArtifactType artifact) const
  1771. {
  1772. switch (this->GetType()) {
  1773. case cmStateEnums::STATIC_LIBRARY:
  1774. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  1775. case cmStateEnums::SHARED_LIBRARY:
  1776. switch (artifact) {
  1777. case cmStateEnums::RuntimeBinaryArtifact:
  1778. return "CMAKE_SHARED_LIBRARY_SUFFIX";
  1779. case cmStateEnums::ImportLibraryArtifact:
  1780. return "CMAKE_IMPORT_LIBRARY_SUFFIX";
  1781. }
  1782. break;
  1783. case cmStateEnums::MODULE_LIBRARY:
  1784. switch (artifact) {
  1785. case cmStateEnums::RuntimeBinaryArtifact:
  1786. return "CMAKE_SHARED_MODULE_SUFFIX";
  1787. case cmStateEnums::ImportLibraryArtifact:
  1788. return "CMAKE_IMPORT_LIBRARY_SUFFIX";
  1789. }
  1790. break;
  1791. case cmStateEnums::EXECUTABLE:
  1792. switch (artifact) {
  1793. case cmStateEnums::RuntimeBinaryArtifact:
  1794. // Android GUI application packages store the native
  1795. // binary as a shared library.
  1796. return (this->IsAndroidGuiExecutable()
  1797. ? "CMAKE_SHARED_LIBRARY_SUFFIX"
  1798. : "CMAKE_EXECUTABLE_SUFFIX");
  1799. case cmStateEnums::ImportLibraryArtifact:
  1800. return (this->impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_SUFFIX"
  1801. : "CMAKE_IMPORT_LIBRARY_SUFFIX");
  1802. }
  1803. break;
  1804. default:
  1805. break;
  1806. }
  1807. return "";
  1808. }
  1809. const char* cmTarget::GetPrefixVariableInternal(
  1810. cmStateEnums::ArtifactType artifact) const
  1811. {
  1812. switch (this->GetType()) {
  1813. case cmStateEnums::STATIC_LIBRARY:
  1814. return "CMAKE_STATIC_LIBRARY_PREFIX";
  1815. case cmStateEnums::SHARED_LIBRARY:
  1816. switch (artifact) {
  1817. case cmStateEnums::RuntimeBinaryArtifact:
  1818. return "CMAKE_SHARED_LIBRARY_PREFIX";
  1819. case cmStateEnums::ImportLibraryArtifact:
  1820. return "CMAKE_IMPORT_LIBRARY_PREFIX";
  1821. }
  1822. break;
  1823. case cmStateEnums::MODULE_LIBRARY:
  1824. switch (artifact) {
  1825. case cmStateEnums::RuntimeBinaryArtifact:
  1826. return "CMAKE_SHARED_MODULE_PREFIX";
  1827. case cmStateEnums::ImportLibraryArtifact:
  1828. return "CMAKE_IMPORT_LIBRARY_PREFIX";
  1829. }
  1830. break;
  1831. case cmStateEnums::EXECUTABLE:
  1832. switch (artifact) {
  1833. case cmStateEnums::RuntimeBinaryArtifact:
  1834. // Android GUI application packages store the native
  1835. // binary as a shared library.
  1836. return (this->IsAndroidGuiExecutable()
  1837. ? "CMAKE_SHARED_LIBRARY_PREFIX"
  1838. : "");
  1839. case cmStateEnums::ImportLibraryArtifact:
  1840. return (this->impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_PREFIX"
  1841. : "CMAKE_IMPORT_LIBRARY_PREFIX");
  1842. }
  1843. break;
  1844. default:
  1845. break;
  1846. }
  1847. return "";
  1848. }
  1849. std::string cmTarget::ImportedGetFullPath(
  1850. const std::string& config, cmStateEnums::ArtifactType artifact) const
  1851. {
  1852. assert(this->IsImported());
  1853. // Lookup/compute/cache the import information for this
  1854. // configuration.
  1855. std::string desired_config = config;
  1856. if (config.empty()) {
  1857. desired_config = "NOCONFIG";
  1858. }
  1859. std::string result;
  1860. cmProp loc = nullptr;
  1861. cmProp imp = nullptr;
  1862. std::string suffix;
  1863. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  1864. this->GetMappedConfig(desired_config, loc, imp, suffix)) {
  1865. switch (artifact) {
  1866. case cmStateEnums::RuntimeBinaryArtifact:
  1867. if (loc) {
  1868. result = *loc;
  1869. } else {
  1870. std::string impProp = cmStrCat("IMPORTED_LOCATION", suffix);
  1871. if (cmProp config_location = this->GetProperty(impProp)) {
  1872. result = *config_location;
  1873. } else if (cmProp location =
  1874. this->GetProperty("IMPORTED_LOCATION")) {
  1875. result = *location;
  1876. }
  1877. }
  1878. break;
  1879. case cmStateEnums::ImportLibraryArtifact:
  1880. if (imp) {
  1881. result = *imp;
  1882. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1883. this->IsExecutableWithExports()) {
  1884. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  1885. if (cmProp config_implib = this->GetProperty(impProp)) {
  1886. result = *config_implib;
  1887. } else if (cmProp implib = this->GetProperty("IMPORTED_IMPLIB")) {
  1888. result = *implib;
  1889. }
  1890. }
  1891. break;
  1892. }
  1893. }
  1894. if (result.empty()) {
  1895. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  1896. auto message = [&]() -> std::string {
  1897. std::string unset;
  1898. std::string configuration;
  1899. if (artifact == cmStateEnums::RuntimeBinaryArtifact) {
  1900. unset = "IMPORTED_LOCATION";
  1901. } else if (artifact == cmStateEnums::ImportLibraryArtifact) {
  1902. unset = "IMPORTED_IMPLIB";
  1903. }
  1904. if (!config.empty()) {
  1905. configuration = cmStrCat(" configuration \"", config, "\"");
  1906. }
  1907. return cmStrCat(unset, " not set for imported target \"",
  1908. this->GetName(), "\"", configuration, ".");
  1909. };
  1910. switch (this->GetPolicyStatus(cmPolicies::CMP0111)) {
  1911. case cmPolicies::WARN:
  1912. this->impl->Makefile->IssueMessage(
  1913. MessageType::AUTHOR_WARNING,
  1914. cmPolicies::GetPolicyWarning(cmPolicies::CMP0111) + "\n" +
  1915. message());
  1916. CM_FALLTHROUGH;
  1917. case cmPolicies::OLD:
  1918. break;
  1919. default:
  1920. this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1921. message());
  1922. }
  1923. }
  1924. result = cmStrCat(this->GetName(), "-NOTFOUND");
  1925. }
  1926. return result;
  1927. }
  1928. bool cmTargetInternals::CheckImportedLibName(std::string const& prop,
  1929. std::string const& value) const
  1930. {
  1931. if (this->TargetType != cmStateEnums::INTERFACE_LIBRARY ||
  1932. !this->IsImportedTarget) {
  1933. this->Makefile->IssueMessage(
  1934. MessageType::FATAL_ERROR,
  1935. prop +
  1936. " property may be set only on imported INTERFACE library targets.");
  1937. return false;
  1938. }
  1939. if (!value.empty()) {
  1940. if (value[0] == '-') {
  1941. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1942. prop + " property value\n " + value +
  1943. "\nmay not start with '-'.");
  1944. return false;
  1945. }
  1946. std::string::size_type bad = value.find_first_of(":/\\;");
  1947. if (bad != std::string::npos) {
  1948. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  1949. prop + " property value\n " + value +
  1950. "\nmay not contain '" +
  1951. value.substr(bad, 1) + "'.");
  1952. return false;
  1953. }
  1954. }
  1955. return true;
  1956. }
  1957. bool cmTarget::GetMappedConfig(std::string const& desired_config, cmProp& loc,
  1958. cmProp& imp, std::string& suffix) const
  1959. {
  1960. std::string config_upper;
  1961. if (!desired_config.empty()) {
  1962. config_upper = cmSystemTools::UpperCase(desired_config);
  1963. }
  1964. std::string locPropBase;
  1965. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  1966. locPropBase = "IMPORTED_LIBNAME";
  1967. } else if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1968. locPropBase = "IMPORTED_OBJECTS";
  1969. } else {
  1970. locPropBase = "IMPORTED_LOCATION";
  1971. }
  1972. // Track the configuration-specific property suffix.
  1973. suffix = cmStrCat('_', config_upper);
  1974. std::vector<std::string> mappedConfigs;
  1975. {
  1976. std::string mapProp = cmStrCat("MAP_IMPORTED_CONFIG_", config_upper);
  1977. if (cmProp mapValue = this->GetProperty(mapProp)) {
  1978. cmExpandList(*mapValue, mappedConfigs, true);
  1979. }
  1980. }
  1981. // If we needed to find one of the mapped configurations but did not
  1982. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  1983. // library or an executable with exports.
  1984. bool allowImp = (this->IsDLLPlatform() &&
  1985. (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1986. this->IsExecutableWithExports())) ||
  1987. (this->IsAIX() && this->IsExecutableWithExports());
  1988. // If a mapping was found, check its configurations.
  1989. for (auto mci = mappedConfigs.begin();
  1990. !loc && !imp && mci != mappedConfigs.end(); ++mci) {
  1991. // Look for this configuration.
  1992. if (mci->empty()) {
  1993. // An empty string in the mapping has a special meaning:
  1994. // look up the config-less properties.
  1995. loc = this->GetProperty(locPropBase);
  1996. if (allowImp) {
  1997. imp = this->GetProperty("IMPORTED_IMPLIB");
  1998. }
  1999. // If it was found, set the suffix.
  2000. if (loc || imp) {
  2001. suffix.clear();
  2002. }
  2003. } else {
  2004. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  2005. std::string locProp = cmStrCat(locPropBase, '_', mcUpper);
  2006. loc = this->GetProperty(locProp);
  2007. if (allowImp) {
  2008. std::string impProp = cmStrCat("IMPORTED_IMPLIB_", mcUpper);
  2009. imp = this->GetProperty(impProp);
  2010. }
  2011. // If it was found, use it for all properties below.
  2012. if (loc || imp) {
  2013. suffix = cmStrCat('_', mcUpper);
  2014. }
  2015. }
  2016. }
  2017. // If we needed to find one of the mapped configurations but did not
  2018. // then the target location is not found. The project does not want
  2019. // any other configuration.
  2020. if (!mappedConfigs.empty() && !loc && !imp) {
  2021. // Interface libraries are always available because their
  2022. // library name is optional so it is okay to leave loc empty.
  2023. return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
  2024. }
  2025. // If we have not yet found it then there are no mapped
  2026. // configurations. Look for an exact-match.
  2027. if (!loc && !imp) {
  2028. std::string locProp = cmStrCat(locPropBase, suffix);
  2029. loc = this->GetProperty(locProp);
  2030. if (allowImp) {
  2031. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  2032. imp = this->GetProperty(impProp);
  2033. }
  2034. }
  2035. // If we have not yet found it then there are no mapped
  2036. // configurations and no exact match.
  2037. if (!loc && !imp) {
  2038. // The suffix computed above is not useful.
  2039. suffix.clear();
  2040. // Look for a configuration-less location. This may be set by
  2041. // manually-written code.
  2042. loc = this->GetProperty(locPropBase);
  2043. if (allowImp) {
  2044. imp = this->GetProperty("IMPORTED_IMPLIB");
  2045. }
  2046. }
  2047. // If we have not yet found it then the project is willing to try
  2048. // any available configuration.
  2049. if (!loc && !imp) {
  2050. std::vector<std::string> availableConfigs;
  2051. if (cmProp iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS")) {
  2052. cmExpandList(*iconfigs, availableConfigs);
  2053. }
  2054. for (auto aci = availableConfigs.begin();
  2055. !loc && !imp && aci != availableConfigs.end(); ++aci) {
  2056. suffix = cmStrCat('_', cmSystemTools::UpperCase(*aci));
  2057. std::string locProp = cmStrCat(locPropBase, suffix);
  2058. loc = this->GetProperty(locProp);
  2059. if (allowImp) {
  2060. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  2061. imp = this->GetProperty(impProp);
  2062. }
  2063. }
  2064. }
  2065. // If we have not yet found it then the target location is not available.
  2066. if (!loc && !imp) {
  2067. // Interface libraries are always available because their
  2068. // library name is optional so it is okay to leave loc empty.
  2069. return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
  2070. }
  2071. return true;
  2072. }