cmTarget.cxx 56 KB

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