cmTarget.cxx 55 KB

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