cmTarget.cxx 72 KB

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