cmTarget.cxx 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmTarget.h"
  11. #include "cmake.h"
  12. #include "cmMakefile.h"
  13. #include "cmSourceFile.h"
  14. #include "cmOutputConverter.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmComputeLinkInformation.h"
  17. #include "cmListFileCache.h"
  18. #include "cmGeneratorExpression.h"
  19. #include "cmGeneratorExpressionDAGChecker.h"
  20. #include "cmAlgorithms.h"
  21. #include <cmsys/RegularExpression.hxx>
  22. #include <map>
  23. #include <set>
  24. #include <stdlib.h> // required for atof
  25. #include <assert.h>
  26. #include <errno.h>
  27. #if defined(CMAKE_BUILD_WITH_CMAKE)
  28. #include <cmsys/hash_set.hxx>
  29. #define UNORDERED_SET cmsys::hash_set
  30. #else
  31. #define UNORDERED_SET std::set
  32. #endif
  33. //----------------------------------------------------------------------------
  34. class cmTargetInternals
  35. {
  36. public:
  37. std::vector<std::string> IncludeDirectoriesEntries;
  38. std::vector<cmListFileBacktrace> IncludeDirectoriesBacktraces;
  39. std::vector<std::string> CompileOptionsEntries;
  40. std::vector<cmListFileBacktrace> CompileOptionsBacktraces;
  41. std::vector<std::string> CompileFeaturesEntries;
  42. std::vector<cmListFileBacktrace> CompileFeaturesBacktraces;
  43. std::vector<std::string> CompileDefinitionsEntries;
  44. std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces;
  45. std::vector<std::string> SourceEntries;
  46. std::vector<cmListFileBacktrace> SourceBacktraces;
  47. std::vector<std::string> LinkImplementationPropertyEntries;
  48. std::vector<cmListFileBacktrace> LinkImplementationPropertyBacktraces;
  49. };
  50. //----------------------------------------------------------------------------
  51. cmTarget::cmTarget()
  52. {
  53. this->Makefile = 0;
  54. #if defined(_WIN32) && !defined(__CYGWIN__)
  55. this->LinkLibrariesForVS6Analyzed = false;
  56. #endif
  57. this->HaveInstallRule = false;
  58. this->DLLPlatform = false;
  59. this->IsAndroid = false;
  60. this->IsApple = false;
  61. this->IsImportedTarget = false;
  62. this->BuildInterfaceIncludesAppended = false;
  63. }
  64. void cmTarget::SetType(cmState::TargetType type, const std::string& name)
  65. {
  66. this->Name = name;
  67. // only add dependency information for library targets
  68. this->TargetTypeValue = type;
  69. if(this->TargetTypeValue >= cmState::STATIC_LIBRARY
  70. && this->TargetTypeValue <= cmState::MODULE_LIBRARY)
  71. {
  72. this->RecordDependencies = true;
  73. }
  74. else
  75. {
  76. this->RecordDependencies = false;
  77. }
  78. }
  79. //----------------------------------------------------------------------------
  80. void cmTarget::SetMakefile(cmMakefile* mf)
  81. {
  82. // Set our makefile.
  83. this->Makefile = mf;
  84. // Check whether this is a DLL platform.
  85. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  86. this->Makefile->IsOn("CYGWIN") ||
  87. this->Makefile->IsOn("MINGW"));
  88. // Check whether we are targeting an Android platform.
  89. this->IsAndroid =
  90. strcmp(this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME"),
  91. "Android") == 0;
  92. // Check whether we are targeting an Apple platform.
  93. this->IsApple = this->Makefile->IsOn("APPLE");
  94. // Setup default property values.
  95. if (this->GetType() != cmState::INTERFACE_LIBRARY
  96. && this->GetType() != cmState::UTILITY)
  97. {
  98. this->SetPropertyDefault("ANDROID_API", 0);
  99. this->SetPropertyDefault("ANDROID_API_MIN", 0);
  100. this->SetPropertyDefault("ANDROID_ARCH", 0);
  101. this->SetPropertyDefault("ANDROID_STL_TYPE", 0);
  102. this->SetPropertyDefault("ANDROID_SKIP_ANT_STEP", 0);
  103. this->SetPropertyDefault("ANDROID_PROCESS_MAX", 0);
  104. this->SetPropertyDefault("ANDROID_PROGUARD", 0);
  105. this->SetPropertyDefault("ANDROID_PROGUARD_CONFIG_PATH", 0);
  106. this->SetPropertyDefault("ANDROID_SECURE_PROPS_PATH", 0);
  107. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DIRECTORIES", 0);
  108. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DEPENDENCIES", 0);
  109. this->SetPropertyDefault("ANDROID_JAVA_SOURCE_DIR", 0);
  110. this->SetPropertyDefault("ANDROID_JAR_DIRECTORIES", 0);
  111. this->SetPropertyDefault("ANDROID_JAR_DEPENDENCIES", 0);
  112. this->SetPropertyDefault("ANDROID_ASSETS_DIRECTORIES", 0);
  113. this->SetPropertyDefault("ANDROID_ANT_ADDITIONAL_OPTIONS", 0);
  114. this->SetPropertyDefault("INSTALL_NAME_DIR", 0);
  115. this->SetPropertyDefault("INSTALL_RPATH", "");
  116. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  117. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  118. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  119. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
  120. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
  121. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
  122. this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
  123. this->SetPropertyDefault("COMPILE_PDB_OUTPUT_DIRECTORY", 0);
  124. this->SetPropertyDefault("Fortran_FORMAT", 0);
  125. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
  126. this->SetPropertyDefault("GNUtoMS", 0);
  127. this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
  128. this->SetPropertyDefault("AUTOMOC", 0);
  129. this->SetPropertyDefault("AUTOUIC", 0);
  130. this->SetPropertyDefault("AUTORCC", 0);
  131. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
  132. this->SetPropertyDefault("AUTOUIC_OPTIONS", 0);
  133. this->SetPropertyDefault("AUTORCC_OPTIONS", 0);
  134. this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
  135. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
  136. this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
  137. this->SetPropertyDefault("MACOSX_BUNDLE", 0);
  138. this->SetPropertyDefault("MACOSX_RPATH", 0);
  139. this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0);
  140. this->SetPropertyDefault("C_COMPILER_LAUNCHER", 0);
  141. this->SetPropertyDefault("C_INCLUDE_WHAT_YOU_USE", 0);
  142. this->SetPropertyDefault("C_STANDARD", 0);
  143. this->SetPropertyDefault("C_STANDARD_REQUIRED", 0);
  144. this->SetPropertyDefault("C_EXTENSIONS", 0);
  145. this->SetPropertyDefault("CXX_COMPILER_LAUNCHER", 0);
  146. this->SetPropertyDefault("CXX_INCLUDE_WHAT_YOU_USE", 0);
  147. this->SetPropertyDefault("CXX_STANDARD", 0);
  148. this->SetPropertyDefault("CXX_STANDARD_REQUIRED", 0);
  149. this->SetPropertyDefault("CXX_EXTENSIONS", 0);
  150. this->SetPropertyDefault("LINK_SEARCH_START_STATIC", 0);
  151. this->SetPropertyDefault("LINK_SEARCH_END_STATIC", 0);
  152. }
  153. // Collect the set of configuration types.
  154. std::vector<std::string> configNames;
  155. mf->GetConfigurations(configNames);
  156. // Setup per-configuration property default values.
  157. if (this->GetType() != cmState::UTILITY)
  158. {
  159. const char* configProps[] = {
  160. "ARCHIVE_OUTPUT_DIRECTORY_",
  161. "LIBRARY_OUTPUT_DIRECTORY_",
  162. "RUNTIME_OUTPUT_DIRECTORY_",
  163. "PDB_OUTPUT_DIRECTORY_",
  164. "COMPILE_PDB_OUTPUT_DIRECTORY_",
  165. "MAP_IMPORTED_CONFIG_",
  166. 0};
  167. for(std::vector<std::string>::iterator ci = configNames.begin();
  168. ci != configNames.end(); ++ci)
  169. {
  170. std::string configUpper = cmSystemTools::UpperCase(*ci);
  171. for(const char** p = configProps; *p; ++p)
  172. {
  173. if (this->TargetTypeValue == cmState::INTERFACE_LIBRARY
  174. && strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0)
  175. {
  176. continue;
  177. }
  178. std::string property = *p;
  179. property += configUpper;
  180. this->SetPropertyDefault(property, 0);
  181. }
  182. // Initialize per-configuration name postfix property from the
  183. // variable only for non-executable targets. This preserves
  184. // compatibility with previous CMake versions in which executables
  185. // did not support this variable. Projects may still specify the
  186. // property directly.
  187. if(this->TargetTypeValue != cmState::EXECUTABLE
  188. && this->TargetTypeValue != cmState::INTERFACE_LIBRARY)
  189. {
  190. std::string property = cmSystemTools::UpperCase(*ci);
  191. property += "_POSTFIX";
  192. this->SetPropertyDefault(property, 0);
  193. }
  194. }
  195. }
  196. // Save the backtrace of target construction.
  197. this->Backtrace = this->Makefile->GetBacktrace();
  198. if (!this->IsImported())
  199. {
  200. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  201. // of the same directory property:
  202. const cmStringRange parentIncludes =
  203. this->Makefile->GetIncludeDirectoriesEntries();
  204. const cmBacktraceRange parentIncludesBts =
  205. this->Makefile->GetIncludeDirectoriesBacktraces();
  206. this->Internal->IncludeDirectoriesEntries.insert(
  207. this->Internal->IncludeDirectoriesEntries.end(),
  208. parentIncludes.begin(), parentIncludes.end());
  209. this->Internal->IncludeDirectoriesBacktraces.insert(
  210. this->Internal->IncludeDirectoriesBacktraces.end(),
  211. parentIncludesBts.begin(), parentIncludesBts.end());
  212. const std::set<std::string> parentSystemIncludes =
  213. this->Makefile->GetSystemIncludeDirectories();
  214. this->SystemIncludeDirectories.insert(parentSystemIncludes.begin(),
  215. parentSystemIncludes.end());
  216. const cmStringRange parentOptions =
  217. this->Makefile->GetCompileOptionsEntries();
  218. const cmBacktraceRange parentOptionsBts =
  219. this->Makefile->GetCompileOptionsBacktraces();
  220. this->Internal->CompileOptionsEntries.insert(
  221. this->Internal->CompileOptionsEntries.end(),
  222. parentOptions.begin(), parentOptions.end());
  223. this->Internal->CompileOptionsBacktraces.insert(
  224. this->Internal->CompileOptionsBacktraces.end(),
  225. parentOptionsBts.begin(), parentOptionsBts.end());
  226. }
  227. if (this->GetType() != cmState::INTERFACE_LIBRARY
  228. && this->GetType() != cmState::UTILITY)
  229. {
  230. this->SetPropertyDefault("C_VISIBILITY_PRESET", 0);
  231. this->SetPropertyDefault("CXX_VISIBILITY_PRESET", 0);
  232. this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
  233. }
  234. if(this->TargetTypeValue == cmState::EXECUTABLE)
  235. {
  236. this->SetPropertyDefault("ANDROID_GUI", 0);
  237. this->SetPropertyDefault("CROSSCOMPILING_EMULATOR", 0);
  238. this->SetPropertyDefault("ENABLE_EXPORTS", 0);
  239. }
  240. if(this->TargetTypeValue == cmState::SHARED_LIBRARY
  241. || this->TargetTypeValue == cmState::MODULE_LIBRARY)
  242. {
  243. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  244. }
  245. if(this->TargetTypeValue == cmState::SHARED_LIBRARY)
  246. {
  247. this->SetPropertyDefault("WINDOWS_EXPORT_ALL_SYMBOLS", 0);
  248. }
  249. if (this->GetType() != cmState::INTERFACE_LIBRARY
  250. && this->GetType() != cmState::UTILITY)
  251. {
  252. this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
  253. }
  254. // Record current policies for later use.
  255. this->Makefile->RecordPolicies(this->PolicyMap);
  256. if (this->TargetTypeValue == cmState::INTERFACE_LIBRARY)
  257. {
  258. // This policy is checked in a few conditions. The properties relevant
  259. // to the policy are always ignored for cmState::INTERFACE_LIBRARY targets,
  260. // so ensure that the conditions don't lead to nonsense.
  261. this->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
  262. }
  263. if (this->GetType() != cmState::INTERFACE_LIBRARY
  264. && this->GetType() != cmState::UTILITY)
  265. {
  266. this->SetPropertyDefault("JOB_POOL_COMPILE", 0);
  267. this->SetPropertyDefault("JOB_POOL_LINK", 0);
  268. }
  269. }
  270. //----------------------------------------------------------------------------
  271. void cmTarget::AddUtility(const std::string& u, cmMakefile *makefile)
  272. {
  273. if(this->Utilities.insert(u).second && makefile)
  274. {
  275. UtilityBacktraces.insert(std::make_pair(u, makefile->GetBacktrace()));
  276. }
  277. }
  278. //----------------------------------------------------------------------------
  279. cmListFileBacktrace const* cmTarget::GetUtilityBacktrace(
  280. const std::string& u) const
  281. {
  282. std::map<std::string, cmListFileBacktrace>::const_iterator i =
  283. this->UtilityBacktraces.find(u);
  284. if(i == this->UtilityBacktraces.end()) return 0;
  285. return &i->second;
  286. }
  287. //----------------------------------------------------------------------------
  288. void cmTarget::FinishConfigure()
  289. {
  290. // Erase any cached link information that might have been comptued
  291. // on-demand during the configuration. This ensures that build
  292. // system generation uses up-to-date information even if other cache
  293. // invalidation code in this source file is buggy.
  294. #if defined(_WIN32) && !defined(__CYGWIN__)
  295. // Do old-style link dependency analysis only for CM_USE_OLD_VS6.
  296. if(this->Makefile->GetGlobalGenerator()->IsForVS6())
  297. {
  298. this->AnalyzeLibDependenciesForVS6(*this->Makefile);
  299. }
  300. #endif
  301. }
  302. //----------------------------------------------------------------------------
  303. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  304. {
  305. return this->Backtrace;
  306. }
  307. //----------------------------------------------------------------------------
  308. bool cmTarget::IsExecutableWithExports() const
  309. {
  310. return (this->GetType() == cmState::EXECUTABLE &&
  311. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  312. }
  313. //----------------------------------------------------------------------------
  314. bool cmTarget::IsLinkable() const
  315. {
  316. return (this->GetType() == cmState::STATIC_LIBRARY ||
  317. this->GetType() == cmState::SHARED_LIBRARY ||
  318. this->GetType() == cmState::MODULE_LIBRARY ||
  319. this->GetType() == cmState::UNKNOWN_LIBRARY ||
  320. this->GetType() == cmState::INTERFACE_LIBRARY ||
  321. this->IsExecutableWithExports());
  322. }
  323. //----------------------------------------------------------------------------
  324. bool cmTarget::HasImportLibrary() const
  325. {
  326. return (this->DLLPlatform &&
  327. (this->GetType() == cmState::SHARED_LIBRARY ||
  328. this->IsExecutableWithExports()));
  329. }
  330. //----------------------------------------------------------------------------
  331. bool cmTarget::IsFrameworkOnApple() const
  332. {
  333. return (this->GetType() == cmState::SHARED_LIBRARY &&
  334. this->Makefile->IsOn("APPLE") &&
  335. this->GetPropertyAsBool("FRAMEWORK"));
  336. }
  337. //----------------------------------------------------------------------------
  338. bool cmTarget::IsAppBundleOnApple() const
  339. {
  340. return (this->GetType() == cmState::EXECUTABLE &&
  341. this->Makefile->IsOn("APPLE") &&
  342. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  343. }
  344. //----------------------------------------------------------------------------
  345. bool cmTarget::IsCFBundleOnApple() const
  346. {
  347. return (this->GetType() == cmState::MODULE_LIBRARY &&
  348. this->Makefile->IsOn("APPLE") &&
  349. this->GetPropertyAsBool("BUNDLE"));
  350. }
  351. //----------------------------------------------------------------------------
  352. bool cmTarget::IsXCTestOnApple() const
  353. {
  354. return (this->IsCFBundleOnApple() &&
  355. this->GetPropertyAsBool("XCTEST"));
  356. }
  357. //----------------------------------------------------------------------------
  358. void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
  359. {
  360. if (!srcs.empty())
  361. {
  362. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  363. this->Internal->SourceEntries.push_back(cmJoin(srcs, ";"));
  364. this->Internal->SourceBacktraces.push_back(lfbt);
  365. }
  366. }
  367. //----------------------------------------------------------------------------
  368. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  369. {
  370. std::string srcFiles;
  371. const char* sep = "";
  372. for(std::vector<std::string>::const_iterator i = srcs.begin();
  373. i != srcs.end(); ++i)
  374. {
  375. std::string filename = *i;
  376. const char* src = filename.c_str();
  377. if(!(src[0] == '$' && src[1] == '<'))
  378. {
  379. if(!filename.empty())
  380. {
  381. filename = this->ProcessSourceItemCMP0049(filename);
  382. if(filename.empty())
  383. {
  384. return;
  385. }
  386. }
  387. this->Makefile->GetOrCreateSource(filename);
  388. }
  389. srcFiles += sep;
  390. srcFiles += filename;
  391. sep = ";";
  392. }
  393. if (!srcFiles.empty())
  394. {
  395. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  396. this->Internal->SourceEntries.push_back(srcFiles);
  397. this->Internal->SourceBacktraces.push_back(lfbt);
  398. }
  399. }
  400. //----------------------------------------------------------------------------
  401. std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
  402. {
  403. std::string src = s;
  404. // For backwards compatibility replace varibles in source names.
  405. // This should eventually be removed.
  406. this->Makefile->ExpandVariablesInString(src);
  407. if (src != s)
  408. {
  409. std::ostringstream e;
  410. bool noMessage = false;
  411. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  412. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0049))
  413. {
  414. case cmPolicies::WARN:
  415. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0049) << "\n";
  416. break;
  417. case cmPolicies::OLD:
  418. noMessage = true;
  419. break;
  420. case cmPolicies::REQUIRED_ALWAYS:
  421. case cmPolicies::REQUIRED_IF_USED:
  422. case cmPolicies::NEW:
  423. messageType = cmake::FATAL_ERROR;
  424. }
  425. if (!noMessage)
  426. {
  427. e << "Legacy variable expansion in source file \""
  428. << s << "\" expanded to \"" << src << "\" in target \""
  429. << this->GetName() << "\". This behavior will be removed in a "
  430. "future version of CMake.";
  431. this->Makefile->IssueMessage(messageType, e.str());
  432. if (messageType == cmake::FATAL_ERROR)
  433. {
  434. return "";
  435. }
  436. }
  437. }
  438. return src;
  439. }
  440. //----------------------------------------------------------------------------
  441. cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s)
  442. {
  443. std::string src = this->ProcessSourceItemCMP0049(s);
  444. if(!s.empty() && src.empty())
  445. {
  446. return 0;
  447. }
  448. return this->AddSource(src);
  449. }
  450. //----------------------------------------------------------------------------
  451. struct CreateLocation
  452. {
  453. cmMakefile const* Makefile;
  454. CreateLocation(cmMakefile const* mf)
  455. : Makefile(mf)
  456. {
  457. }
  458. cmSourceFileLocation operator()(const std::string& filename)
  459. {
  460. return cmSourceFileLocation(this->Makefile, filename);
  461. }
  462. };
  463. //----------------------------------------------------------------------------
  464. struct LocationMatcher
  465. {
  466. const cmSourceFileLocation& Needle;
  467. LocationMatcher(const cmSourceFileLocation& needle)
  468. : Needle(needle)
  469. {
  470. }
  471. bool operator()(cmSourceFileLocation &loc)
  472. {
  473. return loc.Matches(this->Needle);
  474. }
  475. };
  476. //----------------------------------------------------------------------------
  477. struct TargetPropertyEntryFinder
  478. {
  479. private:
  480. const cmSourceFileLocation& Needle;
  481. public:
  482. TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
  483. : Needle(needle)
  484. {
  485. }
  486. bool operator()(std::string const& entry)
  487. {
  488. std::vector<std::string> files;
  489. cmSystemTools::ExpandListArgument(entry, files);
  490. std::vector<cmSourceFileLocation> locations(files.size());
  491. std::transform(files.begin(), files.end(), locations.begin(),
  492. CreateLocation(this->Needle.GetMakefile()));
  493. return std::find_if(locations.begin(), locations.end(),
  494. LocationMatcher(this->Needle)) != locations.end();
  495. }
  496. };
  497. //----------------------------------------------------------------------------
  498. cmSourceFile* cmTarget::AddSource(const std::string& src)
  499. {
  500. cmSourceFileLocation sfl(this->Makefile, src);
  501. if (std::find_if(this->Internal->SourceEntries.begin(),
  502. this->Internal->SourceEntries.end(),
  503. TargetPropertyEntryFinder(sfl))
  504. == this->Internal->SourceEntries.end())
  505. {
  506. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  507. this->Internal->SourceEntries.push_back(src);
  508. this->Internal->SourceBacktraces.push_back(lfbt);
  509. }
  510. if (cmGeneratorExpression::Find(src) != std::string::npos)
  511. {
  512. return 0;
  513. }
  514. return this->Makefile->GetOrCreateSource(src);
  515. }
  516. //----------------------------------------------------------------------------
  517. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  518. const std::string& selfname,
  519. const LinkLibraryVectorType& libs )
  520. {
  521. // Only add on libraries we haven't added on before.
  522. // Assumption: the global link libraries could only grow, never shrink
  523. LinkLibraryVectorType::const_iterator i = libs.begin();
  524. i += this->PrevLinkedLibraries.size();
  525. for( ; i != libs.end(); ++i )
  526. {
  527. // This is equivalent to the target_link_libraries plain signature.
  528. this->AddLinkLibrary( mf, selfname, i->first, i->second );
  529. this->AppendProperty("INTERFACE_LINK_LIBRARIES",
  530. this->GetDebugGeneratorExpressions(i->first, i->second).c_str());
  531. }
  532. this->PrevLinkedLibraries = libs;
  533. }
  534. //----------------------------------------------------------------------------
  535. void cmTarget::AddLinkDirectory(const std::string& d)
  536. {
  537. // Make sure we don't add unnecessary search directories.
  538. if(this->LinkDirectoriesEmmitted.insert(d).second)
  539. {
  540. this->LinkDirectories.push_back(d);
  541. }
  542. }
  543. //----------------------------------------------------------------------------
  544. const std::vector<std::string>& cmTarget::GetLinkDirectories() const
  545. {
  546. return this->LinkDirectories;
  547. }
  548. //----------------------------------------------------------------------------
  549. cmTargetLinkLibraryType cmTarget::ComputeLinkType(
  550. const std::string& config) const
  551. {
  552. // No configuration is always optimized.
  553. if(config.empty())
  554. {
  555. return OPTIMIZED_LibraryType;
  556. }
  557. // Get the list of configurations considered to be DEBUG.
  558. std::vector<std::string> debugConfigs =
  559. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  560. // Check if any entry in the list matches this configuration.
  561. std::string configUpper = cmSystemTools::UpperCase(config);
  562. if (std::find(debugConfigs.begin(), debugConfigs.end(), configUpper) !=
  563. debugConfigs.end())
  564. {
  565. return DEBUG_LibraryType;
  566. }
  567. // The current configuration is not a debug configuration.
  568. return OPTIMIZED_LibraryType;
  569. }
  570. //----------------------------------------------------------------------------
  571. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  572. const std::string& target )
  573. {
  574. // Clear the dependencies. The cache variable must exist iff we are
  575. // recording dependency information for this target.
  576. std::string depname = target;
  577. depname += "_LIB_DEPENDS";
  578. if (this->RecordDependencies)
  579. {
  580. mf.AddCacheDefinition(depname, "",
  581. "Dependencies for target", cmState::STATIC);
  582. }
  583. else
  584. {
  585. if (mf.GetDefinition( depname ))
  586. {
  587. std::string message = "Target ";
  588. message += target;
  589. message += " has dependency information when it shouldn't.\n";
  590. message += "Your cache is probably stale. Please remove the entry\n ";
  591. message += depname;
  592. message += "\nfrom the cache.";
  593. cmSystemTools::Error( message.c_str() );
  594. }
  595. }
  596. }
  597. //----------------------------------------------------------------------------
  598. bool cmTarget::NameResolvesToFramework(const std::string& libname) const
  599. {
  600. return this->Makefile->GetGlobalGenerator()->
  601. NameResolvesToFramework(libname);
  602. }
  603. //----------------------------------------------------------------------------
  604. std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
  605. cmTargetLinkLibraryType llt) const
  606. {
  607. if (llt == GENERAL_LibraryType)
  608. {
  609. return value;
  610. }
  611. // Get the list of configurations considered to be DEBUG.
  612. std::vector<std::string> debugConfigs =
  613. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  614. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  615. if (debugConfigs.size() > 1)
  616. {
  617. for(std::vector<std::string>::const_iterator
  618. li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
  619. {
  620. configString += ",$<CONFIG:" + *li + ">";
  621. }
  622. configString = "$<OR:" + configString + ">";
  623. }
  624. if (llt == OPTIMIZED_LibraryType)
  625. {
  626. configString = "$<NOT:" + configString + ">";
  627. }
  628. return "$<" + configString + ":" + value + ">";
  629. }
  630. //----------------------------------------------------------------------------
  631. static std::string targetNameGenex(const std::string& lib)
  632. {
  633. return "$<TARGET_NAME:" + lib + ">";
  634. }
  635. //----------------------------------------------------------------------------
  636. bool cmTarget::PushTLLCommandTrace(TLLSignature signature,
  637. cmListFileContext const& lfc)
  638. {
  639. bool ret = true;
  640. if (!this->TLLCommands.empty())
  641. {
  642. if (this->TLLCommands.back().first != signature)
  643. {
  644. ret = false;
  645. }
  646. }
  647. if (this->TLLCommands.empty() || this->TLLCommands.back().second != lfc)
  648. {
  649. this->TLLCommands.push_back(std::make_pair(signature, lfc));
  650. }
  651. return ret;
  652. }
  653. //----------------------------------------------------------------------------
  654. void cmTarget::GetTllSignatureTraces(std::ostringstream &s,
  655. TLLSignature sig) const
  656. {
  657. const char *sigString = (sig == cmTarget::KeywordTLLSignature ? "keyword"
  658. : "plain");
  659. s << "The uses of the " << sigString << " signature are here:\n";
  660. typedef std::vector<std::pair<TLLSignature, cmListFileContext> > Container;
  661. cmOutputConverter converter(this->GetMakefile()->GetStateSnapshot());
  662. for(Container::const_iterator it = this->TLLCommands.begin();
  663. it != this->TLLCommands.end(); ++it)
  664. {
  665. if (it->first == sig)
  666. {
  667. cmListFileContext lfc = it->second;
  668. lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
  669. s << " * " << lfc << std::endl;
  670. }
  671. }
  672. }
  673. //----------------------------------------------------------------------------
  674. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  675. const std::string& target,
  676. const std::string& lib,
  677. cmTargetLinkLibraryType llt)
  678. {
  679. cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
  680. {
  681. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  682. const std::string libName =
  683. (isNonImportedTarget && llt != GENERAL_LibraryType)
  684. ? targetNameGenex(lib)
  685. : lib;
  686. this->AppendProperty("LINK_LIBRARIES",
  687. this->GetDebugGeneratorExpressions(libName,
  688. llt).c_str());
  689. }
  690. if (cmGeneratorExpression::Find(lib) != std::string::npos
  691. || (tgt && tgt->GetType() == cmState::INTERFACE_LIBRARY)
  692. || (target == lib ))
  693. {
  694. return;
  695. }
  696. cmTarget::LibraryID tmp;
  697. tmp.first = lib;
  698. tmp.second = llt;
  699. #if defined(_WIN32) && !defined(__CYGWIN__)
  700. this->LinkLibrariesForVS6.push_back( tmp );
  701. #endif
  702. this->OriginalLinkLibraries.push_back(tmp);
  703. // Add the explicit dependency information for this target. This is
  704. // simply a set of libraries separated by ";". There should always
  705. // be a trailing ";". These library names are not canonical, in that
  706. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  707. // We shouldn't remove duplicates here because external libraries
  708. // may be purposefully duplicated to handle recursive dependencies,
  709. // and we removing one instance will break the link line. Duplicates
  710. // will be appropriately eliminated at emit time.
  711. if(this->RecordDependencies)
  712. {
  713. std::string targetEntry = target;
  714. targetEntry += "_LIB_DEPENDS";
  715. std::string dependencies;
  716. const char* old_val = mf.GetDefinition( targetEntry );
  717. if( old_val )
  718. {
  719. dependencies += old_val;
  720. }
  721. switch (llt)
  722. {
  723. case GENERAL_LibraryType:
  724. dependencies += "general";
  725. break;
  726. case DEBUG_LibraryType:
  727. dependencies += "debug";
  728. break;
  729. case OPTIMIZED_LibraryType:
  730. dependencies += "optimized";
  731. break;
  732. }
  733. dependencies += ";";
  734. dependencies += lib;
  735. dependencies += ";";
  736. mf.AddCacheDefinition( targetEntry, dependencies.c_str(),
  737. "Dependencies for the target",
  738. cmState::STATIC );
  739. }
  740. }
  741. //----------------------------------------------------------------------------
  742. void
  743. cmTarget::AddSystemIncludeDirectories(const std::set<std::string> &incs)
  744. {
  745. this->SystemIncludeDirectories.insert(incs.begin(), incs.end());
  746. }
  747. cmStringRange cmTarget::GetIncludeDirectoriesEntries() const
  748. {
  749. return cmMakeRange(this->Internal->IncludeDirectoriesEntries);
  750. }
  751. cmBacktraceRange cmTarget::GetIncludeDirectoriesBacktraces() const
  752. {
  753. return cmMakeRange(this->Internal->IncludeDirectoriesBacktraces);
  754. }
  755. cmStringRange cmTarget::GetCompileOptionsEntries() const
  756. {
  757. return cmMakeRange(this->Internal->CompileOptionsEntries);
  758. }
  759. cmBacktraceRange cmTarget::GetCompileOptionsBacktraces() const
  760. {
  761. return cmMakeRange(this->Internal->CompileOptionsBacktraces);
  762. }
  763. cmStringRange cmTarget::GetCompileFeaturesEntries() const
  764. {
  765. return cmMakeRange(this->Internal->CompileFeaturesEntries);
  766. }
  767. cmBacktraceRange cmTarget::GetCompileFeaturesBacktraces() const
  768. {
  769. return cmMakeRange(this->Internal->CompileFeaturesBacktraces);
  770. }
  771. cmStringRange cmTarget::GetCompileDefinitionsEntries() const
  772. {
  773. return cmMakeRange(this->Internal->CompileDefinitionsEntries);
  774. }
  775. cmBacktraceRange cmTarget::GetCompileDefinitionsBacktraces() const
  776. {
  777. return cmMakeRange(this->Internal->CompileDefinitionsBacktraces);
  778. }
  779. cmStringRange cmTarget::GetSourceEntries() const
  780. {
  781. return cmMakeRange(this->Internal->SourceEntries);
  782. }
  783. cmBacktraceRange cmTarget::GetSourceBacktraces() const
  784. {
  785. return cmMakeRange(this->Internal->SourceBacktraces);
  786. }
  787. cmStringRange cmTarget::GetLinkImplementationEntries() const
  788. {
  789. return cmMakeRange(this->Internal->LinkImplementationPropertyEntries);
  790. }
  791. cmBacktraceRange cmTarget::GetLinkImplementationBacktraces() const
  792. {
  793. return cmMakeRange(this->Internal->LinkImplementationPropertyBacktraces);
  794. }
  795. #if defined(_WIN32) && !defined(__CYGWIN__)
  796. //----------------------------------------------------------------------------
  797. void
  798. cmTarget::AnalyzeLibDependenciesForVS6( const cmMakefile& mf )
  799. {
  800. // There are two key parts of the dependency analysis: (1)
  801. // determining the libraries in the link line, and (2) constructing
  802. // the dependency graph for those libraries.
  803. //
  804. // The latter is done using the cache entries that record the
  805. // dependencies of each library.
  806. //
  807. // The former is a more thorny issue, since it is not clear how to
  808. // determine if two libraries listed on the link line refer to the a
  809. // single library or not. For example, consider the link "libraries"
  810. // /usr/lib/libtiff.so -ltiff
  811. // Is this one library or two? The solution implemented here is the
  812. // simplest (and probably the only practical) one: two libraries are
  813. // the same if their "link strings" are identical. Thus, the two
  814. // libraries above are considered distinct. This also means that for
  815. // dependency analysis to be effective, the CMake user must specify
  816. // libraries build by his project without using any linker flags or
  817. // file extensions. That is,
  818. // LINK_LIBRARIES( One Two )
  819. // instead of
  820. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  821. // The former is probably what most users would do, but it never
  822. // hurts to document the assumptions. :-) Therefore, in the analysis
  823. // code, the "canonical name" of a library is simply its name as
  824. // given to a LINK_LIBRARIES command.
  825. //
  826. // Also, we will leave the original link line intact; we will just add any
  827. // dependencies that were missing.
  828. //
  829. // There is a problem with recursive external libraries
  830. // (i.e. libraries with no dependency information that are
  831. // recursively dependent). We must make sure that the we emit one of
  832. // the libraries twice to satisfy the recursion, but we shouldn't
  833. // emit it more times than necessary. In particular, we must make
  834. // sure that handling this improbable case doesn't cost us when
  835. // dealing with the common case of non-recursive libraries. The
  836. // solution is to assume that the recursion is satisfied at one node
  837. // of the dependency tree. To illustrate, assume libA and libB are
  838. // extrenal and mutually dependent. Suppose libX depends on
  839. // libA, and libY on libA and libX. Then
  840. // TARGET_LINK_LIBRARIES( Y X A B A )
  841. // TARGET_LINK_LIBRARIES( X A B A )
  842. // TARGET_LINK_LIBRARIES( Exec Y )
  843. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  844. // specify the dependencies, since the mutual dependency of A and B
  845. // is resolved *every time libA is specified*.
  846. //
  847. // Something like
  848. // TARGET_LINK_LIBRARIES( Y X A B A )
  849. // TARGET_LINK_LIBRARIES( X A B )
  850. // TARGET_LINK_LIBRARIES( Exec Y )
  851. // would result in "-lY -lX -lA -lB", and the mutual dependency
  852. // information is lost. This is because in some case (Y), the mutual
  853. // dependency of A and B is listed, while in another other case (X),
  854. // it is not. Depending on which line actually emits A, the mutual
  855. // dependency may or may not be on the final link line. We can't
  856. // handle this pathalogical case cleanly without emitting extra
  857. // libraries for the normal cases. Besides, the dependency
  858. // information for X is wrong anyway: if we build an executable
  859. // depending on X alone, we would not have the mutual dependency on
  860. // A and B resolved.
  861. //
  862. // IMPROVEMENTS:
  863. // -- The current algorithm will not always pick the "optimal" link line
  864. // when recursive dependencies are present. It will instead break the
  865. // cycles at an aribtrary point. The majority of projects won't have
  866. // cyclic dependencies, so this is probably not a big deal. Note that
  867. // the link line is always correct, just not necessary optimal.
  868. {
  869. // Expand variables in link library names. This is for backwards
  870. // compatibility with very early CMake versions and should
  871. // eventually be removed. This code was moved here from the end of
  872. // old source list processing code which was called just before this
  873. // method.
  874. for(LinkLibraryVectorType::iterator p = this->LinkLibrariesForVS6.begin();
  875. p != this->LinkLibrariesForVS6.end(); ++p)
  876. {
  877. this->Makefile->ExpandVariablesInString(p->first, true, true);
  878. }
  879. }
  880. // The dependency map.
  881. DependencyMap dep_map;
  882. // 1. Build the dependency graph
  883. //
  884. for(LinkLibraryVectorType::reverse_iterator lib
  885. = this->LinkLibrariesForVS6.rbegin();
  886. lib != this->LinkLibrariesForVS6.rend(); ++lib)
  887. {
  888. this->GatherDependenciesForVS6( mf, *lib, dep_map);
  889. }
  890. // 2. Remove any dependencies that are already satisfied in the original
  891. // link line.
  892. //
  893. for(LinkLibraryVectorType::iterator lib = this->LinkLibrariesForVS6.begin();
  894. lib != this->LinkLibrariesForVS6.end(); ++lib)
  895. {
  896. for( LinkLibraryVectorType::iterator lib2 = lib;
  897. lib2 != this->LinkLibrariesForVS6.end(); ++lib2)
  898. {
  899. this->DeleteDependencyForVS6( dep_map, *lib, *lib2);
  900. }
  901. }
  902. // 3. Create the new link line by simply emitting any dependencies that are
  903. // missing. Start from the back and keep adding.
  904. //
  905. std::set<DependencyMap::key_type> done, visited;
  906. std::vector<DependencyMap::key_type> newLinkLibrariesForVS6;
  907. for(LinkLibraryVectorType::reverse_iterator lib =
  908. this->LinkLibrariesForVS6.rbegin();
  909. lib != this->LinkLibrariesForVS6.rend(); ++lib)
  910. {
  911. // skip zero size library entries, this may happen
  912. // if a variable expands to nothing.
  913. if (!lib->first.empty())
  914. {
  915. this->EmitForVS6( *lib, dep_map, done, visited, newLinkLibrariesForVS6 );
  916. }
  917. }
  918. // 4. Add the new libraries to the link line.
  919. //
  920. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  921. newLinkLibrariesForVS6.rbegin();
  922. k != newLinkLibrariesForVS6.rend(); ++k )
  923. {
  924. // get the llt from the dep_map
  925. this->LinkLibrariesForVS6.push_back( std::make_pair(k->first,k->second) );
  926. }
  927. this->LinkLibrariesForVS6Analyzed = true;
  928. }
  929. //----------------------------------------------------------------------------
  930. void cmTarget::InsertDependencyForVS6( DependencyMap& depMap,
  931. const LibraryID& lib,
  932. const LibraryID& dep)
  933. {
  934. depMap[lib].push_back(dep);
  935. }
  936. //----------------------------------------------------------------------------
  937. void cmTarget::DeleteDependencyForVS6( DependencyMap& depMap,
  938. const LibraryID& lib,
  939. const LibraryID& dep)
  940. {
  941. // Make sure there is an entry in the map for lib. If so, delete all
  942. // dependencies to dep. There may be repeated entries because of
  943. // external libraries that are specified multiple times.
  944. DependencyMap::iterator map_itr = depMap.find( lib );
  945. if( map_itr != depMap.end() )
  946. {
  947. DependencyList& depList = map_itr->second;
  948. DependencyList::iterator begin =
  949. std::remove(depList.begin(), depList.end(), dep);
  950. depList.erase(begin, depList.end());
  951. }
  952. }
  953. //----------------------------------------------------------------------------
  954. void cmTarget::EmitForVS6(const LibraryID lib,
  955. const DependencyMap& dep_map,
  956. std::set<LibraryID>& emitted,
  957. std::set<LibraryID>& visited,
  958. DependencyList& link_line )
  959. {
  960. // It's already been emitted
  961. if( emitted.find(lib) != emitted.end() )
  962. {
  963. return;
  964. }
  965. // Emit the dependencies only if this library node hasn't been
  966. // visited before. If it has, then we have a cycle. The recursion
  967. // that got us here should take care of everything.
  968. if( visited.insert(lib).second )
  969. {
  970. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  971. {
  972. const DependencyList& dep_on = dep_map.find( lib )->second;
  973. DependencyList::const_reverse_iterator i;
  974. // To cater for recursive external libraries, we must emit
  975. // duplicates on this link line *unless* they were emitted by
  976. // some other node, in which case we assume that the recursion
  977. // was resolved then. We making the simplifying assumption that
  978. // any duplicates on a single link line are on purpose, and must
  979. // be preserved.
  980. // This variable will keep track of the libraries that were
  981. // emitted directly from the current node, and not from a
  982. // recursive call. This way, if we come across a library that
  983. // has already been emitted, we repeat it iff it has been
  984. // emitted here.
  985. std::set<DependencyMap::key_type> emitted_here;
  986. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  987. {
  988. if( emitted_here.find(*i) != emitted_here.end() )
  989. {
  990. // a repeat. Must emit.
  991. emitted.insert(*i);
  992. link_line.push_back( *i );
  993. }
  994. else
  995. {
  996. // Emit only if no-one else has
  997. if( emitted.find(*i) == emitted.end() )
  998. {
  999. // emit dependencies
  1000. this->EmitForVS6( *i, dep_map, emitted, visited, link_line );
  1001. // emit self
  1002. emitted.insert(*i);
  1003. emitted_here.insert(*i);
  1004. link_line.push_back( *i );
  1005. }
  1006. }
  1007. }
  1008. }
  1009. }
  1010. }
  1011. //----------------------------------------------------------------------------
  1012. void cmTarget::GatherDependenciesForVS6( const cmMakefile& mf,
  1013. const LibraryID& lib,
  1014. DependencyMap& dep_map)
  1015. {
  1016. // If the library is already in the dependency map, then it has
  1017. // already been fully processed.
  1018. if( dep_map.find(lib) != dep_map.end() )
  1019. {
  1020. return;
  1021. }
  1022. const char* deps = mf.GetDefinition( lib.first+"_LIB_DEPENDS" );
  1023. if( deps && strcmp(deps,"") != 0 )
  1024. {
  1025. // Make sure this library is in the map, even if it has an empty
  1026. // set of dependencies. This distinguishes the case of explicitly
  1027. // no dependencies with that of unspecified dependencies.
  1028. dep_map[lib];
  1029. // Parse the dependency information, which is a set of
  1030. // type, library pairs separated by ";". There is always a trailing ";".
  1031. cmTargetLinkLibraryType llt = GENERAL_LibraryType;
  1032. std::string depline = deps;
  1033. std::string::size_type start = 0;
  1034. std::string::size_type end;
  1035. end = depline.find( ";", start );
  1036. while( end != std::string::npos )
  1037. {
  1038. std::string l = depline.substr( start, end-start );
  1039. if(!l.empty())
  1040. {
  1041. if (l == "debug")
  1042. {
  1043. llt = DEBUG_LibraryType;
  1044. }
  1045. else if (l == "optimized")
  1046. {
  1047. llt = OPTIMIZED_LibraryType;
  1048. }
  1049. else if (l == "general")
  1050. {
  1051. llt = GENERAL_LibraryType;
  1052. }
  1053. else
  1054. {
  1055. LibraryID lib2(l,llt);
  1056. this->InsertDependencyForVS6( dep_map, lib, lib2);
  1057. this->GatherDependenciesForVS6( mf, lib2, dep_map);
  1058. llt = GENERAL_LibraryType;
  1059. }
  1060. }
  1061. start = end+1; // skip the ;
  1062. end = depline.find( ";", start );
  1063. }
  1064. // cannot depend on itself
  1065. this->DeleteDependencyForVS6( dep_map, lib, lib);
  1066. }
  1067. }
  1068. #endif
  1069. //----------------------------------------------------------------------------
  1070. static bool whiteListedInterfaceProperty(const std::string& prop)
  1071. {
  1072. if(cmHasLiteralPrefix(prop, "INTERFACE_"))
  1073. {
  1074. return true;
  1075. }
  1076. static UNORDERED_SET<std::string> builtIns;
  1077. if (builtIns.empty())
  1078. {
  1079. builtIns.insert("COMPATIBLE_INTERFACE_BOOL");
  1080. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");
  1081. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MIN");
  1082. builtIns.insert("COMPATIBLE_INTERFACE_STRING");
  1083. builtIns.insert("EXPORT_NAME");
  1084. builtIns.insert("IMPORTED");
  1085. builtIns.insert("NAME");
  1086. builtIns.insert("TYPE");
  1087. }
  1088. if (builtIns.count(prop))
  1089. {
  1090. return true;
  1091. }
  1092. if (cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_"))
  1093. {
  1094. return true;
  1095. }
  1096. return false;
  1097. }
  1098. //----------------------------------------------------------------------------
  1099. void cmTarget::SetProperty(const std::string& prop, const char* value)
  1100. {
  1101. if (this->GetType() == cmState::INTERFACE_LIBRARY
  1102. && !whiteListedInterfaceProperty(prop))
  1103. {
  1104. std::ostringstream e;
  1105. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1106. "The property \"" << prop << "\" is not allowed.";
  1107. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1108. return;
  1109. }
  1110. else if (prop == "NAME")
  1111. {
  1112. std::ostringstream e;
  1113. e << "NAME property is read-only\n";
  1114. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1115. return;
  1116. }
  1117. else if(prop == "INCLUDE_DIRECTORIES")
  1118. {
  1119. this->Internal->IncludeDirectoriesEntries.clear();
  1120. this->Internal->IncludeDirectoriesBacktraces.clear();
  1121. if (value)
  1122. {
  1123. this->Internal->IncludeDirectoriesEntries.push_back(value);
  1124. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1125. this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
  1126. }
  1127. }
  1128. else if(prop == "COMPILE_OPTIONS")
  1129. {
  1130. this->Internal->CompileOptionsEntries.clear();
  1131. this->Internal->CompileOptionsBacktraces.clear();
  1132. if (value)
  1133. {
  1134. this->Internal->CompileOptionsEntries.push_back(value);
  1135. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1136. this->Internal->CompileOptionsBacktraces.push_back(lfbt);
  1137. }
  1138. }
  1139. else if(prop == "COMPILE_FEATURES")
  1140. {
  1141. this->Internal->CompileFeaturesEntries.clear();
  1142. this->Internal->CompileFeaturesBacktraces.clear();
  1143. if (value)
  1144. {
  1145. this->Internal->CompileFeaturesEntries.push_back(value);
  1146. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1147. this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
  1148. }
  1149. }
  1150. else if(prop == "COMPILE_DEFINITIONS")
  1151. {
  1152. this->Internal->CompileDefinitionsEntries.clear();
  1153. this->Internal->CompileDefinitionsBacktraces.clear();
  1154. if (value)
  1155. {
  1156. this->Internal->CompileDefinitionsEntries.push_back(value);
  1157. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1158. this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
  1159. }
  1160. }
  1161. else if(prop == "EXPORT_NAME" && this->IsImported())
  1162. {
  1163. std::ostringstream e;
  1164. e << "EXPORT_NAME property can't be set on imported targets (\""
  1165. << this->Name << "\")\n";
  1166. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1167. }
  1168. else if (prop == "LINK_LIBRARIES")
  1169. {
  1170. this->Internal->LinkImplementationPropertyEntries.clear();
  1171. this->Internal->LinkImplementationPropertyBacktraces.clear();
  1172. if (value)
  1173. {
  1174. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1175. this->Internal->LinkImplementationPropertyEntries.push_back(value);
  1176. this->Internal->LinkImplementationPropertyBacktraces.push_back(lfbt);
  1177. }
  1178. }
  1179. else if (prop == "SOURCES")
  1180. {
  1181. if(this->IsImported())
  1182. {
  1183. std::ostringstream e;
  1184. e << "SOURCES property can't be set on imported targets (\""
  1185. << this->Name << "\")\n";
  1186. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1187. return;
  1188. }
  1189. this->Internal->SourceEntries.clear();
  1190. this->Internal->SourceBacktraces.clear();
  1191. if (value)
  1192. {
  1193. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1194. this->Internal->SourceEntries.push_back(value);
  1195. this->Internal->SourceBacktraces.push_back(lfbt);
  1196. }
  1197. }
  1198. else
  1199. {
  1200. this->Properties.SetProperty(prop, value);
  1201. }
  1202. }
  1203. //----------------------------------------------------------------------------
  1204. void cmTarget::AppendProperty(const std::string& prop, const char* value,
  1205. bool asString)
  1206. {
  1207. if (this->GetType() == cmState::INTERFACE_LIBRARY
  1208. && !whiteListedInterfaceProperty(prop))
  1209. {
  1210. std::ostringstream e;
  1211. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1212. "The property \"" << prop << "\" is not allowed.";
  1213. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1214. return;
  1215. }
  1216. else if (prop == "NAME")
  1217. {
  1218. std::ostringstream e;
  1219. e << "NAME property is read-only\n";
  1220. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1221. return;
  1222. }
  1223. else if(prop == "INCLUDE_DIRECTORIES")
  1224. {
  1225. if (value && *value)
  1226. {
  1227. this->Internal->IncludeDirectoriesEntries.push_back(value);
  1228. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1229. this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
  1230. }
  1231. }
  1232. else if(prop == "COMPILE_OPTIONS")
  1233. {
  1234. if (value && *value)
  1235. {
  1236. this->Internal->CompileOptionsEntries.push_back(value);
  1237. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1238. this->Internal->CompileOptionsBacktraces.push_back(lfbt);
  1239. }
  1240. }
  1241. else if(prop == "COMPILE_FEATURES")
  1242. {
  1243. if (value && *value)
  1244. {
  1245. this->Internal->CompileFeaturesEntries.push_back(value);
  1246. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1247. this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
  1248. }
  1249. }
  1250. else if(prop == "COMPILE_DEFINITIONS")
  1251. {
  1252. if (value && *value)
  1253. {
  1254. this->Internal->CompileDefinitionsEntries.push_back(value);
  1255. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1256. this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
  1257. }
  1258. }
  1259. else if(prop == "EXPORT_NAME" && this->IsImported())
  1260. {
  1261. std::ostringstream e;
  1262. e << "EXPORT_NAME property can't be set on imported targets (\""
  1263. << this->Name << "\")\n";
  1264. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1265. }
  1266. else if (prop == "LINK_LIBRARIES")
  1267. {
  1268. if (value && *value)
  1269. {
  1270. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1271. this->Internal->LinkImplementationPropertyEntries.push_back(value);
  1272. this->Internal->LinkImplementationPropertyBacktraces.push_back(lfbt);
  1273. }
  1274. }
  1275. else if (prop == "SOURCES")
  1276. {
  1277. if(this->IsImported())
  1278. {
  1279. std::ostringstream e;
  1280. e << "SOURCES property can't be set on imported targets (\""
  1281. << this->Name << "\")\n";
  1282. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1283. return;
  1284. }
  1285. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1286. this->Internal->SourceEntries.push_back(value);
  1287. this->Internal->SourceBacktraces.push_back(lfbt);
  1288. }
  1289. else
  1290. {
  1291. this->Properties.AppendProperty(prop, value, asString);
  1292. }
  1293. }
  1294. //----------------------------------------------------------------------------
  1295. std::string cmTarget::GetExportName() const
  1296. {
  1297. const char *exportName = this->GetProperty("EXPORT_NAME");
  1298. if (exportName && *exportName)
  1299. {
  1300. if (!cmGeneratorExpression::IsValidTargetName(exportName))
  1301. {
  1302. std::ostringstream e;
  1303. e << "EXPORT_NAME property \"" << exportName << "\" for \""
  1304. << this->GetName() << "\": is not valid.";
  1305. cmSystemTools::Error(e.str().c_str());
  1306. return "";
  1307. }
  1308. return exportName;
  1309. }
  1310. return this->GetName();
  1311. }
  1312. //----------------------------------------------------------------------------
  1313. void cmTarget::AppendBuildInterfaceIncludes()
  1314. {
  1315. if(this->GetType() != cmState::SHARED_LIBRARY &&
  1316. this->GetType() != cmState::STATIC_LIBRARY &&
  1317. this->GetType() != cmState::MODULE_LIBRARY &&
  1318. this->GetType() != cmState::INTERFACE_LIBRARY &&
  1319. !this->IsExecutableWithExports())
  1320. {
  1321. return;
  1322. }
  1323. if (this->BuildInterfaceIncludesAppended)
  1324. {
  1325. return;
  1326. }
  1327. this->BuildInterfaceIncludesAppended = true;
  1328. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE"))
  1329. {
  1330. const char *binDir = this->Makefile->GetCurrentBinaryDirectory();
  1331. const char *srcDir = this->Makefile->GetCurrentSourceDirectory();
  1332. const std::string dirs = std::string(binDir ? binDir : "")
  1333. + std::string(binDir ? ";" : "")
  1334. + std::string(srcDir ? srcDir : "");
  1335. if (!dirs.empty())
  1336. {
  1337. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  1338. ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
  1339. }
  1340. }
  1341. }
  1342. //----------------------------------------------------------------------------
  1343. void cmTarget::InsertInclude(std::string const& entry,
  1344. cmListFileBacktrace const& bt,
  1345. bool before)
  1346. {
  1347. std::vector<std::string>::iterator position =
  1348. before ? this->Internal->IncludeDirectoriesEntries.begin()
  1349. : this->Internal->IncludeDirectoriesEntries.end();
  1350. std::vector<cmListFileBacktrace>::iterator btPosition =
  1351. before ? this->Internal->IncludeDirectoriesBacktraces.begin()
  1352. : this->Internal->IncludeDirectoriesBacktraces.end();
  1353. this->Internal->IncludeDirectoriesEntries.insert(position, entry);
  1354. this->Internal->IncludeDirectoriesBacktraces.insert(btPosition, bt);
  1355. }
  1356. //----------------------------------------------------------------------------
  1357. void cmTarget::InsertCompileOption(std::string const& entry,
  1358. cmListFileBacktrace const& bt,
  1359. bool before)
  1360. {
  1361. std::vector<std::string>::iterator position =
  1362. before ? this->Internal->CompileOptionsEntries.begin()
  1363. : this->Internal->CompileOptionsEntries.end();
  1364. std::vector<cmListFileBacktrace>::iterator btPosition =
  1365. before ? this->Internal->CompileOptionsBacktraces.begin()
  1366. : this->Internal->CompileOptionsBacktraces.end();
  1367. this->Internal->CompileOptionsEntries.insert(position, entry);
  1368. this->Internal->CompileOptionsBacktraces.insert(btPosition, bt);
  1369. }
  1370. //----------------------------------------------------------------------------
  1371. void cmTarget::InsertCompileDefinition(std::string const& entry,
  1372. cmListFileBacktrace const& bt)
  1373. {
  1374. this->Internal->CompileDefinitionsEntries.push_back(entry);
  1375. this->Internal->CompileDefinitionsBacktraces.push_back(bt);
  1376. }
  1377. //----------------------------------------------------------------------------
  1378. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
  1379. const std::string& prop, const char* value, cmMakefile* context,
  1380. bool imported)
  1381. {
  1382. // Look for link-type keywords in the value.
  1383. static cmsys::RegularExpression
  1384. keys("(^|;)(debug|optimized|general)(;|$)");
  1385. if(!keys.find(value))
  1386. {
  1387. return;
  1388. }
  1389. // Support imported and non-imported versions of the property.
  1390. const char* base = (imported?
  1391. "IMPORTED_LINK_INTERFACE_LIBRARIES" :
  1392. "LINK_INTERFACE_LIBRARIES");
  1393. // Report an error.
  1394. std::ostringstream e;
  1395. e << "Property " << prop << " may not contain link-type keyword \""
  1396. << keys.match(2) << "\". "
  1397. << "The " << base << " property has a per-configuration "
  1398. << "version called " << base << "_<CONFIG> which may be "
  1399. << "used to specify per-configuration rules.";
  1400. if(!imported)
  1401. {
  1402. e << " "
  1403. << "Alternatively, an IMPORTED library may be created, configured "
  1404. << "with a per-configuration location, and then named in the "
  1405. << "property value. "
  1406. << "See the add_library command's IMPORTED mode for details."
  1407. << "\n"
  1408. << "If you have a list of libraries that already contains the "
  1409. << "keyword, use the target_link_libraries command with its "
  1410. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  1411. << "The command automatically recognizes link-type keywords and sets "
  1412. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  1413. << "properties accordingly.";
  1414. }
  1415. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  1416. }
  1417. //----------------------------------------------------------------------------
  1418. static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
  1419. cmMakefile* context)
  1420. {
  1421. // Look for link-type keywords in the value.
  1422. static cmsys::RegularExpression
  1423. keys("(^|;)(debug|optimized|general)(;|$)");
  1424. if(!keys.find(value))
  1425. {
  1426. return;
  1427. }
  1428. // Report an error.
  1429. std::ostringstream e;
  1430. e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
  1431. "keyword \"" << keys.match(2) << "\". The INTERFACE_LINK_LIBRARIES "
  1432. "property may contain configuration-sensitive generator-expressions "
  1433. "which may be used to specify per-configuration rules.";
  1434. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  1435. }
  1436. //----------------------------------------------------------------------------
  1437. void cmTarget::CheckProperty(const std::string& prop,
  1438. cmMakefile* context) const
  1439. {
  1440. // Certain properties need checking.
  1441. if(cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES"))
  1442. {
  1443. if(const char* value = this->GetProperty(prop))
  1444. {
  1445. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  1446. }
  1447. }
  1448. if(cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES"))
  1449. {
  1450. if(const char* value = this->GetProperty(prop))
  1451. {
  1452. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  1453. }
  1454. }
  1455. if(cmHasLiteralPrefix(prop, "INTERFACE_LINK_LIBRARIES"))
  1456. {
  1457. if(const char* value = this->GetProperty(prop))
  1458. {
  1459. cmTargetCheckINTERFACE_LINK_LIBRARIES(value, context);
  1460. }
  1461. }
  1462. }
  1463. //----------------------------------------------------------------------------
  1464. void cmTarget::MarkAsImported()
  1465. {
  1466. this->IsImportedTarget = true;
  1467. }
  1468. //----------------------------------------------------------------------------
  1469. bool cmTarget::HaveWellDefinedOutputFiles() const
  1470. {
  1471. return
  1472. this->GetType() == cmState::STATIC_LIBRARY ||
  1473. this->GetType() == cmState::SHARED_LIBRARY ||
  1474. this->GetType() == cmState::MODULE_LIBRARY ||
  1475. this->GetType() == cmState::EXECUTABLE;
  1476. }
  1477. //----------------------------------------------------------------------------
  1478. void cmTarget::GetTargetVersion(int& major, int& minor) const
  1479. {
  1480. int patch;
  1481. this->GetTargetVersion(false, major, minor, patch);
  1482. }
  1483. //----------------------------------------------------------------------------
  1484. void cmTarget::GetTargetVersion(bool soversion,
  1485. int& major, int& minor, int& patch) const
  1486. {
  1487. // Set the default values.
  1488. major = 0;
  1489. minor = 0;
  1490. patch = 0;
  1491. assert(this->GetType() != cmState::INTERFACE_LIBRARY);
  1492. // Look for a VERSION or SOVERSION property.
  1493. const char* prop = soversion? "SOVERSION" : "VERSION";
  1494. if(const char* version = this->GetProperty(prop))
  1495. {
  1496. // Try to parse the version number and store the results that were
  1497. // successfully parsed.
  1498. int parsed_major;
  1499. int parsed_minor;
  1500. int parsed_patch;
  1501. switch(sscanf(version, "%d.%d.%d",
  1502. &parsed_major, &parsed_minor, &parsed_patch))
  1503. {
  1504. case 3: patch = parsed_patch; // no break!
  1505. case 2: minor = parsed_minor; // no break!
  1506. case 1: major = parsed_major; // no break!
  1507. default: break;
  1508. }
  1509. }
  1510. }
  1511. //----------------------------------------------------------------------------
  1512. bool cmTarget::HandleLocationPropertyPolicy(cmMakefile* context) const
  1513. {
  1514. if (this->IsImported())
  1515. {
  1516. return true;
  1517. }
  1518. std::ostringstream e;
  1519. const char *modal = 0;
  1520. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  1521. switch (context->GetPolicyStatus(cmPolicies::CMP0026))
  1522. {
  1523. case cmPolicies::WARN:
  1524. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0026) << "\n";
  1525. modal = "should";
  1526. case cmPolicies::OLD:
  1527. break;
  1528. case cmPolicies::REQUIRED_ALWAYS:
  1529. case cmPolicies::REQUIRED_IF_USED:
  1530. case cmPolicies::NEW:
  1531. modal = "may";
  1532. messageType = cmake::FATAL_ERROR;
  1533. }
  1534. if (modal)
  1535. {
  1536. e << "The LOCATION property " << modal << " not be read from target \""
  1537. << this->GetName() << "\". Use the target name directly with "
  1538. "add_custom_command, or use the generator expression $<TARGET_FILE>, "
  1539. "as appropriate.\n";
  1540. context->IssueMessage(messageType, e.str());
  1541. }
  1542. return messageType != cmake::FATAL_ERROR;
  1543. }
  1544. //----------------------------------------------------------------------------
  1545. const char *cmTarget::GetProperty(const std::string& prop) const
  1546. {
  1547. return this->GetProperty(prop, this->Makefile);
  1548. }
  1549. //----------------------------------------------------------------------------
  1550. const char *cmTarget::GetProperty(const std::string& prop,
  1551. cmMakefile* context) const
  1552. {
  1553. if (this->GetType() == cmState::INTERFACE_LIBRARY
  1554. && !whiteListedInterfaceProperty(prop))
  1555. {
  1556. std::ostringstream e;
  1557. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1558. "The property \"" << prop << "\" is not allowed.";
  1559. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  1560. return 0;
  1561. }
  1562. // Watch for special "computed" properties that are dependent on
  1563. // other properties or variables. Always recompute them.
  1564. if(this->GetType() == cmState::EXECUTABLE ||
  1565. this->GetType() == cmState::STATIC_LIBRARY ||
  1566. this->GetType() == cmState::SHARED_LIBRARY ||
  1567. this->GetType() == cmState::MODULE_LIBRARY ||
  1568. this->GetType() == cmState::UNKNOWN_LIBRARY)
  1569. {
  1570. static const std::string propLOCATION = "LOCATION";
  1571. if(prop == propLOCATION)
  1572. {
  1573. if (!this->HandleLocationPropertyPolicy(context))
  1574. {
  1575. return 0;
  1576. }
  1577. // Set the LOCATION property of the target.
  1578. //
  1579. // For an imported target this is the location of an arbitrary
  1580. // available configuration.
  1581. //
  1582. if(this->IsImported())
  1583. {
  1584. this->Properties.SetProperty(
  1585. propLOCATION, this->ImportedGetFullPath("", false).c_str());
  1586. }
  1587. else
  1588. {
  1589. // For a non-imported target this is deprecated because it
  1590. // cannot take into account the per-configuration name of the
  1591. // target because the configuration type may not be known at
  1592. // CMake time.
  1593. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  1594. gg->CreateGenerationObjects();
  1595. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  1596. this->Properties.SetProperty(propLOCATION,
  1597. gt->GetLocationForBuild());
  1598. }
  1599. }
  1600. // Support "LOCATION_<CONFIG>".
  1601. else if(cmHasLiteralPrefix(prop, "LOCATION_"))
  1602. {
  1603. if (!this->HandleLocationPropertyPolicy(context))
  1604. {
  1605. return 0;
  1606. }
  1607. const char* configName = prop.c_str() + 9;
  1608. if (this->IsImported())
  1609. {
  1610. this->Properties.SetProperty(
  1611. prop, this->ImportedGetFullPath(configName, false).c_str());
  1612. }
  1613. else
  1614. {
  1615. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  1616. gg->CreateGenerationObjects();
  1617. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  1618. this->Properties.SetProperty(
  1619. prop, gt->GetFullPath(configName, false).c_str());
  1620. }
  1621. }
  1622. // Support "<CONFIG>_LOCATION".
  1623. else if(cmHasLiteralSuffix(prop, "_LOCATION"))
  1624. {
  1625. std::string configName(prop.c_str(), prop.size() - 9);
  1626. if(configName != "IMPORTED")
  1627. {
  1628. if (!this->HandleLocationPropertyPolicy(context))
  1629. {
  1630. return 0;
  1631. }
  1632. if (this->IsImported())
  1633. {
  1634. this->Properties.SetProperty(
  1635. prop, this->ImportedGetFullPath(configName, false).c_str());
  1636. }
  1637. else
  1638. {
  1639. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  1640. gg->CreateGenerationObjects();
  1641. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  1642. this->Properties.SetProperty(
  1643. prop, gt->GetFullPath(configName, false).c_str());
  1644. }
  1645. }
  1646. }
  1647. }
  1648. static UNORDERED_SET<std::string> specialProps;
  1649. #define MAKE_STATIC_PROP(PROP) \
  1650. static const std::string prop##PROP = #PROP
  1651. MAKE_STATIC_PROP(LINK_LIBRARIES);
  1652. MAKE_STATIC_PROP(TYPE);
  1653. MAKE_STATIC_PROP(INCLUDE_DIRECTORIES);
  1654. MAKE_STATIC_PROP(COMPILE_FEATURES);
  1655. MAKE_STATIC_PROP(COMPILE_OPTIONS);
  1656. MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
  1657. MAKE_STATIC_PROP(IMPORTED);
  1658. MAKE_STATIC_PROP(NAME);
  1659. MAKE_STATIC_PROP(BINARY_DIR);
  1660. MAKE_STATIC_PROP(SOURCE_DIR);
  1661. MAKE_STATIC_PROP(SOURCES);
  1662. #undef MAKE_STATIC_PROP
  1663. if(specialProps.empty())
  1664. {
  1665. specialProps.insert(propLINK_LIBRARIES);
  1666. specialProps.insert(propTYPE);
  1667. specialProps.insert(propINCLUDE_DIRECTORIES);
  1668. specialProps.insert(propCOMPILE_FEATURES);
  1669. specialProps.insert(propCOMPILE_OPTIONS);
  1670. specialProps.insert(propCOMPILE_DEFINITIONS);
  1671. specialProps.insert(propIMPORTED);
  1672. specialProps.insert(propNAME);
  1673. specialProps.insert(propBINARY_DIR);
  1674. specialProps.insert(propSOURCE_DIR);
  1675. specialProps.insert(propSOURCES);
  1676. }
  1677. if(specialProps.count(prop))
  1678. {
  1679. if(prop == propLINK_LIBRARIES)
  1680. {
  1681. if (this->Internal->LinkImplementationPropertyEntries.empty())
  1682. {
  1683. return 0;
  1684. }
  1685. static std::string output;
  1686. output = cmJoin(this->Internal->LinkImplementationPropertyEntries, ";");
  1687. return output.c_str();
  1688. }
  1689. // the type property returns what type the target is
  1690. else if (prop == propTYPE)
  1691. {
  1692. return cmState::GetTargetTypeName(this->GetType());
  1693. }
  1694. else if(prop == propINCLUDE_DIRECTORIES)
  1695. {
  1696. if (this->Internal->IncludeDirectoriesEntries.empty())
  1697. {
  1698. return 0;
  1699. }
  1700. static std::string output;
  1701. output = cmJoin(this->Internal->IncludeDirectoriesEntries, ";");
  1702. return output.c_str();
  1703. }
  1704. else if(prop == propCOMPILE_FEATURES)
  1705. {
  1706. if (this->Internal->CompileFeaturesEntries.empty())
  1707. {
  1708. return 0;
  1709. }
  1710. static std::string output;
  1711. output = cmJoin(this->Internal->CompileFeaturesEntries, ";");
  1712. return output.c_str();
  1713. }
  1714. else if(prop == propCOMPILE_OPTIONS)
  1715. {
  1716. if (this->Internal->CompileOptionsEntries.empty())
  1717. {
  1718. return 0;
  1719. }
  1720. static std::string output;
  1721. output = cmJoin(this->Internal->CompileOptionsEntries, ";");
  1722. return output.c_str();
  1723. }
  1724. else if(prop == propCOMPILE_DEFINITIONS)
  1725. {
  1726. if (this->Internal->CompileDefinitionsEntries.empty())
  1727. {
  1728. return 0;
  1729. }
  1730. static std::string output;
  1731. output = cmJoin(this->Internal->CompileDefinitionsEntries, ";");
  1732. return output.c_str();
  1733. }
  1734. else if (prop == propIMPORTED)
  1735. {
  1736. return this->IsImported()?"TRUE":"FALSE";
  1737. }
  1738. else if (prop == propNAME)
  1739. {
  1740. return this->GetName().c_str();
  1741. }
  1742. else if (prop == propBINARY_DIR)
  1743. {
  1744. return this->GetMakefile()->GetCurrentBinaryDirectory();
  1745. }
  1746. else if (prop == propSOURCE_DIR)
  1747. {
  1748. return this->GetMakefile()->GetCurrentSourceDirectory();
  1749. }
  1750. else if(prop == propSOURCES)
  1751. {
  1752. if (this->Internal->SourceEntries.empty())
  1753. {
  1754. return 0;
  1755. }
  1756. std::ostringstream ss;
  1757. const char* sep = "";
  1758. for(std::vector<std::string>::const_iterator
  1759. i = this->Internal->SourceEntries.begin();
  1760. i != this->Internal->SourceEntries.end(); ++i)
  1761. {
  1762. std::string const& entry = *i;
  1763. std::vector<std::string> files;
  1764. cmSystemTools::ExpandListArgument(entry, files);
  1765. for (std::vector<std::string>::const_iterator
  1766. li = files.begin(); li != files.end(); ++li)
  1767. {
  1768. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  1769. (*li)[li->size() - 1] == '>')
  1770. {
  1771. std::string objLibName = li->substr(17, li->size()-18);
  1772. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  1773. {
  1774. ss << sep;
  1775. sep = ";";
  1776. ss << *li;
  1777. continue;
  1778. }
  1779. bool addContent = false;
  1780. bool noMessage = true;
  1781. std::ostringstream e;
  1782. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  1783. switch(context->GetPolicyStatus(cmPolicies::CMP0051))
  1784. {
  1785. case cmPolicies::WARN:
  1786. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
  1787. noMessage = false;
  1788. case cmPolicies::OLD:
  1789. break;
  1790. case cmPolicies::REQUIRED_ALWAYS:
  1791. case cmPolicies::REQUIRED_IF_USED:
  1792. case cmPolicies::NEW:
  1793. addContent = true;
  1794. }
  1795. if (!noMessage)
  1796. {
  1797. e << "Target \"" << this->Name << "\" contains "
  1798. "$<TARGET_OBJECTS> generator expression in its sources list. "
  1799. "This content was not previously part of the SOURCES property "
  1800. "when that property was read at configure time. Code reading "
  1801. "that property needs to be adapted to ignore the generator "
  1802. "expression using the string(GENEX_STRIP) command.";
  1803. context->IssueMessage(messageType, e.str());
  1804. }
  1805. if (addContent)
  1806. {
  1807. ss << sep;
  1808. sep = ";";
  1809. ss << *li;
  1810. }
  1811. }
  1812. else if (cmGeneratorExpression::Find(*li) == std::string::npos)
  1813. {
  1814. ss << sep;
  1815. sep = ";";
  1816. ss << *li;
  1817. }
  1818. else
  1819. {
  1820. cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li);
  1821. // Construct what is known about this source file location.
  1822. cmSourceFileLocation const& location = sf->GetLocation();
  1823. std::string sname = location.GetDirectory();
  1824. if(!sname.empty())
  1825. {
  1826. sname += "/";
  1827. }
  1828. sname += location.GetName();
  1829. ss << sep;
  1830. sep = ";";
  1831. // Append this list entry.
  1832. ss << sname;
  1833. }
  1834. }
  1835. }
  1836. this->Properties.SetProperty("SOURCES", ss.str().c_str());
  1837. }
  1838. }
  1839. const char *retVal = this->Properties.GetPropertyValue(prop);
  1840. if (!retVal)
  1841. {
  1842. const bool chain = this->GetMakefile()->GetState()->
  1843. IsPropertyChained(prop, cmProperty::TARGET);
  1844. if (chain)
  1845. {
  1846. return this->Makefile->GetProperty(prop, chain);
  1847. }
  1848. }
  1849. return retVal;
  1850. }
  1851. //----------------------------------------------------------------------------
  1852. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  1853. {
  1854. return cmSystemTools::IsOn(this->GetProperty(prop));
  1855. }
  1856. //----------------------------------------------------------------------------
  1857. const char* cmTarget::GetSuffixVariableInternal(bool implib) const
  1858. {
  1859. switch(this->GetType())
  1860. {
  1861. case cmState::STATIC_LIBRARY:
  1862. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  1863. case cmState::SHARED_LIBRARY:
  1864. return (implib
  1865. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  1866. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  1867. case cmState::MODULE_LIBRARY:
  1868. return (implib
  1869. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  1870. : "CMAKE_SHARED_MODULE_SUFFIX");
  1871. case cmState::EXECUTABLE:
  1872. return (implib
  1873. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  1874. // Android GUI application packages store the native
  1875. // binary as a shared library.
  1876. : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
  1877. "CMAKE_SHARED_LIBRARY_SUFFIX" : "CMAKE_EXECUTABLE_SUFFIX"));
  1878. default:
  1879. break;
  1880. }
  1881. return "";
  1882. }
  1883. //----------------------------------------------------------------------------
  1884. const char* cmTarget::GetPrefixVariableInternal(bool implib) const
  1885. {
  1886. switch(this->GetType())
  1887. {
  1888. case cmState::STATIC_LIBRARY:
  1889. return "CMAKE_STATIC_LIBRARY_PREFIX";
  1890. case cmState::SHARED_LIBRARY:
  1891. return (implib
  1892. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  1893. : "CMAKE_SHARED_LIBRARY_PREFIX");
  1894. case cmState::MODULE_LIBRARY:
  1895. return (implib
  1896. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  1897. : "CMAKE_SHARED_MODULE_PREFIX");
  1898. case cmState::EXECUTABLE:
  1899. return (implib
  1900. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  1901. // Android GUI application packages store the native
  1902. // binary as a shared library.
  1903. : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
  1904. "CMAKE_SHARED_LIBRARY_PREFIX" : ""));
  1905. default:
  1906. break;
  1907. }
  1908. return "";
  1909. }
  1910. //----------------------------------------------------------------------------
  1911. std::string
  1912. cmTarget::ImportedGetFullPath(const std::string& config, bool pimplib) const
  1913. {
  1914. assert(this->IsImported());
  1915. // Lookup/compute/cache the import information for this
  1916. // configuration.
  1917. std::string config_upper;
  1918. if(!config.empty())
  1919. {
  1920. config_upper = cmSystemTools::UpperCase(config);
  1921. }
  1922. else
  1923. {
  1924. config_upper = "NOCONFIG";
  1925. }
  1926. std::string result;
  1927. const char* loc = 0;
  1928. const char* imp = 0;
  1929. std::string suffix;
  1930. if(this->GetType() != cmState::INTERFACE_LIBRARY
  1931. && this->GetMappedConfig(config_upper, &loc, &imp, suffix))
  1932. {
  1933. if (!pimplib)
  1934. {
  1935. if(loc)
  1936. {
  1937. result = loc;
  1938. }
  1939. else
  1940. {
  1941. std::string impProp = "IMPORTED_LOCATION";
  1942. impProp += suffix;
  1943. if(const char* config_location = this->GetProperty(impProp))
  1944. {
  1945. result = config_location;
  1946. }
  1947. else if(const char* location =
  1948. this->GetProperty("IMPORTED_LOCATION"))
  1949. {
  1950. result = location;
  1951. }
  1952. }
  1953. }
  1954. else
  1955. {
  1956. if(imp)
  1957. {
  1958. result = imp;
  1959. }
  1960. else if(this->GetType() == cmState::SHARED_LIBRARY ||
  1961. this->IsExecutableWithExports())
  1962. {
  1963. std::string impProp = "IMPORTED_IMPLIB";
  1964. impProp += suffix;
  1965. if(const char* config_implib = this->GetProperty(impProp))
  1966. {
  1967. result = config_implib;
  1968. }
  1969. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  1970. {
  1971. result = implib;
  1972. }
  1973. }
  1974. }
  1975. }
  1976. if(result.empty())
  1977. {
  1978. result = this->GetName();
  1979. result += "-NOTFOUND";
  1980. }
  1981. return result;
  1982. }
  1983. //----------------------------------------------------------------------------
  1984. void cmTarget::ComputeVersionedName(std::string& vName,
  1985. std::string const& prefix,
  1986. std::string const& base,
  1987. std::string const& suffix,
  1988. std::string const& name,
  1989. const char* version) const
  1990. {
  1991. vName = this->IsApple? (prefix+base) : name;
  1992. if(version)
  1993. {
  1994. vName += ".";
  1995. vName += version;
  1996. }
  1997. vName += this->IsApple? suffix : std::string();
  1998. }
  1999. //----------------------------------------------------------------------------
  2000. void cmTarget::SetPropertyDefault(const std::string& property,
  2001. const char* default_value)
  2002. {
  2003. // Compute the name of the variable holding the default value.
  2004. std::string var = "CMAKE_";
  2005. var += property;
  2006. if(const char* value = this->Makefile->GetDefinition(var))
  2007. {
  2008. this->SetProperty(property, value);
  2009. }
  2010. else if(default_value)
  2011. {
  2012. this->SetProperty(property, default_value);
  2013. }
  2014. }
  2015. //----------------------------------------------------------------------------
  2016. std::string cmTarget::GetFrameworkVersion() const
  2017. {
  2018. assert(this->GetType() != cmState::INTERFACE_LIBRARY);
  2019. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  2020. {
  2021. return fversion;
  2022. }
  2023. else if(const char* tversion = this->GetProperty("VERSION"))
  2024. {
  2025. return tversion;
  2026. }
  2027. else
  2028. {
  2029. return "A";
  2030. }
  2031. }
  2032. //----------------------------------------------------------------------------
  2033. const char* cmTarget::GetExportMacro() const
  2034. {
  2035. // Define the symbol for targets that export symbols.
  2036. if(this->GetType() == cmState::SHARED_LIBRARY ||
  2037. this->GetType() == cmState::MODULE_LIBRARY ||
  2038. this->IsExecutableWithExports())
  2039. {
  2040. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  2041. {
  2042. this->ExportMacro = custom_export_name;
  2043. }
  2044. else
  2045. {
  2046. std::string in = this->GetName();
  2047. in += "_EXPORTS";
  2048. this->ExportMacro = cmSystemTools::MakeCindentifier(in);
  2049. }
  2050. return this->ExportMacro.c_str();
  2051. }
  2052. else
  2053. {
  2054. return 0;
  2055. }
  2056. }
  2057. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  2058. const char** loc,
  2059. const char** imp,
  2060. std::string& suffix) const
  2061. {
  2062. if (this->GetType() == cmState::INTERFACE_LIBRARY)
  2063. {
  2064. // This method attempts to find a config-specific LOCATION for the
  2065. // IMPORTED library. In the case of cmState::INTERFACE_LIBRARY, there is no
  2066. // LOCATION at all, so leaving *loc and *imp unchanged is the appropriate
  2067. // and valid response.
  2068. return true;
  2069. }
  2070. // Track the configuration-specific property suffix.
  2071. suffix = "_";
  2072. suffix += desired_config;
  2073. std::vector<std::string> mappedConfigs;
  2074. {
  2075. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  2076. mapProp += desired_config;
  2077. if(const char* mapValue = this->GetProperty(mapProp))
  2078. {
  2079. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  2080. }
  2081. }
  2082. // If we needed to find one of the mapped configurations but did not
  2083. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  2084. // library or an executable with exports.
  2085. bool allowImp = this->HasImportLibrary();
  2086. // If a mapping was found, check its configurations.
  2087. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  2088. !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
  2089. {
  2090. // Look for this configuration.
  2091. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  2092. std::string locProp = "IMPORTED_LOCATION_";
  2093. locProp += mcUpper;
  2094. *loc = this->GetProperty(locProp);
  2095. if(allowImp)
  2096. {
  2097. std::string impProp = "IMPORTED_IMPLIB_";
  2098. impProp += mcUpper;
  2099. *imp = this->GetProperty(impProp);
  2100. }
  2101. // If it was found, use it for all properties below.
  2102. if(*loc || *imp)
  2103. {
  2104. suffix = "_";
  2105. suffix += mcUpper;
  2106. }
  2107. }
  2108. // If we needed to find one of the mapped configurations but did not
  2109. // then the target is not found. The project does not want any
  2110. // other configuration.
  2111. if(!mappedConfigs.empty() && !*loc && !*imp)
  2112. {
  2113. return false;
  2114. }
  2115. // If we have not yet found it then there are no mapped
  2116. // configurations. Look for an exact-match.
  2117. if(!*loc && !*imp)
  2118. {
  2119. std::string locProp = "IMPORTED_LOCATION";
  2120. locProp += suffix;
  2121. *loc = this->GetProperty(locProp);
  2122. if(allowImp)
  2123. {
  2124. std::string impProp = "IMPORTED_IMPLIB";
  2125. impProp += suffix;
  2126. *imp = this->GetProperty(impProp);
  2127. }
  2128. }
  2129. // If we have not yet found it then there are no mapped
  2130. // configurations and no exact match.
  2131. if(!*loc && !*imp)
  2132. {
  2133. // The suffix computed above is not useful.
  2134. suffix = "";
  2135. // Look for a configuration-less location. This may be set by
  2136. // manually-written code.
  2137. *loc = this->GetProperty("IMPORTED_LOCATION");
  2138. if(allowImp)
  2139. {
  2140. *imp = this->GetProperty("IMPORTED_IMPLIB");
  2141. }
  2142. }
  2143. // If we have not yet found it then the project is willing to try
  2144. // any available configuration.
  2145. if(!*loc && !*imp)
  2146. {
  2147. std::vector<std::string> availableConfigs;
  2148. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  2149. {
  2150. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  2151. }
  2152. for(std::vector<std::string>::const_iterator
  2153. aci = availableConfigs.begin();
  2154. !*loc && !*imp && aci != availableConfigs.end(); ++aci)
  2155. {
  2156. suffix = "_";
  2157. suffix += cmSystemTools::UpperCase(*aci);
  2158. std::string locProp = "IMPORTED_LOCATION";
  2159. locProp += suffix;
  2160. *loc = this->GetProperty(locProp);
  2161. if(allowImp)
  2162. {
  2163. std::string impProp = "IMPORTED_IMPLIB";
  2164. impProp += suffix;
  2165. *imp = this->GetProperty(impProp);
  2166. }
  2167. }
  2168. }
  2169. // If we have not yet found it then the target is not available.
  2170. if(!*loc && !*imp)
  2171. {
  2172. return false;
  2173. }
  2174. return true;
  2175. }
  2176. //----------------------------------------------------------------------------
  2177. std::string cmTarget::CheckCMP0004(std::string const& item) const
  2178. {
  2179. // Strip whitespace off the library names because we used to do this
  2180. // in case variables were expanded at generate time. We no longer
  2181. // do the expansion but users link to libraries like " ${VAR} ".
  2182. std::string lib = item;
  2183. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  2184. if(pos != lib.npos)
  2185. {
  2186. lib = lib.substr(pos, lib.npos);
  2187. }
  2188. pos = lib.find_last_not_of(" \t\r\n");
  2189. if(pos != lib.npos)
  2190. {
  2191. lib = lib.substr(0, pos+1);
  2192. }
  2193. if(lib != item)
  2194. {
  2195. cmake* cm = this->Makefile->GetCMakeInstance();
  2196. switch(this->GetPolicyStatusCMP0004())
  2197. {
  2198. case cmPolicies::WARN:
  2199. {
  2200. std::ostringstream w;
  2201. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
  2202. << "Target \"" << this->GetName() << "\" links to item \""
  2203. << item << "\" which has leading or trailing whitespace.";
  2204. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  2205. this->GetBacktrace());
  2206. }
  2207. case cmPolicies::OLD:
  2208. break;
  2209. case cmPolicies::NEW:
  2210. {
  2211. std::ostringstream e;
  2212. e << "Target \"" << this->GetName() << "\" links to item \""
  2213. << item << "\" which has leading or trailing whitespace. "
  2214. << "This is now an error according to policy CMP0004.";
  2215. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  2216. }
  2217. break;
  2218. case cmPolicies::REQUIRED_IF_USED:
  2219. case cmPolicies::REQUIRED_ALWAYS:
  2220. {
  2221. std::ostringstream e;
  2222. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
  2223. << "Target \"" << this->GetName() << "\" links to item \""
  2224. << item << "\" which has leading or trailing whitespace.";
  2225. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  2226. }
  2227. break;
  2228. }
  2229. }
  2230. return lib;
  2231. }
  2232. //----------------------------------------------------------------------------
  2233. cmTargetInternalPointer::cmTargetInternalPointer()
  2234. {
  2235. this->Pointer = new cmTargetInternals;
  2236. }
  2237. //----------------------------------------------------------------------------
  2238. cmTargetInternalPointer
  2239. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  2240. {
  2241. // Ideally cmTarget instances should never be copied. However until
  2242. // we can make a sweep to remove that, this copy constructor avoids
  2243. // allowing the resources (Internals) to be copied.
  2244. this->Pointer = new cmTargetInternals(*r.Pointer);
  2245. }
  2246. //----------------------------------------------------------------------------
  2247. cmTargetInternalPointer::~cmTargetInternalPointer()
  2248. {
  2249. delete this->Pointer;
  2250. }
  2251. //----------------------------------------------------------------------------
  2252. cmTargetInternalPointer&
  2253. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  2254. {
  2255. if(this == &r) { return *this; } // avoid warning on HP about self check
  2256. // Ideally cmTarget instances should never be copied. However until
  2257. // we can make a sweep to remove that, this copy constructor avoids
  2258. // allowing the resources (Internals) to be copied.
  2259. cmTargetInternals* oldPointer = this->Pointer;
  2260. this->Pointer = new cmTargetInternals(*r.Pointer);
  2261. delete oldPointer;
  2262. return *this;
  2263. }