cmTarget.cxx 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  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 "cmsys/RegularExpression.hxx"
  5. #include <algorithm>
  6. #include <assert.h>
  7. #include <map>
  8. #include <set>
  9. #include <sstream>
  10. #include <string.h>
  11. #include <unordered_set>
  12. #include "cmAlgorithms.h"
  13. #include "cmGeneratorExpression.h"
  14. #include "cmGeneratorTarget.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmListFileCache.h"
  17. #include "cmMakefile.h"
  18. #include "cmMessenger.h"
  19. #include "cmOutputConverter.h"
  20. #include "cmProperty.h"
  21. #include "cmSourceFile.h"
  22. #include "cmSourceFileLocation.h"
  23. #include "cmState.h"
  24. #include "cmStateDirectory.h"
  25. #include "cmStateSnapshot.h"
  26. #include "cmSystemTools.h"
  27. #include "cmTargetPropertyComputer.h"
  28. #include "cmake.h"
  29. template <>
  30. const char* cmTargetPropertyComputer::ComputeLocationForBuild<cmTarget>(
  31. cmTarget const* tgt)
  32. {
  33. static std::string loc;
  34. if (tgt->IsImported()) {
  35. loc = tgt->ImportedGetFullPath("", cmStateEnums::RuntimeBinaryArtifact);
  36. return loc.c_str();
  37. }
  38. cmGlobalGenerator* gg = tgt->GetGlobalGenerator();
  39. if (!gg->GetConfigureDoneCMP0026()) {
  40. gg->CreateGenerationObjects();
  41. }
  42. cmGeneratorTarget* gt = gg->FindGeneratorTarget(tgt->GetName());
  43. loc = gt->GetLocationForBuild();
  44. return loc.c_str();
  45. }
  46. template <>
  47. const char* cmTargetPropertyComputer::ComputeLocation<cmTarget>(
  48. cmTarget const* tgt, const std::string& config)
  49. {
  50. static std::string loc;
  51. if (tgt->IsImported()) {
  52. loc =
  53. tgt->ImportedGetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  54. return loc.c_str();
  55. }
  56. cmGlobalGenerator* gg = tgt->GetGlobalGenerator();
  57. if (!gg->GetConfigureDoneCMP0026()) {
  58. gg->CreateGenerationObjects();
  59. }
  60. cmGeneratorTarget* gt = gg->FindGeneratorTarget(tgt->GetName());
  61. loc = gt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  62. return loc.c_str();
  63. }
  64. template <>
  65. const char* cmTargetPropertyComputer::GetSources<cmTarget>(
  66. cmTarget const* tgt, cmMessenger* messenger,
  67. cmListFileBacktrace const& context)
  68. {
  69. cmStringRange entries = tgt->GetSourceEntries();
  70. if (entries.empty()) {
  71. return nullptr;
  72. }
  73. std::ostringstream ss;
  74. const char* sep = "";
  75. for (std::string const& entry : entries) {
  76. std::vector<std::string> files;
  77. cmSystemTools::ExpandListArgument(entry, files);
  78. for (std::string const& file : files) {
  79. if (cmHasLiteralPrefix(file, "$<TARGET_OBJECTS:") &&
  80. file[file.size() - 1] == '>') {
  81. std::string objLibName = file.substr(17, file.size() - 18);
  82. if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
  83. ss << sep;
  84. sep = ";";
  85. ss << file;
  86. continue;
  87. }
  88. bool addContent = false;
  89. bool noMessage = true;
  90. std::ostringstream e;
  91. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  92. switch (context.GetBottom().GetPolicy(cmPolicies::CMP0051)) {
  93. case cmPolicies::WARN:
  94. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
  95. noMessage = false;
  96. case cmPolicies::OLD:
  97. break;
  98. case cmPolicies::REQUIRED_ALWAYS:
  99. case cmPolicies::REQUIRED_IF_USED:
  100. case cmPolicies::NEW:
  101. addContent = true;
  102. }
  103. if (!noMessage) {
  104. e << "Target \"" << tgt->GetName()
  105. << "\" contains "
  106. "$<TARGET_OBJECTS> generator expression in its sources "
  107. "list. "
  108. "This content was not previously part of the SOURCES "
  109. "property "
  110. "when that property was read at configure time. Code "
  111. "reading "
  112. "that property needs to be adapted to ignore the generator "
  113. "expression using the string(GENEX_STRIP) command.";
  114. messenger->IssueMessage(messageType, e.str(), context);
  115. }
  116. if (addContent) {
  117. ss << sep;
  118. sep = ";";
  119. ss << file;
  120. }
  121. } else if (cmGeneratorExpression::Find(file) == std::string::npos) {
  122. ss << sep;
  123. sep = ";";
  124. ss << file;
  125. } else {
  126. cmSourceFile* sf = tgt->GetMakefile()->GetOrCreateSource(file);
  127. // Construct what is known about this source file location.
  128. cmSourceFileLocation const& location = sf->GetLocation();
  129. std::string sname = location.GetDirectory();
  130. if (!sname.empty()) {
  131. sname += "/";
  132. }
  133. sname += location.GetName();
  134. ss << sep;
  135. sep = ";";
  136. // Append this list entry.
  137. ss << sname;
  138. }
  139. }
  140. }
  141. static std::string srcs;
  142. srcs = ss.str();
  143. return srcs.c_str();
  144. }
  145. class cmTargetInternals
  146. {
  147. public:
  148. std::vector<std::string> IncludeDirectoriesEntries;
  149. std::vector<cmListFileBacktrace> IncludeDirectoriesBacktraces;
  150. std::vector<std::string> CompileOptionsEntries;
  151. std::vector<cmListFileBacktrace> CompileOptionsBacktraces;
  152. std::vector<std::string> CompileFeaturesEntries;
  153. std::vector<cmListFileBacktrace> CompileFeaturesBacktraces;
  154. std::vector<std::string> CompileDefinitionsEntries;
  155. std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces;
  156. std::vector<std::string> SourceEntries;
  157. std::vector<cmListFileBacktrace> SourceBacktraces;
  158. std::vector<std::string> LinkImplementationPropertyEntries;
  159. std::vector<cmListFileBacktrace> LinkImplementationPropertyBacktraces;
  160. };
  161. cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
  162. Visibility vis, cmMakefile* mf)
  163. {
  164. assert(mf);
  165. this->Name = name;
  166. this->TargetTypeValue = type;
  167. this->Makefile = mf;
  168. this->HaveInstallRule = false;
  169. this->DLLPlatform = false;
  170. this->IsAndroid = false;
  171. this->IsImportedTarget =
  172. (vis == VisibilityImported || vis == VisibilityImportedGlobally);
  173. this->ImportedGloballyVisible = vis == VisibilityImportedGlobally;
  174. this->BuildInterfaceIncludesAppended = false;
  175. // only add dependency information for library targets
  176. if (this->TargetTypeValue >= cmStateEnums::STATIC_LIBRARY &&
  177. this->TargetTypeValue <= cmStateEnums::MODULE_LIBRARY) {
  178. this->RecordDependencies = true;
  179. } else {
  180. this->RecordDependencies = false;
  181. }
  182. // Check whether this is a DLL platform.
  183. this->DLLPlatform =
  184. (this->Makefile->IsOn("WIN32") || this->Makefile->IsOn("CYGWIN") ||
  185. this->Makefile->IsOn("MINGW"));
  186. // Check whether we are targeting an Android platform.
  187. this->IsAndroid =
  188. strcmp(this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME"),
  189. "Android") == 0;
  190. // Setup default property values.
  191. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  192. this->GetType() != cmStateEnums::UTILITY) {
  193. this->SetPropertyDefault("ANDROID_API", nullptr);
  194. this->SetPropertyDefault("ANDROID_API_MIN", nullptr);
  195. this->SetPropertyDefault("ANDROID_ARCH", nullptr);
  196. this->SetPropertyDefault("ANDROID_STL_TYPE", nullptr);
  197. this->SetPropertyDefault("ANDROID_SKIP_ANT_STEP", nullptr);
  198. this->SetPropertyDefault("ANDROID_PROCESS_MAX", nullptr);
  199. this->SetPropertyDefault("ANDROID_PROGUARD", nullptr);
  200. this->SetPropertyDefault("ANDROID_PROGUARD_CONFIG_PATH", nullptr);
  201. this->SetPropertyDefault("ANDROID_SECURE_PROPS_PATH", nullptr);
  202. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DIRECTORIES", nullptr);
  203. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DEPENDENCIES", nullptr);
  204. this->SetPropertyDefault("ANDROID_JAVA_SOURCE_DIR", nullptr);
  205. this->SetPropertyDefault("ANDROID_JAR_DIRECTORIES", nullptr);
  206. this->SetPropertyDefault("ANDROID_JAR_DEPENDENCIES", nullptr);
  207. this->SetPropertyDefault("ANDROID_ASSETS_DIRECTORIES", nullptr);
  208. this->SetPropertyDefault("ANDROID_ANT_ADDITIONAL_OPTIONS", nullptr);
  209. this->SetPropertyDefault("BUILD_RPATH", nullptr);
  210. this->SetPropertyDefault("INSTALL_NAME_DIR", nullptr);
  211. this->SetPropertyDefault("INSTALL_RPATH", "");
  212. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  213. this->SetPropertyDefault("INTERPROCEDURAL_OPTIMIZATION", nullptr);
  214. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  215. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  216. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", nullptr);
  217. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", nullptr);
  218. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", nullptr);
  219. this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", nullptr);
  220. this->SetPropertyDefault("COMPILE_PDB_OUTPUT_DIRECTORY", nullptr);
  221. this->SetPropertyDefault("Fortran_FORMAT", nullptr);
  222. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", nullptr);
  223. this->SetPropertyDefault("GNUtoMS", nullptr);
  224. this->SetPropertyDefault("OSX_ARCHITECTURES", nullptr);
  225. this->SetPropertyDefault("IOS_INSTALL_COMBINED", nullptr);
  226. this->SetPropertyDefault("AUTOMOC", nullptr);
  227. this->SetPropertyDefault("AUTOUIC", nullptr);
  228. this->SetPropertyDefault("AUTORCC", nullptr);
  229. this->SetPropertyDefault("AUTOMOC_DEPEND_FILTERS", nullptr);
  230. this->SetPropertyDefault("AUTOMOC_MACRO_NAMES", nullptr);
  231. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", nullptr);
  232. this->SetPropertyDefault("AUTOUIC_OPTIONS", nullptr);
  233. this->SetPropertyDefault("AUTOUIC_SEARCH_PATHS", nullptr);
  234. this->SetPropertyDefault("AUTORCC_OPTIONS", nullptr);
  235. this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", nullptr);
  236. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", nullptr);
  237. this->SetPropertyDefault("WIN32_EXECUTABLE", nullptr);
  238. this->SetPropertyDefault("MACOSX_BUNDLE", nullptr);
  239. this->SetPropertyDefault("MACOSX_RPATH", nullptr);
  240. this->SetPropertyDefault("BUILD_WITH_INSTALL_NAME_DIR", nullptr);
  241. this->SetPropertyDefault("C_CLANG_TIDY", nullptr);
  242. this->SetPropertyDefault("C_COMPILER_LAUNCHER", nullptr);
  243. this->SetPropertyDefault("C_CPPLINT", nullptr);
  244. this->SetPropertyDefault("C_CPPCHECK", nullptr);
  245. this->SetPropertyDefault("C_INCLUDE_WHAT_YOU_USE", nullptr);
  246. this->SetPropertyDefault("LINK_WHAT_YOU_USE", nullptr);
  247. this->SetPropertyDefault("C_STANDARD", nullptr);
  248. this->SetPropertyDefault("C_STANDARD_REQUIRED", nullptr);
  249. this->SetPropertyDefault("C_EXTENSIONS", nullptr);
  250. this->SetPropertyDefault("CXX_CLANG_TIDY", nullptr);
  251. this->SetPropertyDefault("CXX_COMPILER_LAUNCHER", nullptr);
  252. this->SetPropertyDefault("CXX_CPPLINT", nullptr);
  253. this->SetPropertyDefault("CXX_CPPCHECK", nullptr);
  254. this->SetPropertyDefault("CXX_INCLUDE_WHAT_YOU_USE", nullptr);
  255. this->SetPropertyDefault("CXX_STANDARD", nullptr);
  256. this->SetPropertyDefault("CXX_STANDARD_REQUIRED", nullptr);
  257. this->SetPropertyDefault("CXX_EXTENSIONS", nullptr);
  258. this->SetPropertyDefault("CUDA_STANDARD", nullptr);
  259. this->SetPropertyDefault("CUDA_STANDARD_REQUIRED", nullptr);
  260. this->SetPropertyDefault("CUDA_EXTENSIONS", nullptr);
  261. this->SetPropertyDefault("CUDA_COMPILER_LAUNCHER", nullptr);
  262. this->SetPropertyDefault("LINK_SEARCH_START_STATIC", nullptr);
  263. this->SetPropertyDefault("LINK_SEARCH_END_STATIC", nullptr);
  264. }
  265. if (this->GetType() != cmStateEnums::UTILITY) {
  266. this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", nullptr);
  267. }
  268. // Collect the set of configuration types.
  269. std::vector<std::string> configNames;
  270. mf->GetConfigurations(configNames);
  271. // Setup per-configuration property default values.
  272. if (this->GetType() != cmStateEnums::UTILITY) {
  273. const char* configProps[] = {
  274. /* clang-format needs this comment to break after the opening brace */
  275. "ARCHIVE_OUTPUT_DIRECTORY_", "LIBRARY_OUTPUT_DIRECTORY_",
  276. "RUNTIME_OUTPUT_DIRECTORY_", "PDB_OUTPUT_DIRECTORY_",
  277. "COMPILE_PDB_OUTPUT_DIRECTORY_", "MAP_IMPORTED_CONFIG_",
  278. "INTERPROCEDURAL_OPTIMIZATION_", nullptr
  279. };
  280. for (std::string const& configName : configNames) {
  281. std::string configUpper = cmSystemTools::UpperCase(configName);
  282. for (const char** p = configProps; *p; ++p) {
  283. // Interface libraries have no output locations, so honor only
  284. // the configuration map.
  285. if (this->TargetTypeValue == cmStateEnums::INTERFACE_LIBRARY &&
  286. strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0) {
  287. continue;
  288. }
  289. std::string property = *p;
  290. property += configUpper;
  291. this->SetPropertyDefault(property, nullptr);
  292. }
  293. // Initialize per-configuration name postfix property from the
  294. // variable only for non-executable targets. This preserves
  295. // compatibility with previous CMake versions in which executables
  296. // did not support this variable. Projects may still specify the
  297. // property directly.
  298. if (this->TargetTypeValue != cmStateEnums::EXECUTABLE &&
  299. this->TargetTypeValue != cmStateEnums::INTERFACE_LIBRARY) {
  300. std::string property = cmSystemTools::UpperCase(configName);
  301. property += "_POSTFIX";
  302. this->SetPropertyDefault(property, nullptr);
  303. }
  304. }
  305. }
  306. // Save the backtrace of target construction.
  307. this->Backtrace = this->Makefile->GetBacktrace();
  308. if (!this->IsImported()) {
  309. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  310. // of the same directory property:
  311. const cmStringRange parentIncludes =
  312. this->Makefile->GetIncludeDirectoriesEntries();
  313. const cmBacktraceRange parentIncludesBts =
  314. this->Makefile->GetIncludeDirectoriesBacktraces();
  315. this->Internal->IncludeDirectoriesEntries.insert(
  316. this->Internal->IncludeDirectoriesEntries.end(), parentIncludes.begin(),
  317. parentIncludes.end());
  318. this->Internal->IncludeDirectoriesBacktraces.insert(
  319. this->Internal->IncludeDirectoriesBacktraces.end(),
  320. parentIncludesBts.begin(), parentIncludesBts.end());
  321. const std::set<std::string> parentSystemIncludes =
  322. this->Makefile->GetSystemIncludeDirectories();
  323. this->SystemIncludeDirectories.insert(parentSystemIncludes.begin(),
  324. parentSystemIncludes.end());
  325. const cmStringRange parentOptions =
  326. this->Makefile->GetCompileOptionsEntries();
  327. const cmBacktraceRange parentOptionsBts =
  328. this->Makefile->GetCompileOptionsBacktraces();
  329. this->Internal->CompileOptionsEntries.insert(
  330. this->Internal->CompileOptionsEntries.end(), parentOptions.begin(),
  331. parentOptions.end());
  332. this->Internal->CompileOptionsBacktraces.insert(
  333. this->Internal->CompileOptionsBacktraces.end(), parentOptionsBts.begin(),
  334. parentOptionsBts.end());
  335. }
  336. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  337. this->GetType() != cmStateEnums::UTILITY) {
  338. this->SetPropertyDefault("C_VISIBILITY_PRESET", nullptr);
  339. this->SetPropertyDefault("CXX_VISIBILITY_PRESET", nullptr);
  340. this->SetPropertyDefault("CUDA_VISIBILITY_PRESET", nullptr);
  341. this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", nullptr);
  342. }
  343. if (this->TargetTypeValue == cmStateEnums::EXECUTABLE) {
  344. this->SetPropertyDefault("ANDROID_GUI", nullptr);
  345. this->SetPropertyDefault("CROSSCOMPILING_EMULATOR", nullptr);
  346. this->SetPropertyDefault("ENABLE_EXPORTS", nullptr);
  347. }
  348. if (this->TargetTypeValue == cmStateEnums::SHARED_LIBRARY ||
  349. this->TargetTypeValue == cmStateEnums::MODULE_LIBRARY) {
  350. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  351. }
  352. if (this->TargetTypeValue == cmStateEnums::SHARED_LIBRARY ||
  353. this->TargetTypeValue == cmStateEnums::EXECUTABLE) {
  354. this->SetPropertyDefault("WINDOWS_EXPORT_ALL_SYMBOLS", nullptr);
  355. }
  356. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  357. this->GetType() != cmStateEnums::UTILITY) {
  358. this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", nullptr);
  359. }
  360. // Record current policies for later use.
  361. this->Makefile->RecordPolicies(this->PolicyMap);
  362. if (this->TargetTypeValue == cmStateEnums::INTERFACE_LIBRARY) {
  363. // This policy is checked in a few conditions. The properties relevant
  364. // to the policy are always ignored for cmStateEnums::INTERFACE_LIBRARY
  365. // targets,
  366. // so ensure that the conditions don't lead to nonsense.
  367. this->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
  368. }
  369. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  370. this->GetType() != cmStateEnums::UTILITY) {
  371. this->SetPropertyDefault("JOB_POOL_COMPILE", nullptr);
  372. this->SetPropertyDefault("JOB_POOL_LINK", nullptr);
  373. }
  374. }
  375. cmGlobalGenerator* cmTarget::GetGlobalGenerator() const
  376. {
  377. return this->GetMakefile()->GetGlobalGenerator();
  378. }
  379. void cmTarget::AddUtility(const std::string& u, cmMakefile* makefile)
  380. {
  381. if (this->Utilities.insert(u).second && makefile) {
  382. this->UtilityBacktraces.insert(
  383. std::make_pair(u, makefile->GetBacktrace()));
  384. }
  385. }
  386. cmListFileBacktrace const* cmTarget::GetUtilityBacktrace(
  387. const std::string& u) const
  388. {
  389. std::map<std::string, cmListFileBacktrace>::const_iterator i =
  390. this->UtilityBacktraces.find(u);
  391. if (i == this->UtilityBacktraces.end()) {
  392. return nullptr;
  393. }
  394. return &i->second;
  395. }
  396. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  397. {
  398. return this->Backtrace;
  399. }
  400. bool cmTarget::IsExecutableWithExports() const
  401. {
  402. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  403. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  404. }
  405. bool cmTarget::HasImportLibrary() const
  406. {
  407. return (this->DLLPlatform &&
  408. (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  409. this->IsExecutableWithExports()));
  410. }
  411. bool cmTarget::IsFrameworkOnApple() const
  412. {
  413. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  414. this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  415. this->Makefile->IsOn("APPLE") &&
  416. this->GetPropertyAsBool("FRAMEWORK"));
  417. }
  418. bool cmTarget::IsAppBundleOnApple() const
  419. {
  420. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  421. this->Makefile->IsOn("APPLE") &&
  422. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  423. }
  424. void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
  425. {
  426. if (!srcs.empty()) {
  427. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  428. this->Internal->SourceEntries.push_back(cmJoin(srcs, ";"));
  429. this->Internal->SourceBacktraces.push_back(lfbt);
  430. }
  431. }
  432. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  433. {
  434. std::string srcFiles;
  435. const char* sep = "";
  436. for (auto filename : srcs) {
  437. const char* src = filename.c_str();
  438. if (!(src[0] == '$' && src[1] == '<')) {
  439. if (!filename.empty()) {
  440. filename = this->ProcessSourceItemCMP0049(filename);
  441. if (filename.empty()) {
  442. return;
  443. }
  444. }
  445. this->Makefile->GetOrCreateSource(filename);
  446. }
  447. srcFiles += sep;
  448. srcFiles += filename;
  449. sep = ";";
  450. }
  451. if (!srcFiles.empty()) {
  452. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  453. this->Internal->SourceEntries.push_back(srcFiles);
  454. this->Internal->SourceBacktraces.push_back(lfbt);
  455. }
  456. }
  457. std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
  458. {
  459. std::string src = s;
  460. // For backwards compatibility replace varibles in source names.
  461. // This should eventually be removed.
  462. this->Makefile->ExpandVariablesInString(src);
  463. if (src != s) {
  464. std::ostringstream e;
  465. bool noMessage = false;
  466. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  467. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0049)) {
  468. case cmPolicies::WARN:
  469. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0049) << "\n";
  470. break;
  471. case cmPolicies::OLD:
  472. noMessage = true;
  473. break;
  474. case cmPolicies::REQUIRED_ALWAYS:
  475. case cmPolicies::REQUIRED_IF_USED:
  476. case cmPolicies::NEW:
  477. messageType = cmake::FATAL_ERROR;
  478. }
  479. if (!noMessage) {
  480. e << "Legacy variable expansion in source file \"" << s
  481. << "\" expanded to \"" << src << "\" in target \"" << this->GetName()
  482. << "\". This behavior will be removed in a "
  483. "future version of CMake.";
  484. this->Makefile->IssueMessage(messageType, e.str());
  485. if (messageType == cmake::FATAL_ERROR) {
  486. return "";
  487. }
  488. }
  489. }
  490. return src;
  491. }
  492. cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s)
  493. {
  494. std::string src = this->ProcessSourceItemCMP0049(s);
  495. if (!s.empty() && src.empty()) {
  496. return nullptr;
  497. }
  498. return this->AddSource(src);
  499. }
  500. struct CreateLocation
  501. {
  502. cmMakefile const* Makefile;
  503. CreateLocation(cmMakefile const* mf)
  504. : Makefile(mf)
  505. {
  506. }
  507. cmSourceFileLocation operator()(const std::string& filename)
  508. {
  509. return cmSourceFileLocation(this->Makefile, filename);
  510. }
  511. };
  512. struct LocationMatcher
  513. {
  514. const cmSourceFileLocation& Needle;
  515. LocationMatcher(const cmSourceFileLocation& needle)
  516. : Needle(needle)
  517. {
  518. }
  519. bool operator()(cmSourceFileLocation& loc)
  520. {
  521. return loc.Matches(this->Needle);
  522. }
  523. };
  524. struct TargetPropertyEntryFinder
  525. {
  526. private:
  527. const cmSourceFileLocation& Needle;
  528. public:
  529. TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
  530. : Needle(needle)
  531. {
  532. }
  533. bool operator()(std::string const& entry)
  534. {
  535. std::vector<std::string> files;
  536. cmSystemTools::ExpandListArgument(entry, files);
  537. std::vector<cmSourceFileLocation> locations(files.size());
  538. std::transform(files.begin(), files.end(), locations.begin(),
  539. CreateLocation(this->Needle.GetMakefile()));
  540. return std::find_if(locations.begin(), locations.end(),
  541. LocationMatcher(this->Needle)) != locations.end();
  542. }
  543. };
  544. cmSourceFile* cmTarget::AddSource(const std::string& src)
  545. {
  546. cmSourceFileLocation sfl(this->Makefile, src);
  547. if (std::find_if(this->Internal->SourceEntries.begin(),
  548. this->Internal->SourceEntries.end(),
  549. TargetPropertyEntryFinder(sfl)) ==
  550. this->Internal->SourceEntries.end()) {
  551. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  552. this->Internal->SourceEntries.push_back(src);
  553. this->Internal->SourceBacktraces.push_back(lfbt);
  554. }
  555. if (cmGeneratorExpression::Find(src) != std::string::npos) {
  556. return nullptr;
  557. }
  558. return this->Makefile->GetOrCreateSource(src);
  559. }
  560. void cmTarget::AddLinkDirectory(const std::string& d)
  561. {
  562. // Make sure we don't add unnecessary search directories.
  563. if (this->LinkDirectoriesEmmitted.insert(d).second) {
  564. this->LinkDirectories.push_back(d);
  565. }
  566. }
  567. const std::vector<std::string>& cmTarget::GetLinkDirectories() const
  568. {
  569. return this->LinkDirectories;
  570. }
  571. void cmTarget::ClearDependencyInformation(cmMakefile& mf,
  572. const std::string& target)
  573. {
  574. // Clear the dependencies. The cache variable must exist iff we are
  575. // recording dependency information for this target.
  576. std::string depname = target;
  577. depname += "_LIB_DEPENDS";
  578. if (this->RecordDependencies) {
  579. mf.AddCacheDefinition(depname, "", "Dependencies for target",
  580. cmStateEnums::STATIC);
  581. } else {
  582. if (mf.GetDefinition(depname)) {
  583. std::string message = "Target ";
  584. message += target;
  585. message += " has dependency information when it shouldn't.\n";
  586. message += "Your cache is probably stale. Please remove the entry\n ";
  587. message += depname;
  588. message += "\nfrom the cache.";
  589. cmSystemTools::Error(message.c_str());
  590. }
  591. }
  592. }
  593. std::string cmTarget::GetDebugGeneratorExpressions(
  594. const std::string& value, cmTargetLinkLibraryType llt) const
  595. {
  596. if (llt == GENERAL_LibraryType) {
  597. return value;
  598. }
  599. // Get the list of configurations considered to be DEBUG.
  600. std::vector<std::string> debugConfigs =
  601. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  602. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  603. if (debugConfigs.size() > 1) {
  604. for (std::vector<std::string>::const_iterator li =
  605. debugConfigs.begin() + 1;
  606. li != debugConfigs.end(); ++li) {
  607. configString += ",$<CONFIG:" + *li + ">";
  608. }
  609. configString = "$<OR:" + configString + ">";
  610. }
  611. if (llt == OPTIMIZED_LibraryType) {
  612. configString = "$<NOT:" + configString + ">";
  613. }
  614. return "$<" + configString + ":" + value + ">";
  615. }
  616. static std::string targetNameGenex(const std::string& lib)
  617. {
  618. return "$<TARGET_NAME:" + lib + ">";
  619. }
  620. bool cmTarget::PushTLLCommandTrace(TLLSignature signature,
  621. cmListFileContext const& lfc)
  622. {
  623. bool ret = true;
  624. if (!this->TLLCommands.empty()) {
  625. if (this->TLLCommands.back().first != signature) {
  626. ret = false;
  627. }
  628. }
  629. if (this->TLLCommands.empty() || this->TLLCommands.back().second != lfc) {
  630. this->TLLCommands.push_back(std::make_pair(signature, lfc));
  631. }
  632. return ret;
  633. }
  634. void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const
  635. {
  636. const char* sigString =
  637. (sig == cmTarget::KeywordTLLSignature ? "keyword" : "plain");
  638. s << "The uses of the " << sigString << " signature are here:\n";
  639. cmOutputConverter converter(this->GetMakefile()->GetStateSnapshot());
  640. for (auto const& cmd : this->TLLCommands) {
  641. if (cmd.first == sig) {
  642. cmListFileContext lfc = cmd.second;
  643. lfc.FilePath = converter.ConvertToRelativePath(
  644. this->Makefile->GetState()->GetSourceDirectory(), lfc.FilePath);
  645. s << " * " << lfc << std::endl;
  646. }
  647. }
  648. }
  649. void cmTarget::AddLinkLibrary(cmMakefile& mf, const std::string& lib,
  650. cmTargetLinkLibraryType llt)
  651. {
  652. cmTarget* tgt = this->Makefile->FindTargetToUse(lib);
  653. {
  654. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  655. const std::string libName =
  656. (isNonImportedTarget && llt != GENERAL_LibraryType)
  657. ? targetNameGenex(lib)
  658. : lib;
  659. this->AppendProperty(
  660. "LINK_LIBRARIES",
  661. this->GetDebugGeneratorExpressions(libName, llt).c_str());
  662. }
  663. if (cmGeneratorExpression::Find(lib) != std::string::npos ||
  664. (tgt && tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) ||
  665. (this->Name == lib)) {
  666. return;
  667. }
  668. cmTarget::LibraryID tmp;
  669. tmp.first = lib;
  670. tmp.second = llt;
  671. this->OriginalLinkLibraries.push_back(tmp);
  672. // Add the explicit dependency information for this target. This is
  673. // simply a set of libraries separated by ";". There should always
  674. // be a trailing ";". These library names are not canonical, in that
  675. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  676. // We shouldn't remove duplicates here because external libraries
  677. // may be purposefully duplicated to handle recursive dependencies,
  678. // and we removing one instance will break the link line. Duplicates
  679. // will be appropriately eliminated at emit time.
  680. if (this->RecordDependencies) {
  681. std::string targetEntry = this->Name;
  682. targetEntry += "_LIB_DEPENDS";
  683. std::string dependencies;
  684. const char* old_val = mf.GetDefinition(targetEntry);
  685. if (old_val) {
  686. dependencies += old_val;
  687. }
  688. switch (llt) {
  689. case GENERAL_LibraryType:
  690. dependencies += "general";
  691. break;
  692. case DEBUG_LibraryType:
  693. dependencies += "debug";
  694. break;
  695. case OPTIMIZED_LibraryType:
  696. dependencies += "optimized";
  697. break;
  698. }
  699. dependencies += ";";
  700. dependencies += lib;
  701. dependencies += ";";
  702. mf.AddCacheDefinition(targetEntry, dependencies.c_str(),
  703. "Dependencies for the target", cmStateEnums::STATIC);
  704. }
  705. }
  706. void cmTarget::AddSystemIncludeDirectories(const std::set<std::string>& incs)
  707. {
  708. this->SystemIncludeDirectories.insert(incs.begin(), incs.end());
  709. }
  710. cmStringRange cmTarget::GetIncludeDirectoriesEntries() const
  711. {
  712. return cmMakeRange(this->Internal->IncludeDirectoriesEntries);
  713. }
  714. cmBacktraceRange cmTarget::GetIncludeDirectoriesBacktraces() const
  715. {
  716. return cmMakeRange(this->Internal->IncludeDirectoriesBacktraces);
  717. }
  718. cmStringRange cmTarget::GetCompileOptionsEntries() const
  719. {
  720. return cmMakeRange(this->Internal->CompileOptionsEntries);
  721. }
  722. cmBacktraceRange cmTarget::GetCompileOptionsBacktraces() const
  723. {
  724. return cmMakeRange(this->Internal->CompileOptionsBacktraces);
  725. }
  726. cmStringRange cmTarget::GetCompileFeaturesEntries() const
  727. {
  728. return cmMakeRange(this->Internal->CompileFeaturesEntries);
  729. }
  730. cmBacktraceRange cmTarget::GetCompileFeaturesBacktraces() const
  731. {
  732. return cmMakeRange(this->Internal->CompileFeaturesBacktraces);
  733. }
  734. cmStringRange cmTarget::GetCompileDefinitionsEntries() const
  735. {
  736. return cmMakeRange(this->Internal->CompileDefinitionsEntries);
  737. }
  738. cmBacktraceRange cmTarget::GetCompileDefinitionsBacktraces() const
  739. {
  740. return cmMakeRange(this->Internal->CompileDefinitionsBacktraces);
  741. }
  742. cmStringRange cmTarget::GetSourceEntries() const
  743. {
  744. return cmMakeRange(this->Internal->SourceEntries);
  745. }
  746. cmBacktraceRange cmTarget::GetSourceBacktraces() const
  747. {
  748. return cmMakeRange(this->Internal->SourceBacktraces);
  749. }
  750. cmStringRange cmTarget::GetLinkImplementationEntries() const
  751. {
  752. return cmMakeRange(this->Internal->LinkImplementationPropertyEntries);
  753. }
  754. cmBacktraceRange cmTarget::GetLinkImplementationBacktraces() const
  755. {
  756. return cmMakeRange(this->Internal->LinkImplementationPropertyBacktraces);
  757. }
  758. void cmTarget::SetProperty(const std::string& prop, const char* value)
  759. {
  760. if (!cmTargetPropertyComputer::PassesWhitelist(
  761. this->GetType(), prop, this->Makefile->GetMessenger(),
  762. this->Makefile->GetBacktrace())) {
  763. return;
  764. }
  765. if (prop == "MANUALLY_ADDED_DEPENDENCIES") {
  766. std::ostringstream e;
  767. e << "MANUALLY_ADDED_DEPENDENCIES property is read-only\n";
  768. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  769. return;
  770. }
  771. if (prop == "NAME") {
  772. std::ostringstream e;
  773. e << "NAME property is read-only\n";
  774. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  775. return;
  776. }
  777. if (prop == "TYPE") {
  778. std::ostringstream e;
  779. e << "TYPE property is read-only\n";
  780. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  781. return;
  782. }
  783. if (prop == "EXPORT_NAME" && this->IsImported()) {
  784. std::ostringstream e;
  785. e << "EXPORT_NAME property can't be set on imported targets (\""
  786. << this->Name << "\")\n";
  787. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  788. return;
  789. }
  790. if (prop == "SOURCES" && this->IsImported()) {
  791. std::ostringstream e;
  792. e << "SOURCES property can't be set on imported targets (\"" << this->Name
  793. << "\")\n";
  794. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  795. return;
  796. }
  797. if (prop == "INCLUDE_DIRECTORIES") {
  798. this->Internal->IncludeDirectoriesEntries.clear();
  799. this->Internal->IncludeDirectoriesBacktraces.clear();
  800. if (value) {
  801. this->Internal->IncludeDirectoriesEntries.push_back(value);
  802. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  803. this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
  804. }
  805. } else if (prop == "COMPILE_OPTIONS") {
  806. this->Internal->CompileOptionsEntries.clear();
  807. this->Internal->CompileOptionsBacktraces.clear();
  808. if (value) {
  809. this->Internal->CompileOptionsEntries.push_back(value);
  810. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  811. this->Internal->CompileOptionsBacktraces.push_back(lfbt);
  812. }
  813. } else if (prop == "COMPILE_FEATURES") {
  814. this->Internal->CompileFeaturesEntries.clear();
  815. this->Internal->CompileFeaturesBacktraces.clear();
  816. if (value) {
  817. this->Internal->CompileFeaturesEntries.push_back(value);
  818. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  819. this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
  820. }
  821. } else if (prop == "COMPILE_DEFINITIONS") {
  822. this->Internal->CompileDefinitionsEntries.clear();
  823. this->Internal->CompileDefinitionsBacktraces.clear();
  824. if (value) {
  825. this->Internal->CompileDefinitionsEntries.push_back(value);
  826. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  827. this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
  828. }
  829. } else if (prop == "LINK_LIBRARIES") {
  830. this->Internal->LinkImplementationPropertyEntries.clear();
  831. this->Internal->LinkImplementationPropertyBacktraces.clear();
  832. if (value) {
  833. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  834. this->Internal->LinkImplementationPropertyEntries.push_back(value);
  835. this->Internal->LinkImplementationPropertyBacktraces.push_back(lfbt);
  836. }
  837. } else if (prop == "SOURCES") {
  838. this->Internal->SourceEntries.clear();
  839. this->Internal->SourceBacktraces.clear();
  840. if (value) {
  841. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  842. this->Internal->SourceEntries.push_back(value);
  843. this->Internal->SourceBacktraces.push_back(lfbt);
  844. }
  845. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME") &&
  846. !this->CheckImportedLibName(prop, value ? value : "")) {
  847. /* error was reported by check method */
  848. } else if (prop == "CUDA_PTX_COMPILATION" &&
  849. this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  850. std::ostringstream e;
  851. e << "CUDA_PTX_COMPILATION property can only be applied to OBJECT "
  852. "targets (\""
  853. << this->Name << "\")\n";
  854. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  855. return;
  856. } else {
  857. this->Properties.SetProperty(prop, value);
  858. }
  859. }
  860. void cmTarget::AppendProperty(const std::string& prop, const char* value,
  861. bool asString)
  862. {
  863. if (!cmTargetPropertyComputer::PassesWhitelist(
  864. this->GetType(), prop, this->Makefile->GetMessenger(),
  865. this->Makefile->GetBacktrace())) {
  866. return;
  867. }
  868. if (prop == "NAME") {
  869. std::ostringstream e;
  870. e << "NAME property is read-only\n";
  871. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  872. return;
  873. }
  874. if (prop == "EXPORT_NAME" && this->IsImported()) {
  875. std::ostringstream e;
  876. e << "EXPORT_NAME property can't be set on imported targets (\""
  877. << this->Name << "\")\n";
  878. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  879. return;
  880. }
  881. if (prop == "SOURCES" && this->IsImported()) {
  882. std::ostringstream e;
  883. e << "SOURCES property can't be set on imported targets (\"" << this->Name
  884. << "\")\n";
  885. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  886. return;
  887. }
  888. if (prop == "INCLUDE_DIRECTORIES") {
  889. if (value && *value) {
  890. this->Internal->IncludeDirectoriesEntries.push_back(value);
  891. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  892. this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
  893. }
  894. } else if (prop == "COMPILE_OPTIONS") {
  895. if (value && *value) {
  896. this->Internal->CompileOptionsEntries.push_back(value);
  897. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  898. this->Internal->CompileOptionsBacktraces.push_back(lfbt);
  899. }
  900. } else if (prop == "COMPILE_FEATURES") {
  901. if (value && *value) {
  902. this->Internal->CompileFeaturesEntries.push_back(value);
  903. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  904. this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
  905. }
  906. } else if (prop == "COMPILE_DEFINITIONS") {
  907. if (value && *value) {
  908. this->Internal->CompileDefinitionsEntries.push_back(value);
  909. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  910. this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
  911. }
  912. } else if (prop == "LINK_LIBRARIES") {
  913. if (value && *value) {
  914. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  915. this->Internal->LinkImplementationPropertyEntries.push_back(value);
  916. this->Internal->LinkImplementationPropertyBacktraces.push_back(lfbt);
  917. }
  918. } else if (prop == "SOURCES") {
  919. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  920. this->Internal->SourceEntries.push_back(value);
  921. this->Internal->SourceBacktraces.push_back(lfbt);
  922. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) {
  923. this->Makefile->IssueMessage(cmake::FATAL_ERROR,
  924. prop + " property may not be APPENDed.");
  925. } else {
  926. this->Properties.AppendProperty(prop, value, asString);
  927. }
  928. }
  929. void cmTarget::AppendBuildInterfaceIncludes()
  930. {
  931. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  932. this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  933. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  934. this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  935. !this->IsExecutableWithExports()) {
  936. return;
  937. }
  938. if (this->BuildInterfaceIncludesAppended) {
  939. return;
  940. }
  941. this->BuildInterfaceIncludesAppended = true;
  942. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE")) {
  943. const char* binDir = this->Makefile->GetCurrentBinaryDirectory();
  944. const char* srcDir = this->Makefile->GetCurrentSourceDirectory();
  945. const std::string dirs = std::string(binDir ? binDir : "") +
  946. std::string(binDir ? ";" : "") + std::string(srcDir ? srcDir : "");
  947. if (!dirs.empty()) {
  948. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  949. ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
  950. }
  951. }
  952. }
  953. void cmTarget::InsertInclude(std::string const& entry,
  954. cmListFileBacktrace const& bt, bool before)
  955. {
  956. std::vector<std::string>::iterator position = before
  957. ? this->Internal->IncludeDirectoriesEntries.begin()
  958. : this->Internal->IncludeDirectoriesEntries.end();
  959. std::vector<cmListFileBacktrace>::iterator btPosition = before
  960. ? this->Internal->IncludeDirectoriesBacktraces.begin()
  961. : this->Internal->IncludeDirectoriesBacktraces.end();
  962. this->Internal->IncludeDirectoriesEntries.insert(position, entry);
  963. this->Internal->IncludeDirectoriesBacktraces.insert(btPosition, bt);
  964. }
  965. void cmTarget::InsertCompileOption(std::string const& entry,
  966. cmListFileBacktrace const& bt, bool before)
  967. {
  968. std::vector<std::string>::iterator position = before
  969. ? this->Internal->CompileOptionsEntries.begin()
  970. : this->Internal->CompileOptionsEntries.end();
  971. std::vector<cmListFileBacktrace>::iterator btPosition = before
  972. ? this->Internal->CompileOptionsBacktraces.begin()
  973. : this->Internal->CompileOptionsBacktraces.end();
  974. this->Internal->CompileOptionsEntries.insert(position, entry);
  975. this->Internal->CompileOptionsBacktraces.insert(btPosition, bt);
  976. }
  977. void cmTarget::InsertCompileDefinition(std::string const& entry,
  978. cmListFileBacktrace const& bt)
  979. {
  980. this->Internal->CompileDefinitionsEntries.push_back(entry);
  981. this->Internal->CompileDefinitionsBacktraces.push_back(bt);
  982. }
  983. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(const std::string& prop,
  984. const char* value,
  985. cmMakefile* context,
  986. bool imported)
  987. {
  988. // Look for link-type keywords in the value.
  989. static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
  990. if (!keys.find(value)) {
  991. return;
  992. }
  993. // Support imported and non-imported versions of the property.
  994. const char* base = (imported ? "IMPORTED_LINK_INTERFACE_LIBRARIES"
  995. : "LINK_INTERFACE_LIBRARIES");
  996. // Report an error.
  997. std::ostringstream e;
  998. e << "Property " << prop << " may not contain link-type keyword \""
  999. << keys.match(2) << "\". "
  1000. << "The " << base << " property has a per-configuration "
  1001. << "version called " << base << "_<CONFIG> which may be "
  1002. << "used to specify per-configuration rules.";
  1003. if (!imported) {
  1004. e << " "
  1005. << "Alternatively, an IMPORTED library may be created, configured "
  1006. << "with a per-configuration location, and then named in the "
  1007. << "property value. "
  1008. << "See the add_library command's IMPORTED mode for details."
  1009. << "\n"
  1010. << "If you have a list of libraries that already contains the "
  1011. << "keyword, use the target_link_libraries command with its "
  1012. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  1013. << "The command automatically recognizes link-type keywords and sets "
  1014. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  1015. << "properties accordingly.";
  1016. }
  1017. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  1018. }
  1019. static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
  1020. cmMakefile* context)
  1021. {
  1022. // Look for link-type keywords in the value.
  1023. static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
  1024. if (!keys.find(value)) {
  1025. return;
  1026. }
  1027. // Report an error.
  1028. std::ostringstream e;
  1029. e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
  1030. "keyword \""
  1031. << keys.match(2)
  1032. << "\". The INTERFACE_LINK_LIBRARIES "
  1033. "property may contain configuration-sensitive generator-expressions "
  1034. "which may be used to specify per-configuration rules.";
  1035. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  1036. }
  1037. void cmTarget::CheckProperty(const std::string& prop,
  1038. cmMakefile* context) const
  1039. {
  1040. // Certain properties need checking.
  1041. if (cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES")) {
  1042. if (const char* value = this->GetProperty(prop)) {
  1043. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  1044. }
  1045. }
  1046. if (cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES")) {
  1047. if (const char* value = this->GetProperty(prop)) {
  1048. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  1049. }
  1050. }
  1051. if (cmHasLiteralPrefix(prop, "INTERFACE_LINK_LIBRARIES")) {
  1052. if (const char* value = this->GetProperty(prop)) {
  1053. cmTargetCheckINTERFACE_LINK_LIBRARIES(value, context);
  1054. }
  1055. }
  1056. }
  1057. const char* cmTarget::GetComputedProperty(
  1058. const std::string& prop, cmMessenger* messenger,
  1059. cmListFileBacktrace const& context) const
  1060. {
  1061. return cmTargetPropertyComputer::GetProperty(this, prop, messenger, context);
  1062. }
  1063. const char* cmTarget::GetProperty(const std::string& prop) const
  1064. {
  1065. static std::unordered_set<std::string> specialProps;
  1066. #define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP
  1067. MAKE_STATIC_PROP(LINK_LIBRARIES);
  1068. MAKE_STATIC_PROP(TYPE);
  1069. MAKE_STATIC_PROP(INCLUDE_DIRECTORIES);
  1070. MAKE_STATIC_PROP(COMPILE_FEATURES);
  1071. MAKE_STATIC_PROP(COMPILE_OPTIONS);
  1072. MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
  1073. MAKE_STATIC_PROP(IMPORTED);
  1074. MAKE_STATIC_PROP(MANUALLY_ADDED_DEPENDENCIES);
  1075. MAKE_STATIC_PROP(NAME);
  1076. MAKE_STATIC_PROP(BINARY_DIR);
  1077. MAKE_STATIC_PROP(SOURCE_DIR);
  1078. MAKE_STATIC_PROP(SOURCES);
  1079. #undef MAKE_STATIC_PROP
  1080. if (specialProps.empty()) {
  1081. specialProps.insert(propLINK_LIBRARIES);
  1082. specialProps.insert(propTYPE);
  1083. specialProps.insert(propINCLUDE_DIRECTORIES);
  1084. specialProps.insert(propCOMPILE_FEATURES);
  1085. specialProps.insert(propCOMPILE_OPTIONS);
  1086. specialProps.insert(propCOMPILE_DEFINITIONS);
  1087. specialProps.insert(propIMPORTED);
  1088. specialProps.insert(propMANUALLY_ADDED_DEPENDENCIES);
  1089. specialProps.insert(propNAME);
  1090. specialProps.insert(propBINARY_DIR);
  1091. specialProps.insert(propSOURCE_DIR);
  1092. specialProps.insert(propSOURCES);
  1093. }
  1094. if (specialProps.count(prop)) {
  1095. if (prop == propLINK_LIBRARIES) {
  1096. if (this->Internal->LinkImplementationPropertyEntries.empty()) {
  1097. return nullptr;
  1098. }
  1099. static std::string output;
  1100. output = cmJoin(this->Internal->LinkImplementationPropertyEntries, ";");
  1101. return output.c_str();
  1102. }
  1103. // the type property returns what type the target is
  1104. if (prop == propTYPE) {
  1105. return cmState::GetTargetTypeName(this->GetType());
  1106. }
  1107. if (prop == propINCLUDE_DIRECTORIES) {
  1108. if (this->Internal->IncludeDirectoriesEntries.empty()) {
  1109. return nullptr;
  1110. }
  1111. static std::string output;
  1112. output = cmJoin(this->Internal->IncludeDirectoriesEntries, ";");
  1113. return output.c_str();
  1114. }
  1115. if (prop == propCOMPILE_FEATURES) {
  1116. if (this->Internal->CompileFeaturesEntries.empty()) {
  1117. return nullptr;
  1118. }
  1119. static std::string output;
  1120. output = cmJoin(this->Internal->CompileFeaturesEntries, ";");
  1121. return output.c_str();
  1122. }
  1123. if (prop == propCOMPILE_OPTIONS) {
  1124. if (this->Internal->CompileOptionsEntries.empty()) {
  1125. return nullptr;
  1126. }
  1127. static std::string output;
  1128. output = cmJoin(this->Internal->CompileOptionsEntries, ";");
  1129. return output.c_str();
  1130. }
  1131. if (prop == propCOMPILE_DEFINITIONS) {
  1132. if (this->Internal->CompileDefinitionsEntries.empty()) {
  1133. return nullptr;
  1134. }
  1135. static std::string output;
  1136. output = cmJoin(this->Internal->CompileDefinitionsEntries, ";");
  1137. return output.c_str();
  1138. }
  1139. if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
  1140. if (this->Utilities.empty()) {
  1141. return nullptr;
  1142. }
  1143. static std::string output;
  1144. output = cmJoin(this->Utilities, ";");
  1145. return output.c_str();
  1146. }
  1147. if (prop == propIMPORTED) {
  1148. return this->IsImported() ? "TRUE" : "FALSE";
  1149. }
  1150. if (prop == propNAME) {
  1151. return this->GetName().c_str();
  1152. }
  1153. if (prop == propBINARY_DIR) {
  1154. return this->GetMakefile()
  1155. ->GetStateSnapshot()
  1156. .GetDirectory()
  1157. .GetCurrentBinary();
  1158. }
  1159. if (prop == propSOURCE_DIR) {
  1160. return this->GetMakefile()
  1161. ->GetStateSnapshot()
  1162. .GetDirectory()
  1163. .GetCurrentSource();
  1164. }
  1165. }
  1166. const char* retVal = this->Properties.GetPropertyValue(prop);
  1167. if (!retVal) {
  1168. const bool chain = this->GetMakefile()->GetState()->IsPropertyChained(
  1169. prop, cmProperty::TARGET);
  1170. if (chain) {
  1171. return this->Makefile->GetStateSnapshot().GetDirectory().GetProperty(
  1172. prop, chain);
  1173. }
  1174. }
  1175. return retVal;
  1176. }
  1177. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  1178. {
  1179. return cmSystemTools::IsOn(this->GetProperty(prop));
  1180. }
  1181. const char* cmTarget::GetSuffixVariableInternal(
  1182. cmStateEnums::ArtifactType artifact) const
  1183. {
  1184. switch (this->GetType()) {
  1185. case cmStateEnums::STATIC_LIBRARY:
  1186. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  1187. case cmStateEnums::SHARED_LIBRARY:
  1188. switch (artifact) {
  1189. case cmStateEnums::RuntimeBinaryArtifact:
  1190. return "CMAKE_SHARED_LIBRARY_SUFFIX";
  1191. case cmStateEnums::ImportLibraryArtifact:
  1192. return "CMAKE_IMPORT_LIBRARY_SUFFIX";
  1193. }
  1194. break;
  1195. case cmStateEnums::MODULE_LIBRARY:
  1196. switch (artifact) {
  1197. case cmStateEnums::RuntimeBinaryArtifact:
  1198. return "CMAKE_SHARED_MODULE_SUFFIX";
  1199. case cmStateEnums::ImportLibraryArtifact:
  1200. return "CMAKE_IMPORT_LIBRARY_SUFFIX";
  1201. }
  1202. break;
  1203. case cmStateEnums::EXECUTABLE:
  1204. switch (artifact) {
  1205. case cmStateEnums::RuntimeBinaryArtifact:
  1206. // Android GUI application packages store the native
  1207. // binary as a shared library.
  1208. return (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")
  1209. ? "CMAKE_SHARED_LIBRARY_SUFFIX"
  1210. : "CMAKE_EXECUTABLE_SUFFIX");
  1211. case cmStateEnums::ImportLibraryArtifact:
  1212. return "CMAKE_IMPORT_LIBRARY_SUFFIX";
  1213. }
  1214. break;
  1215. default:
  1216. break;
  1217. }
  1218. return "";
  1219. }
  1220. const char* cmTarget::GetPrefixVariableInternal(
  1221. cmStateEnums::ArtifactType artifact) const
  1222. {
  1223. switch (this->GetType()) {
  1224. case cmStateEnums::STATIC_LIBRARY:
  1225. return "CMAKE_STATIC_LIBRARY_PREFIX";
  1226. case cmStateEnums::SHARED_LIBRARY:
  1227. switch (artifact) {
  1228. case cmStateEnums::RuntimeBinaryArtifact:
  1229. return "CMAKE_SHARED_LIBRARY_PREFIX";
  1230. case cmStateEnums::ImportLibraryArtifact:
  1231. return "CMAKE_IMPORT_LIBRARY_PREFIX";
  1232. }
  1233. break;
  1234. case cmStateEnums::MODULE_LIBRARY:
  1235. switch (artifact) {
  1236. case cmStateEnums::RuntimeBinaryArtifact:
  1237. return "CMAKE_SHARED_MODULE_PREFIX";
  1238. case cmStateEnums::ImportLibraryArtifact:
  1239. return "CMAKE_IMPORT_LIBRARY_PREFIX";
  1240. }
  1241. break;
  1242. case cmStateEnums::EXECUTABLE:
  1243. switch (artifact) {
  1244. case cmStateEnums::RuntimeBinaryArtifact:
  1245. // Android GUI application packages store the native
  1246. // binary as a shared library.
  1247. return (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")
  1248. ? "CMAKE_SHARED_LIBRARY_PREFIX"
  1249. : "");
  1250. case cmStateEnums::ImportLibraryArtifact:
  1251. return "CMAKE_IMPORT_LIBRARY_PREFIX";
  1252. }
  1253. break;
  1254. default:
  1255. break;
  1256. }
  1257. return "";
  1258. }
  1259. std::string cmTarget::ImportedGetFullPath(
  1260. const std::string& config, cmStateEnums::ArtifactType artifact) const
  1261. {
  1262. assert(this->IsImported());
  1263. // Lookup/compute/cache the import information for this
  1264. // configuration.
  1265. std::string desired_config = config;
  1266. if (config.empty()) {
  1267. desired_config = "NOCONFIG";
  1268. }
  1269. std::string result;
  1270. const char* loc = nullptr;
  1271. const char* imp = nullptr;
  1272. std::string suffix;
  1273. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  1274. this->GetMappedConfig(desired_config, &loc, &imp, suffix)) {
  1275. switch (artifact) {
  1276. case cmStateEnums::RuntimeBinaryArtifact:
  1277. if (loc) {
  1278. result = loc;
  1279. } else {
  1280. std::string impProp = "IMPORTED_LOCATION";
  1281. impProp += suffix;
  1282. if (const char* config_location = this->GetProperty(impProp)) {
  1283. result = config_location;
  1284. } else if (const char* location =
  1285. this->GetProperty("IMPORTED_LOCATION")) {
  1286. result = location;
  1287. }
  1288. }
  1289. break;
  1290. case cmStateEnums::ImportLibraryArtifact:
  1291. if (imp) {
  1292. result = imp;
  1293. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1294. this->IsExecutableWithExports()) {
  1295. std::string impProp = "IMPORTED_IMPLIB";
  1296. impProp += suffix;
  1297. if (const char* config_implib = this->GetProperty(impProp)) {
  1298. result = config_implib;
  1299. } else if (const char* implib =
  1300. this->GetProperty("IMPORTED_IMPLIB")) {
  1301. result = implib;
  1302. }
  1303. }
  1304. break;
  1305. }
  1306. }
  1307. if (result.empty()) {
  1308. result = this->GetName();
  1309. result += "-NOTFOUND";
  1310. }
  1311. return result;
  1312. }
  1313. void cmTarget::SetPropertyDefault(const std::string& property,
  1314. const char* default_value)
  1315. {
  1316. // Compute the name of the variable holding the default value.
  1317. std::string var = "CMAKE_";
  1318. var += property;
  1319. if (const char* value = this->Makefile->GetDefinition(var)) {
  1320. this->SetProperty(property, value);
  1321. } else if (default_value) {
  1322. this->SetProperty(property, default_value);
  1323. }
  1324. }
  1325. bool cmTarget::CheckImportedLibName(std::string const& prop,
  1326. std::string const& value) const
  1327. {
  1328. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY ||
  1329. !this->IsImported()) {
  1330. this->Makefile->IssueMessage(
  1331. cmake::FATAL_ERROR, prop +
  1332. " property may be set only on imported INTERFACE library targets.");
  1333. return false;
  1334. }
  1335. if (!value.empty()) {
  1336. if (value[0] == '-') {
  1337. this->Makefile->IssueMessage(cmake::FATAL_ERROR, prop +
  1338. " property value\n " + value +
  1339. "\nmay not start with '-'.");
  1340. return false;
  1341. }
  1342. std::string::size_type bad = value.find_first_of(":/\\;");
  1343. if (bad != std::string::npos) {
  1344. this->Makefile->IssueMessage(
  1345. cmake::FATAL_ERROR, prop + " property value\n " + value +
  1346. "\nmay not contain '" + value.substr(bad, 1) + "'.");
  1347. return false;
  1348. }
  1349. }
  1350. return true;
  1351. }
  1352. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  1353. const char** loc, const char** imp,
  1354. std::string& suffix) const
  1355. {
  1356. std::string config_upper;
  1357. if (!desired_config.empty()) {
  1358. config_upper = cmSystemTools::UpperCase(desired_config);
  1359. }
  1360. std::string locPropBase;
  1361. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  1362. locPropBase = "IMPORTED_LIBNAME";
  1363. } else if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1364. locPropBase = "IMPORTED_OBJECTS";
  1365. } else {
  1366. locPropBase = "IMPORTED_LOCATION";
  1367. }
  1368. // Track the configuration-specific property suffix.
  1369. suffix = "_";
  1370. suffix += config_upper;
  1371. std::vector<std::string> mappedConfigs;
  1372. {
  1373. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  1374. mapProp += config_upper;
  1375. if (const char* mapValue = this->GetProperty(mapProp)) {
  1376. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs, true);
  1377. }
  1378. }
  1379. // If we needed to find one of the mapped configurations but did not
  1380. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  1381. // library or an executable with exports.
  1382. bool allowImp = this->HasImportLibrary();
  1383. // If a mapping was found, check its configurations.
  1384. for (std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  1385. !*loc && !*imp && mci != mappedConfigs.end(); ++mci) {
  1386. // Look for this configuration.
  1387. if (mci->empty()) {
  1388. // An empty string in the mapping has a special meaning:
  1389. // look up the config-less properties.
  1390. *loc = this->GetProperty(locPropBase);
  1391. if (allowImp) {
  1392. *imp = this->GetProperty("IMPORTED_IMPLIB");
  1393. }
  1394. // If it was found, set the suffix.
  1395. if (*loc || *imp) {
  1396. suffix.clear();
  1397. }
  1398. } else {
  1399. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  1400. std::string locProp = locPropBase + "_";
  1401. locProp += mcUpper;
  1402. *loc = this->GetProperty(locProp);
  1403. if (allowImp) {
  1404. std::string impProp = "IMPORTED_IMPLIB_";
  1405. impProp += mcUpper;
  1406. *imp = this->GetProperty(impProp);
  1407. }
  1408. // If it was found, use it for all properties below.
  1409. if (*loc || *imp) {
  1410. suffix = "_";
  1411. suffix += mcUpper;
  1412. }
  1413. }
  1414. }
  1415. // If we needed to find one of the mapped configurations but did not
  1416. // then the target location is not found. The project does not want
  1417. // any other configuration.
  1418. if (!mappedConfigs.empty() && !*loc && !*imp) {
  1419. // Interface libraries are always available because their
  1420. // library name is optional so it is okay to leave *loc empty.
  1421. return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
  1422. }
  1423. // If we have not yet found it then there are no mapped
  1424. // configurations. Look for an exact-match.
  1425. if (!*loc && !*imp) {
  1426. std::string locProp = locPropBase;
  1427. locProp += suffix;
  1428. *loc = this->GetProperty(locProp);
  1429. if (allowImp) {
  1430. std::string impProp = "IMPORTED_IMPLIB";
  1431. impProp += suffix;
  1432. *imp = this->GetProperty(impProp);
  1433. }
  1434. }
  1435. // If we have not yet found it then there are no mapped
  1436. // configurations and no exact match.
  1437. if (!*loc && !*imp) {
  1438. // The suffix computed above is not useful.
  1439. suffix.clear();
  1440. // Look for a configuration-less location. This may be set by
  1441. // manually-written code.
  1442. *loc = this->GetProperty(locPropBase);
  1443. if (allowImp) {
  1444. *imp = this->GetProperty("IMPORTED_IMPLIB");
  1445. }
  1446. }
  1447. // If we have not yet found it then the project is willing to try
  1448. // any available configuration.
  1449. if (!*loc && !*imp) {
  1450. std::vector<std::string> availableConfigs;
  1451. if (const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS")) {
  1452. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  1453. }
  1454. for (std::vector<std::string>::const_iterator aci =
  1455. availableConfigs.begin();
  1456. !*loc && !*imp && aci != availableConfigs.end(); ++aci) {
  1457. suffix = "_";
  1458. suffix += cmSystemTools::UpperCase(*aci);
  1459. std::string locProp = locPropBase;
  1460. locProp += suffix;
  1461. *loc = this->GetProperty(locProp);
  1462. if (allowImp) {
  1463. std::string impProp = "IMPORTED_IMPLIB";
  1464. impProp += suffix;
  1465. *imp = this->GetProperty(impProp);
  1466. }
  1467. }
  1468. }
  1469. // If we have not yet found it then the target location is not available.
  1470. if (!*loc && !*imp) {
  1471. // Interface libraries are always available because their
  1472. // library name is optional so it is okay to leave *loc empty.
  1473. return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
  1474. }
  1475. return true;
  1476. }
  1477. cmTargetInternalPointer::cmTargetInternalPointer()
  1478. {
  1479. this->Pointer = new cmTargetInternals;
  1480. }
  1481. cmTargetInternalPointer::cmTargetInternalPointer(
  1482. cmTargetInternalPointer const& r)
  1483. {
  1484. // Ideally cmTarget instances should never be copied. However until
  1485. // we can make a sweep to remove that, this copy constructor avoids
  1486. // allowing the resources (Internals) to be copied.
  1487. this->Pointer = new cmTargetInternals(*r.Pointer);
  1488. }
  1489. cmTargetInternalPointer::~cmTargetInternalPointer()
  1490. {
  1491. delete this->Pointer;
  1492. }
  1493. cmTargetInternalPointer& cmTargetInternalPointer::operator=(
  1494. cmTargetInternalPointer const& r)
  1495. {
  1496. if (this == &r) {
  1497. return *this;
  1498. } // avoid warning on HP about self check
  1499. // Ideally cmTarget instances should never be copied. However until
  1500. // we can make a sweep to remove that, this copy constructor avoids
  1501. // allowing the resources (Internals) to be copied.
  1502. cmTargetInternals* oldPointer = this->Pointer;
  1503. this->Pointer = new cmTargetInternals(*r.Pointer);
  1504. delete oldPointer;
  1505. return *this;
  1506. }