cmTarget.cxx 85 KB

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