cmTarget.cxx 56 KB

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