cmTarget.cxx 55 KB

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