cmTarget.cxx 72 KB

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