cmTarget.cxx 88 KB

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