cmTarget.cxx 55 KB

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