cmTarget.cxx 55 KB

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