cmTarget.cxx 73 KB

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