cmTarget.cxx 72 KB

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