cmTarget.cxx 56 KB

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