cmTarget.cxx 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349
  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 "cmake.h"
  12. #include "cmMakefile.h"
  13. #include "cmSourceFile.h"
  14. #include "cmOutputConverter.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmComputeLinkInformation.h"
  17. #include "cmListFileCache.h"
  18. #include "cmGeneratorExpression.h"
  19. #include "cmGeneratorExpressionDAGChecker.h"
  20. #include "cmAlgorithms.h"
  21. #include <cmsys/RegularExpression.hxx>
  22. #include <map>
  23. #include <set>
  24. #include <stdlib.h> // required for atof
  25. #include <assert.h>
  26. #include <errno.h>
  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. //----------------------------------------------------------------------------
  34. class cmTargetInternals
  35. {
  36. public:
  37. std::vector<std::string> IncludeDirectoriesEntries;
  38. std::vector<cmListFileBacktrace> IncludeDirectoriesBacktraces;
  39. std::vector<std::string> CompileOptionsEntries;
  40. std::vector<cmListFileBacktrace> CompileOptionsBacktraces;
  41. std::vector<std::string> CompileFeaturesEntries;
  42. std::vector<cmListFileBacktrace> CompileFeaturesBacktraces;
  43. std::vector<std::string> CompileDefinitionsEntries;
  44. std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces;
  45. std::vector<std::string> SourceEntries;
  46. std::vector<cmListFileBacktrace> SourceBacktraces;
  47. std::vector<std::string> LinkImplementationPropertyEntries;
  48. std::vector<cmListFileBacktrace> LinkImplementationPropertyBacktraces;
  49. };
  50. //----------------------------------------------------------------------------
  51. cmTarget::cmTarget()
  52. {
  53. this->Makefile = 0;
  54. #if defined(_WIN32) && !defined(__CYGWIN__)
  55. this->LinkLibrariesForVS6Analyzed = false;
  56. #endif
  57. this->HaveInstallRule = false;
  58. this->DLLPlatform = false;
  59. this->IsAndroid = false;
  60. this->IsApple = false;
  61. this->IsImportedTarget = false;
  62. this->BuildInterfaceIncludesAppended = false;
  63. }
  64. void cmTarget::SetType(cmState::TargetType type, const std::string& name)
  65. {
  66. this->Name = name;
  67. // only add dependency information for library targets
  68. this->TargetTypeValue = type;
  69. if(this->TargetTypeValue >= cmState::STATIC_LIBRARY
  70. && this->TargetTypeValue <= cmState::MODULE_LIBRARY)
  71. {
  72. this->RecordDependencies = true;
  73. }
  74. else
  75. {
  76. this->RecordDependencies = false;
  77. }
  78. }
  79. //----------------------------------------------------------------------------
  80. void cmTarget::SetMakefile(cmMakefile* mf)
  81. {
  82. // Set our makefile.
  83. this->Makefile = mf;
  84. // Check whether this is a DLL platform.
  85. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  86. this->Makefile->IsOn("CYGWIN") ||
  87. this->Makefile->IsOn("MINGW"));
  88. // Check whether we are targeting an Android platform.
  89. this->IsAndroid =
  90. strcmp(this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME"),
  91. "Android") == 0;
  92. // Check whether we are targeting an Apple platform.
  93. this->IsApple = this->Makefile->IsOn("APPLE");
  94. // Setup default property values.
  95. if (this->GetType() != cmState::INTERFACE_LIBRARY
  96. && this->GetType() != cmState::UTILITY)
  97. {
  98. this->SetPropertyDefault("ANDROID_API", 0);
  99. this->SetPropertyDefault("ANDROID_API_MIN", 0);
  100. this->SetPropertyDefault("ANDROID_ARCH", 0);
  101. this->SetPropertyDefault("ANDROID_STL_TYPE", 0);
  102. this->SetPropertyDefault("ANDROID_SKIP_ANT_STEP", 0);
  103. this->SetPropertyDefault("ANDROID_PROCESS_MAX", 0);
  104. this->SetPropertyDefault("ANDROID_PROGUARD", 0);
  105. this->SetPropertyDefault("ANDROID_PROGUARD_CONFIG_PATH", 0);
  106. this->SetPropertyDefault("ANDROID_SECURE_PROPS_PATH", 0);
  107. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DIRECTORIES", 0);
  108. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DEPENDENCIES", 0);
  109. this->SetPropertyDefault("ANDROID_JAVA_SOURCE_DIR", 0);
  110. this->SetPropertyDefault("ANDROID_JAR_DIRECTORIES", 0);
  111. this->SetPropertyDefault("ANDROID_JAR_DEPENDENCIES", 0);
  112. this->SetPropertyDefault("ANDROID_ASSETS_DIRECTORIES", 0);
  113. this->SetPropertyDefault("ANDROID_ANT_ADDITIONAL_OPTIONS", 0);
  114. this->SetPropertyDefault("INSTALL_NAME_DIR", 0);
  115. this->SetPropertyDefault("INSTALL_RPATH", "");
  116. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  117. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  118. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  119. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
  120. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
  121. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
  122. this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
  123. this->SetPropertyDefault("COMPILE_PDB_OUTPUT_DIRECTORY", 0);
  124. this->SetPropertyDefault("Fortran_FORMAT", 0);
  125. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
  126. this->SetPropertyDefault("GNUtoMS", 0);
  127. this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
  128. this->SetPropertyDefault("AUTOMOC", 0);
  129. this->SetPropertyDefault("AUTOUIC", 0);
  130. this->SetPropertyDefault("AUTORCC", 0);
  131. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
  132. this->SetPropertyDefault("AUTOUIC_OPTIONS", 0);
  133. this->SetPropertyDefault("AUTORCC_OPTIONS", 0);
  134. this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
  135. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
  136. this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
  137. this->SetPropertyDefault("MACOSX_BUNDLE", 0);
  138. this->SetPropertyDefault("MACOSX_RPATH", 0);
  139. this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0);
  140. this->SetPropertyDefault("C_COMPILER_LAUNCHER", 0);
  141. this->SetPropertyDefault("C_INCLUDE_WHAT_YOU_USE", 0);
  142. this->SetPropertyDefault("C_STANDARD", 0);
  143. this->SetPropertyDefault("C_STANDARD_REQUIRED", 0);
  144. this->SetPropertyDefault("C_EXTENSIONS", 0);
  145. this->SetPropertyDefault("CXX_COMPILER_LAUNCHER", 0);
  146. this->SetPropertyDefault("CXX_INCLUDE_WHAT_YOU_USE", 0);
  147. this->SetPropertyDefault("CXX_STANDARD", 0);
  148. this->SetPropertyDefault("CXX_STANDARD_REQUIRED", 0);
  149. this->SetPropertyDefault("CXX_EXTENSIONS", 0);
  150. this->SetPropertyDefault("LINK_SEARCH_START_STATIC", 0);
  151. this->SetPropertyDefault("LINK_SEARCH_END_STATIC", 0);
  152. }
  153. // Collect the set of configuration types.
  154. std::vector<std::string> configNames;
  155. mf->GetConfigurations(configNames);
  156. // Setup per-configuration property default values.
  157. if (this->GetType() != cmState::UTILITY)
  158. {
  159. const char* configProps[] = {
  160. "ARCHIVE_OUTPUT_DIRECTORY_",
  161. "LIBRARY_OUTPUT_DIRECTORY_",
  162. "RUNTIME_OUTPUT_DIRECTORY_",
  163. "PDB_OUTPUT_DIRECTORY_",
  164. "COMPILE_PDB_OUTPUT_DIRECTORY_",
  165. "MAP_IMPORTED_CONFIG_",
  166. 0};
  167. for(std::vector<std::string>::iterator ci = configNames.begin();
  168. ci != configNames.end(); ++ci)
  169. {
  170. std::string configUpper = cmSystemTools::UpperCase(*ci);
  171. for(const char** p = configProps; *p; ++p)
  172. {
  173. if (this->TargetTypeValue == cmState::INTERFACE_LIBRARY
  174. && strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0)
  175. {
  176. continue;
  177. }
  178. std::string property = *p;
  179. property += configUpper;
  180. this->SetPropertyDefault(property, 0);
  181. }
  182. // Initialize per-configuration name postfix property from the
  183. // variable only for non-executable targets. This preserves
  184. // compatibility with previous CMake versions in which executables
  185. // did not support this variable. Projects may still specify the
  186. // property directly.
  187. if(this->TargetTypeValue != cmState::EXECUTABLE
  188. && this->TargetTypeValue != cmState::INTERFACE_LIBRARY)
  189. {
  190. std::string property = cmSystemTools::UpperCase(*ci);
  191. property += "_POSTFIX";
  192. this->SetPropertyDefault(property, 0);
  193. }
  194. }
  195. }
  196. // Save the backtrace of target construction.
  197. this->Backtrace = this->Makefile->GetBacktrace();
  198. if (!this->IsImported())
  199. {
  200. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  201. // of the same directory property:
  202. const cmStringRange parentIncludes =
  203. this->Makefile->GetIncludeDirectoriesEntries();
  204. const cmBacktraceRange parentIncludesBts =
  205. this->Makefile->GetIncludeDirectoriesBacktraces();
  206. this->Internal->IncludeDirectoriesEntries.insert(
  207. this->Internal->IncludeDirectoriesEntries.end(),
  208. parentIncludes.begin(), parentIncludes.end());
  209. this->Internal->IncludeDirectoriesBacktraces.insert(
  210. this->Internal->IncludeDirectoriesBacktraces.end(),
  211. parentIncludesBts.begin(), parentIncludesBts.end());
  212. const std::set<std::string> parentSystemIncludes =
  213. this->Makefile->GetSystemIncludeDirectories();
  214. this->SystemIncludeDirectories.insert(parentSystemIncludes.begin(),
  215. parentSystemIncludes.end());
  216. const cmStringRange parentOptions =
  217. this->Makefile->GetCompileOptionsEntries();
  218. const cmBacktraceRange parentOptionsBts =
  219. this->Makefile->GetCompileOptionsBacktraces();
  220. this->Internal->CompileOptionsEntries.insert(
  221. this->Internal->CompileOptionsEntries.end(),
  222. parentOptions.begin(), parentOptions.end());
  223. this->Internal->CompileOptionsBacktraces.insert(
  224. this->Internal->CompileOptionsBacktraces.end(),
  225. parentOptionsBts.begin(), parentOptionsBts.end());
  226. }
  227. if (this->GetType() != cmState::INTERFACE_LIBRARY
  228. && this->GetType() != cmState::UTILITY)
  229. {
  230. this->SetPropertyDefault("C_VISIBILITY_PRESET", 0);
  231. this->SetPropertyDefault("CXX_VISIBILITY_PRESET", 0);
  232. this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
  233. }
  234. if(this->TargetTypeValue == cmState::EXECUTABLE)
  235. {
  236. this->SetPropertyDefault("ANDROID_GUI", 0);
  237. this->SetPropertyDefault("CROSSCOMPILING_EMULATOR", 0);
  238. this->SetPropertyDefault("ENABLE_EXPORTS", 0);
  239. }
  240. if(this->TargetTypeValue == cmState::SHARED_LIBRARY
  241. || this->TargetTypeValue == cmState::MODULE_LIBRARY)
  242. {
  243. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  244. }
  245. if(this->TargetTypeValue == cmState::SHARED_LIBRARY)
  246. {
  247. this->SetPropertyDefault("WINDOWS_EXPORT_ALL_SYMBOLS", 0);
  248. }
  249. if (this->GetType() != cmState::INTERFACE_LIBRARY
  250. && this->GetType() != cmState::UTILITY)
  251. {
  252. this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
  253. }
  254. // Record current policies for later use.
  255. this->Makefile->RecordPolicies(this->PolicyMap);
  256. if (this->TargetTypeValue == cmState::INTERFACE_LIBRARY)
  257. {
  258. // This policy is checked in a few conditions. The properties relevant
  259. // to the policy are always ignored for cmState::INTERFACE_LIBRARY targets,
  260. // so ensure that the conditions don't lead to nonsense.
  261. this->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
  262. }
  263. if (this->GetType() != cmState::INTERFACE_LIBRARY
  264. && this->GetType() != cmState::UTILITY)
  265. {
  266. this->SetPropertyDefault("JOB_POOL_COMPILE", 0);
  267. this->SetPropertyDefault("JOB_POOL_LINK", 0);
  268. }
  269. }
  270. //----------------------------------------------------------------------------
  271. void cmTarget::AddUtility(const std::string& u, cmMakefile *makefile)
  272. {
  273. if(this->Utilities.insert(u).second && makefile)
  274. {
  275. UtilityBacktraces.insert(std::make_pair(u, makefile->GetBacktrace()));
  276. }
  277. }
  278. //----------------------------------------------------------------------------
  279. cmListFileBacktrace const* cmTarget::GetUtilityBacktrace(
  280. const std::string& u) const
  281. {
  282. std::map<std::string, cmListFileBacktrace>::const_iterator i =
  283. this->UtilityBacktraces.find(u);
  284. if(i == this->UtilityBacktraces.end()) return 0;
  285. return &i->second;
  286. }
  287. //----------------------------------------------------------------------------
  288. void cmTarget::FinishConfigure()
  289. {
  290. // Erase any cached link information that might have been comptued
  291. // on-demand during the configuration. This ensures that build
  292. // system generation uses up-to-date information even if other cache
  293. // invalidation code in this source file is buggy.
  294. #if defined(_WIN32) && !defined(__CYGWIN__)
  295. // Do old-style link dependency analysis only for CM_USE_OLD_VS6.
  296. if(this->Makefile->GetGlobalGenerator()->IsForVS6())
  297. {
  298. this->AnalyzeLibDependenciesForVS6(*this->Makefile);
  299. }
  300. #endif
  301. }
  302. //----------------------------------------------------------------------------
  303. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  304. {
  305. return this->Backtrace;
  306. }
  307. //----------------------------------------------------------------------------
  308. bool cmTarget::IsExecutableWithExports() const
  309. {
  310. return (this->GetType() == cmState::EXECUTABLE &&
  311. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  312. }
  313. //----------------------------------------------------------------------------
  314. bool cmTarget::IsLinkable() const
  315. {
  316. return (this->GetType() == cmState::STATIC_LIBRARY ||
  317. this->GetType() == cmState::SHARED_LIBRARY ||
  318. this->GetType() == cmState::MODULE_LIBRARY ||
  319. this->GetType() == cmState::UNKNOWN_LIBRARY ||
  320. this->GetType() == cmState::INTERFACE_LIBRARY ||
  321. this->IsExecutableWithExports());
  322. }
  323. //----------------------------------------------------------------------------
  324. bool cmTarget::HasImportLibrary() const
  325. {
  326. return (this->DLLPlatform &&
  327. (this->GetType() == cmState::SHARED_LIBRARY ||
  328. this->IsExecutableWithExports()));
  329. }
  330. //----------------------------------------------------------------------------
  331. bool cmTarget::IsFrameworkOnApple() const
  332. {
  333. return (this->GetType() == cmState::SHARED_LIBRARY &&
  334. this->Makefile->IsOn("APPLE") &&
  335. this->GetPropertyAsBool("FRAMEWORK"));
  336. }
  337. //----------------------------------------------------------------------------
  338. bool cmTarget::IsAppBundleOnApple() const
  339. {
  340. return (this->GetType() == cmState::EXECUTABLE &&
  341. this->Makefile->IsOn("APPLE") &&
  342. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  343. }
  344. //----------------------------------------------------------------------------
  345. bool cmTarget::IsCFBundleOnApple() const
  346. {
  347. return (this->GetType() == cmState::MODULE_LIBRARY &&
  348. this->Makefile->IsOn("APPLE") &&
  349. this->GetPropertyAsBool("BUNDLE"));
  350. }
  351. //----------------------------------------------------------------------------
  352. bool cmTarget::IsXCTestOnApple() const
  353. {
  354. return (this->IsCFBundleOnApple() &&
  355. this->GetPropertyAsBool("XCTEST"));
  356. }
  357. //----------------------------------------------------------------------------
  358. void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
  359. {
  360. if (!srcs.empty())
  361. {
  362. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  363. this->Internal->SourceEntries.push_back(cmJoin(srcs, ";"));
  364. this->Internal->SourceBacktraces.push_back(lfbt);
  365. }
  366. }
  367. //----------------------------------------------------------------------------
  368. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  369. {
  370. std::string srcFiles;
  371. const char* sep = "";
  372. for(std::vector<std::string>::const_iterator i = srcs.begin();
  373. i != srcs.end(); ++i)
  374. {
  375. std::string filename = *i;
  376. const char* src = filename.c_str();
  377. if(!(src[0] == '$' && src[1] == '<'))
  378. {
  379. if(!filename.empty())
  380. {
  381. filename = this->ProcessSourceItemCMP0049(filename);
  382. if(filename.empty())
  383. {
  384. return;
  385. }
  386. }
  387. this->Makefile->GetOrCreateSource(filename);
  388. }
  389. srcFiles += sep;
  390. srcFiles += filename;
  391. sep = ";";
  392. }
  393. if (!srcFiles.empty())
  394. {
  395. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  396. this->Internal->SourceEntries.push_back(srcFiles);
  397. this->Internal->SourceBacktraces.push_back(lfbt);
  398. }
  399. }
  400. //----------------------------------------------------------------------------
  401. std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
  402. {
  403. std::string src = s;
  404. // For backwards compatibility replace varibles in source names.
  405. // This should eventually be removed.
  406. this->Makefile->ExpandVariablesInString(src);
  407. if (src != s)
  408. {
  409. std::ostringstream e;
  410. bool noMessage = false;
  411. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  412. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0049))
  413. {
  414. case cmPolicies::WARN:
  415. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0049) << "\n";
  416. break;
  417. case cmPolicies::OLD:
  418. noMessage = true;
  419. break;
  420. case cmPolicies::REQUIRED_ALWAYS:
  421. case cmPolicies::REQUIRED_IF_USED:
  422. case cmPolicies::NEW:
  423. messageType = cmake::FATAL_ERROR;
  424. }
  425. if (!noMessage)
  426. {
  427. e << "Legacy variable expansion in source file \""
  428. << s << "\" expanded to \"" << src << "\" in target \""
  429. << this->GetName() << "\". This behavior will be removed in a "
  430. "future version of CMake.";
  431. this->Makefile->IssueMessage(messageType, e.str());
  432. if (messageType == cmake::FATAL_ERROR)
  433. {
  434. return "";
  435. }
  436. }
  437. }
  438. return src;
  439. }
  440. //----------------------------------------------------------------------------
  441. cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s)
  442. {
  443. std::string src = this->ProcessSourceItemCMP0049(s);
  444. if(!s.empty() && src.empty())
  445. {
  446. return 0;
  447. }
  448. return this->AddSource(src);
  449. }
  450. //----------------------------------------------------------------------------
  451. struct CreateLocation
  452. {
  453. cmMakefile const* Makefile;
  454. CreateLocation(cmMakefile const* mf)
  455. : Makefile(mf)
  456. {
  457. }
  458. cmSourceFileLocation operator()(const std::string& filename)
  459. {
  460. return cmSourceFileLocation(this->Makefile, filename);
  461. }
  462. };
  463. //----------------------------------------------------------------------------
  464. struct LocationMatcher
  465. {
  466. const cmSourceFileLocation& Needle;
  467. LocationMatcher(const cmSourceFileLocation& needle)
  468. : Needle(needle)
  469. {
  470. }
  471. bool operator()(cmSourceFileLocation &loc)
  472. {
  473. return loc.Matches(this->Needle);
  474. }
  475. };
  476. //----------------------------------------------------------------------------
  477. struct TargetPropertyEntryFinder
  478. {
  479. private:
  480. const cmSourceFileLocation& Needle;
  481. public:
  482. TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
  483. : Needle(needle)
  484. {
  485. }
  486. bool operator()(std::string const& entry)
  487. {
  488. std::vector<std::string> files;
  489. cmSystemTools::ExpandListArgument(entry, files);
  490. std::vector<cmSourceFileLocation> locations(files.size());
  491. std::transform(files.begin(), files.end(), locations.begin(),
  492. CreateLocation(this->Needle.GetMakefile()));
  493. return std::find_if(locations.begin(), locations.end(),
  494. LocationMatcher(this->Needle)) != locations.end();
  495. }
  496. };
  497. //----------------------------------------------------------------------------
  498. cmSourceFile* cmTarget::AddSource(const std::string& src)
  499. {
  500. cmSourceFileLocation sfl(this->Makefile, src);
  501. if (std::find_if(this->Internal->SourceEntries.begin(),
  502. this->Internal->SourceEntries.end(),
  503. TargetPropertyEntryFinder(sfl))
  504. == this->Internal->SourceEntries.end())
  505. {
  506. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  507. this->Internal->SourceEntries.push_back(src);
  508. this->Internal->SourceBacktraces.push_back(lfbt);
  509. }
  510. if (cmGeneratorExpression::Find(src) != std::string::npos)
  511. {
  512. return 0;
  513. }
  514. return this->Makefile->GetOrCreateSource(src);
  515. }
  516. //----------------------------------------------------------------------------
  517. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  518. const std::string& selfname,
  519. const LinkLibraryVectorType& libs )
  520. {
  521. // Only add on libraries we haven't added on before.
  522. // Assumption: the global link libraries could only grow, never shrink
  523. LinkLibraryVectorType::const_iterator i = libs.begin();
  524. i += this->PrevLinkedLibraries.size();
  525. for( ; i != libs.end(); ++i )
  526. {
  527. // This is equivalent to the target_link_libraries plain signature.
  528. this->AddLinkLibrary( mf, selfname, i->first, i->second );
  529. this->AppendProperty("INTERFACE_LINK_LIBRARIES",
  530. this->GetDebugGeneratorExpressions(i->first, i->second).c_str());
  531. }
  532. this->PrevLinkedLibraries = libs;
  533. }
  534. //----------------------------------------------------------------------------
  535. void cmTarget::AddLinkDirectory(const std::string& d)
  536. {
  537. // Make sure we don't add unnecessary search directories.
  538. if(this->LinkDirectoriesEmmitted.insert(d).second)
  539. {
  540. this->LinkDirectories.push_back(d);
  541. }
  542. }
  543. //----------------------------------------------------------------------------
  544. const std::vector<std::string>& cmTarget::GetLinkDirectories() const
  545. {
  546. return this->LinkDirectories;
  547. }
  548. //----------------------------------------------------------------------------
  549. cmTargetLinkLibraryType cmTarget::ComputeLinkType(
  550. const std::string& config) const
  551. {
  552. // No configuration is always optimized.
  553. if(config.empty())
  554. {
  555. return OPTIMIZED_LibraryType;
  556. }
  557. // Get the list of configurations considered to be DEBUG.
  558. std::vector<std::string> debugConfigs =
  559. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  560. // Check if any entry in the list matches this configuration.
  561. std::string configUpper = cmSystemTools::UpperCase(config);
  562. if (std::find(debugConfigs.begin(), debugConfigs.end(), configUpper) !=
  563. debugConfigs.end())
  564. {
  565. return DEBUG_LibraryType;
  566. }
  567. // The current configuration is not a debug configuration.
  568. return OPTIMIZED_LibraryType;
  569. }
  570. //----------------------------------------------------------------------------
  571. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  572. const std::string& target )
  573. {
  574. // Clear the dependencies. The cache variable must exist iff we are
  575. // recording dependency information for this target.
  576. std::string depname = target;
  577. depname += "_LIB_DEPENDS";
  578. if (this->RecordDependencies)
  579. {
  580. mf.AddCacheDefinition(depname, "",
  581. "Dependencies for target", cmState::STATIC);
  582. }
  583. else
  584. {
  585. if (mf.GetDefinition( depname ))
  586. {
  587. std::string message = "Target ";
  588. message += target;
  589. message += " has dependency information when it shouldn't.\n";
  590. message += "Your cache is probably stale. Please remove the entry\n ";
  591. message += depname;
  592. message += "\nfrom the cache.";
  593. cmSystemTools::Error( message.c_str() );
  594. }
  595. }
  596. }
  597. //----------------------------------------------------------------------------
  598. bool cmTarget::NameResolvesToFramework(const std::string& libname) const
  599. {
  600. return this->Makefile->GetGlobalGenerator()->
  601. NameResolvesToFramework(libname);
  602. }
  603. //----------------------------------------------------------------------------
  604. std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
  605. cmTargetLinkLibraryType llt) const
  606. {
  607. if (llt == GENERAL_LibraryType)
  608. {
  609. return value;
  610. }
  611. // Get the list of configurations considered to be DEBUG.
  612. std::vector<std::string> debugConfigs =
  613. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  614. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  615. if (debugConfigs.size() > 1)
  616. {
  617. for(std::vector<std::string>::const_iterator
  618. li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
  619. {
  620. configString += ",$<CONFIG:" + *li + ">";
  621. }
  622. configString = "$<OR:" + configString + ">";
  623. }
  624. if (llt == OPTIMIZED_LibraryType)
  625. {
  626. configString = "$<NOT:" + configString + ">";
  627. }
  628. return "$<" + configString + ":" + value + ">";
  629. }
  630. //----------------------------------------------------------------------------
  631. static std::string targetNameGenex(const std::string& lib)
  632. {
  633. return "$<TARGET_NAME:" + lib + ">";
  634. }
  635. //----------------------------------------------------------------------------
  636. bool cmTarget::PushTLLCommandTrace(TLLSignature signature,
  637. cmListFileContext const& lfc)
  638. {
  639. bool ret = true;
  640. if (!this->TLLCommands.empty())
  641. {
  642. if (this->TLLCommands.back().first != signature)
  643. {
  644. ret = false;
  645. }
  646. }
  647. if (this->TLLCommands.empty() || this->TLLCommands.back().second != lfc)
  648. {
  649. this->TLLCommands.push_back(std::make_pair(signature, lfc));
  650. }
  651. return ret;
  652. }
  653. //----------------------------------------------------------------------------
  654. void cmTarget::GetTllSignatureTraces(std::ostringstream &s,
  655. TLLSignature sig) const
  656. {
  657. const char *sigString = (sig == cmTarget::KeywordTLLSignature ? "keyword"
  658. : "plain");
  659. s << "The uses of the " << sigString << " signature are here:\n";
  660. typedef std::vector<std::pair<TLLSignature, cmListFileContext> > Container;
  661. cmOutputConverter converter(this->GetMakefile()->GetStateSnapshot());
  662. for(Container::const_iterator it = this->TLLCommands.begin();
  663. it != this->TLLCommands.end(); ++it)
  664. {
  665. if (it->first == sig)
  666. {
  667. cmListFileContext lfc = it->second;
  668. lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
  669. s << " * " << lfc << std::endl;
  670. }
  671. }
  672. }
  673. //----------------------------------------------------------------------------
  674. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  675. const std::string& target,
  676. const std::string& lib,
  677. cmTargetLinkLibraryType llt)
  678. {
  679. cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
  680. {
  681. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  682. const std::string libName =
  683. (isNonImportedTarget && llt != GENERAL_LibraryType)
  684. ? targetNameGenex(lib)
  685. : lib;
  686. this->AppendProperty("LINK_LIBRARIES",
  687. this->GetDebugGeneratorExpressions(libName,
  688. llt).c_str());
  689. }
  690. if (cmGeneratorExpression::Find(lib) != std::string::npos
  691. || (tgt && tgt->GetType() == cmState::INTERFACE_LIBRARY)
  692. || (target == lib ))
  693. {
  694. return;
  695. }
  696. cmTarget::LibraryID tmp;
  697. tmp.first = lib;
  698. tmp.second = llt;
  699. #if defined(_WIN32) && !defined(__CYGWIN__)
  700. this->LinkLibrariesForVS6.push_back( tmp );
  701. #endif
  702. this->OriginalLinkLibraries.push_back(tmp);
  703. // Add the explicit dependency information for this target. This is
  704. // simply a set of libraries separated by ";". There should always
  705. // be a trailing ";". These library names are not canonical, in that
  706. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  707. // We shouldn't remove duplicates here because external libraries
  708. // may be purposefully duplicated to handle recursive dependencies,
  709. // and we removing one instance will break the link line. Duplicates
  710. // will be appropriately eliminated at emit time.
  711. if(this->RecordDependencies)
  712. {
  713. std::string targetEntry = target;
  714. targetEntry += "_LIB_DEPENDS";
  715. std::string dependencies;
  716. const char* old_val = mf.GetDefinition( targetEntry );
  717. if( old_val )
  718. {
  719. dependencies += old_val;
  720. }
  721. switch (llt)
  722. {
  723. case GENERAL_LibraryType:
  724. dependencies += "general";
  725. break;
  726. case DEBUG_LibraryType:
  727. dependencies += "debug";
  728. break;
  729. case OPTIMIZED_LibraryType:
  730. dependencies += "optimized";
  731. break;
  732. }
  733. dependencies += ";";
  734. dependencies += lib;
  735. dependencies += ";";
  736. mf.AddCacheDefinition( targetEntry, dependencies.c_str(),
  737. "Dependencies for the target",
  738. cmState::STATIC );
  739. }
  740. }
  741. //----------------------------------------------------------------------------
  742. void
  743. cmTarget::AddSystemIncludeDirectories(const std::set<std::string> &incs)
  744. {
  745. this->SystemIncludeDirectories.insert(incs.begin(), incs.end());
  746. }
  747. cmStringRange cmTarget::GetIncludeDirectoriesEntries() const
  748. {
  749. return cmMakeRange(this->Internal->IncludeDirectoriesEntries);
  750. }
  751. cmBacktraceRange cmTarget::GetIncludeDirectoriesBacktraces() const
  752. {
  753. return cmMakeRange(this->Internal->IncludeDirectoriesBacktraces);
  754. }
  755. cmStringRange cmTarget::GetCompileOptionsEntries() const
  756. {
  757. return cmMakeRange(this->Internal->CompileOptionsEntries);
  758. }
  759. cmBacktraceRange cmTarget::GetCompileOptionsBacktraces() const
  760. {
  761. return cmMakeRange(this->Internal->CompileOptionsBacktraces);
  762. }
  763. cmStringRange cmTarget::GetCompileFeaturesEntries() const
  764. {
  765. return cmMakeRange(this->Internal->CompileFeaturesEntries);
  766. }
  767. cmBacktraceRange cmTarget::GetCompileFeaturesBacktraces() const
  768. {
  769. return cmMakeRange(this->Internal->CompileFeaturesBacktraces);
  770. }
  771. cmStringRange cmTarget::GetCompileDefinitionsEntries() const
  772. {
  773. return cmMakeRange(this->Internal->CompileDefinitionsEntries);
  774. }
  775. cmBacktraceRange cmTarget::GetCompileDefinitionsBacktraces() const
  776. {
  777. return cmMakeRange(this->Internal->CompileDefinitionsBacktraces);
  778. }
  779. cmStringRange cmTarget::GetSourceEntries() const
  780. {
  781. return cmMakeRange(this->Internal->SourceEntries);
  782. }
  783. cmBacktraceRange cmTarget::GetSourceBacktraces() const
  784. {
  785. return cmMakeRange(this->Internal->SourceBacktraces);
  786. }
  787. cmStringRange cmTarget::GetLinkImplementationEntries() const
  788. {
  789. return cmMakeRange(this->Internal->LinkImplementationPropertyEntries);
  790. }
  791. cmBacktraceRange cmTarget::GetLinkImplementationBacktraces() const
  792. {
  793. return cmMakeRange(this->Internal->LinkImplementationPropertyBacktraces);
  794. }
  795. #if defined(_WIN32) && !defined(__CYGWIN__)
  796. //----------------------------------------------------------------------------
  797. void
  798. cmTarget::AnalyzeLibDependenciesForVS6( const cmMakefile& mf )
  799. {
  800. // There are two key parts of the dependency analysis: (1)
  801. // determining the libraries in the link line, and (2) constructing
  802. // the dependency graph for those libraries.
  803. //
  804. // The latter is done using the cache entries that record the
  805. // dependencies of each library.
  806. //
  807. // The former is a more thorny issue, since it is not clear how to
  808. // determine if two libraries listed on the link line refer to the a
  809. // single library or not. For example, consider the link "libraries"
  810. // /usr/lib/libtiff.so -ltiff
  811. // Is this one library or two? The solution implemented here is the
  812. // simplest (and probably the only practical) one: two libraries are
  813. // the same if their "link strings" are identical. Thus, the two
  814. // libraries above are considered distinct. This also means that for
  815. // dependency analysis to be effective, the CMake user must specify
  816. // libraries build by his project without using any linker flags or
  817. // file extensions. That is,
  818. // LINK_LIBRARIES( One Two )
  819. // instead of
  820. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  821. // The former is probably what most users would do, but it never
  822. // hurts to document the assumptions. :-) Therefore, in the analysis
  823. // code, the "canonical name" of a library is simply its name as
  824. // given to a LINK_LIBRARIES command.
  825. //
  826. // Also, we will leave the original link line intact; we will just add any
  827. // dependencies that were missing.
  828. //
  829. // There is a problem with recursive external libraries
  830. // (i.e. libraries with no dependency information that are
  831. // recursively dependent). We must make sure that the we emit one of
  832. // the libraries twice to satisfy the recursion, but we shouldn't
  833. // emit it more times than necessary. In particular, we must make
  834. // sure that handling this improbable case doesn't cost us when
  835. // dealing with the common case of non-recursive libraries. The
  836. // solution is to assume that the recursion is satisfied at one node
  837. // of the dependency tree. To illustrate, assume libA and libB are
  838. // extrenal and mutually dependent. Suppose libX depends on
  839. // libA, and libY on libA and libX. Then
  840. // TARGET_LINK_LIBRARIES( Y X A B A )
  841. // TARGET_LINK_LIBRARIES( X A B A )
  842. // TARGET_LINK_LIBRARIES( Exec Y )
  843. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  844. // specify the dependencies, since the mutual dependency of A and B
  845. // is resolved *every time libA is specified*.
  846. //
  847. // Something like
  848. // TARGET_LINK_LIBRARIES( Y X A B A )
  849. // TARGET_LINK_LIBRARIES( X A B )
  850. // TARGET_LINK_LIBRARIES( Exec Y )
  851. // would result in "-lY -lX -lA -lB", and the mutual dependency
  852. // information is lost. This is because in some case (Y), the mutual
  853. // dependency of A and B is listed, while in another other case (X),
  854. // it is not. Depending on which line actually emits A, the mutual
  855. // dependency may or may not be on the final link line. We can't
  856. // handle this pathalogical case cleanly without emitting extra
  857. // libraries for the normal cases. Besides, the dependency
  858. // information for X is wrong anyway: if we build an executable
  859. // depending on X alone, we would not have the mutual dependency on
  860. // A and B resolved.
  861. //
  862. // IMPROVEMENTS:
  863. // -- The current algorithm will not always pick the "optimal" link line
  864. // when recursive dependencies are present. It will instead break the
  865. // cycles at an aribtrary point. The majority of projects won't have
  866. // cyclic dependencies, so this is probably not a big deal. Note that
  867. // the link line is always correct, just not necessary optimal.
  868. {
  869. // Expand variables in link library names. This is for backwards
  870. // compatibility with very early CMake versions and should
  871. // eventually be removed. This code was moved here from the end of
  872. // old source list processing code which was called just before this
  873. // method.
  874. for(LinkLibraryVectorType::iterator p = this->LinkLibrariesForVS6.begin();
  875. p != this->LinkLibrariesForVS6.end(); ++p)
  876. {
  877. this->Makefile->ExpandVariablesInString(p->first, true, true);
  878. }
  879. }
  880. // The dependency map.
  881. DependencyMap dep_map;
  882. // 1. Build the dependency graph
  883. //
  884. for(LinkLibraryVectorType::reverse_iterator lib
  885. = this->LinkLibrariesForVS6.rbegin();
  886. lib != this->LinkLibrariesForVS6.rend(); ++lib)
  887. {
  888. this->GatherDependenciesForVS6( mf, *lib, dep_map);
  889. }
  890. // 2. Remove any dependencies that are already satisfied in the original
  891. // link line.
  892. //
  893. for(LinkLibraryVectorType::iterator lib = this->LinkLibrariesForVS6.begin();
  894. lib != this->LinkLibrariesForVS6.end(); ++lib)
  895. {
  896. for( LinkLibraryVectorType::iterator lib2 = lib;
  897. lib2 != this->LinkLibrariesForVS6.end(); ++lib2)
  898. {
  899. this->DeleteDependencyForVS6( dep_map, *lib, *lib2);
  900. }
  901. }
  902. // 3. Create the new link line by simply emitting any dependencies that are
  903. // missing. Start from the back and keep adding.
  904. //
  905. std::set<DependencyMap::key_type> done, visited;
  906. std::vector<DependencyMap::key_type> newLinkLibrariesForVS6;
  907. for(LinkLibraryVectorType::reverse_iterator lib =
  908. this->LinkLibrariesForVS6.rbegin();
  909. lib != this->LinkLibrariesForVS6.rend(); ++lib)
  910. {
  911. // skip zero size library entries, this may happen
  912. // if a variable expands to nothing.
  913. if (!lib->first.empty())
  914. {
  915. this->EmitForVS6( *lib, dep_map, done, visited, newLinkLibrariesForVS6 );
  916. }
  917. }
  918. // 4. Add the new libraries to the link line.
  919. //
  920. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  921. newLinkLibrariesForVS6.rbegin();
  922. k != newLinkLibrariesForVS6.rend(); ++k )
  923. {
  924. // get the llt from the dep_map
  925. this->LinkLibrariesForVS6.push_back( std::make_pair(k->first,k->second) );
  926. }
  927. this->LinkLibrariesForVS6Analyzed = true;
  928. }
  929. //----------------------------------------------------------------------------
  930. void cmTarget::InsertDependencyForVS6( DependencyMap& depMap,
  931. const LibraryID& lib,
  932. const LibraryID& dep)
  933. {
  934. depMap[lib].push_back(dep);
  935. }
  936. //----------------------------------------------------------------------------
  937. void cmTarget::DeleteDependencyForVS6( DependencyMap& depMap,
  938. const LibraryID& lib,
  939. const LibraryID& dep)
  940. {
  941. // Make sure there is an entry in the map for lib. If so, delete all
  942. // dependencies to dep. There may be repeated entries because of
  943. // external libraries that are specified multiple times.
  944. DependencyMap::iterator map_itr = depMap.find( lib );
  945. if( map_itr != depMap.end() )
  946. {
  947. DependencyList& depList = map_itr->second;
  948. DependencyList::iterator begin =
  949. std::remove(depList.begin(), depList.end(), dep);
  950. depList.erase(begin, depList.end());
  951. }
  952. }
  953. //----------------------------------------------------------------------------
  954. void cmTarget::EmitForVS6(const LibraryID lib,
  955. const DependencyMap& dep_map,
  956. std::set<LibraryID>& emitted,
  957. std::set<LibraryID>& visited,
  958. DependencyList& link_line )
  959. {
  960. // It's already been emitted
  961. if( emitted.find(lib) != emitted.end() )
  962. {
  963. return;
  964. }
  965. // Emit the dependencies only if this library node hasn't been
  966. // visited before. If it has, then we have a cycle. The recursion
  967. // that got us here should take care of everything.
  968. if( visited.insert(lib).second )
  969. {
  970. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  971. {
  972. const DependencyList& dep_on = dep_map.find( lib )->second;
  973. DependencyList::const_reverse_iterator i;
  974. // To cater for recursive external libraries, we must emit
  975. // duplicates on this link line *unless* they were emitted by
  976. // some other node, in which case we assume that the recursion
  977. // was resolved then. We making the simplifying assumption that
  978. // any duplicates on a single link line are on purpose, and must
  979. // be preserved.
  980. // This variable will keep track of the libraries that were
  981. // emitted directly from the current node, and not from a
  982. // recursive call. This way, if we come across a library that
  983. // has already been emitted, we repeat it iff it has been
  984. // emitted here.
  985. std::set<DependencyMap::key_type> emitted_here;
  986. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  987. {
  988. if( emitted_here.find(*i) != emitted_here.end() )
  989. {
  990. // a repeat. Must emit.
  991. emitted.insert(*i);
  992. link_line.push_back( *i );
  993. }
  994. else
  995. {
  996. // Emit only if no-one else has
  997. if( emitted.find(*i) == emitted.end() )
  998. {
  999. // emit dependencies
  1000. this->EmitForVS6( *i, dep_map, emitted, visited, link_line );
  1001. // emit self
  1002. emitted.insert(*i);
  1003. emitted_here.insert(*i);
  1004. link_line.push_back( *i );
  1005. }
  1006. }
  1007. }
  1008. }
  1009. }
  1010. }
  1011. //----------------------------------------------------------------------------
  1012. void cmTarget::GatherDependenciesForVS6( const cmMakefile& mf,
  1013. const LibraryID& lib,
  1014. DependencyMap& dep_map)
  1015. {
  1016. // If the library is already in the dependency map, then it has
  1017. // already been fully processed.
  1018. if( dep_map.find(lib) != dep_map.end() )
  1019. {
  1020. return;
  1021. }
  1022. const char* deps = mf.GetDefinition( lib.first+"_LIB_DEPENDS" );
  1023. if( deps && strcmp(deps,"") != 0 )
  1024. {
  1025. // Make sure this library is in the map, even if it has an empty
  1026. // set of dependencies. This distinguishes the case of explicitly
  1027. // no dependencies with that of unspecified dependencies.
  1028. dep_map[lib];
  1029. // Parse the dependency information, which is a set of
  1030. // type, library pairs separated by ";". There is always a trailing ";".
  1031. cmTargetLinkLibraryType llt = GENERAL_LibraryType;
  1032. std::string depline = deps;
  1033. std::string::size_type start = 0;
  1034. std::string::size_type end;
  1035. end = depline.find( ";", start );
  1036. while( end != std::string::npos )
  1037. {
  1038. std::string l = depline.substr( start, end-start );
  1039. if(!l.empty())
  1040. {
  1041. if (l == "debug")
  1042. {
  1043. llt = DEBUG_LibraryType;
  1044. }
  1045. else if (l == "optimized")
  1046. {
  1047. llt = OPTIMIZED_LibraryType;
  1048. }
  1049. else if (l == "general")
  1050. {
  1051. llt = GENERAL_LibraryType;
  1052. }
  1053. else
  1054. {
  1055. LibraryID lib2(l,llt);
  1056. this->InsertDependencyForVS6( dep_map, lib, lib2);
  1057. this->GatherDependenciesForVS6( mf, lib2, dep_map);
  1058. llt = GENERAL_LibraryType;
  1059. }
  1060. }
  1061. start = end+1; // skip the ;
  1062. end = depline.find( ";", start );
  1063. }
  1064. // cannot depend on itself
  1065. this->DeleteDependencyForVS6( dep_map, lib, lib);
  1066. }
  1067. }
  1068. #endif
  1069. //----------------------------------------------------------------------------
  1070. static bool whiteListedInterfaceProperty(const std::string& prop)
  1071. {
  1072. if(cmHasLiteralPrefix(prop, "INTERFACE_"))
  1073. {
  1074. return true;
  1075. }
  1076. static UNORDERED_SET<std::string> builtIns;
  1077. if (builtIns.empty())
  1078. {
  1079. builtIns.insert("COMPATIBLE_INTERFACE_BOOL");
  1080. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");
  1081. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MIN");
  1082. builtIns.insert("COMPATIBLE_INTERFACE_STRING");
  1083. builtIns.insert("EXPORT_NAME");
  1084. builtIns.insert("IMPORTED");
  1085. builtIns.insert("NAME");
  1086. builtIns.insert("TYPE");
  1087. }
  1088. if (builtIns.count(prop))
  1089. {
  1090. return true;
  1091. }
  1092. if (cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_"))
  1093. {
  1094. return true;
  1095. }
  1096. return false;
  1097. }
  1098. //----------------------------------------------------------------------------
  1099. void cmTarget::SetProperty(const std::string& prop, const char* value)
  1100. {
  1101. if (this->GetType() == cmState::INTERFACE_LIBRARY
  1102. && !whiteListedInterfaceProperty(prop))
  1103. {
  1104. std::ostringstream e;
  1105. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1106. "The property \"" << prop << "\" is not allowed.";
  1107. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1108. return;
  1109. }
  1110. else if (prop == "NAME")
  1111. {
  1112. std::ostringstream e;
  1113. e << "NAME property is read-only\n";
  1114. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1115. return;
  1116. }
  1117. else if(prop == "INCLUDE_DIRECTORIES")
  1118. {
  1119. this->Internal->IncludeDirectoriesEntries.clear();
  1120. this->Internal->IncludeDirectoriesBacktraces.clear();
  1121. if (value)
  1122. {
  1123. this->Internal->IncludeDirectoriesEntries.push_back(value);
  1124. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1125. this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
  1126. }
  1127. }
  1128. else if(prop == "COMPILE_OPTIONS")
  1129. {
  1130. this->Internal->CompileOptionsEntries.clear();
  1131. this->Internal->CompileOptionsBacktraces.clear();
  1132. if (value)
  1133. {
  1134. this->Internal->CompileOptionsEntries.push_back(value);
  1135. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1136. this->Internal->CompileOptionsBacktraces.push_back(lfbt);
  1137. }
  1138. }
  1139. else if(prop == "COMPILE_FEATURES")
  1140. {
  1141. this->Internal->CompileFeaturesEntries.clear();
  1142. this->Internal->CompileFeaturesBacktraces.clear();
  1143. if (value)
  1144. {
  1145. this->Internal->CompileFeaturesEntries.push_back(value);
  1146. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1147. this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
  1148. }
  1149. }
  1150. else if(prop == "COMPILE_DEFINITIONS")
  1151. {
  1152. this->Internal->CompileDefinitionsEntries.clear();
  1153. this->Internal->CompileDefinitionsBacktraces.clear();
  1154. if (value)
  1155. {
  1156. this->Internal->CompileDefinitionsEntries.push_back(value);
  1157. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1158. this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
  1159. }
  1160. }
  1161. else if(prop == "EXPORT_NAME" && this->IsImported())
  1162. {
  1163. std::ostringstream e;
  1164. e << "EXPORT_NAME property can't be set on imported targets (\""
  1165. << this->Name << "\")\n";
  1166. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1167. }
  1168. else if (prop == "LINK_LIBRARIES")
  1169. {
  1170. this->Internal->LinkImplementationPropertyEntries.clear();
  1171. this->Internal->LinkImplementationPropertyBacktraces.clear();
  1172. if (value)
  1173. {
  1174. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1175. this->Internal->LinkImplementationPropertyEntries.push_back(value);
  1176. this->Internal->LinkImplementationPropertyBacktraces.push_back(lfbt);
  1177. }
  1178. }
  1179. else if (prop == "SOURCES")
  1180. {
  1181. if(this->IsImported())
  1182. {
  1183. std::ostringstream e;
  1184. e << "SOURCES property can't be set on imported targets (\""
  1185. << this->Name << "\")\n";
  1186. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1187. return;
  1188. }
  1189. this->Internal->SourceEntries.clear();
  1190. this->Internal->SourceBacktraces.clear();
  1191. if (value)
  1192. {
  1193. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1194. this->Internal->SourceEntries.push_back(value);
  1195. this->Internal->SourceBacktraces.push_back(lfbt);
  1196. }
  1197. }
  1198. else
  1199. {
  1200. this->Properties.SetProperty(prop, value);
  1201. }
  1202. }
  1203. //----------------------------------------------------------------------------
  1204. void cmTarget::AppendProperty(const std::string& prop, const char* value,
  1205. bool asString)
  1206. {
  1207. if (this->GetType() == cmState::INTERFACE_LIBRARY
  1208. && !whiteListedInterfaceProperty(prop))
  1209. {
  1210. std::ostringstream e;
  1211. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1212. "The property \"" << prop << "\" is not allowed.";
  1213. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1214. return;
  1215. }
  1216. else if (prop == "NAME")
  1217. {
  1218. std::ostringstream e;
  1219. e << "NAME property is read-only\n";
  1220. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1221. return;
  1222. }
  1223. else if(prop == "INCLUDE_DIRECTORIES")
  1224. {
  1225. if (value && *value)
  1226. {
  1227. this->Internal->IncludeDirectoriesEntries.push_back(value);
  1228. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1229. this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
  1230. }
  1231. }
  1232. else if(prop == "COMPILE_OPTIONS")
  1233. {
  1234. if (value && *value)
  1235. {
  1236. this->Internal->CompileOptionsEntries.push_back(value);
  1237. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1238. this->Internal->CompileOptionsBacktraces.push_back(lfbt);
  1239. }
  1240. }
  1241. else if(prop == "COMPILE_FEATURES")
  1242. {
  1243. if (value && *value)
  1244. {
  1245. this->Internal->CompileFeaturesEntries.push_back(value);
  1246. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1247. this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
  1248. }
  1249. }
  1250. else if(prop == "COMPILE_DEFINITIONS")
  1251. {
  1252. if (value && *value)
  1253. {
  1254. this->Internal->CompileDefinitionsEntries.push_back(value);
  1255. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1256. this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
  1257. }
  1258. }
  1259. else if(prop == "EXPORT_NAME" && this->IsImported())
  1260. {
  1261. std::ostringstream e;
  1262. e << "EXPORT_NAME property can't be set on imported targets (\""
  1263. << this->Name << "\")\n";
  1264. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1265. }
  1266. else if (prop == "LINK_LIBRARIES")
  1267. {
  1268. if (value && *value)
  1269. {
  1270. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1271. this->Internal->LinkImplementationPropertyEntries.push_back(value);
  1272. this->Internal->LinkImplementationPropertyBacktraces.push_back(lfbt);
  1273. }
  1274. }
  1275. else if (prop == "SOURCES")
  1276. {
  1277. if(this->IsImported())
  1278. {
  1279. std::ostringstream e;
  1280. e << "SOURCES property can't be set on imported targets (\""
  1281. << this->Name << "\")\n";
  1282. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1283. return;
  1284. }
  1285. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1286. this->Internal->SourceEntries.push_back(value);
  1287. this->Internal->SourceBacktraces.push_back(lfbt);
  1288. }
  1289. else
  1290. {
  1291. this->Properties.AppendProperty(prop, value, asString);
  1292. }
  1293. }
  1294. //----------------------------------------------------------------------------
  1295. std::string cmTarget::GetExportName() const
  1296. {
  1297. const char *exportName = this->GetProperty("EXPORT_NAME");
  1298. if (exportName && *exportName)
  1299. {
  1300. if (!cmGeneratorExpression::IsValidTargetName(exportName))
  1301. {
  1302. std::ostringstream e;
  1303. e << "EXPORT_NAME property \"" << exportName << "\" for \""
  1304. << this->GetName() << "\": is not valid.";
  1305. cmSystemTools::Error(e.str().c_str());
  1306. return "";
  1307. }
  1308. return exportName;
  1309. }
  1310. return this->GetName();
  1311. }
  1312. //----------------------------------------------------------------------------
  1313. void cmTarget::AppendBuildInterfaceIncludes()
  1314. {
  1315. if(this->GetType() != cmState::SHARED_LIBRARY &&
  1316. this->GetType() != cmState::STATIC_LIBRARY &&
  1317. this->GetType() != cmState::MODULE_LIBRARY &&
  1318. this->GetType() != cmState::INTERFACE_LIBRARY &&
  1319. !this->IsExecutableWithExports())
  1320. {
  1321. return;
  1322. }
  1323. if (this->BuildInterfaceIncludesAppended)
  1324. {
  1325. return;
  1326. }
  1327. this->BuildInterfaceIncludesAppended = true;
  1328. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE"))
  1329. {
  1330. const char *binDir = this->Makefile->GetCurrentBinaryDirectory();
  1331. const char *srcDir = this->Makefile->GetCurrentSourceDirectory();
  1332. const std::string dirs = std::string(binDir ? binDir : "")
  1333. + std::string(binDir ? ";" : "")
  1334. + std::string(srcDir ? srcDir : "");
  1335. if (!dirs.empty())
  1336. {
  1337. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  1338. ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
  1339. }
  1340. }
  1341. }
  1342. //----------------------------------------------------------------------------
  1343. void cmTarget::InsertInclude(std::string const& entry,
  1344. cmListFileBacktrace const& bt,
  1345. bool before)
  1346. {
  1347. std::vector<std::string>::iterator position =
  1348. before ? this->Internal->IncludeDirectoriesEntries.begin()
  1349. : this->Internal->IncludeDirectoriesEntries.end();
  1350. std::vector<cmListFileBacktrace>::iterator btPosition =
  1351. before ? this->Internal->IncludeDirectoriesBacktraces.begin()
  1352. : this->Internal->IncludeDirectoriesBacktraces.end();
  1353. this->Internal->IncludeDirectoriesEntries.insert(position, entry);
  1354. this->Internal->IncludeDirectoriesBacktraces.insert(btPosition, bt);
  1355. }
  1356. //----------------------------------------------------------------------------
  1357. void cmTarget::InsertCompileOption(std::string const& entry,
  1358. cmListFileBacktrace const& bt,
  1359. bool before)
  1360. {
  1361. std::vector<std::string>::iterator position =
  1362. before ? this->Internal->CompileOptionsEntries.begin()
  1363. : this->Internal->CompileOptionsEntries.end();
  1364. std::vector<cmListFileBacktrace>::iterator btPosition =
  1365. before ? this->Internal->CompileOptionsBacktraces.begin()
  1366. : this->Internal->CompileOptionsBacktraces.end();
  1367. this->Internal->CompileOptionsEntries.insert(position, entry);
  1368. this->Internal->CompileOptionsBacktraces.insert(btPosition, bt);
  1369. }
  1370. //----------------------------------------------------------------------------
  1371. void cmTarget::InsertCompileDefinition(std::string const& entry,
  1372. cmListFileBacktrace const& bt)
  1373. {
  1374. this->Internal->CompileDefinitionsEntries.push_back(entry);
  1375. this->Internal->CompileDefinitionsBacktraces.push_back(bt);
  1376. }
  1377. //----------------------------------------------------------------------------
  1378. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
  1379. const std::string& prop, const char* value, cmMakefile* context,
  1380. bool imported)
  1381. {
  1382. // Look for link-type keywords in the value.
  1383. static cmsys::RegularExpression
  1384. keys("(^|;)(debug|optimized|general)(;|$)");
  1385. if(!keys.find(value))
  1386. {
  1387. return;
  1388. }
  1389. // Support imported and non-imported versions of the property.
  1390. const char* base = (imported?
  1391. "IMPORTED_LINK_INTERFACE_LIBRARIES" :
  1392. "LINK_INTERFACE_LIBRARIES");
  1393. // Report an error.
  1394. std::ostringstream e;
  1395. e << "Property " << prop << " may not contain link-type keyword \""
  1396. << keys.match(2) << "\". "
  1397. << "The " << base << " property has a per-configuration "
  1398. << "version called " << base << "_<CONFIG> which may be "
  1399. << "used to specify per-configuration rules.";
  1400. if(!imported)
  1401. {
  1402. e << " "
  1403. << "Alternatively, an IMPORTED library may be created, configured "
  1404. << "with a per-configuration location, and then named in the "
  1405. << "property value. "
  1406. << "See the add_library command's IMPORTED mode for details."
  1407. << "\n"
  1408. << "If you have a list of libraries that already contains the "
  1409. << "keyword, use the target_link_libraries command with its "
  1410. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  1411. << "The command automatically recognizes link-type keywords and sets "
  1412. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  1413. << "properties accordingly.";
  1414. }
  1415. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  1416. }
  1417. //----------------------------------------------------------------------------
  1418. static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
  1419. cmMakefile* context)
  1420. {
  1421. // Look for link-type keywords in the value.
  1422. static cmsys::RegularExpression
  1423. keys("(^|;)(debug|optimized|general)(;|$)");
  1424. if(!keys.find(value))
  1425. {
  1426. return;
  1427. }
  1428. // Report an error.
  1429. std::ostringstream e;
  1430. e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
  1431. "keyword \"" << keys.match(2) << "\". The INTERFACE_LINK_LIBRARIES "
  1432. "property may contain configuration-sensitive generator-expressions "
  1433. "which may be used to specify per-configuration rules.";
  1434. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  1435. }
  1436. //----------------------------------------------------------------------------
  1437. void cmTarget::CheckProperty(const std::string& prop,
  1438. cmMakefile* context) const
  1439. {
  1440. // Certain properties need checking.
  1441. if(cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES"))
  1442. {
  1443. if(const char* value = this->GetProperty(prop))
  1444. {
  1445. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  1446. }
  1447. }
  1448. if(cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES"))
  1449. {
  1450. if(const char* value = this->GetProperty(prop))
  1451. {
  1452. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  1453. }
  1454. }
  1455. if(cmHasLiteralPrefix(prop, "INTERFACE_LINK_LIBRARIES"))
  1456. {
  1457. if(const char* value = this->GetProperty(prop))
  1458. {
  1459. cmTargetCheckINTERFACE_LINK_LIBRARIES(value, context);
  1460. }
  1461. }
  1462. }
  1463. //----------------------------------------------------------------------------
  1464. void cmTarget::MarkAsImported()
  1465. {
  1466. this->IsImportedTarget = true;
  1467. }
  1468. //----------------------------------------------------------------------------
  1469. bool cmTarget::HaveWellDefinedOutputFiles() const
  1470. {
  1471. return
  1472. this->GetType() == cmState::STATIC_LIBRARY ||
  1473. this->GetType() == cmState::SHARED_LIBRARY ||
  1474. this->GetType() == cmState::MODULE_LIBRARY ||
  1475. this->GetType() == cmState::EXECUTABLE;
  1476. }
  1477. //----------------------------------------------------------------------------
  1478. bool cmTarget::HandleLocationPropertyPolicy(cmMakefile* context) const
  1479. {
  1480. if (this->IsImported())
  1481. {
  1482. return true;
  1483. }
  1484. std::ostringstream e;
  1485. const char *modal = 0;
  1486. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  1487. switch (context->GetPolicyStatus(cmPolicies::CMP0026))
  1488. {
  1489. case cmPolicies::WARN:
  1490. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0026) << "\n";
  1491. modal = "should";
  1492. case cmPolicies::OLD:
  1493. break;
  1494. case cmPolicies::REQUIRED_ALWAYS:
  1495. case cmPolicies::REQUIRED_IF_USED:
  1496. case cmPolicies::NEW:
  1497. modal = "may";
  1498. messageType = cmake::FATAL_ERROR;
  1499. }
  1500. if (modal)
  1501. {
  1502. e << "The LOCATION property " << modal << " not be read from target \""
  1503. << this->GetName() << "\". Use the target name directly with "
  1504. "add_custom_command, or use the generator expression $<TARGET_FILE>, "
  1505. "as appropriate.\n";
  1506. context->IssueMessage(messageType, e.str());
  1507. }
  1508. return messageType != cmake::FATAL_ERROR;
  1509. }
  1510. //----------------------------------------------------------------------------
  1511. const char *cmTarget::GetProperty(const std::string& prop) const
  1512. {
  1513. return this->GetProperty(prop, this->Makefile);
  1514. }
  1515. //----------------------------------------------------------------------------
  1516. const char *cmTarget::GetProperty(const std::string& prop,
  1517. cmMakefile* context) const
  1518. {
  1519. if (this->GetType() == cmState::INTERFACE_LIBRARY
  1520. && !whiteListedInterfaceProperty(prop))
  1521. {
  1522. std::ostringstream e;
  1523. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1524. "The property \"" << prop << "\" is not allowed.";
  1525. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  1526. return 0;
  1527. }
  1528. // Watch for special "computed" properties that are dependent on
  1529. // other properties or variables. Always recompute them.
  1530. if(this->GetType() == cmState::EXECUTABLE ||
  1531. this->GetType() == cmState::STATIC_LIBRARY ||
  1532. this->GetType() == cmState::SHARED_LIBRARY ||
  1533. this->GetType() == cmState::MODULE_LIBRARY ||
  1534. this->GetType() == cmState::UNKNOWN_LIBRARY)
  1535. {
  1536. static const std::string propLOCATION = "LOCATION";
  1537. if(prop == propLOCATION)
  1538. {
  1539. if (!this->HandleLocationPropertyPolicy(context))
  1540. {
  1541. return 0;
  1542. }
  1543. // Set the LOCATION property of the target.
  1544. //
  1545. // For an imported target this is the location of an arbitrary
  1546. // available configuration.
  1547. //
  1548. if(this->IsImported())
  1549. {
  1550. this->Properties.SetProperty(
  1551. propLOCATION, this->ImportedGetFullPath("", false).c_str());
  1552. }
  1553. else
  1554. {
  1555. // For a non-imported target this is deprecated because it
  1556. // cannot take into account the per-configuration name of the
  1557. // target because the configuration type may not be known at
  1558. // CMake time.
  1559. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  1560. gg->CreateGenerationObjects();
  1561. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  1562. this->Properties.SetProperty(propLOCATION,
  1563. gt->GetLocationForBuild());
  1564. }
  1565. }
  1566. // Support "LOCATION_<CONFIG>".
  1567. else if(cmHasLiteralPrefix(prop, "LOCATION_"))
  1568. {
  1569. if (!this->HandleLocationPropertyPolicy(context))
  1570. {
  1571. return 0;
  1572. }
  1573. const char* configName = prop.c_str() + 9;
  1574. if (this->IsImported())
  1575. {
  1576. this->Properties.SetProperty(
  1577. prop, this->ImportedGetFullPath(configName, false).c_str());
  1578. }
  1579. else
  1580. {
  1581. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  1582. gg->CreateGenerationObjects();
  1583. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  1584. this->Properties.SetProperty(
  1585. prop, gt->GetFullPath(configName, false).c_str());
  1586. }
  1587. }
  1588. // Support "<CONFIG>_LOCATION".
  1589. else if(cmHasLiteralSuffix(prop, "_LOCATION"))
  1590. {
  1591. std::string configName(prop.c_str(), prop.size() - 9);
  1592. if(configName != "IMPORTED")
  1593. {
  1594. if (!this->HandleLocationPropertyPolicy(context))
  1595. {
  1596. return 0;
  1597. }
  1598. if (this->IsImported())
  1599. {
  1600. this->Properties.SetProperty(
  1601. prop, this->ImportedGetFullPath(configName, false).c_str());
  1602. }
  1603. else
  1604. {
  1605. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  1606. gg->CreateGenerationObjects();
  1607. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  1608. this->Properties.SetProperty(
  1609. prop, gt->GetFullPath(configName, false).c_str());
  1610. }
  1611. }
  1612. }
  1613. }
  1614. static UNORDERED_SET<std::string> specialProps;
  1615. #define MAKE_STATIC_PROP(PROP) \
  1616. static const std::string prop##PROP = #PROP
  1617. MAKE_STATIC_PROP(LINK_LIBRARIES);
  1618. MAKE_STATIC_PROP(TYPE);
  1619. MAKE_STATIC_PROP(INCLUDE_DIRECTORIES);
  1620. MAKE_STATIC_PROP(COMPILE_FEATURES);
  1621. MAKE_STATIC_PROP(COMPILE_OPTIONS);
  1622. MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
  1623. MAKE_STATIC_PROP(IMPORTED);
  1624. MAKE_STATIC_PROP(NAME);
  1625. MAKE_STATIC_PROP(BINARY_DIR);
  1626. MAKE_STATIC_PROP(SOURCE_DIR);
  1627. MAKE_STATIC_PROP(SOURCES);
  1628. #undef MAKE_STATIC_PROP
  1629. if(specialProps.empty())
  1630. {
  1631. specialProps.insert(propLINK_LIBRARIES);
  1632. specialProps.insert(propTYPE);
  1633. specialProps.insert(propINCLUDE_DIRECTORIES);
  1634. specialProps.insert(propCOMPILE_FEATURES);
  1635. specialProps.insert(propCOMPILE_OPTIONS);
  1636. specialProps.insert(propCOMPILE_DEFINITIONS);
  1637. specialProps.insert(propIMPORTED);
  1638. specialProps.insert(propNAME);
  1639. specialProps.insert(propBINARY_DIR);
  1640. specialProps.insert(propSOURCE_DIR);
  1641. specialProps.insert(propSOURCES);
  1642. }
  1643. if(specialProps.count(prop))
  1644. {
  1645. if(prop == propLINK_LIBRARIES)
  1646. {
  1647. if (this->Internal->LinkImplementationPropertyEntries.empty())
  1648. {
  1649. return 0;
  1650. }
  1651. static std::string output;
  1652. output = cmJoin(this->Internal->LinkImplementationPropertyEntries, ";");
  1653. return output.c_str();
  1654. }
  1655. // the type property returns what type the target is
  1656. else if (prop == propTYPE)
  1657. {
  1658. return cmState::GetTargetTypeName(this->GetType());
  1659. }
  1660. else if(prop == propINCLUDE_DIRECTORIES)
  1661. {
  1662. if (this->Internal->IncludeDirectoriesEntries.empty())
  1663. {
  1664. return 0;
  1665. }
  1666. static std::string output;
  1667. output = cmJoin(this->Internal->IncludeDirectoriesEntries, ";");
  1668. return output.c_str();
  1669. }
  1670. else if(prop == propCOMPILE_FEATURES)
  1671. {
  1672. if (this->Internal->CompileFeaturesEntries.empty())
  1673. {
  1674. return 0;
  1675. }
  1676. static std::string output;
  1677. output = cmJoin(this->Internal->CompileFeaturesEntries, ";");
  1678. return output.c_str();
  1679. }
  1680. else if(prop == propCOMPILE_OPTIONS)
  1681. {
  1682. if (this->Internal->CompileOptionsEntries.empty())
  1683. {
  1684. return 0;
  1685. }
  1686. static std::string output;
  1687. output = cmJoin(this->Internal->CompileOptionsEntries, ";");
  1688. return output.c_str();
  1689. }
  1690. else if(prop == propCOMPILE_DEFINITIONS)
  1691. {
  1692. if (this->Internal->CompileDefinitionsEntries.empty())
  1693. {
  1694. return 0;
  1695. }
  1696. static std::string output;
  1697. output = cmJoin(this->Internal->CompileDefinitionsEntries, ";");
  1698. return output.c_str();
  1699. }
  1700. else if (prop == propIMPORTED)
  1701. {
  1702. return this->IsImported()?"TRUE":"FALSE";
  1703. }
  1704. else if (prop == propNAME)
  1705. {
  1706. return this->GetName().c_str();
  1707. }
  1708. else if (prop == propBINARY_DIR)
  1709. {
  1710. return this->GetMakefile()->GetCurrentBinaryDirectory();
  1711. }
  1712. else if (prop == propSOURCE_DIR)
  1713. {
  1714. return this->GetMakefile()->GetCurrentSourceDirectory();
  1715. }
  1716. else if(prop == propSOURCES)
  1717. {
  1718. if (this->Internal->SourceEntries.empty())
  1719. {
  1720. return 0;
  1721. }
  1722. std::ostringstream ss;
  1723. const char* sep = "";
  1724. for(std::vector<std::string>::const_iterator
  1725. i = this->Internal->SourceEntries.begin();
  1726. i != this->Internal->SourceEntries.end(); ++i)
  1727. {
  1728. std::string const& entry = *i;
  1729. std::vector<std::string> files;
  1730. cmSystemTools::ExpandListArgument(entry, files);
  1731. for (std::vector<std::string>::const_iterator
  1732. li = files.begin(); li != files.end(); ++li)
  1733. {
  1734. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  1735. (*li)[li->size() - 1] == '>')
  1736. {
  1737. std::string objLibName = li->substr(17, li->size()-18);
  1738. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  1739. {
  1740. ss << sep;
  1741. sep = ";";
  1742. ss << *li;
  1743. continue;
  1744. }
  1745. bool addContent = false;
  1746. bool noMessage = true;
  1747. std::ostringstream e;
  1748. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  1749. switch(context->GetPolicyStatus(cmPolicies::CMP0051))
  1750. {
  1751. case cmPolicies::WARN:
  1752. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
  1753. noMessage = false;
  1754. case cmPolicies::OLD:
  1755. break;
  1756. case cmPolicies::REQUIRED_ALWAYS:
  1757. case cmPolicies::REQUIRED_IF_USED:
  1758. case cmPolicies::NEW:
  1759. addContent = true;
  1760. }
  1761. if (!noMessage)
  1762. {
  1763. e << "Target \"" << this->Name << "\" contains "
  1764. "$<TARGET_OBJECTS> generator expression in its sources list. "
  1765. "This content was not previously part of the SOURCES property "
  1766. "when that property was read at configure time. Code reading "
  1767. "that property needs to be adapted to ignore the generator "
  1768. "expression using the string(GENEX_STRIP) command.";
  1769. context->IssueMessage(messageType, e.str());
  1770. }
  1771. if (addContent)
  1772. {
  1773. ss << sep;
  1774. sep = ";";
  1775. ss << *li;
  1776. }
  1777. }
  1778. else if (cmGeneratorExpression::Find(*li) == std::string::npos)
  1779. {
  1780. ss << sep;
  1781. sep = ";";
  1782. ss << *li;
  1783. }
  1784. else
  1785. {
  1786. cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li);
  1787. // Construct what is known about this source file location.
  1788. cmSourceFileLocation const& location = sf->GetLocation();
  1789. std::string sname = location.GetDirectory();
  1790. if(!sname.empty())
  1791. {
  1792. sname += "/";
  1793. }
  1794. sname += location.GetName();
  1795. ss << sep;
  1796. sep = ";";
  1797. // Append this list entry.
  1798. ss << sname;
  1799. }
  1800. }
  1801. }
  1802. this->Properties.SetProperty("SOURCES", ss.str().c_str());
  1803. }
  1804. }
  1805. const char *retVal = this->Properties.GetPropertyValue(prop);
  1806. if (!retVal)
  1807. {
  1808. const bool chain = this->GetMakefile()->GetState()->
  1809. IsPropertyChained(prop, cmProperty::TARGET);
  1810. if (chain)
  1811. {
  1812. return this->Makefile->GetProperty(prop, chain);
  1813. }
  1814. }
  1815. return retVal;
  1816. }
  1817. //----------------------------------------------------------------------------
  1818. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  1819. {
  1820. return cmSystemTools::IsOn(this->GetProperty(prop));
  1821. }
  1822. //----------------------------------------------------------------------------
  1823. const char* cmTarget::GetSuffixVariableInternal(bool implib) const
  1824. {
  1825. switch(this->GetType())
  1826. {
  1827. case cmState::STATIC_LIBRARY:
  1828. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  1829. case cmState::SHARED_LIBRARY:
  1830. return (implib
  1831. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  1832. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  1833. case cmState::MODULE_LIBRARY:
  1834. return (implib
  1835. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  1836. : "CMAKE_SHARED_MODULE_SUFFIX");
  1837. case cmState::EXECUTABLE:
  1838. return (implib
  1839. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  1840. // Android GUI application packages store the native
  1841. // binary as a shared library.
  1842. : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
  1843. "CMAKE_SHARED_LIBRARY_SUFFIX" : "CMAKE_EXECUTABLE_SUFFIX"));
  1844. default:
  1845. break;
  1846. }
  1847. return "";
  1848. }
  1849. //----------------------------------------------------------------------------
  1850. const char* cmTarget::GetPrefixVariableInternal(bool implib) const
  1851. {
  1852. switch(this->GetType())
  1853. {
  1854. case cmState::STATIC_LIBRARY:
  1855. return "CMAKE_STATIC_LIBRARY_PREFIX";
  1856. case cmState::SHARED_LIBRARY:
  1857. return (implib
  1858. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  1859. : "CMAKE_SHARED_LIBRARY_PREFIX");
  1860. case cmState::MODULE_LIBRARY:
  1861. return (implib
  1862. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  1863. : "CMAKE_SHARED_MODULE_PREFIX");
  1864. case cmState::EXECUTABLE:
  1865. return (implib
  1866. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  1867. // Android GUI application packages store the native
  1868. // binary as a shared library.
  1869. : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
  1870. "CMAKE_SHARED_LIBRARY_PREFIX" : ""));
  1871. default:
  1872. break;
  1873. }
  1874. return "";
  1875. }
  1876. //----------------------------------------------------------------------------
  1877. std::string
  1878. cmTarget::ImportedGetFullPath(const std::string& config, bool pimplib) const
  1879. {
  1880. assert(this->IsImported());
  1881. // Lookup/compute/cache the import information for this
  1882. // configuration.
  1883. std::string config_upper;
  1884. if(!config.empty())
  1885. {
  1886. config_upper = cmSystemTools::UpperCase(config);
  1887. }
  1888. else
  1889. {
  1890. config_upper = "NOCONFIG";
  1891. }
  1892. std::string result;
  1893. const char* loc = 0;
  1894. const char* imp = 0;
  1895. std::string suffix;
  1896. if(this->GetType() != cmState::INTERFACE_LIBRARY
  1897. && this->GetMappedConfig(config_upper, &loc, &imp, suffix))
  1898. {
  1899. if (!pimplib)
  1900. {
  1901. if(loc)
  1902. {
  1903. result = loc;
  1904. }
  1905. else
  1906. {
  1907. std::string impProp = "IMPORTED_LOCATION";
  1908. impProp += suffix;
  1909. if(const char* config_location = this->GetProperty(impProp))
  1910. {
  1911. result = config_location;
  1912. }
  1913. else if(const char* location =
  1914. this->GetProperty("IMPORTED_LOCATION"))
  1915. {
  1916. result = location;
  1917. }
  1918. }
  1919. }
  1920. else
  1921. {
  1922. if(imp)
  1923. {
  1924. result = imp;
  1925. }
  1926. else if(this->GetType() == cmState::SHARED_LIBRARY ||
  1927. this->IsExecutableWithExports())
  1928. {
  1929. std::string impProp = "IMPORTED_IMPLIB";
  1930. impProp += suffix;
  1931. if(const char* config_implib = this->GetProperty(impProp))
  1932. {
  1933. result = config_implib;
  1934. }
  1935. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  1936. {
  1937. result = implib;
  1938. }
  1939. }
  1940. }
  1941. }
  1942. if(result.empty())
  1943. {
  1944. result = this->GetName();
  1945. result += "-NOTFOUND";
  1946. }
  1947. return result;
  1948. }
  1949. //----------------------------------------------------------------------------
  1950. void cmTarget::SetPropertyDefault(const std::string& property,
  1951. const char* default_value)
  1952. {
  1953. // Compute the name of the variable holding the default value.
  1954. std::string var = "CMAKE_";
  1955. var += property;
  1956. if(const char* value = this->Makefile->GetDefinition(var))
  1957. {
  1958. this->SetProperty(property, value);
  1959. }
  1960. else if(default_value)
  1961. {
  1962. this->SetProperty(property, default_value);
  1963. }
  1964. }
  1965. //----------------------------------------------------------------------------
  1966. std::string cmTarget::GetFrameworkVersion() const
  1967. {
  1968. assert(this->GetType() != cmState::INTERFACE_LIBRARY);
  1969. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  1970. {
  1971. return fversion;
  1972. }
  1973. else if(const char* tversion = this->GetProperty("VERSION"))
  1974. {
  1975. return tversion;
  1976. }
  1977. else
  1978. {
  1979. return "A";
  1980. }
  1981. }
  1982. //----------------------------------------------------------------------------
  1983. const char* cmTarget::GetExportMacro() const
  1984. {
  1985. // Define the symbol for targets that export symbols.
  1986. if(this->GetType() == cmState::SHARED_LIBRARY ||
  1987. this->GetType() == cmState::MODULE_LIBRARY ||
  1988. this->IsExecutableWithExports())
  1989. {
  1990. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  1991. {
  1992. this->ExportMacro = custom_export_name;
  1993. }
  1994. else
  1995. {
  1996. std::string in = this->GetName();
  1997. in += "_EXPORTS";
  1998. this->ExportMacro = cmSystemTools::MakeCindentifier(in);
  1999. }
  2000. return this->ExportMacro.c_str();
  2001. }
  2002. else
  2003. {
  2004. return 0;
  2005. }
  2006. }
  2007. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  2008. const char** loc,
  2009. const char** imp,
  2010. std::string& suffix) const
  2011. {
  2012. if (this->GetType() == cmState::INTERFACE_LIBRARY)
  2013. {
  2014. // This method attempts to find a config-specific LOCATION for the
  2015. // IMPORTED library. In the case of cmState::INTERFACE_LIBRARY, there is no
  2016. // LOCATION at all, so leaving *loc and *imp unchanged is the appropriate
  2017. // and valid response.
  2018. return true;
  2019. }
  2020. // Track the configuration-specific property suffix.
  2021. suffix = "_";
  2022. suffix += desired_config;
  2023. std::vector<std::string> mappedConfigs;
  2024. {
  2025. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  2026. mapProp += desired_config;
  2027. if(const char* mapValue = this->GetProperty(mapProp))
  2028. {
  2029. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  2030. }
  2031. }
  2032. // If we needed to find one of the mapped configurations but did not
  2033. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  2034. // library or an executable with exports.
  2035. bool allowImp = this->HasImportLibrary();
  2036. // If a mapping was found, check its configurations.
  2037. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  2038. !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
  2039. {
  2040. // Look for this configuration.
  2041. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  2042. std::string locProp = "IMPORTED_LOCATION_";
  2043. locProp += mcUpper;
  2044. *loc = this->GetProperty(locProp);
  2045. if(allowImp)
  2046. {
  2047. std::string impProp = "IMPORTED_IMPLIB_";
  2048. impProp += mcUpper;
  2049. *imp = this->GetProperty(impProp);
  2050. }
  2051. // If it was found, use it for all properties below.
  2052. if(*loc || *imp)
  2053. {
  2054. suffix = "_";
  2055. suffix += mcUpper;
  2056. }
  2057. }
  2058. // If we needed to find one of the mapped configurations but did not
  2059. // then the target is not found. The project does not want any
  2060. // other configuration.
  2061. if(!mappedConfigs.empty() && !*loc && !*imp)
  2062. {
  2063. return false;
  2064. }
  2065. // If we have not yet found it then there are no mapped
  2066. // configurations. Look for an exact-match.
  2067. if(!*loc && !*imp)
  2068. {
  2069. std::string locProp = "IMPORTED_LOCATION";
  2070. locProp += suffix;
  2071. *loc = this->GetProperty(locProp);
  2072. if(allowImp)
  2073. {
  2074. std::string impProp = "IMPORTED_IMPLIB";
  2075. impProp += suffix;
  2076. *imp = this->GetProperty(impProp);
  2077. }
  2078. }
  2079. // If we have not yet found it then there are no mapped
  2080. // configurations and no exact match.
  2081. if(!*loc && !*imp)
  2082. {
  2083. // The suffix computed above is not useful.
  2084. suffix = "";
  2085. // Look for a configuration-less location. This may be set by
  2086. // manually-written code.
  2087. *loc = this->GetProperty("IMPORTED_LOCATION");
  2088. if(allowImp)
  2089. {
  2090. *imp = this->GetProperty("IMPORTED_IMPLIB");
  2091. }
  2092. }
  2093. // If we have not yet found it then the project is willing to try
  2094. // any available configuration.
  2095. if(!*loc && !*imp)
  2096. {
  2097. std::vector<std::string> availableConfigs;
  2098. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  2099. {
  2100. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  2101. }
  2102. for(std::vector<std::string>::const_iterator
  2103. aci = availableConfigs.begin();
  2104. !*loc && !*imp && aci != availableConfigs.end(); ++aci)
  2105. {
  2106. suffix = "_";
  2107. suffix += cmSystemTools::UpperCase(*aci);
  2108. std::string locProp = "IMPORTED_LOCATION";
  2109. locProp += suffix;
  2110. *loc = this->GetProperty(locProp);
  2111. if(allowImp)
  2112. {
  2113. std::string impProp = "IMPORTED_IMPLIB";
  2114. impProp += suffix;
  2115. *imp = this->GetProperty(impProp);
  2116. }
  2117. }
  2118. }
  2119. // If we have not yet found it then the target is not available.
  2120. if(!*loc && !*imp)
  2121. {
  2122. return false;
  2123. }
  2124. return true;
  2125. }
  2126. //----------------------------------------------------------------------------
  2127. cmTargetInternalPointer::cmTargetInternalPointer()
  2128. {
  2129. this->Pointer = new cmTargetInternals;
  2130. }
  2131. //----------------------------------------------------------------------------
  2132. cmTargetInternalPointer
  2133. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  2134. {
  2135. // Ideally cmTarget instances should never be copied. However until
  2136. // we can make a sweep to remove that, this copy constructor avoids
  2137. // allowing the resources (Internals) to be copied.
  2138. this->Pointer = new cmTargetInternals(*r.Pointer);
  2139. }
  2140. //----------------------------------------------------------------------------
  2141. cmTargetInternalPointer::~cmTargetInternalPointer()
  2142. {
  2143. delete this->Pointer;
  2144. }
  2145. //----------------------------------------------------------------------------
  2146. cmTargetInternalPointer&
  2147. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  2148. {
  2149. if(this == &r) { return *this; } // avoid warning on HP about self check
  2150. // Ideally cmTarget instances should never be copied. However until
  2151. // we can make a sweep to remove that, this copy constructor avoids
  2152. // allowing the resources (Internals) to be copied.
  2153. cmTargetInternals* oldPointer = this->Pointer;
  2154. this->Pointer = new cmTargetInternals(*r.Pointer);
  2155. delete oldPointer;
  2156. return *this;
  2157. }