1
0

cmTarget.cxx 70 KB

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