cmTarget.cxx 73 KB

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