cmTarget.cxx 56 KB

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