cmGeneratorTarget.cxx 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2012 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 "cmGeneratorTarget.h"
  11. #include "cmTarget.h"
  12. #include "cmMakefile.h"
  13. #include "cmLocalGenerator.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmSourceFile.h"
  16. #include "cmGeneratorExpression.h"
  17. #include "cmGeneratorExpressionDAGChecker.h"
  18. #include "cmComputeLinkInformation.h"
  19. #include "cmCustomCommandGenerator.h"
  20. #include "cmAlgorithms.h"
  21. #include <queue>
  22. #include <errno.h>
  23. #include "assert.h"
  24. //----------------------------------------------------------------------------
  25. void reportBadObjLib(std::vector<cmSourceFile*> const& badObjLib,
  26. cmTarget *target, cmake *cm)
  27. {
  28. if(!badObjLib.empty())
  29. {
  30. std::ostringstream e;
  31. e << "OBJECT library \"" << target->GetName() << "\" contains:\n";
  32. for(std::vector<cmSourceFile*>::const_iterator i = badObjLib.begin();
  33. i != badObjLib.end(); ++i)
  34. {
  35. e << " " << (*i)->GetLocation().GetName() << "\n";
  36. }
  37. e << "but may contain only sources that compile, header files, and "
  38. "other files that would not affect linking of a normal library.";
  39. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  40. target->GetBacktrace());
  41. }
  42. }
  43. struct ObjectSourcesTag {};
  44. struct CustomCommandsTag {};
  45. struct ExtraSourcesTag {};
  46. struct HeaderSourcesTag {};
  47. struct ExternalObjectsTag {};
  48. struct IDLSourcesTag {};
  49. struct ResxTag {};
  50. struct ModuleDefinitionFileTag {};
  51. struct AppManifestTag{};
  52. struct CertificatesTag{};
  53. struct XamlTag{};
  54. template<typename Tag, typename OtherTag>
  55. struct IsSameTag
  56. {
  57. enum {
  58. Result = false
  59. };
  60. };
  61. template<typename Tag>
  62. struct IsSameTag<Tag, Tag>
  63. {
  64. enum {
  65. Result = true
  66. };
  67. };
  68. template<bool>
  69. struct DoAccept
  70. {
  71. template <typename T> static void Do(T&, cmSourceFile*) {}
  72. };
  73. template<>
  74. struct DoAccept<true>
  75. {
  76. static void Do(std::vector<cmSourceFile const*>& files, cmSourceFile* f)
  77. {
  78. files.push_back(f);
  79. }
  80. static void Do(cmGeneratorTarget::ResxData& data, cmSourceFile* f)
  81. {
  82. // Build and save the name of the corresponding .h file
  83. // This relationship will be used later when building the project files.
  84. // Both names would have been auto generated from Visual Studio
  85. // where the user supplied the file name and Visual Studio
  86. // appended the suffix.
  87. std::string resx = f->GetFullPath();
  88. std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
  89. data.ExpectedResxHeaders.insert(hFileName);
  90. data.ResxSources.push_back(f);
  91. }
  92. static void Do(cmGeneratorTarget::XamlData& data, cmSourceFile* f)
  93. {
  94. // Build and save the name of the corresponding .h and .cpp file
  95. // This relationship will be used later when building the project files.
  96. // Both names would have been auto generated from Visual Studio
  97. // where the user supplied the file name and Visual Studio
  98. // appended the suffix.
  99. std::string xaml = f->GetFullPath();
  100. std::string hFileName = xaml + ".h";
  101. std::string cppFileName = xaml + ".cpp";
  102. data.ExpectedXamlHeaders.insert(hFileName);
  103. data.ExpectedXamlSources.insert(cppFileName);
  104. data.XamlSources.push_back(f);
  105. }
  106. static void Do(std::string& data, cmSourceFile* f)
  107. {
  108. data = f->GetFullPath();
  109. }
  110. };
  111. //----------------------------------------------------------------------------
  112. template<typename Tag, typename DataType = std::vector<cmSourceFile const*> >
  113. struct TagVisitor
  114. {
  115. DataType& Data;
  116. std::vector<cmSourceFile*> BadObjLibFiles;
  117. cmTarget *Target;
  118. cmGlobalGenerator *GlobalGenerator;
  119. cmsys::RegularExpression Header;
  120. bool IsObjLib;
  121. TagVisitor(cmTarget *target, DataType& data)
  122. : Data(data), Target(target),
  123. GlobalGenerator(target->GetMakefile()->GetGlobalGenerator()),
  124. Header(CM_HEADER_REGEX),
  125. IsObjLib(target->GetType() == cmTarget::OBJECT_LIBRARY)
  126. {
  127. }
  128. ~TagVisitor()
  129. {
  130. reportBadObjLib(this->BadObjLibFiles, this->Target,
  131. this->GlobalGenerator->GetCMakeInstance());
  132. }
  133. void Accept(cmSourceFile *sf)
  134. {
  135. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  136. if(sf->GetCustomCommand())
  137. {
  138. DoAccept<IsSameTag<Tag, CustomCommandsTag>::Result>::Do(this->Data, sf);
  139. }
  140. else if(this->Target->GetType() == cmTarget::UTILITY)
  141. {
  142. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  143. }
  144. else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
  145. {
  146. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  147. }
  148. else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  149. {
  150. DoAccept<IsSameTag<Tag, ExternalObjectsTag>::Result>::Do(this->Data, sf);
  151. if(this->IsObjLib)
  152. {
  153. this->BadObjLibFiles.push_back(sf);
  154. }
  155. }
  156. else if(!sf->GetLanguage().empty())
  157. {
  158. DoAccept<IsSameTag<Tag, ObjectSourcesTag>::Result>::Do(this->Data, sf);
  159. }
  160. else if(ext == "def")
  161. {
  162. DoAccept<IsSameTag<Tag, ModuleDefinitionFileTag>::Result>::Do(this->Data,
  163. sf);
  164. if(this->IsObjLib)
  165. {
  166. this->BadObjLibFiles.push_back(sf);
  167. }
  168. }
  169. else if(ext == "idl")
  170. {
  171. DoAccept<IsSameTag<Tag, IDLSourcesTag>::Result>::Do(this->Data, sf);
  172. if(this->IsObjLib)
  173. {
  174. this->BadObjLibFiles.push_back(sf);
  175. }
  176. }
  177. else if(ext == "resx")
  178. {
  179. DoAccept<IsSameTag<Tag, ResxTag>::Result>::Do(this->Data, sf);
  180. }
  181. else if (ext == "appxmanifest")
  182. {
  183. DoAccept<IsSameTag<Tag, AppManifestTag>::Result>::Do(this->Data, sf);
  184. }
  185. else if (ext == "pfx")
  186. {
  187. DoAccept<IsSameTag<Tag, CertificatesTag>::Result>::Do(this->Data, sf);
  188. }
  189. else if (ext == "xaml")
  190. {
  191. DoAccept<IsSameTag<Tag, XamlTag>::Result>::Do(this->Data, sf);
  192. }
  193. else if(this->Header.find(sf->GetFullPath().c_str()))
  194. {
  195. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  196. }
  197. else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
  198. {
  199. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  200. }
  201. else
  202. {
  203. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  204. }
  205. }
  206. };
  207. //----------------------------------------------------------------------------
  208. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  209. : Target(t),
  210. SourceFileFlagsConstructed(false)
  211. {
  212. this->Makefile = this->Target->GetMakefile();
  213. this->LocalGenerator = lg;
  214. this->GlobalGenerator = this->Makefile->GetGlobalGenerator();
  215. }
  216. cmGeneratorTarget::~cmGeneratorTarget()
  217. {
  218. cmDeleteAll(this->LinkInformation);
  219. this->LinkInformation.clear();
  220. }
  221. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  222. {
  223. return this->LocalGenerator;
  224. }
  225. //----------------------------------------------------------------------------
  226. int cmGeneratorTarget::GetType() const
  227. {
  228. return this->Target->GetType();
  229. }
  230. //----------------------------------------------------------------------------
  231. std::string cmGeneratorTarget::GetName() const
  232. {
  233. return this->Target->GetName();
  234. }
  235. //----------------------------------------------------------------------------
  236. const char *cmGeneratorTarget::GetProperty(const std::string& prop) const
  237. {
  238. return this->Target->GetProperty(prop);
  239. }
  240. //----------------------------------------------------------------------------
  241. std::vector<cmSourceFile*> const*
  242. cmGeneratorTarget::GetSourceDepends(cmSourceFile const* sf) const
  243. {
  244. SourceEntriesType::const_iterator i = this->SourceEntries.find(sf);
  245. if(i != this->SourceEntries.end())
  246. {
  247. return &i->second.Depends;
  248. }
  249. return 0;
  250. }
  251. static void handleSystemIncludesDep(cmMakefile *mf, cmTarget const* depTgt,
  252. const std::string& config,
  253. cmTarget *headTarget,
  254. cmGeneratorExpressionDAGChecker *dagChecker,
  255. std::vector<std::string>& result,
  256. bool excludeImported)
  257. {
  258. if (const char* dirs =
  259. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES"))
  260. {
  261. cmGeneratorExpression ge;
  262. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  263. ->Evaluate(mf,
  264. config, false, headTarget,
  265. depTgt, dagChecker), result);
  266. }
  267. if (!depTgt->IsImported() || excludeImported)
  268. {
  269. return;
  270. }
  271. if (const char* dirs =
  272. depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES"))
  273. {
  274. cmGeneratorExpression ge;
  275. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  276. ->Evaluate(mf,
  277. config, false, headTarget,
  278. depTgt, dagChecker), result);
  279. }
  280. }
  281. #define IMPLEMENT_VISIT_IMPL(DATA, DATATYPE) \
  282. { \
  283. std::vector<cmSourceFile*> sourceFiles; \
  284. this->Target->GetSourceFiles(sourceFiles, config); \
  285. TagVisitor<DATA ## Tag DATATYPE> visitor(this->Target, data); \
  286. for(std::vector<cmSourceFile*>::const_iterator si = sourceFiles.begin(); \
  287. si != sourceFiles.end(); ++si) \
  288. { \
  289. visitor.Accept(*si); \
  290. } \
  291. } \
  292. #define IMPLEMENT_VISIT(DATA) \
  293. IMPLEMENT_VISIT_IMPL(DATA, EMPTY) \
  294. #define EMPTY
  295. #define COMMA ,
  296. //----------------------------------------------------------------------------
  297. void
  298. cmGeneratorTarget
  299. ::GetObjectSources(std::vector<cmSourceFile const*> &data,
  300. const std::string& config) const
  301. {
  302. IMPLEMENT_VISIT(ObjectSources);
  303. if (!this->Objects.empty())
  304. {
  305. return;
  306. }
  307. for(std::vector<cmSourceFile const*>::const_iterator it = data.begin();
  308. it != data.end(); ++it)
  309. {
  310. this->Objects[*it];
  311. }
  312. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  313. }
  314. void cmGeneratorTarget::ComputeObjectMapping()
  315. {
  316. if(!this->Objects.empty())
  317. {
  318. return;
  319. }
  320. std::vector<std::string> configs;
  321. this->Makefile->GetConfigurations(configs);
  322. if (configs.empty())
  323. {
  324. configs.push_back("");
  325. }
  326. for(std::vector<std::string>::const_iterator ci = configs.begin();
  327. ci != configs.end(); ++ci)
  328. {
  329. std::vector<cmSourceFile const*> sourceFiles;
  330. this->GetObjectSources(sourceFiles, *ci);
  331. }
  332. }
  333. //----------------------------------------------------------------------------
  334. const char* cmGeneratorTarget::GetFeature(const std::string& feature,
  335. const std::string& config) const
  336. {
  337. if(!config.empty())
  338. {
  339. std::string featureConfig = feature;
  340. featureConfig += "_";
  341. featureConfig += cmSystemTools::UpperCase(config);
  342. if(const char* value = this->Target->GetProperty(featureConfig))
  343. {
  344. return value;
  345. }
  346. }
  347. if(const char* value = this->Target->GetProperty(feature))
  348. {
  349. return value;
  350. }
  351. return this->LocalGenerator->GetFeature(feature, config);
  352. }
  353. //----------------------------------------------------------------------------
  354. bool cmGeneratorTarget::GetFeatureAsBool(const std::string& feature,
  355. const std::string& config) const
  356. {
  357. return cmSystemTools::IsOn(this->GetFeature(feature, config));
  358. }
  359. //----------------------------------------------------------------------------
  360. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  361. {
  362. this->ComputeObjectMapping();
  363. return this->Objects[file];
  364. }
  365. //----------------------------------------------------------------------------
  366. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  367. {
  368. this->ExplicitObjectName.insert(sf);
  369. }
  370. //----------------------------------------------------------------------------
  371. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  372. {
  373. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  374. std::set<cmSourceFile const*>::const_iterator it
  375. = this->ExplicitObjectName.find(file);
  376. return it != this->ExplicitObjectName.end();
  377. }
  378. //----------------------------------------------------------------------------
  379. void cmGeneratorTarget
  380. ::GetIDLSources(std::vector<cmSourceFile const*>& data,
  381. const std::string& config) const
  382. {
  383. IMPLEMENT_VISIT(IDLSources);
  384. }
  385. //----------------------------------------------------------------------------
  386. void
  387. cmGeneratorTarget
  388. ::GetHeaderSources(std::vector<cmSourceFile const*>& data,
  389. const std::string& config) const
  390. {
  391. IMPLEMENT_VISIT(HeaderSources);
  392. }
  393. //----------------------------------------------------------------------------
  394. void cmGeneratorTarget
  395. ::GetExtraSources(std::vector<cmSourceFile const*>& data,
  396. const std::string& config) const
  397. {
  398. IMPLEMENT_VISIT(ExtraSources);
  399. }
  400. //----------------------------------------------------------------------------
  401. void
  402. cmGeneratorTarget
  403. ::GetCustomCommands(std::vector<cmSourceFile const*>& data,
  404. const std::string& config) const
  405. {
  406. IMPLEMENT_VISIT(CustomCommands);
  407. }
  408. //----------------------------------------------------------------------------
  409. void
  410. cmGeneratorTarget
  411. ::GetExternalObjects(std::vector<cmSourceFile const*>& data,
  412. const std::string& config) const
  413. {
  414. IMPLEMENT_VISIT(ExternalObjects);
  415. }
  416. //----------------------------------------------------------------------------
  417. void
  418. cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& srcs,
  419. const std::string& config) const
  420. {
  421. ResxData data;
  422. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  423. srcs = data.ExpectedResxHeaders;
  424. }
  425. //----------------------------------------------------------------------------
  426. void cmGeneratorTarget
  427. ::GetResxSources(std::vector<cmSourceFile const*>& srcs,
  428. const std::string& config) const
  429. {
  430. ResxData data;
  431. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  432. srcs = data.ResxSources;
  433. }
  434. //----------------------------------------------------------------------------
  435. void
  436. cmGeneratorTarget
  437. ::GetAppManifest(std::vector<cmSourceFile const*>& data,
  438. const std::string& config) const
  439. {
  440. IMPLEMENT_VISIT(AppManifest);
  441. }
  442. //----------------------------------------------------------------------------
  443. void
  444. cmGeneratorTarget
  445. ::GetCertificates(std::vector<cmSourceFile const*>& data,
  446. const std::string& config) const
  447. {
  448. IMPLEMENT_VISIT(Certificates);
  449. }
  450. //----------------------------------------------------------------------------
  451. void
  452. cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
  453. const std::string& config) const
  454. {
  455. XamlData data;
  456. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  457. headers = data.ExpectedXamlHeaders;
  458. }
  459. //----------------------------------------------------------------------------
  460. void
  461. cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
  462. const std::string& config) const
  463. {
  464. XamlData data;
  465. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  466. srcs = data.ExpectedXamlSources;
  467. }
  468. //----------------------------------------------------------------------------
  469. void cmGeneratorTarget
  470. ::GetXamlSources(std::vector<cmSourceFile const*>& srcs,
  471. const std::string& config) const
  472. {
  473. XamlData data;
  474. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  475. srcs = data.XamlSources;
  476. }
  477. //----------------------------------------------------------------------------
  478. const char* cmGeneratorTarget::GetLocation(const std::string& config) const
  479. {
  480. static std::string location;
  481. if (this->Target->IsImported())
  482. {
  483. location = this->Target->ImportedGetFullPath(config, false);
  484. }
  485. else
  486. {
  487. location = this->GetFullPath(config, false);
  488. }
  489. return location.c_str();
  490. }
  491. bool cmGeneratorTarget::IsImported() const
  492. {
  493. return this->Target->IsImported();
  494. }
  495. //----------------------------------------------------------------------------
  496. const char* cmGeneratorTarget::GetLocationForBuild() const
  497. {
  498. static std::string location;
  499. if(this->IsImported())
  500. {
  501. location = this->Target->ImportedGetFullPath("", false);
  502. return location.c_str();
  503. }
  504. // Now handle the deprecated build-time configuration location.
  505. location = this->Target->GetDirectory();
  506. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  507. if(cfgid && strcmp(cfgid, ".") != 0)
  508. {
  509. location += "/";
  510. location += cfgid;
  511. }
  512. if(this->Target->IsAppBundleOnApple())
  513. {
  514. std::string macdir = this->Target->BuildMacContentDirectory("", "",
  515. false);
  516. if(!macdir.empty())
  517. {
  518. location += "/";
  519. location += macdir;
  520. }
  521. }
  522. location += "/";
  523. location += this->Target->GetFullName("", false);
  524. return location.c_str();
  525. }
  526. //----------------------------------------------------------------------------
  527. bool cmGeneratorTarget::IsSystemIncludeDirectory(const std::string& dir,
  528. const std::string& config) const
  529. {
  530. assert(this->GetType() != cmTarget::INTERFACE_LIBRARY);
  531. std::string config_upper;
  532. if(!config.empty())
  533. {
  534. config_upper = cmSystemTools::UpperCase(config);
  535. }
  536. typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
  537. IncludeCacheType::const_iterator iter =
  538. this->SystemIncludesCache.find(config_upper);
  539. if (iter == this->SystemIncludesCache.end())
  540. {
  541. cmGeneratorExpressionDAGChecker dagChecker(
  542. this->GetName(),
  543. "SYSTEM_INCLUDE_DIRECTORIES", 0, 0);
  544. bool excludeImported
  545. = this->Target->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  546. std::vector<std::string> result;
  547. for (std::set<std::string>::const_iterator
  548. it = this->Target->GetSystemIncludeDirectories().begin();
  549. it != this->Target->GetSystemIncludeDirectories().end(); ++it)
  550. {
  551. cmGeneratorExpression ge;
  552. cmSystemTools::ExpandListArgument(ge.Parse(*it)
  553. ->Evaluate(this->Makefile,
  554. config, false, this->Target,
  555. &dagChecker), result);
  556. }
  557. std::vector<cmTarget const*> const& deps =
  558. this->GetLinkImplementationClosure(config);
  559. for(std::vector<cmTarget const*>::const_iterator
  560. li = deps.begin(), le = deps.end(); li != le; ++li)
  561. {
  562. handleSystemIncludesDep(this->Makefile, *li, config, this->Target,
  563. &dagChecker, result, excludeImported);
  564. }
  565. std::set<std::string> unique;
  566. for(std::vector<std::string>::iterator li = result.begin();
  567. li != result.end(); ++li)
  568. {
  569. cmSystemTools::ConvertToUnixSlashes(*li);
  570. unique.insert(*li);
  571. }
  572. result.clear();
  573. result.insert(result.end(), unique.begin(), unique.end());
  574. IncludeCacheType::value_type entry(config_upper, result);
  575. iter = this->SystemIncludesCache.insert(entry).first;
  576. }
  577. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  578. }
  579. //----------------------------------------------------------------------------
  580. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  581. {
  582. return this->Target->GetPropertyAsBool(prop);
  583. }
  584. //----------------------------------------------------------------------------
  585. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
  586. const std::string& config) const
  587. {
  588. this->Target->GetSourceFiles(files, config);
  589. }
  590. //----------------------------------------------------------------------------
  591. std::string cmGeneratorTarget::GetSOName(const std::string& config) const
  592. {
  593. if(this->Target->IsImported())
  594. {
  595. // Lookup the imported soname.
  596. if(cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config))
  597. {
  598. if(info->NoSOName)
  599. {
  600. // The imported library has no builtin soname so the name
  601. // searched at runtime will be just the filename.
  602. return cmSystemTools::GetFilenameName(info->Location);
  603. }
  604. else
  605. {
  606. // Use the soname given if any.
  607. if(info->SOName.find("@rpath/") == 0)
  608. {
  609. return info->SOName.substr(6);
  610. }
  611. return info->SOName;
  612. }
  613. }
  614. else
  615. {
  616. return "";
  617. }
  618. }
  619. else
  620. {
  621. // Compute the soname that will be built.
  622. std::string name;
  623. std::string soName;
  624. std::string realName;
  625. std::string impName;
  626. std::string pdbName;
  627. this->Target->GetLibraryNames(name, soName, realName,
  628. impName, pdbName, config);
  629. return soName;
  630. }
  631. }
  632. //----------------------------------------------------------------------------
  633. std::string
  634. cmGeneratorTarget::GetModuleDefinitionFile(const std::string& config) const
  635. {
  636. std::string data;
  637. IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, COMMA std::string)
  638. return data;
  639. }
  640. //----------------------------------------------------------------------------
  641. void
  642. cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs,
  643. const std::string &config) const
  644. {
  645. std::vector<cmSourceFile const*> objectFiles;
  646. this->GetExternalObjects(objectFiles, config);
  647. std::vector<cmTarget*> objectLibraries;
  648. for(std::vector<cmSourceFile const*>::const_iterator
  649. it = objectFiles.begin(); it != objectFiles.end(); ++it)
  650. {
  651. std::string objLib = (*it)->GetObjectLibrary();
  652. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  653. {
  654. objectLibraries.push_back(tgt);
  655. }
  656. }
  657. std::vector<cmTarget*>::const_iterator end
  658. = cmRemoveDuplicates(objectLibraries);
  659. for(std::vector<cmTarget*>::const_iterator
  660. ti = objectLibraries.begin();
  661. ti != end; ++ti)
  662. {
  663. cmTarget* objLib = *ti;
  664. cmGeneratorTarget* ogt =
  665. this->GlobalGenerator->GetGeneratorTarget(objLib);
  666. std::vector<cmSourceFile const*> objectSources;
  667. ogt->GetObjectSources(objectSources, config);
  668. for(std::vector<cmSourceFile const*>::const_iterator
  669. si = objectSources.begin();
  670. si != objectSources.end(); ++si)
  671. {
  672. std::string obj = ogt->ObjectDirectory;
  673. obj += ogt->Objects[*si];
  674. objs.push_back(obj);
  675. }
  676. }
  677. }
  678. //----------------------------------------------------------------------------
  679. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string> &result,
  680. const std::string& config) const
  681. {
  682. const char *prop
  683. = this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS",
  684. config);
  685. if (!prop)
  686. {
  687. return;
  688. }
  689. cmGeneratorExpression ge;
  690. cmGeneratorExpressionDAGChecker dagChecker(
  691. this->GetName(),
  692. "AUTOUIC_OPTIONS", 0, 0);
  693. cmSystemTools::ExpandListArgument(ge.Parse(prop)
  694. ->Evaluate(this->Makefile,
  695. config,
  696. false,
  697. this->Target,
  698. &dagChecker),
  699. result);
  700. }
  701. //----------------------------------------------------------------------------
  702. void processILibs(const std::string& config,
  703. cmTarget const* headTarget,
  704. cmLinkItem const& item,
  705. std::vector<cmTarget const*>& tgts,
  706. std::set<cmTarget const*>& emitted)
  707. {
  708. if (item.Target && emitted.insert(item.Target).second)
  709. {
  710. tgts.push_back(item.Target);
  711. if(cmTarget::LinkInterfaceLibraries const* iface =
  712. item.Target->GetLinkInterfaceLibraries(config, headTarget, true))
  713. {
  714. for(std::vector<cmLinkItem>::const_iterator
  715. it = iface->Libraries.begin();
  716. it != iface->Libraries.end(); ++it)
  717. {
  718. processILibs(config, headTarget, *it, tgts, emitted);
  719. }
  720. }
  721. }
  722. }
  723. //----------------------------------------------------------------------------
  724. const std::vector<const cmTarget*>&
  725. cmGeneratorTarget::GetLinkImplementationClosure(
  726. const std::string& config) const
  727. {
  728. LinkImplClosure& tgts =
  729. this->LinkImplClosureMap[config];
  730. if(!tgts.Done)
  731. {
  732. tgts.Done = true;
  733. std::set<cmTarget const*> emitted;
  734. cmTarget::LinkImplementationLibraries const* impl
  735. = this->Target->GetLinkImplementationLibraries(config);
  736. for(std::vector<cmLinkImplItem>::const_iterator
  737. it = impl->Libraries.begin();
  738. it != impl->Libraries.end(); ++it)
  739. {
  740. processILibs(config, this->Target, *it, tgts , emitted);
  741. }
  742. }
  743. return tgts;
  744. }
  745. //----------------------------------------------------------------------------
  746. class cmTargetTraceDependencies
  747. {
  748. public:
  749. cmTargetTraceDependencies(cmGeneratorTarget* target);
  750. void Trace();
  751. private:
  752. cmTarget* Target;
  753. cmGeneratorTarget* GeneratorTarget;
  754. cmMakefile* Makefile;
  755. cmGlobalGenerator const* GlobalGenerator;
  756. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  757. SourceEntry* CurrentEntry;
  758. std::queue<cmSourceFile*> SourceQueue;
  759. std::set<cmSourceFile*> SourcesQueued;
  760. typedef std::map<std::string, cmSourceFile*> NameMapType;
  761. NameMapType NameMap;
  762. std::vector<std::string> NewSources;
  763. void QueueSource(cmSourceFile* sf);
  764. void FollowName(std::string const& name);
  765. void FollowNames(std::vector<std::string> const& names);
  766. bool IsUtility(std::string const& dep);
  767. void CheckCustomCommand(cmCustomCommand const& cc);
  768. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  769. void FollowCommandDepends(cmCustomCommand const& cc,
  770. const std::string& config,
  771. std::set<std::string>& emitted);
  772. };
  773. //----------------------------------------------------------------------------
  774. cmTargetTraceDependencies
  775. ::cmTargetTraceDependencies(cmGeneratorTarget* target):
  776. Target(target->Target), GeneratorTarget(target)
  777. {
  778. // Convenience.
  779. this->Makefile = this->Target->GetMakefile();
  780. this->GlobalGenerator = this->Makefile->GetGlobalGenerator();
  781. this->CurrentEntry = 0;
  782. // Queue all the source files already specified for the target.
  783. if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  784. {
  785. std::vector<std::string> configs;
  786. this->Makefile->GetConfigurations(configs);
  787. if (configs.empty())
  788. {
  789. configs.push_back("");
  790. }
  791. std::set<cmSourceFile*> emitted;
  792. for(std::vector<std::string>::const_iterator ci = configs.begin();
  793. ci != configs.end(); ++ci)
  794. {
  795. std::vector<cmSourceFile*> sources;
  796. this->Target->GetSourceFiles(sources, *ci);
  797. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  798. si != sources.end(); ++si)
  799. {
  800. cmSourceFile* sf = *si;
  801. const std::set<cmTarget const*> tgts =
  802. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  803. if (tgts.find(this->Target) != tgts.end())
  804. {
  805. std::ostringstream e;
  806. e << "Evaluation output file\n \"" << sf->GetFullPath()
  807. << "\"\ndepends on the sources of a target it is used in. This "
  808. "is a dependency loop and is not allowed.";
  809. this->GeneratorTarget
  810. ->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  811. return;
  812. }
  813. if(emitted.insert(sf).second && this->SourcesQueued.insert(sf).second)
  814. {
  815. this->SourceQueue.push(sf);
  816. }
  817. }
  818. }
  819. }
  820. // Queue pre-build, pre-link, and post-build rule dependencies.
  821. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  822. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  823. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  824. }
  825. //----------------------------------------------------------------------------
  826. void cmTargetTraceDependencies::Trace()
  827. {
  828. // Process one dependency at a time until the queue is empty.
  829. while(!this->SourceQueue.empty())
  830. {
  831. // Get the next source from the queue.
  832. cmSourceFile* sf = this->SourceQueue.front();
  833. this->SourceQueue.pop();
  834. this->CurrentEntry = &this->GeneratorTarget->SourceEntries[sf];
  835. // Queue dependencies added explicitly by the user.
  836. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  837. {
  838. std::vector<std::string> objDeps;
  839. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  840. for(std::vector<std::string>::iterator odi = objDeps.begin();
  841. odi != objDeps.end(); ++odi)
  842. {
  843. if (cmSystemTools::FileIsFullPath(*odi))
  844. {
  845. *odi = cmSystemTools::CollapseFullPath(*odi);
  846. }
  847. }
  848. this->FollowNames(objDeps);
  849. }
  850. // Queue the source needed to generate this file, if any.
  851. this->FollowName(sf->GetFullPath());
  852. // Queue dependencies added programatically by commands.
  853. this->FollowNames(sf->GetDepends());
  854. // Queue custom command dependencies.
  855. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  856. {
  857. this->CheckCustomCommand(*cc);
  858. }
  859. }
  860. this->CurrentEntry = 0;
  861. this->Target->AddTracedSources(this->NewSources);
  862. }
  863. //----------------------------------------------------------------------------
  864. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  865. {
  866. if(this->SourcesQueued.insert(sf).second)
  867. {
  868. this->SourceQueue.push(sf);
  869. // Make sure this file is in the target at the end.
  870. this->NewSources.push_back(sf->GetFullPath());
  871. }
  872. }
  873. //----------------------------------------------------------------------------
  874. void cmTargetTraceDependencies::FollowName(std::string const& name)
  875. {
  876. NameMapType::iterator i = this->NameMap.find(name);
  877. if(i == this->NameMap.end())
  878. {
  879. // Check if we know how to generate this file.
  880. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  881. NameMapType::value_type entry(name, sf);
  882. i = this->NameMap.insert(entry).first;
  883. }
  884. if(cmSourceFile* sf = i->second)
  885. {
  886. // Record the dependency we just followed.
  887. if(this->CurrentEntry)
  888. {
  889. this->CurrentEntry->Depends.push_back(sf);
  890. }
  891. this->QueueSource(sf);
  892. }
  893. }
  894. //----------------------------------------------------------------------------
  895. void
  896. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  897. {
  898. for(std::vector<std::string>::const_iterator i = names.begin();
  899. i != names.end(); ++i)
  900. {
  901. this->FollowName(*i);
  902. }
  903. }
  904. //----------------------------------------------------------------------------
  905. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  906. {
  907. // Dependencies on targets (utilities) are supposed to be named by
  908. // just the target name. However for compatibility we support
  909. // naming the output file generated by the target (assuming there is
  910. // no output-name property which old code would not have set). In
  911. // that case the target name will be the file basename of the
  912. // dependency.
  913. std::string util = cmSystemTools::GetFilenameName(dep);
  914. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  915. {
  916. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  917. }
  918. // Check for a target with this name.
  919. if(cmGeneratorTarget* t
  920. = this->Makefile->FindGeneratorTargetToUse(util))
  921. {
  922. // If we find the target and the dep was given as a full path,
  923. // then make sure it was not a full path to something else, and
  924. // the fact that the name matched a target was just a coincidence.
  925. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  926. {
  927. if(t->GetType() >= cmTarget::EXECUTABLE &&
  928. t->GetType() <= cmTarget::MODULE_LIBRARY)
  929. {
  930. // This is really only for compatibility so we do not need to
  931. // worry about configuration names and output names.
  932. std::string tLocation = t->GetLocationForBuild();
  933. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  934. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  935. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  936. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  937. if(depLocation == tLocation)
  938. {
  939. this->Target->AddUtility(util);
  940. return true;
  941. }
  942. }
  943. }
  944. else
  945. {
  946. // The original name of the dependency was not a full path. It
  947. // must name a target, so add the target-level dependency.
  948. this->Target->AddUtility(util);
  949. return true;
  950. }
  951. }
  952. // The dependency does not name a target built in this project.
  953. return false;
  954. }
  955. //----------------------------------------------------------------------------
  956. void
  957. cmTargetTraceDependencies
  958. ::CheckCustomCommand(cmCustomCommand const& cc)
  959. {
  960. // Transform command names that reference targets built in this
  961. // project to corresponding target-level dependencies.
  962. cmGeneratorExpression ge(cc.GetBacktrace());
  963. // Add target-level dependencies referenced by generator expressions.
  964. std::set<cmTarget*> targets;
  965. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  966. cit != cc.GetCommandLines().end(); ++cit)
  967. {
  968. std::string const& command = *cit->begin();
  969. // Check for a target with this name.
  970. if(cmTarget* t = this->Makefile->FindTargetToUse(command))
  971. {
  972. if(t->GetType() == cmTarget::EXECUTABLE)
  973. {
  974. // The command refers to an executable target built in
  975. // this project. Add the target-level dependency to make
  976. // sure the executable is up to date before this custom
  977. // command possibly runs.
  978. this->Target->AddUtility(command);
  979. }
  980. }
  981. // Check for target references in generator expressions.
  982. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  983. cli != cit->end(); ++cli)
  984. {
  985. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  986. = ge.Parse(*cli);
  987. cge->Evaluate(this->Makefile, "", true);
  988. std::set<cmTarget*> geTargets = cge->GetTargets();
  989. targets.insert(geTargets.begin(), geTargets.end());
  990. }
  991. }
  992. for(std::set<cmTarget*>::iterator ti = targets.begin();
  993. ti != targets.end(); ++ti)
  994. {
  995. this->Target->AddUtility((*ti)->GetName());
  996. }
  997. // Queue the custom command dependencies.
  998. std::vector<std::string> configs;
  999. std::set<std::string> emitted;
  1000. this->Makefile->GetConfigurations(configs);
  1001. if (configs.empty())
  1002. {
  1003. configs.push_back("");
  1004. }
  1005. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1006. ci != configs.end(); ++ci)
  1007. {
  1008. this->FollowCommandDepends(cc, *ci, emitted);
  1009. }
  1010. }
  1011. //----------------------------------------------------------------------------
  1012. void cmTargetTraceDependencies::FollowCommandDepends(cmCustomCommand const& cc,
  1013. const std::string& config,
  1014. std::set<std::string>& emitted)
  1015. {
  1016. cmCustomCommandGenerator ccg(cc, config,
  1017. this->GeneratorTarget->LocalGenerator);
  1018. const std::vector<std::string>& depends = ccg.GetDepends();
  1019. for(std::vector<std::string>::const_iterator di = depends.begin();
  1020. di != depends.end(); ++di)
  1021. {
  1022. std::string const& dep = *di;
  1023. if(emitted.insert(dep).second)
  1024. {
  1025. if(!this->IsUtility(dep))
  1026. {
  1027. // The dependency does not name a target and may be a file we
  1028. // know how to generate. Queue it.
  1029. this->FollowName(dep);
  1030. }
  1031. }
  1032. }
  1033. }
  1034. //----------------------------------------------------------------------------
  1035. void
  1036. cmTargetTraceDependencies
  1037. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  1038. {
  1039. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  1040. cli != commands.end(); ++cli)
  1041. {
  1042. this->CheckCustomCommand(*cli);
  1043. }
  1044. }
  1045. //----------------------------------------------------------------------------
  1046. void cmGeneratorTarget::TraceDependencies()
  1047. {
  1048. // CMake-generated targets have no dependencies to trace. Normally tracing
  1049. // would find nothing anyway, but when building CMake itself the "install"
  1050. // target command ends up referencing the "cmake" target but we do not
  1051. // really want the dependency because "install" depend on "all" anyway.
  1052. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  1053. {
  1054. return;
  1055. }
  1056. // Use a helper object to trace the dependencies.
  1057. cmTargetTraceDependencies tracer(this);
  1058. tracer.Trace();
  1059. }
  1060. //----------------------------------------------------------------------------
  1061. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  1062. std::vector<std::string>& archVec) const
  1063. {
  1064. const char* archs = 0;
  1065. if(!config.empty())
  1066. {
  1067. std::string defVarName = "OSX_ARCHITECTURES_";
  1068. defVarName += cmSystemTools::UpperCase(config);
  1069. archs = this->Target->GetProperty(defVarName);
  1070. }
  1071. if(!archs)
  1072. {
  1073. archs = this->Target->GetProperty("OSX_ARCHITECTURES");
  1074. }
  1075. if(archs)
  1076. {
  1077. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  1078. }
  1079. }
  1080. //----------------------------------------------------------------------------
  1081. std::string
  1082. cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang,
  1083. std::string const& config) const
  1084. {
  1085. switch(this->GetType())
  1086. {
  1087. case cmTarget::STATIC_LIBRARY:
  1088. {
  1089. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  1090. if(this->GetFeatureAsBool(
  1091. "INTERPROCEDURAL_OPTIMIZATION", config))
  1092. {
  1093. std::string varIPO = var + "_IPO";
  1094. if(this->Makefile->GetDefinition(varIPO))
  1095. {
  1096. return varIPO;
  1097. }
  1098. }
  1099. return var;
  1100. }
  1101. case cmTarget::SHARED_LIBRARY:
  1102. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  1103. case cmTarget::MODULE_LIBRARY:
  1104. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  1105. case cmTarget::EXECUTABLE:
  1106. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  1107. default:
  1108. break;
  1109. }
  1110. return "";
  1111. }
  1112. //----------------------------------------------------------------------------
  1113. std::vector<std::string>
  1114. cmGeneratorTarget::GetIncludeDirectories(const std::string& config,
  1115. const std::string& lang) const
  1116. {
  1117. return this->Target->GetIncludeDirectories(config, lang);
  1118. }
  1119. //----------------------------------------------------------------------------
  1120. void cmGeneratorTarget::GenerateTargetManifest(
  1121. const std::string& config) const
  1122. {
  1123. if (this->Target->IsImported())
  1124. {
  1125. return;
  1126. }
  1127. cmMakefile* mf = this->Target->GetMakefile();
  1128. cmGlobalGenerator* gg = mf->GetGlobalGenerator();
  1129. // Get the names.
  1130. std::string name;
  1131. std::string soName;
  1132. std::string realName;
  1133. std::string impName;
  1134. std::string pdbName;
  1135. if(this->GetType() == cmTarget::EXECUTABLE)
  1136. {
  1137. this->GetExecutableNames(name, realName, impName, pdbName, config);
  1138. }
  1139. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  1140. this->GetType() == cmTarget::SHARED_LIBRARY ||
  1141. this->GetType() == cmTarget::MODULE_LIBRARY)
  1142. {
  1143. this->Target->GetLibraryNames(name, soName, realName, impName, pdbName,
  1144. config);
  1145. }
  1146. else
  1147. {
  1148. return;
  1149. }
  1150. // Get the directory.
  1151. std::string dir = this->Target->GetDirectory(config, false);
  1152. // Add each name.
  1153. std::string f;
  1154. if(!name.empty())
  1155. {
  1156. f = dir;
  1157. f += "/";
  1158. f += name;
  1159. gg->AddToManifest(f);
  1160. }
  1161. if(!soName.empty())
  1162. {
  1163. f = dir;
  1164. f += "/";
  1165. f += soName;
  1166. gg->AddToManifest(f);
  1167. }
  1168. if(!realName.empty())
  1169. {
  1170. f = dir;
  1171. f += "/";
  1172. f += realName;
  1173. gg->AddToManifest(f);
  1174. }
  1175. if(!pdbName.empty())
  1176. {
  1177. f = dir;
  1178. f += "/";
  1179. f += pdbName;
  1180. gg->AddToManifest(f);
  1181. }
  1182. if(!impName.empty())
  1183. {
  1184. f = this->Target->GetDirectory(config, true);
  1185. f += "/";
  1186. f += impName;
  1187. gg->AddToManifest(f);
  1188. }
  1189. }
  1190. //----------------------------------------------------------------------------
  1191. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  1192. bool implib, bool realname) const
  1193. {
  1194. if(this->Target->IsImported())
  1195. {
  1196. return this->Target->ImportedGetFullPath(config, implib);
  1197. }
  1198. else
  1199. {
  1200. return this->NormalGetFullPath(config, implib, realname);
  1201. }
  1202. }
  1203. std::string cmGeneratorTarget::NormalGetFullPath(const std::string& config,
  1204. bool implib,
  1205. bool realname) const
  1206. {
  1207. std::string fpath = this->Target->GetDirectory(config, implib);
  1208. fpath += "/";
  1209. if(this->Target->IsAppBundleOnApple())
  1210. {
  1211. fpath = this->Target->BuildMacContentDirectory(fpath, config, false);
  1212. fpath += "/";
  1213. }
  1214. // Add the full name of the target.
  1215. if(implib)
  1216. {
  1217. fpath += this->Target->GetFullName(config, true);
  1218. }
  1219. else if(realname)
  1220. {
  1221. fpath += this->NormalGetRealName(config);
  1222. }
  1223. else
  1224. {
  1225. fpath += this->Target->GetFullName(config, false);
  1226. }
  1227. return fpath;
  1228. }
  1229. //----------------------------------------------------------------------------
  1230. std::string
  1231. cmGeneratorTarget::NormalGetRealName(const std::string& config) const
  1232. {
  1233. // This should not be called for imported targets.
  1234. // TODO: Split cmTarget into a class hierarchy to get compile-time
  1235. // enforcement of the limited imported target API.
  1236. if(this->Target->IsImported())
  1237. {
  1238. std::string msg = "NormalGetRealName called on imported target: ";
  1239. msg += this->GetName();
  1240. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1241. }
  1242. if(this->GetType() == cmTarget::EXECUTABLE)
  1243. {
  1244. // Compute the real name that will be built.
  1245. std::string name;
  1246. std::string realName;
  1247. std::string impName;
  1248. std::string pdbName;
  1249. this->GetExecutableNames(name, realName, impName, pdbName, config);
  1250. return realName;
  1251. }
  1252. else
  1253. {
  1254. // Compute the real name that will be built.
  1255. std::string name;
  1256. std::string soName;
  1257. std::string realName;
  1258. std::string impName;
  1259. std::string pdbName;
  1260. this->Target->GetLibraryNames(name, soName, realName,
  1261. impName, pdbName, config);
  1262. return realName;
  1263. }
  1264. }
  1265. //----------------------------------------------------------------------------
  1266. void cmGeneratorTarget::GetExecutableNames(std::string& name,
  1267. std::string& realName,
  1268. std::string& impName,
  1269. std::string& pdbName,
  1270. const std::string& config) const
  1271. {
  1272. // This should not be called for imported targets.
  1273. // TODO: Split cmTarget into a class hierarchy to get compile-time
  1274. // enforcement of the limited imported target API.
  1275. if(this->Target->IsImported())
  1276. {
  1277. std::string msg =
  1278. "GetExecutableNames called on imported target: ";
  1279. msg += this->GetName();
  1280. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1281. }
  1282. // This versioning is supported only for executables and then only
  1283. // when the platform supports symbolic links.
  1284. #if defined(_WIN32) && !defined(__CYGWIN__)
  1285. const char* version = 0;
  1286. #else
  1287. // Check for executable version properties.
  1288. const char* version = this->GetProperty("VERSION");
  1289. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  1290. {
  1291. version = 0;
  1292. }
  1293. #endif
  1294. // Get the components of the executable name.
  1295. std::string prefix;
  1296. std::string base;
  1297. std::string suffix;
  1298. this->Target->GetFullNameInternal(config, false, prefix, base, suffix);
  1299. // The executable name.
  1300. name = prefix+base+suffix;
  1301. // The executable's real name on disk.
  1302. #if defined(__CYGWIN__)
  1303. realName = prefix+base;
  1304. #else
  1305. realName = name;
  1306. #endif
  1307. if(version)
  1308. {
  1309. realName += "-";
  1310. realName += version;
  1311. }
  1312. #if defined(__CYGWIN__)
  1313. realName += suffix;
  1314. #endif
  1315. // The import library name.
  1316. impName = this->Target->GetFullNameInternal(config, true);
  1317. // The program database file name.
  1318. pdbName = this->Target->GetPDBName(config);
  1319. }
  1320. bool cmStrictTargetComparison::operator()(cmTarget const* t1,
  1321. cmTarget const* t2) const
  1322. {
  1323. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  1324. if (nameResult == 0)
  1325. {
  1326. return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory(),
  1327. t2->GetMakefile()->GetCurrentBinaryDirectory()) < 0;
  1328. }
  1329. return nameResult < 0;
  1330. }
  1331. //----------------------------------------------------------------------------
  1332. struct cmGeneratorTarget::SourceFileFlags
  1333. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  1334. {
  1335. struct SourceFileFlags flags;
  1336. this->ConstructSourceFileFlags();
  1337. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  1338. this->SourceFlagsMap.find(sf);
  1339. if(si != this->SourceFlagsMap.end())
  1340. {
  1341. flags = si->second;
  1342. }
  1343. else
  1344. {
  1345. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  1346. // were not listed in one of the other lists.
  1347. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  1348. {
  1349. flags.MacFolder = location;
  1350. if(strcmp(location, "Resources") == 0)
  1351. {
  1352. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  1353. }
  1354. else
  1355. {
  1356. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  1357. }
  1358. }
  1359. }
  1360. return flags;
  1361. }
  1362. //----------------------------------------------------------------------------
  1363. void cmGeneratorTarget::ConstructSourceFileFlags() const
  1364. {
  1365. if(this->SourceFileFlagsConstructed)
  1366. {
  1367. return;
  1368. }
  1369. this->SourceFileFlagsConstructed = true;
  1370. // Process public headers to mark the source files.
  1371. if(const char* files = this->Target->GetProperty("PUBLIC_HEADER"))
  1372. {
  1373. std::vector<std::string> relFiles;
  1374. cmSystemTools::ExpandListArgument(files, relFiles);
  1375. for(std::vector<std::string>::iterator it = relFiles.begin();
  1376. it != relFiles.end(); ++it)
  1377. {
  1378. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  1379. {
  1380. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  1381. flags.MacFolder = "Headers";
  1382. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  1383. }
  1384. }
  1385. }
  1386. // Process private headers after public headers so that they take
  1387. // precedence if a file is listed in both.
  1388. if(const char* files = this->Target->GetProperty("PRIVATE_HEADER"))
  1389. {
  1390. std::vector<std::string> relFiles;
  1391. cmSystemTools::ExpandListArgument(files, relFiles);
  1392. for(std::vector<std::string>::iterator it = relFiles.begin();
  1393. it != relFiles.end(); ++it)
  1394. {
  1395. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  1396. {
  1397. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  1398. flags.MacFolder = "PrivateHeaders";
  1399. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  1400. }
  1401. }
  1402. }
  1403. // Mark sources listed as resources.
  1404. if(const char* files = this->Target->GetProperty("RESOURCE"))
  1405. {
  1406. std::vector<std::string> relFiles;
  1407. cmSystemTools::ExpandListArgument(files, relFiles);
  1408. for(std::vector<std::string>::iterator it = relFiles.begin();
  1409. it != relFiles.end(); ++it)
  1410. {
  1411. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  1412. {
  1413. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  1414. flags.MacFolder = "Resources";
  1415. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  1416. }
  1417. }
  1418. }
  1419. }
  1420. //----------------------------------------------------------------------------
  1421. const cmGeneratorTarget::CompatibleInterfacesBase&
  1422. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  1423. {
  1424. cmGeneratorTarget::CompatibleInterfaces& compat =
  1425. this->CompatibleInterfacesMap[config];
  1426. if(!compat.Done)
  1427. {
  1428. compat.Done = true;
  1429. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  1430. compat.PropsString.insert("AUTOUIC_OPTIONS");
  1431. std::vector<cmTarget const*> const& deps =
  1432. this->GetLinkImplementationClosure(config);
  1433. for(std::vector<cmTarget const*>::const_iterator li = deps.begin();
  1434. li != deps.end(); ++li)
  1435. {
  1436. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  1437. if(const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) \
  1438. { \
  1439. std::vector<std::string> props; \
  1440. cmSystemTools::ExpandListArgument(prop, props); \
  1441. compat.Props##x.insert(props.begin(), props.end()); \
  1442. }
  1443. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  1444. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  1445. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  1446. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  1447. #undef CM_READ_COMPATIBLE_INTERFACE
  1448. }
  1449. }
  1450. return compat;
  1451. }
  1452. //----------------------------------------------------------------------------
  1453. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  1454. const std::string &p, const std::string& config) const
  1455. {
  1456. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  1457. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  1458. {
  1459. return false;
  1460. }
  1461. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  1462. }
  1463. //----------------------------------------------------------------------------
  1464. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  1465. const std::string &p, const std::string& config) const
  1466. {
  1467. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  1468. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  1469. {
  1470. return false;
  1471. }
  1472. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  1473. }
  1474. //----------------------------------------------------------------------------
  1475. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  1476. const std::string &p, const std::string& config) const
  1477. {
  1478. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  1479. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  1480. {
  1481. return false;
  1482. }
  1483. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  1484. }
  1485. //----------------------------------------------------------------------------
  1486. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  1487. const std::string &p, const std::string& config) const
  1488. {
  1489. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  1490. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  1491. {
  1492. return false;
  1493. }
  1494. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  1495. }
  1496. enum CompatibleType
  1497. {
  1498. BoolType,
  1499. StringType,
  1500. NumberMinType,
  1501. NumberMaxType
  1502. };
  1503. template<typename PropertyType>
  1504. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  1505. const std::string& prop,
  1506. const std::string& config,
  1507. CompatibleType,
  1508. PropertyType *);
  1509. template<>
  1510. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  1511. const std::string& prop,
  1512. const std::string& config,
  1513. CompatibleType, bool *)
  1514. {
  1515. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  1516. }
  1517. template<>
  1518. const char * getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  1519. const std::string& prop,
  1520. const std::string& config,
  1521. CompatibleType t,
  1522. const char **)
  1523. {
  1524. switch(t)
  1525. {
  1526. case BoolType:
  1527. assert(0 && "String compatibility check function called for boolean");
  1528. return 0;
  1529. case StringType:
  1530. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  1531. case NumberMinType:
  1532. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  1533. case NumberMaxType:
  1534. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  1535. }
  1536. assert(0 && "Unreachable!");
  1537. return 0;
  1538. }
  1539. //----------------------------------------------------------------------------
  1540. template<typename PropertyType>
  1541. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  1542. cmTarget const* dependee,
  1543. const std::string& propName,
  1544. std::set<std::string> &emitted,
  1545. const std::string& config,
  1546. CompatibleType t,
  1547. PropertyType *)
  1548. {
  1549. const char *prop = dependee->GetProperty(propName);
  1550. if (!prop)
  1551. {
  1552. return;
  1553. }
  1554. std::vector<std::string> props;
  1555. cmSystemTools::ExpandListArgument(prop, props);
  1556. std::string pdir =
  1557. dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
  1558. pdir += "/Help/prop_tgt/";
  1559. for(std::vector<std::string>::iterator pi = props.begin();
  1560. pi != props.end(); ++pi)
  1561. {
  1562. std::string pname = cmSystemTools::HelpFileName(*pi);
  1563. std::string pfile = pdir + pname + ".rst";
  1564. if(cmSystemTools::FileExists(pfile.c_str(), true))
  1565. {
  1566. std::ostringstream e;
  1567. e << "Target \"" << dependee->GetName() << "\" has property \""
  1568. << *pi << "\" listed in its " << propName << " property. "
  1569. "This is not allowed. Only user-defined properties may appear "
  1570. "listed in the " << propName << " property.";
  1571. depender->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
  1572. return;
  1573. }
  1574. if(emitted.insert(*pi).second)
  1575. {
  1576. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  1577. t, 0);
  1578. if (cmSystemTools::GetErrorOccuredFlag())
  1579. {
  1580. return;
  1581. }
  1582. }
  1583. }
  1584. }
  1585. static std::string intersect(const std::set<std::string> &s1,
  1586. const std::set<std::string> &s2)
  1587. {
  1588. std::set<std::string> intersect;
  1589. std::set_intersection(s1.begin(),s1.end(),
  1590. s2.begin(),s2.end(),
  1591. std::inserter(intersect,intersect.begin()));
  1592. if (!intersect.empty())
  1593. {
  1594. return *intersect.begin();
  1595. }
  1596. return "";
  1597. }
  1598. static std::string intersect(const std::set<std::string> &s1,
  1599. const std::set<std::string> &s2,
  1600. const std::set<std::string> &s3)
  1601. {
  1602. std::string result;
  1603. result = intersect(s1, s2);
  1604. if (!result.empty())
  1605. return result;
  1606. result = intersect(s1, s3);
  1607. if (!result.empty())
  1608. return result;
  1609. return intersect(s2, s3);
  1610. }
  1611. static std::string intersect(const std::set<std::string> &s1,
  1612. const std::set<std::string> &s2,
  1613. const std::set<std::string> &s3,
  1614. const std::set<std::string> &s4)
  1615. {
  1616. std::string result;
  1617. result = intersect(s1, s2);
  1618. if (!result.empty())
  1619. return result;
  1620. result = intersect(s1, s3);
  1621. if (!result.empty())
  1622. return result;
  1623. result = intersect(s1, s4);
  1624. if (!result.empty())
  1625. return result;
  1626. return intersect(s2, s3, s4);
  1627. }
  1628. //----------------------------------------------------------------------------
  1629. void cmGeneratorTarget::CheckPropertyCompatibility(
  1630. cmComputeLinkInformation *info, const std::string& config) const
  1631. {
  1632. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  1633. std::set<std::string> emittedBools;
  1634. static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  1635. std::set<std::string> emittedStrings;
  1636. static std::string strString = "COMPATIBLE_INTERFACE_STRING";
  1637. std::set<std::string> emittedMinNumbers;
  1638. static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  1639. std::set<std::string> emittedMaxNumbers;
  1640. static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  1641. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  1642. deps.begin(); li != deps.end(); ++li)
  1643. {
  1644. if (!li->Target)
  1645. {
  1646. continue;
  1647. }
  1648. checkPropertyConsistency<bool>(this, li->Target,
  1649. strBool,
  1650. emittedBools, config, BoolType, 0);
  1651. if (cmSystemTools::GetErrorOccuredFlag())
  1652. {
  1653. return;
  1654. }
  1655. checkPropertyConsistency<const char *>(this, li->Target,
  1656. strString,
  1657. emittedStrings, config,
  1658. StringType, 0);
  1659. if (cmSystemTools::GetErrorOccuredFlag())
  1660. {
  1661. return;
  1662. }
  1663. checkPropertyConsistency<const char *>(this, li->Target,
  1664. strNumMin,
  1665. emittedMinNumbers, config,
  1666. NumberMinType, 0);
  1667. if (cmSystemTools::GetErrorOccuredFlag())
  1668. {
  1669. return;
  1670. }
  1671. checkPropertyConsistency<const char *>(this, li->Target,
  1672. strNumMax,
  1673. emittedMaxNumbers, config,
  1674. NumberMaxType, 0);
  1675. if (cmSystemTools::GetErrorOccuredFlag())
  1676. {
  1677. return;
  1678. }
  1679. }
  1680. std::string prop = intersect(emittedBools,
  1681. emittedStrings,
  1682. emittedMinNumbers,
  1683. emittedMaxNumbers);
  1684. if (!prop.empty())
  1685. {
  1686. // Use a sorted std::vector to keep the error message sorted.
  1687. std::vector<std::string> props;
  1688. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  1689. if (i != emittedBools.end())
  1690. {
  1691. props.push_back(strBool);
  1692. }
  1693. i = emittedStrings.find(prop);
  1694. if (i != emittedStrings.end())
  1695. {
  1696. props.push_back(strString);
  1697. }
  1698. i = emittedMinNumbers.find(prop);
  1699. if (i != emittedMinNumbers.end())
  1700. {
  1701. props.push_back(strNumMin);
  1702. }
  1703. i = emittedMaxNumbers.find(prop);
  1704. if (i != emittedMaxNumbers.end())
  1705. {
  1706. props.push_back(strNumMax);
  1707. }
  1708. std::sort(props.begin(), props.end());
  1709. std::string propsString = cmJoin(cmMakeRange(props).retreat(1), ", ");
  1710. propsString += " and the " + props.back();
  1711. std::ostringstream e;
  1712. e << "Property \"" << prop << "\" appears in both the "
  1713. << propsString <<
  1714. " property in the dependencies of target \"" << this->GetName() <<
  1715. "\". This is not allowed. A property may only require compatibility "
  1716. "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
  1717. "string interpretation, but not a mixture.";
  1718. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  1719. }
  1720. }
  1721. //----------------------------------------------------------------------------
  1722. std::string compatibilityType(CompatibleType t)
  1723. {
  1724. switch(t)
  1725. {
  1726. case BoolType:
  1727. return "Boolean compatibility";
  1728. case StringType:
  1729. return "String compatibility";
  1730. case NumberMaxType:
  1731. return "Numeric maximum compatibility";
  1732. case NumberMinType:
  1733. return "Numeric minimum compatibility";
  1734. }
  1735. assert(0 && "Unreachable!");
  1736. return "";
  1737. }
  1738. //----------------------------------------------------------------------------
  1739. std::string compatibilityAgree(CompatibleType t, bool dominant)
  1740. {
  1741. switch(t)
  1742. {
  1743. case BoolType:
  1744. case StringType:
  1745. return dominant ? "(Disagree)\n" : "(Agree)\n";
  1746. case NumberMaxType:
  1747. case NumberMinType:
  1748. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  1749. }
  1750. assert(0 && "Unreachable!");
  1751. return "";
  1752. }
  1753. //----------------------------------------------------------------------------
  1754. template<typename PropertyType>
  1755. PropertyType getTypedProperty(cmTarget const* tgt, const std::string& prop);
  1756. //----------------------------------------------------------------------------
  1757. template<>
  1758. bool getTypedProperty<bool>(cmTarget const* tgt, const std::string& prop)
  1759. {
  1760. return tgt->GetPropertyAsBool(prop);
  1761. }
  1762. //----------------------------------------------------------------------------
  1763. template<>
  1764. const char *getTypedProperty<const char *>(cmTarget const* tgt,
  1765. const std::string& prop)
  1766. {
  1767. return tgt->GetProperty(prop);
  1768. }
  1769. template<typename PropertyType>
  1770. std::string valueAsString(PropertyType);
  1771. template<>
  1772. std::string valueAsString<bool>(bool value)
  1773. {
  1774. return value ? "TRUE" : "FALSE";
  1775. }
  1776. template<>
  1777. std::string valueAsString<const char*>(const char* value)
  1778. {
  1779. return value ? value : "(unset)";
  1780. }
  1781. template<typename PropertyType>
  1782. PropertyType impliedValue(PropertyType);
  1783. template<>
  1784. bool impliedValue<bool>(bool)
  1785. {
  1786. return false;
  1787. }
  1788. template<>
  1789. const char* impliedValue<const char*>(const char*)
  1790. {
  1791. return "";
  1792. }
  1793. //----------------------------------------------------------------------------
  1794. template<typename PropertyType>
  1795. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  1796. PropertyType rhs,
  1797. CompatibleType t);
  1798. //----------------------------------------------------------------------------
  1799. template<>
  1800. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  1801. CompatibleType)
  1802. {
  1803. return std::make_pair(lhs == rhs, lhs);
  1804. }
  1805. //----------------------------------------------------------------------------
  1806. std::pair<bool, const char*> consistentStringProperty(const char *lhs,
  1807. const char *rhs)
  1808. {
  1809. const bool b = strcmp(lhs, rhs) == 0;
  1810. return std::make_pair(b, b ? lhs : 0);
  1811. }
  1812. //----------------------------------------------------------------------------
  1813. std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
  1814. const char *rhs,
  1815. CompatibleType t)
  1816. {
  1817. char *pEnd;
  1818. const char* const null_ptr = 0;
  1819. long lnum = strtol(lhs, &pEnd, 0);
  1820. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
  1821. {
  1822. return std::pair<bool, const char*>(false, null_ptr);
  1823. }
  1824. long rnum = strtol(rhs, &pEnd, 0);
  1825. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
  1826. {
  1827. return std::pair<bool, const char*>(false, null_ptr);
  1828. }
  1829. if (t == NumberMaxType)
  1830. {
  1831. return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs);
  1832. }
  1833. else
  1834. {
  1835. return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs);
  1836. }
  1837. }
  1838. //----------------------------------------------------------------------------
  1839. template<>
  1840. std::pair<bool, const char*> consistentProperty(const char *lhs,
  1841. const char *rhs,
  1842. CompatibleType t)
  1843. {
  1844. if (!lhs && !rhs)
  1845. {
  1846. return std::make_pair(true, lhs);
  1847. }
  1848. if (!lhs)
  1849. {
  1850. return std::make_pair(true, rhs);
  1851. }
  1852. if (!rhs)
  1853. {
  1854. return std::make_pair(true, lhs);
  1855. }
  1856. const char* const null_ptr = 0;
  1857. switch(t)
  1858. {
  1859. case BoolType:
  1860. assert(0 && "consistentProperty for strings called with BoolType");
  1861. return std::pair<bool, const char*>(false, null_ptr);
  1862. case StringType:
  1863. return consistentStringProperty(lhs, rhs);
  1864. case NumberMinType:
  1865. case NumberMaxType:
  1866. return consistentNumberProperty(lhs, rhs, t);
  1867. }
  1868. assert(0 && "Unreachable!");
  1869. return std::pair<bool, const char*>(false, null_ptr);
  1870. }
  1871. //----------------------------------------------------------------------------
  1872. template<typename PropertyType>
  1873. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  1874. const std::string &p,
  1875. const std::string& config,
  1876. const char *defaultValue,
  1877. CompatibleType t,
  1878. PropertyType *)
  1879. {
  1880. PropertyType propContent = getTypedProperty<PropertyType>(tgt->Target, p);
  1881. const bool explicitlySet = tgt->Target->GetProperties()
  1882. .find(p)
  1883. != tgt->Target->GetProperties().end();
  1884. const bool impliedByUse =
  1885. tgt->Target->IsNullImpliedByLinkLibraries(p);
  1886. assert((impliedByUse ^ explicitlySet)
  1887. || (!impliedByUse && !explicitlySet));
  1888. std::vector<cmTarget const*> const& deps =
  1889. tgt->GetLinkImplementationClosure(config);
  1890. if(deps.empty())
  1891. {
  1892. return propContent;
  1893. }
  1894. bool propInitialized = explicitlySet;
  1895. std::string report = " * Target \"";
  1896. report += tgt->GetName();
  1897. if (explicitlySet)
  1898. {
  1899. report += "\" has property content \"";
  1900. report += valueAsString<PropertyType>(propContent);
  1901. report += "\"\n";
  1902. }
  1903. else if (impliedByUse)
  1904. {
  1905. report += "\" property is implied by use.\n";
  1906. }
  1907. else
  1908. {
  1909. report += "\" property not set.\n";
  1910. }
  1911. std::string interfaceProperty = "INTERFACE_" + p;
  1912. for(std::vector<cmTarget const*>::const_iterator li =
  1913. deps.begin();
  1914. li != deps.end(); ++li)
  1915. {
  1916. // An error should be reported if one dependency
  1917. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  1918. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  1919. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  1920. // with a dependency.
  1921. cmTarget const* theTarget = *li;
  1922. const bool ifaceIsSet = theTarget->GetProperties()
  1923. .find(interfaceProperty)
  1924. != theTarget->GetProperties().end();
  1925. PropertyType ifacePropContent =
  1926. getTypedProperty<PropertyType>(theTarget,
  1927. interfaceProperty);
  1928. std::string reportEntry;
  1929. if (ifaceIsSet)
  1930. {
  1931. reportEntry += " * Target \"";
  1932. reportEntry += theTarget->GetName();
  1933. reportEntry += "\" property value \"";
  1934. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  1935. reportEntry += "\" ";
  1936. }
  1937. if (explicitlySet)
  1938. {
  1939. if (ifaceIsSet)
  1940. {
  1941. std::pair<bool, PropertyType> consistent =
  1942. consistentProperty(propContent,
  1943. ifacePropContent, t);
  1944. report += reportEntry;
  1945. report += compatibilityAgree(t, propContent != consistent.second);
  1946. if (!consistent.first)
  1947. {
  1948. std::ostringstream e;
  1949. e << "Property " << p << " on target \""
  1950. << tgt->GetName() << "\" does\nnot match the "
  1951. "INTERFACE_" << p << " property requirement\nof "
  1952. "dependency \"" << theTarget->GetName() << "\".\n";
  1953. cmSystemTools::Error(e.str().c_str());
  1954. break;
  1955. }
  1956. else
  1957. {
  1958. propContent = consistent.second;
  1959. continue;
  1960. }
  1961. }
  1962. else
  1963. {
  1964. // Explicitly set on target and not set in iface. Can't disagree.
  1965. continue;
  1966. }
  1967. }
  1968. else if (impliedByUse)
  1969. {
  1970. propContent = impliedValue<PropertyType>(propContent);
  1971. if (ifaceIsSet)
  1972. {
  1973. std::pair<bool, PropertyType> consistent =
  1974. consistentProperty(propContent,
  1975. ifacePropContent, t);
  1976. report += reportEntry;
  1977. report += compatibilityAgree(t, propContent != consistent.second);
  1978. if (!consistent.first)
  1979. {
  1980. std::ostringstream e;
  1981. e << "Property " << p << " on target \""
  1982. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  1983. << " because it was used to determine the link libraries\n"
  1984. "already. The INTERFACE_" << p << " property on\ndependency \""
  1985. << theTarget->GetName() << "\" is in conflict.\n";
  1986. cmSystemTools::Error(e.str().c_str());
  1987. break;
  1988. }
  1989. else
  1990. {
  1991. propContent = consistent.second;
  1992. continue;
  1993. }
  1994. }
  1995. else
  1996. {
  1997. // Implicitly set on target and not set in iface. Can't disagree.
  1998. continue;
  1999. }
  2000. }
  2001. else
  2002. {
  2003. if (ifaceIsSet)
  2004. {
  2005. if (propInitialized)
  2006. {
  2007. std::pair<bool, PropertyType> consistent =
  2008. consistentProperty(propContent,
  2009. ifacePropContent, t);
  2010. report += reportEntry;
  2011. report += compatibilityAgree(t, propContent != consistent.second);
  2012. if (!consistent.first)
  2013. {
  2014. std::ostringstream e;
  2015. e << "The INTERFACE_" << p << " property of \""
  2016. << theTarget->GetName() << "\" does\nnot agree with the value "
  2017. "of " << p << " already determined\nfor \""
  2018. << tgt->GetName() << "\".\n";
  2019. cmSystemTools::Error(e.str().c_str());
  2020. break;
  2021. }
  2022. else
  2023. {
  2024. propContent = consistent.second;
  2025. continue;
  2026. }
  2027. }
  2028. else
  2029. {
  2030. report += reportEntry + "(Interface set)\n";
  2031. propContent = ifacePropContent;
  2032. propInitialized = true;
  2033. }
  2034. }
  2035. else
  2036. {
  2037. // Not set. Nothing to agree on.
  2038. continue;
  2039. }
  2040. }
  2041. }
  2042. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  2043. report, compatibilityType(t));
  2044. return propContent;
  2045. }
  2046. //----------------------------------------------------------------------------
  2047. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  2048. const std::string &p, const std::string& config) const
  2049. {
  2050. return checkInterfacePropertyCompatibility<bool>(this, p, config,
  2051. "FALSE",
  2052. BoolType, 0);
  2053. }
  2054. //----------------------------------------------------------------------------
  2055. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  2056. const std::string &p,
  2057. const std::string& config) const
  2058. {
  2059. return checkInterfacePropertyCompatibility<const char *>(this,
  2060. p,
  2061. config,
  2062. "empty",
  2063. StringType, 0);
  2064. }
  2065. //----------------------------------------------------------------------------
  2066. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  2067. const std::string &p,
  2068. const std::string& config) const
  2069. {
  2070. return checkInterfacePropertyCompatibility<const char *>(this,
  2071. p,
  2072. config,
  2073. "empty",
  2074. NumberMinType, 0);
  2075. }
  2076. //----------------------------------------------------------------------------
  2077. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  2078. const std::string &p,
  2079. const std::string& config) const
  2080. {
  2081. return checkInterfacePropertyCompatibility<const char *>(this,
  2082. p,
  2083. config,
  2084. "empty",
  2085. NumberMaxType, 0);
  2086. }
  2087. //----------------------------------------------------------------------------
  2088. cmComputeLinkInformation*
  2089. cmGeneratorTarget::GetLinkInformation(const std::string& config) const
  2090. {
  2091. // Lookup any existing information for this configuration.
  2092. std::string key(cmSystemTools::UpperCase(config));
  2093. cmTargetLinkInformationMap::iterator
  2094. i = this->LinkInformation.find(key);
  2095. if(i == this->LinkInformation.end())
  2096. {
  2097. // Compute information for this configuration.
  2098. cmComputeLinkInformation* info =
  2099. new cmComputeLinkInformation(this->Target, config);
  2100. if(!info || !info->Compute())
  2101. {
  2102. delete info;
  2103. info = 0;
  2104. }
  2105. // Store the information for this configuration.
  2106. cmTargetLinkInformationMap::value_type entry(key, info);
  2107. i = this->LinkInformation.insert(entry).first;
  2108. if (info)
  2109. {
  2110. this->CheckPropertyCompatibility(info, config);
  2111. }
  2112. }
  2113. return i->second;
  2114. }
  2115. //----------------------------------------------------------------------------
  2116. void
  2117. cmGeneratorTarget::ReportPropertyOrigin(const std::string &p,
  2118. const std::string &result,
  2119. const std::string &report,
  2120. const std::string &compatibilityType) const
  2121. {
  2122. std::vector<std::string> debugProperties;
  2123. const char *debugProp = this->Target->GetMakefile()
  2124. ->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2125. if (debugProp)
  2126. {
  2127. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2128. }
  2129. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
  2130. && std::find(debugProperties.begin(),
  2131. debugProperties.end(),
  2132. p)
  2133. != debugProperties.end();
  2134. if (this->Target->GetMakefile()->IsConfigured())
  2135. {
  2136. this->DebugCompatiblePropertiesDone[p] = true;
  2137. }
  2138. if (!debugOrigin)
  2139. {
  2140. return;
  2141. }
  2142. std::string areport = compatibilityType;
  2143. areport += std::string(" of property \"") + p + "\" for target \"";
  2144. areport += std::string(this->GetName());
  2145. areport += "\" (result: \"";
  2146. areport += result;
  2147. areport += "\"):\n" + report;
  2148. this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
  2149. }