cmTarget.cxx 72 KB

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