cmTarget.cxx 56 KB

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