cmTarget.cxx 72 KB

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