cmTarget.cxx 72 KB

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