cmTarget.cxx 56 KB

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