cmTarget.cxx 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmTarget.h"
  14. #include "cmake.h"
  15. #include "cmMakefile.h"
  16. #include "cmSourceFile.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmGlobalGenerator.h"
  19. #include <map>
  20. #include <set>
  21. #include <queue>
  22. #include <stdlib.h> // required for atof
  23. const char* cmTarget::TargetTypeNames[] = {
  24. "EXECUTABLE", "STATIC_LIBRARY",
  25. "SHARED_LIBRARY", "MODULE_LIBRARY", "UTILITY", "GLOBAL_TARGET",
  26. "INSTALL_FILES", "INSTALL_PROGRAMS", "INSTALL_DIRECTORY"
  27. };
  28. //----------------------------------------------------------------------------
  29. cmTarget::cmTarget()
  30. {
  31. this->Makefile = 0;
  32. this->LinkLibrariesAnalyzed = false;
  33. this->LinkDirectoriesComputed = false;
  34. this->HaveInstallRule = false;
  35. }
  36. // define properties
  37. void cmTarget::DefineProperties(cmake *cm)
  38. {
  39. cm->DefineProperty
  40. ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET,
  41. "Should build tree targets have install tree rpaths.",
  42. "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link "
  43. "the target in the build tree with the INSTALL_RPATH. This takes "
  44. "precedence over SKIP_BUILD_RPATH and avoids the need for relinking "
  45. "before installation.");
  46. cm->DefineProperty
  47. ("CLEAN_DIRECT_OUTPUT", cmProperty::TARGET,
  48. "Do not delete other varients of this target.",
  49. "When a library is built CMake by default generates code to remove "
  50. "any existing library using all possible names. This is needed "
  51. "to support libraries that switch between STATIC and SHARED by "
  52. "a user option. However when using OUTPUT_NAME to build a static "
  53. "and shared library of the same name using different logical target "
  54. "names the two targets will remove each other's files. This can be "
  55. "prevented by setting the CLEAN_DIRECT_OUTPUT property to 1.");
  56. cm->DefineProperty
  57. ("COMPILE_FLAGS", cmProperty::TARGET,
  58. "Additional flags to yse when compiling this target's sources.",
  59. "The COMPILE_FLAGS property sets additional compiler flags used "
  60. "to build sources within the target. It may also be used to pass "
  61. "additional preprocessor definitions.");
  62. cm->DefineProperty
  63. ("DEFINE_SYMBOL", cmProperty::TARGET,
  64. "Define a symbol when compiling this target's sources.",
  65. "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
  66. "compiling sources in a shared library. "
  67. "If not set here then it is set to target_EXPORTS by default "
  68. "(with some substitutions if the target is not a valid C "
  69. "identifier). This is useful for headers to know whether they are "
  70. "being included from inside their library our outside to properly "
  71. "setup dllexport/dllimport decorations. ");
  72. cm->DefineProperty
  73. ("DEBUG_POSTFIX", cmProperty::TARGET,
  74. "A postfix that will be applied to this target when build debug.",
  75. "A property on a target that sepcifies a postfix to add to the "
  76. "target name when built in debug mode. For example foo.dll "
  77. "versus fooD.dll");
  78. cm->DefineProperty
  79. ("EchoString", cmProperty::TARGET,
  80. "A message to be displayed when the target it built.",
  81. "A message to display on some generaters (such as makefiles) when "
  82. "the target is built.");
  83. cm->DefineProperty
  84. ("HAS_CXX", cmProperty::TARGET,
  85. "Force a target to use the CXX linker.",
  86. "Setting HAS_CXX on a target will force the target to use the "
  87. "C++ linker (and C++ runtime libraries) for linking even if the "
  88. "target has no C++ code in it.");
  89. cm->DefineProperty
  90. ("IMPORT_PREFIX", cmProperty::TARGET,
  91. "What comes before the import library name.",
  92. "Similar to the target property PREFIX, but used for import libraries "
  93. "(typically corresponding to a DLL) instead of regular libraries. "
  94. "A target property that can be set to override the prefix "
  95. "(such as \"lib\") on an import library name.");
  96. cm->DefineProperty
  97. ("IMPORT_SUFFIX", cmProperty::TARGET,
  98. "What comes after the import library name.",
  99. "Similar to the target property SUFFIX, but used for import libraries "
  100. "(typically corresponding to a DLL) instead of regular libraries. "
  101. "A target property that can be set to override the suffix "
  102. "(such as \".lib\") on an import library name.");
  103. cm->DefineProperty
  104. ("IN_ALL", cmProperty::TARGET,
  105. "Is this target part of the all target.",
  106. "A property on a target that indicates if the target is included as "
  107. "part of the default build target. If it is, then with a Makefile "
  108. "for example typing make will couse this target to be built as well. "
  109. "The same concept applies to the default build of other generators.");
  110. cm->DefineProperty
  111. ("INSTALL_NAME_DIR", cmProperty::TARGET,
  112. "Mac OSX directory name for installed targets.",
  113. "INSTALL_NAME_DIR is a string specifying the "
  114. "directory portion of the \"install_name\" field of shared libraries "
  115. "on Mac OSX to use in the installed targets. ");
  116. cm->DefineProperty
  117. ("INSTALL_RPATH", cmProperty::TARGET,
  118. "The rpath to use for installed targets.",
  119. "A semicolon-separated list specifying the rpath "
  120. "to use in installed targets (for platforms that support it).");
  121. cm->DefineProperty
  122. ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET,
  123. "Add paths to linker search and installed rpath.",
  124. "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
  125. "append directories in the linker search path and outside the "
  126. "project to the INSTALL_RPATH. ");
  127. cm->DefineProperty
  128. ("LINK_FLAGS", cmProperty::TARGET,
  129. "Additional flags to use when linking this target.",
  130. "The LINK_FLAGS property can be used to add extra flags to the "
  131. "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
  132. "configuration <CONFIG>, "
  133. "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
  134. cm->DefineProperty
  135. ("LINKER_LANGUAGE", cmProperty::TARGET,
  136. "What tool to use for linking, based on language.",
  137. "The LINKER_LANGUAGE property is used to change the tool "
  138. "used to link an executable or shared library. The default is "
  139. "set the language to match the files in the library. CXX and C "
  140. "are common values for this property.");
  141. cm->DefineProperty
  142. ("LOCATION", cmProperty::TARGET,
  143. "Where a target will be written on disk.",
  144. "A read only property on a target that indicates where that target "
  145. "will be written. For libraries and execuatables this will be where "
  146. "the file is written on disk. This property is computed based on a "
  147. "number of other settings.");
  148. cm->DefineProperty
  149. ("OUTPUT_NAME", cmProperty::TARGET,
  150. "Sets the real name of a target when it is built.",
  151. "Sets the real name of a target when it is built and "
  152. "can be used to help create two targets of the same name even though "
  153. "CMake requires unique logical target names. There is also a "
  154. "<CONFIG>_OUTPUT_NAME that can set the output name on a "
  155. "per-configuration basis.");
  156. cm->DefineProperty
  157. ("PRE_INSTALL_SCRIPT", cmProperty::TARGET,
  158. "Deprecated install support.",
  159. "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
  160. "old way to specify CMake scripts to run before and after "
  161. "installing a target. They are used only when the old "
  162. "INSTALL_TARGETS command is used to install the target. Use the "
  163. "INSTALL command instead.");
  164. cm->DefineProperty
  165. ("PREFIX", cmProperty::TARGET,
  166. "What comes before the library name.",
  167. "A target property that can be set to override the prefix "
  168. "(such as \"lib\") on a library name.");
  169. cm->DefineProperty
  170. ("POST_INSTALL_SCRIPT", cmProperty::TARGET,
  171. "Deprecated install support.",
  172. "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
  173. "old way to specify CMake scripts to run before and after "
  174. "installing a target. They are used only when the old "
  175. "INSTALL_TARGETS command is used to install the target. Use the "
  176. "INSTALL command instead.");
  177. cm->DefineProperty
  178. ("SKIP_BUILD_RPATH", cmProperty::TARGET,
  179. "Should rpaths be used for the build tree.",
  180. "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
  181. "generation of an rpath allowing the target to run from the "
  182. "build tree. ");
  183. cm->DefineProperty
  184. ("SOVERSION", cmProperty::TARGET,
  185. "What version number is this target.",
  186. "For shared libraries VERSION and SOVERSION can be used to specify "
  187. "the build version and api version respectively. When building or "
  188. "installing appropriate symlinks are created if the platform "
  189. "supports symlinks and the linker supports so-names. "
  190. "If only one of both is specified the missing is assumed to have "
  191. "the same version number. "
  192. "For shared libraries and executables on Windows the VERSION "
  193. "attribute is parsed to extract a \"major.minor\" version number. "
  194. "These numbers are used as the image version of the binary. ");
  195. cm->DefineProperty
  196. ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET,
  197. "Extra flags to use when linking static libraries.",
  198. "Extra flags to use when linking a static library.");
  199. cm->DefineProperty
  200. ("SUFFIX", cmProperty::TARGET,
  201. "What comes after the library name.",
  202. "A target property that can be set to override the suffix "
  203. "(such as \".so\") on a library name.");
  204. cm->DefineProperty
  205. ("VERSION", cmProperty::TARGET,
  206. "What version number is this target.",
  207. "For shared libraries VERSION and SOVERSION can be used to specify "
  208. "the build version and api version respectively. When building or "
  209. "installing appropriate symlinks are created if the platform "
  210. "supports symlinks and the linker supports so-names. "
  211. "If only one of both is specified the missing is assumed to have "
  212. "the same version number. "
  213. "For executables VERSION can be used to specify the build version. "
  214. "When building or installing appropriate symlinks are created if "
  215. "the platform supports symlinks. "
  216. "For shared libraries and executables on Windows the VERSION "
  217. "attribute is parsed to extract a \"major.minor\" version number. "
  218. "These numbers are used as the image version of the binary. ");
  219. cm->DefineProperty
  220. ("WIN32_EXECUTABLE", cmProperty::TARGET,
  221. "Used to specify Windows executable with a WinMain entry point.",
  222. "This can be set to indicate that a target is a Windows executable "
  223. "in contrast to a console application for example. This changes "
  224. "how the executable will be linked.");
  225. // define some properties without documentation
  226. cm->DefineProperty("DEBUG_OUTPUT_NAME", cmProperty::TARGET,0,0);
  227. cm->DefineProperty("RELEASE_OUTPUT_NAME", cmProperty::TARGET,0,0);
  228. cm->DefineProperty("LINK_FLAGS_DEBUG", cmProperty::TARGET,0,0);
  229. }
  230. void cmTarget::SetType(TargetType type, const char* name)
  231. {
  232. this->Name = name;
  233. // only add dependency information for library targets
  234. this->TargetTypeValue = type;
  235. if(this->TargetTypeValue >= STATIC_LIBRARY
  236. && this->TargetTypeValue <= MODULE_LIBRARY)
  237. {
  238. this->RecordDependencies = true;
  239. }
  240. else
  241. {
  242. this->RecordDependencies = false;
  243. }
  244. }
  245. //----------------------------------------------------------------------------
  246. void cmTarget::SetMakefile(cmMakefile* mf)
  247. {
  248. // Set our makefile.
  249. this->Makefile = mf;
  250. // set the cmake instance of the properties
  251. this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
  252. // Setup default property values.
  253. this->SetPropertyDefault("INSTALL_NAME_DIR", "");
  254. this->SetPropertyDefault("INSTALL_RPATH", "");
  255. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  256. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  257. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  258. // Collect the set of configuration types.
  259. std::vector<std::string> configNames;
  260. if(const char* configurationTypes =
  261. mf->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  262. {
  263. cmSystemTools::ExpandListArgument(configurationTypes, configNames);
  264. }
  265. else if(const char* buildType = mf->GetDefinition("CMAKE_BUILD_TYPE"))
  266. {
  267. if(*buildType)
  268. {
  269. configNames.push_back(buildType);
  270. }
  271. }
  272. // Setup per-configuration property default values.
  273. for(std::vector<std::string>::iterator ci = configNames.begin();
  274. ci != configNames.end(); ++ci)
  275. {
  276. // Initialize per-configuration name postfix property from the
  277. // variable only for non-executable targets. This preserves
  278. // compatibility with previous CMake versions in which executables
  279. // did not support this variable. Projects may still specify the
  280. // property directly. TODO: Make this depend on backwards
  281. // compatibility setting.
  282. if(this->TargetTypeValue != cmTarget::EXECUTABLE)
  283. {
  284. std::string property = cmSystemTools::UpperCase(*ci);
  285. property += "_POSTFIX";
  286. this->SetPropertyDefault(property.c_str(), 0);
  287. }
  288. }
  289. }
  290. void cmTarget::TraceVSDependencies(std::string projFile,
  291. cmMakefile *makefile)
  292. {
  293. // get the classes from the source lists then add them to the groups
  294. std::vector<cmSourceFile*> & classes = this->GetSourceFiles();
  295. // use a deck to keep track of processed source files
  296. std::queue<std::string> srcFilesToProcess;
  297. std::set<cmStdString> srcFilesQueued;
  298. std::string name;
  299. std::vector<cmSourceFile*> newClasses;
  300. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  301. i != classes.end(); ++i)
  302. {
  303. name = (*i)->GetSourceName();
  304. if ((*i)->GetSourceExtension() != "rule")
  305. {
  306. name += ".";
  307. name += (*i)->GetSourceExtension();
  308. }
  309. srcFilesToProcess.push(name);
  310. srcFilesQueued.insert(name);
  311. // does this sourcefile have object depends on it?
  312. // If so then add them as well
  313. const char* additionalDeps = (*i)->GetProperty("OBJECT_DEPENDS");
  314. std::vector<std::string> depends = (*i)->GetDepends();
  315. if (additionalDeps || depends.size())
  316. {
  317. if(additionalDeps)
  318. {
  319. cmSystemTools::ExpandListArgument(additionalDeps, depends);
  320. }
  321. for(std::vector<std::string>::iterator id = depends.begin();
  322. id != depends.end(); ++id)
  323. {
  324. // if there is a custom rule to generate that dependency
  325. // then add it to the list
  326. cmSourceFile* outsf =
  327. makefile->GetSourceFileWithOutput(id->c_str());
  328. // if a source file was found then add it
  329. if (outsf &&
  330. (std::find(classes.begin(),classes.end(),outsf) == classes.end())
  331. &&
  332. (std::find(newClasses.begin(),newClasses.end(),outsf)
  333. == newClasses.end()))
  334. {
  335. // then add the source to this target and add it to the queue
  336. newClasses.push_back(outsf);
  337. name = outsf->GetSourceName();
  338. if (outsf->GetSourceExtension() != "rule")
  339. {
  340. name += ".";
  341. name += outsf->GetSourceExtension();
  342. }
  343. std::string temp =
  344. cmSystemTools::GetFilenamePath(outsf->GetFullPath());
  345. temp += "/";
  346. temp += name;
  347. // if it hasn't been processed
  348. if (srcFilesQueued.find(temp) == srcFilesQueued.end())
  349. {
  350. srcFilesToProcess.push(temp);
  351. srcFilesQueued.insert(temp);
  352. }
  353. }
  354. }
  355. }
  356. }
  357. for(std::vector<cmSourceFile*>::const_iterator i = newClasses.begin();
  358. i != newClasses.end(); ++i)
  359. {
  360. classes.push_back(*i);
  361. }
  362. // add in the project file itself
  363. if (projFile.size())
  364. {
  365. srcFilesToProcess.push(projFile);
  366. srcFilesQueued.insert(projFile);
  367. }
  368. // add in the library depends for custom targets
  369. if (this->GetType() == cmTarget::UTILITY ||
  370. this->GetType() == cmTarget::GLOBAL_TARGET)
  371. {
  372. for (std::vector<cmCustomCommand>::iterator ic =
  373. this->GetPostBuildCommands().begin();
  374. ic != this->GetPostBuildCommands().end(); ++ic)
  375. {
  376. cmCustomCommand &c = *ic;
  377. for (std::vector<std::string>::const_iterator i
  378. = c.GetDepends().begin(); i != c.GetDepends().end(); ++i)
  379. {
  380. srcFilesToProcess.push(*i);
  381. srcFilesQueued.insert(*i);
  382. }
  383. }
  384. }
  385. while (!srcFilesToProcess.empty())
  386. {
  387. // is this source the output of a custom command
  388. cmSourceFile* outsf =
  389. makefile->GetSourceFileWithOutput(srcFilesToProcess.front().c_str());
  390. if (outsf)
  391. {
  392. // is it not already in the target?
  393. if (std::find(classes.begin(),classes.end(),outsf) == classes.end())
  394. {
  395. // then add the source to this target and add it to the queue
  396. classes.push_back(outsf);
  397. name = outsf->GetSourceName();
  398. if (outsf->GetSourceExtension() != "rule")
  399. {
  400. name += ".";
  401. name += outsf->GetSourceExtension();
  402. }
  403. std::string temp =
  404. cmSystemTools::GetFilenamePath(outsf->GetFullPath());
  405. temp += "/";
  406. temp += name;
  407. // if it hasn't been processed
  408. if (srcFilesQueued.find(temp) == srcFilesQueued.end())
  409. {
  410. srcFilesToProcess.push(temp);
  411. srcFilesQueued.insert(temp);
  412. }
  413. }
  414. // add its dependencies to the list to check
  415. unsigned int i;
  416. for (i = 0; i < outsf->GetCustomCommand()->GetDepends().size(); ++i)
  417. {
  418. const std::string& fullName
  419. = outsf->GetCustomCommand()->GetDepends()[i];
  420. std::string dep = cmSystemTools::GetFilenameName(fullName);
  421. if (cmSystemTools::GetFilenameLastExtension(dep) == ".exe")
  422. {
  423. dep = cmSystemTools::GetFilenameWithoutLastExtension(dep);
  424. }
  425. bool isUtility = false;
  426. // see if we can find a target with this name
  427. cmTarget* t = this->Makefile->GetLocalGenerator()->
  428. GetGlobalGenerator()->FindTarget(0, dep.c_str());
  429. if(t)
  430. {
  431. // if we find the target and the dep was given as a full
  432. // path, then make sure it was not a full path to something
  433. // else, and the fact that the name matched a target was
  434. // just a coincident
  435. if(cmSystemTools::FileIsFullPath(fullName.c_str()))
  436. {
  437. std::string tLocation = t->GetLocation(0);
  438. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  439. std::string depLocation = cmSystemTools::GetFilenamePath(
  440. std::string(fullName));
  441. depLocation =
  442. cmSystemTools::CollapseFullPath(depLocation.c_str());
  443. tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
  444. if(depLocation == tLocation)
  445. {
  446. isUtility = true;
  447. }
  448. }
  449. // if it was not a full path then it must be a target
  450. else
  451. {
  452. isUtility = true;
  453. }
  454. }
  455. if(isUtility)
  456. {
  457. // add the depend as a utility on the target
  458. this->AddUtility(dep.c_str());
  459. }
  460. else
  461. {
  462. if (srcFilesQueued.find(outsf->GetCustomCommand()->GetDepends()[i])
  463. == srcFilesQueued.end())
  464. {
  465. srcFilesToProcess.push
  466. (outsf->GetCustomCommand()->GetDepends()[i]);
  467. srcFilesQueued.insert(outsf->GetCustomCommand()->GetDepends()[i]);
  468. }
  469. }
  470. }
  471. }
  472. // finished with this SF move to the next
  473. srcFilesToProcess.pop();
  474. }
  475. // mark all custom commands in the targets list of source files as used.
  476. for(std::vector<cmSourceFile*>::iterator i = this->SourceFiles.begin();
  477. i != this->SourceFiles.end(); ++i)
  478. {
  479. cmCustomCommand* cc = (*i)->GetCustomCommand();
  480. if(cc)
  481. {
  482. cc->SetUsed();
  483. }
  484. }
  485. }
  486. void cmTarget::GenerateSourceFilesFromSourceLists( cmMakefile &mf)
  487. {
  488. // this is only done for non install targets
  489. if ((this->TargetTypeValue == cmTarget::INSTALL_FILES)
  490. || (this->TargetTypeValue == cmTarget::INSTALL_PROGRAMS))
  491. {
  492. return;
  493. }
  494. // for each src lists add the classes
  495. for (std::vector<std::string>::const_iterator s = this->SourceLists.begin();
  496. s != this->SourceLists.end(); ++s)
  497. {
  498. int done = 0;
  499. // replace any variables
  500. std::string temps = *s;
  501. mf.ExpandVariablesInString(temps);
  502. // Next if one wasn't found then assume it is a single class
  503. // check to see if it is an existing source file
  504. if (!done)
  505. {
  506. cmSourceFile* sourceFile = mf.GetSource(temps.c_str());
  507. if ( sourceFile )
  508. {
  509. this->SourceFiles.push_back(sourceFile);
  510. done = 1;
  511. }
  512. }
  513. // if we still are not done, try to create the SourceFile structure
  514. if (!done)
  515. {
  516. cmSourceFile file;
  517. file.GetProperties().
  518. SetCMakeInstance(this->Makefile->GetCMakeInstance());
  519. file.SetProperty("ABSTRACT","0");
  520. file.SetName(temps.c_str(), mf.GetCurrentDirectory(),
  521. mf.GetSourceExtensions(),
  522. mf.GetHeaderExtensions(), this->Name.c_str());
  523. this->SourceFiles.push_back(mf.AddSource(file));
  524. }
  525. }
  526. // expand any link library variables whle we are at it
  527. LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
  528. for (;p != this->LinkLibraries.end(); ++p)
  529. {
  530. mf.ExpandVariablesInString(p->first, true, true);
  531. }
  532. }
  533. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  534. const char *selfname,
  535. const LinkLibraryVectorType& libs )
  536. {
  537. // Only add on libraries we haven't added on before.
  538. // Assumption: the global link libraries could only grow, never shrink
  539. LinkLibraryVectorType::const_iterator i = libs.begin();
  540. i += this->PrevLinkedLibraries.size();
  541. for( ; i != libs.end(); ++i )
  542. {
  543. // We call this so that the dependencies get written to the cache
  544. this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
  545. }
  546. this->PrevLinkedLibraries = libs;
  547. }
  548. //----------------------------------------------------------------------------
  549. void cmTarget::AddLinkDirectory(const char* d)
  550. {
  551. // Make sure we don't add unnecessary search directories.
  552. if(std::find(this->ExplicitLinkDirectories.begin(),
  553. this->ExplicitLinkDirectories.end(), d)
  554. == this->ExplicitLinkDirectories.end() )
  555. {
  556. this->ExplicitLinkDirectories.push_back( d );
  557. this->LinkDirectoriesComputed = false;
  558. }
  559. }
  560. //----------------------------------------------------------------------------
  561. const std::vector<std::string>& cmTarget::GetLinkDirectories()
  562. {
  563. // Make sure all library dependencies have been analyzed.
  564. if(!this->LinkLibrariesAnalyzed && !this->LinkLibraries.empty())
  565. {
  566. cmSystemTools::Error(
  567. "cmTarget::GetLinkDirectories called before "
  568. "cmTarget::AnalyzeLibDependencies on target ",
  569. this->Name.c_str());
  570. }
  571. // Make sure the complete set of link directories has been computed.
  572. if(!this->LinkDirectoriesComputed)
  573. {
  574. // Compute the full set of link directories including the
  575. // locations of targets that have been linked in. Start with the
  576. // link directories given explicitly.
  577. this->LinkDirectories = this->ExplicitLinkDirectories;
  578. for(LinkLibraryVectorType::iterator ll = this->LinkLibraries.begin();
  579. ll != this->LinkLibraries.end(); ++ll)
  580. {
  581. // If this library is a CMake target then add its location as a
  582. // link directory.
  583. std::string lib = ll->first;
  584. cmTarget* tgt = 0;
  585. if(this->Makefile && this->Makefile->GetLocalGenerator() &&
  586. this->Makefile->GetLocalGenerator()->GetGlobalGenerator())
  587. {
  588. tgt = (this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  589. ->FindTarget(0, lib.c_str()));
  590. }
  591. if(tgt)
  592. {
  593. // Add the directory only if it is not already present. This
  594. // is an N^2 algorithm for adding the directories, but N
  595. // should not get very big.
  596. const char* libpath = tgt->GetDirectory();
  597. if(std::find(this->LinkDirectories.begin(),
  598. this->LinkDirectories.end(),
  599. libpath) == this->LinkDirectories.end())
  600. {
  601. this->LinkDirectories.push_back(libpath);
  602. }
  603. }
  604. }
  605. // The complete set of link directories has now been computed.
  606. this->LinkDirectoriesComputed = true;
  607. }
  608. // Return the complete set of link directories.
  609. return this->LinkDirectories;
  610. }
  611. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  612. const char* target )
  613. {
  614. // Clear the dependencies. The cache variable must exist iff we are
  615. // recording dependency information for this target.
  616. std::string depname = target;
  617. depname += "_LIB_DEPENDS";
  618. if (this->RecordDependencies)
  619. {
  620. mf.AddCacheDefinition(depname.c_str(), "",
  621. "Dependencies for target", cmCacheManager::STATIC);
  622. }
  623. else
  624. {
  625. if (mf.GetDefinition( depname.c_str() ))
  626. {
  627. std::string message = "Target ";
  628. message += target;
  629. message += " has dependency information when it shouldn't.\n";
  630. message += "Your cache is probably stale. Please remove the entry\n ";
  631. message += depname;
  632. message += "\nfrom the cache.";
  633. cmSystemTools::Error( message.c_str() );
  634. }
  635. }
  636. }
  637. void cmTarget::AddLinkLibrary(const std::string& lib,
  638. LinkLibraryType llt)
  639. {
  640. this->AddFramework(lib.c_str(), llt);
  641. cmTarget::LibraryID tmp;
  642. tmp.first = lib;
  643. tmp.second = llt;
  644. this->LinkLibraries.push_back(tmp);
  645. }
  646. bool cmTarget::AddFramework(const std::string& libname, LinkLibraryType llt)
  647. {
  648. (void)llt; // TODO: What is this?
  649. if(cmSystemTools::IsPathToFramework(libname.c_str()))
  650. {
  651. std::string frameworkDir = libname;
  652. frameworkDir += "/../";
  653. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  654. std::vector<std::string>::iterator i =
  655. std::find(this->Frameworks.begin(),
  656. this->Frameworks.end(), frameworkDir);
  657. if(i == this->Frameworks.end())
  658. {
  659. this->Frameworks.push_back(frameworkDir);
  660. }
  661. return true;
  662. }
  663. return false;
  664. }
  665. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  666. const char *target, const char* lib,
  667. LinkLibraryType llt)
  668. {
  669. // Never add a self dependency, even if the user asks for it.
  670. if(strcmp( target, lib ) == 0)
  671. {
  672. return;
  673. }
  674. this->AddFramework(lib, llt);
  675. cmTarget::LibraryID tmp;
  676. tmp.first = lib;
  677. tmp.second = llt;
  678. this->LinkLibraries.push_back( tmp );
  679. // Add the explicit dependency information for this target. This is
  680. // simply a set of libraries separated by ";". There should always
  681. // be a trailing ";". These library names are not canonical, in that
  682. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  683. // We shouldn't remove duplicates here because external libraries
  684. // may be purposefully duplicated to handle recursive dependencies,
  685. // and we removing one instance will break the link line. Duplicates
  686. // will be appropriately eliminated at emit time.
  687. if(this->RecordDependencies)
  688. {
  689. std::string targetEntry = target;
  690. targetEntry += "_LIB_DEPENDS";
  691. std::string dependencies;
  692. const char* old_val = mf.GetDefinition( targetEntry.c_str() );
  693. if( old_val )
  694. {
  695. dependencies += old_val;
  696. }
  697. switch (llt)
  698. {
  699. case cmTarget::GENERAL:
  700. dependencies += "general";
  701. break;
  702. case cmTarget::DEBUG:
  703. dependencies += "debug";
  704. break;
  705. case cmTarget::OPTIMIZED:
  706. dependencies += "optimized";
  707. break;
  708. }
  709. dependencies += ";";
  710. dependencies += lib;
  711. dependencies += ";";
  712. mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
  713. "Dependencies for the target",
  714. cmCacheManager::STATIC );
  715. }
  716. }
  717. void
  718. cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
  719. {
  720. // There are two key parts of the dependency analysis: (1)
  721. // determining the libraries in the link line, and (2) constructing
  722. // the dependency graph for those libraries.
  723. //
  724. // The latter is done using the cache entries that record the
  725. // dependencies of each library.
  726. //
  727. // The former is a more thorny issue, since it is not clear how to
  728. // determine if two libraries listed on the link line refer to the a
  729. // single library or not. For example, consider the link "libraries"
  730. // /usr/lib/libtiff.so -ltiff
  731. // Is this one library or two? The solution implemented here is the
  732. // simplest (and probably the only practical) one: two libraries are
  733. // the same if their "link strings" are identical. Thus, the two
  734. // libraries above are considered distinct. This also means that for
  735. // dependency analysis to be effective, the CMake user must specify
  736. // libraries build by his project without using any linker flags or
  737. // file extensions. That is,
  738. // LINK_LIBRARIES( One Two )
  739. // instead of
  740. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  741. // The former is probably what most users would do, but it never
  742. // hurts to document the assumptions. :-) Therefore, in the analysis
  743. // code, the "canonical name" of a library is simply its name as
  744. // given to a LINK_LIBRARIES command.
  745. //
  746. // Also, we will leave the original link line intact; we will just add any
  747. // dependencies that were missing.
  748. //
  749. // There is a problem with recursive external libraries
  750. // (i.e. libraries with no dependency information that are
  751. // recursively dependent). We must make sure that the we emit one of
  752. // the libraries twice to satisfy the recursion, but we shouldn't
  753. // emit it more times than necessary. In particular, we must make
  754. // sure that handling this improbable case doesn't cost us when
  755. // dealing with the common case of non-recursive libraries. The
  756. // solution is to assume that the recursion is satisfied at one node
  757. // of the dependency tree. To illustrate, assume libA and libB are
  758. // extrenal and mutually dependent. Suppose libX depends on
  759. // libA, and libY on libA and libX. Then
  760. // TARGET_LINK_LIBRARIES( Y X A B A )
  761. // TARGET_LINK_LIBRARIES( X A B A )
  762. // TARGET_LINK_LIBRARIES( Exec Y )
  763. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  764. // specify the dependencies, since the mutual dependency of A and B
  765. // is resolved *every time libA is specified*.
  766. //
  767. // Something like
  768. // TARGET_LINK_LIBRARIES( Y X A B A )
  769. // TARGET_LINK_LIBRARIES( X A B )
  770. // TARGET_LINK_LIBRARIES( Exec Y )
  771. // would result in "-lY -lX -lA -lB", and the mutual dependency
  772. // information is lost. This is because in some case (Y), the mutual
  773. // dependency of A and B is listed, while in another other case (X),
  774. // it is not. Depending on which line actually emits A, the mutual
  775. // dependency may or may not be on the final link line. We can't
  776. // handle this pathalogical case cleanly without emitting extra
  777. // libraries for the normal cases. Besides, the dependency
  778. // information for X is wrong anyway: if we build an executable
  779. // depending on X alone, we would not have the mutual dependency on
  780. // A and B resolved.
  781. //
  782. // IMPROVEMENTS:
  783. // -- The current algorithm will not always pick the "optimal" link line
  784. // when recursive dependencies are present. It will instead break the
  785. // cycles at an aribtrary point. The majority of projects won't have
  786. // cyclic dependencies, so this is probably not a big deal. Note that
  787. // the link line is always correct, just not necessary optimal.
  788. typedef std::vector< std::string > LinkLine;
  789. // The dependency map.
  790. DependencyMap dep_map;
  791. if ( this->OriginalLinkLibraries.size() == 0 )
  792. {
  793. this->OriginalLinkLibraries = this->LinkLibraries;
  794. }
  795. // 1. Build the dependency graph
  796. //
  797. for(LinkLibraryVectorType::reverse_iterator lib
  798. = this->LinkLibraries.rbegin();
  799. lib != this->LinkLibraries.rend(); ++lib)
  800. {
  801. this->GatherDependencies( mf, *lib, dep_map);
  802. }
  803. // 2. Remove any dependencies that are already satisfied in the original
  804. // link line.
  805. //
  806. for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
  807. lib != this->LinkLibraries.end(); ++lib)
  808. {
  809. for( LinkLibraryVectorType::iterator lib2 = lib;
  810. lib2 != this->LinkLibraries.end(); ++lib2)
  811. {
  812. this->DeleteDependency( dep_map, *lib, *lib2);
  813. }
  814. }
  815. // 3. Create the new link line by simply emitting any dependencies that are
  816. // missing. Start from the back and keep adding.
  817. //
  818. std::set<DependencyMap::key_type> done, visited;
  819. std::vector<DependencyMap::key_type> newLinkLibraries;
  820. for(LinkLibraryVectorType::reverse_iterator lib =
  821. this->LinkLibraries.rbegin();
  822. lib != this->LinkLibraries.rend(); ++lib)
  823. {
  824. // skip zero size library entries, this may happen
  825. // if a variable expands to nothing.
  826. if (lib->first.size() != 0)
  827. {
  828. this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
  829. }
  830. }
  831. // 4. Add the new libraries to the link line.
  832. //
  833. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  834. newLinkLibraries.rbegin();
  835. k != newLinkLibraries.rend(); ++k )
  836. {
  837. // get the llt from the dep_map
  838. this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
  839. }
  840. this->LinkLibrariesAnalyzed = true;
  841. }
  842. void cmTarget::InsertDependency( DependencyMap& depMap,
  843. const LibraryID& lib,
  844. const LibraryID& dep)
  845. {
  846. depMap[lib].push_back(dep);
  847. }
  848. void cmTarget::DeleteDependency( DependencyMap& depMap,
  849. const LibraryID& lib,
  850. const LibraryID& dep)
  851. {
  852. // Make sure there is an entry in the map for lib. If so, delete all
  853. // dependencies to dep. There may be repeated entries because of
  854. // external libraries that are specified multiple times.
  855. DependencyMap::iterator map_itr = depMap.find( lib );
  856. if( map_itr != depMap.end() )
  857. {
  858. DependencyList& depList = map_itr->second;
  859. DependencyList::iterator itr;
  860. while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
  861. depList.end() )
  862. {
  863. depList.erase( itr );
  864. }
  865. }
  866. }
  867. void cmTarget::Emit(const LibraryID lib,
  868. const DependencyMap& dep_map,
  869. std::set<LibraryID>& emitted,
  870. std::set<LibraryID>& visited,
  871. DependencyList& link_line )
  872. {
  873. // It's already been emitted
  874. if( emitted.find(lib) != emitted.end() )
  875. {
  876. return;
  877. }
  878. // Emit the dependencies only if this library node hasn't been
  879. // visited before. If it has, then we have a cycle. The recursion
  880. // that got us here should take care of everything.
  881. if( visited.insert(lib).second )
  882. {
  883. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  884. {
  885. const DependencyList& dep_on = dep_map.find( lib )->second;
  886. DependencyList::const_reverse_iterator i;
  887. // To cater for recursive external libraries, we must emit
  888. // duplicates on this link line *unless* they were emitted by
  889. // some other node, in which case we assume that the recursion
  890. // was resolved then. We making the simplifying assumption that
  891. // any duplicates on a single link line are on purpose, and must
  892. // be preserved.
  893. // This variable will keep track of the libraries that were
  894. // emitted directory from the current node, and not from a
  895. // recursive call. This way, if we come across a library that
  896. // has already been emitted, we repeat it iff it has been
  897. // emitted here.
  898. std::set<DependencyMap::key_type> emitted_here;
  899. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  900. {
  901. if( emitted_here.find(*i) != emitted_here.end() )
  902. {
  903. // a repeat. Must emit.
  904. emitted.insert(*i);
  905. link_line.push_back( *i );
  906. }
  907. else
  908. {
  909. // Emit only if no-one else has
  910. if( emitted.find(*i) == emitted.end() )
  911. {
  912. // emit dependencies
  913. Emit( *i, dep_map, emitted, visited, link_line );
  914. // emit self
  915. emitted.insert(*i);
  916. emitted_here.insert(*i);
  917. link_line.push_back( *i );
  918. }
  919. }
  920. }
  921. }
  922. }
  923. }
  924. void cmTarget::GatherDependencies( const cmMakefile& mf,
  925. const LibraryID& lib,
  926. DependencyMap& dep_map)
  927. {
  928. // If the library is already in the dependency map, then it has
  929. // already been fully processed.
  930. if( dep_map.find(lib) != dep_map.end() )
  931. {
  932. return;
  933. }
  934. const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
  935. if( deps && strcmp(deps,"") != 0 )
  936. {
  937. // Make sure this library is in the map, even if it has an empty
  938. // set of dependencies. This distinguishes the case of explicitly
  939. // no dependencies with that of unspecified dependencies.
  940. dep_map[lib];
  941. // Parse the dependency information, which is a set of
  942. // type, library pairs separated by ";". There is always a trailing ";".
  943. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  944. std::string depline = deps;
  945. std::string::size_type start = 0;
  946. std::string::size_type end;
  947. end = depline.find( ";", start );
  948. while( end != std::string::npos )
  949. {
  950. std::string l = depline.substr( start, end-start );
  951. if( l.size() != 0 )
  952. {
  953. if (l == "debug")
  954. {
  955. llt = cmTarget::DEBUG;
  956. }
  957. else if (l == "optimized")
  958. {
  959. llt = cmTarget::OPTIMIZED;
  960. }
  961. else if (l == "general")
  962. {
  963. llt = cmTarget::GENERAL;
  964. }
  965. else
  966. {
  967. LibraryID lib2(l,llt);
  968. this->InsertDependency( dep_map, lib, lib2);
  969. this->GatherDependencies( mf, lib2, dep_map);
  970. llt = cmTarget::GENERAL;
  971. }
  972. }
  973. start = end+1; // skip the ;
  974. end = depline.find( ";", start );
  975. }
  976. // cannot depend on itself
  977. this->DeleteDependency( dep_map, lib, lib);
  978. }
  979. }
  980. void cmTarget::SetProperty(const char* prop, const char* value)
  981. {
  982. if (!prop)
  983. {
  984. return;
  985. }
  986. if (!value)
  987. {
  988. value = "NOTFOUND";
  989. }
  990. this->Properties.SetProperty(prop, value, cmProperty::TARGET);
  991. }
  992. const char* cmTarget::GetDirectory(const char* config)
  993. {
  994. switch( this->GetType() )
  995. {
  996. case cmTarget::STATIC_LIBRARY:
  997. case cmTarget::MODULE_LIBRARY:
  998. case cmTarget::SHARED_LIBRARY:
  999. this->Directory =
  1000. this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  1001. break;
  1002. case cmTarget::EXECUTABLE:
  1003. this->Directory =
  1004. this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  1005. break;
  1006. default:
  1007. this->Directory = this->Makefile->GetStartOutputDirectory();
  1008. break;
  1009. }
  1010. if(this->Directory.empty())
  1011. {
  1012. this->Directory = this->Makefile->GetStartOutputDirectory();
  1013. }
  1014. // if LIBRARY_OUTPUT_PATH or EXECUTABLE_OUTPUT_PATH was relative
  1015. // then make them full paths because this directory MUST
  1016. // be a full path or things will not work!!!
  1017. if(!cmSystemTools::FileIsFullPath(this->Directory.c_str()))
  1018. {
  1019. this->Directory = this->Makefile->GetCurrentOutputDirectory() +
  1020. std::string("/") + this->Directory;
  1021. }
  1022. if(config)
  1023. {
  1024. // Add the configuration's subdirectory.
  1025. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  1026. AppendDirectoryForConfig("/", config, "", this->Directory);
  1027. }
  1028. return this->Directory.c_str();
  1029. }
  1030. const char* cmTarget::GetLocation(const char* config)
  1031. {
  1032. this->Location = this->GetDirectory();
  1033. if(!this->Location.empty())
  1034. {
  1035. this->Location += "/";
  1036. }
  1037. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  1038. if(cfgid && strcmp(cfgid, ".") != 0)
  1039. {
  1040. this->Location += cfgid;
  1041. this->Location += "/";
  1042. }
  1043. this->Location += this->GetFullName(config, false);
  1044. return this->Location.c_str();
  1045. }
  1046. //----------------------------------------------------------------------------
  1047. void cmTarget::GetTargetVersion(int& major, int& minor)
  1048. {
  1049. // Set the default values.
  1050. major = 0;
  1051. minor = 0;
  1052. // Look for a VERSION property.
  1053. if(const char* version = this->GetProperty("VERSION"))
  1054. {
  1055. // Try to parse the version number and store the results that were
  1056. // successfully parsed.
  1057. int parsed_major;
  1058. int parsed_minor;
  1059. switch(sscanf(version, "%d.%d", &parsed_major, &parsed_minor))
  1060. {
  1061. case 2: minor = parsed_minor; // no break!
  1062. case 1: major = parsed_major; // no break!
  1063. default: break;
  1064. }
  1065. }
  1066. }
  1067. const char *cmTarget::GetProperty(const char* prop)
  1068. {
  1069. return this->GetProperty(prop, cmProperty::TARGET);
  1070. }
  1071. const char *cmTarget::GetProperty(const char* prop,
  1072. cmProperty::ScopeType scope)
  1073. {
  1074. // watch for special "computed" properties that are dependent on other
  1075. // properties or variables, always recompute them
  1076. if (!strcmp(prop,"LOCATION"))
  1077. {
  1078. // Set the LOCATION property of the target. Note that this cannot take
  1079. // into account the per-configuration name of the target because the
  1080. // configuration type may not be known at CMake time. We should
  1081. // deprecate this feature and instead support transforming an executable
  1082. // target name given as the command part of custom commands into the
  1083. // proper path at build time. Alternatively we could put environment
  1084. // variable settings in all custom commands that hold the name of the
  1085. // target for each configuration and then give a reference to the
  1086. // variable in the location.
  1087. this->SetProperty("LOCATION", this->GetLocation(0));
  1088. }
  1089. // Per-configuration location can be computed.
  1090. int len = static_cast<int>(strlen(prop));
  1091. if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
  1092. {
  1093. std::string configName(prop, len-9);
  1094. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  1095. }
  1096. // the type property returns what type the target is
  1097. if (!strcmp(prop,"TYPE"))
  1098. {
  1099. switch( this->GetType() )
  1100. {
  1101. case cmTarget::STATIC_LIBRARY:
  1102. return "STATIC_LIBRARY";
  1103. // break; /* unreachable */
  1104. case cmTarget::MODULE_LIBRARY:
  1105. return "MODULE_LIBRARY";
  1106. // break; /* unreachable */
  1107. case cmTarget::SHARED_LIBRARY:
  1108. return "SHARED_LIBRARY";
  1109. // break; /* unreachable */
  1110. case cmTarget::EXECUTABLE:
  1111. return "EXECUTABLE";
  1112. // break; /* unreachable */
  1113. case cmTarget::UTILITY:
  1114. return "UTILITY";
  1115. // break; /* unreachable */
  1116. case cmTarget::GLOBAL_TARGET:
  1117. return "GLOBAL_TARGET";
  1118. // break; /* unreachable */
  1119. case cmTarget::INSTALL_FILES:
  1120. return "INSTALL_FILES";
  1121. // break; /* unreachable */
  1122. case cmTarget::INSTALL_PROGRAMS:
  1123. return "INSTALL_PROGRAMS";
  1124. // break; /* unreachable */
  1125. case cmTarget::INSTALL_DIRECTORY:
  1126. return "INSTALL_DIRECTORY";
  1127. // break; /* unreachable */
  1128. }
  1129. return 0;
  1130. }
  1131. bool chain = false;
  1132. const char *retVal =
  1133. this->Properties.GetPropertyValue(prop, scope, chain);
  1134. if (chain)
  1135. {
  1136. return this->Makefile->GetProperty(prop,scope);
  1137. }
  1138. return retVal;
  1139. }
  1140. bool cmTarget::GetPropertyAsBool(const char* prop)
  1141. {
  1142. return cmSystemTools::IsOn(this->GetProperty(prop));
  1143. }
  1144. const char* cmTarget::GetLinkerLanguage(cmGlobalGenerator* gg)
  1145. {
  1146. if(this->GetProperty("HAS_CXX"))
  1147. {
  1148. const_cast<cmTarget*>(this)->SetProperty("LINKER_LANGUAGE", "CXX");
  1149. }
  1150. const char* linkerLang = this->GetProperty("LINKER_LANGUAGE");
  1151. if(linkerLang)
  1152. {
  1153. return linkerLang;
  1154. }
  1155. std::set<cmStdString> languages;
  1156. for(std::vector<cmSourceFile*>::const_iterator i
  1157. = this->SourceFiles.begin();
  1158. i != this->SourceFiles.end(); ++i)
  1159. {
  1160. const char* lang =
  1161. gg->GetLanguageFromExtension((*i)->GetSourceExtension().c_str());
  1162. if(lang)
  1163. {
  1164. languages.insert(lang);
  1165. }
  1166. }
  1167. if(languages.size() == 0)
  1168. {
  1169. return 0;
  1170. }
  1171. if(languages.size() == 1)
  1172. {
  1173. const_cast<cmTarget*>(this)->SetProperty("LINKER_LANGUAGE",
  1174. languages.begin()->c_str());
  1175. return this->GetProperty("LINKER_LANGUAGE");
  1176. }
  1177. const char* prefLang = 0;
  1178. for(std::set<cmStdString>::const_iterator s = languages.begin();
  1179. s != languages.end(); ++s)
  1180. {
  1181. const char* lpref = gg->GetLinkerPreference(s->c_str());
  1182. if(lpref[0] == 'P')
  1183. {
  1184. if(prefLang && !(*s == prefLang))
  1185. {
  1186. std::string m = "Error Target: ";
  1187. m += this->Name + " Contains more than one Prefered language: ";
  1188. m += *s;
  1189. m += " and ";
  1190. m += prefLang;
  1191. m += "\nYou must set the LINKER_LANGUAGE property for this target.";
  1192. cmSystemTools::Error(m.c_str());
  1193. }
  1194. else
  1195. {
  1196. prefLang = s->c_str();
  1197. }
  1198. }
  1199. }
  1200. if(!prefLang)
  1201. {
  1202. prefLang = languages.begin()->c_str();
  1203. }
  1204. const_cast<cmTarget*>(this)->SetProperty("LINKER_LANGUAGE", prefLang);
  1205. return this->GetProperty("LINKER_LANGUAGE");
  1206. }
  1207. const char* cmTarget::GetCreateRuleVariable()
  1208. {
  1209. switch(this->GetType())
  1210. {
  1211. case cmTarget::STATIC_LIBRARY:
  1212. return "_CREATE_STATIC_LIBRARY";
  1213. case cmTarget::SHARED_LIBRARY:
  1214. return "_CREATE_SHARED_LIBRARY";
  1215. case cmTarget::MODULE_LIBRARY:
  1216. return "_CREATE_SHARED_MODULE";
  1217. case cmTarget::EXECUTABLE:
  1218. return "_LINK_EXECUTABLE";
  1219. case cmTarget::UTILITY:
  1220. case cmTarget::GLOBAL_TARGET:
  1221. case cmTarget::INSTALL_FILES:
  1222. case cmTarget::INSTALL_PROGRAMS:
  1223. case cmTarget::INSTALL_DIRECTORY:
  1224. break;
  1225. }
  1226. return "";
  1227. }
  1228. const char* cmTarget::GetSuffixVariableInternal(TargetType type,
  1229. bool implib)
  1230. {
  1231. switch(type)
  1232. {
  1233. case cmTarget::STATIC_LIBRARY:
  1234. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  1235. case cmTarget::SHARED_LIBRARY:
  1236. return (implib
  1237. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  1238. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  1239. case cmTarget::MODULE_LIBRARY:
  1240. return "CMAKE_SHARED_MODULE_SUFFIX";
  1241. case cmTarget::EXECUTABLE:
  1242. return "CMAKE_EXECUTABLE_SUFFIX";
  1243. case cmTarget::UTILITY:
  1244. case cmTarget::GLOBAL_TARGET:
  1245. case cmTarget::INSTALL_FILES:
  1246. case cmTarget::INSTALL_PROGRAMS:
  1247. case cmTarget::INSTALL_DIRECTORY:
  1248. break;
  1249. }
  1250. return "";
  1251. }
  1252. const char* cmTarget::GetPrefixVariableInternal(TargetType type,
  1253. bool implib)
  1254. {
  1255. switch(type)
  1256. {
  1257. case cmTarget::STATIC_LIBRARY:
  1258. return "CMAKE_STATIC_LIBRARY_PREFIX";
  1259. case cmTarget::SHARED_LIBRARY:
  1260. return (implib
  1261. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  1262. : "CMAKE_SHARED_LIBRARY_PREFIX");
  1263. case cmTarget::MODULE_LIBRARY:
  1264. return "CMAKE_SHARED_MODULE_PREFIX";
  1265. case cmTarget::EXECUTABLE:
  1266. case cmTarget::UTILITY:
  1267. case cmTarget::GLOBAL_TARGET:
  1268. case cmTarget::INSTALL_FILES:
  1269. case cmTarget::INSTALL_PROGRAMS:
  1270. case cmTarget::INSTALL_DIRECTORY:
  1271. break;
  1272. }
  1273. return "";
  1274. }
  1275. //----------------------------------------------------------------------------
  1276. std::string cmTarget::GetPDBName(const char* config)
  1277. {
  1278. std::string prefix;
  1279. std::string base;
  1280. std::string suffix;
  1281. this->GetFullNameInternal(this->GetType(), config, false,
  1282. prefix, base, suffix);
  1283. return prefix+base+".pdb";
  1284. }
  1285. //----------------------------------------------------------------------------
  1286. std::string cmTarget::GetFullName(const char* config, bool implib)
  1287. {
  1288. return this->GetFullNameInternal(this->GetType(), config, implib);
  1289. }
  1290. //----------------------------------------------------------------------------
  1291. void cmTarget::GetFullName(std::string& prefix, std::string& base,
  1292. std::string& suffix, const char* config,
  1293. bool implib)
  1294. {
  1295. this->GetFullNameInternal(this->GetType(), config, implib,
  1296. prefix, base, suffix);
  1297. }
  1298. //----------------------------------------------------------------------------
  1299. std::string cmTarget::GetFullPath(const char* config, bool implib)
  1300. {
  1301. // Start with the output directory for the target.
  1302. std::string fpath = this->GetDirectory(config);
  1303. fpath += "/";
  1304. // Add the full name of the target.
  1305. fpath += this->GetFullName(config, implib);
  1306. return fpath;
  1307. }
  1308. //----------------------------------------------------------------------------
  1309. std::string cmTarget::GetFullNameInternal(TargetType type, const char* config,
  1310. bool implib)
  1311. {
  1312. std::string prefix;
  1313. std::string base;
  1314. std::string suffix;
  1315. this->GetFullNameInternal(type, config, implib, prefix, base, suffix);
  1316. return prefix+base+suffix;
  1317. }
  1318. //----------------------------------------------------------------------------
  1319. void cmTarget::GetFullNameInternal(TargetType type,
  1320. const char* config,
  1321. bool implib,
  1322. std::string& outPrefix,
  1323. std::string& outBase,
  1324. std::string& outSuffix)
  1325. {
  1326. // Use just the target name for non-main target types.
  1327. if(type != cmTarget::STATIC_LIBRARY &&
  1328. type != cmTarget::SHARED_LIBRARY &&
  1329. type != cmTarget::MODULE_LIBRARY &&
  1330. type != cmTarget::EXECUTABLE)
  1331. {
  1332. outPrefix = "";
  1333. outBase = this->GetName();
  1334. outSuffix = "";
  1335. return;
  1336. }
  1337. // Return an empty name for the import library if this platform
  1338. // does not support import libraries.
  1339. if(implib &&
  1340. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  1341. {
  1342. outPrefix = "";
  1343. outBase = "";
  1344. outSuffix = "";
  1345. return;
  1346. }
  1347. // The implib option is only allowed for shared libraries.
  1348. if(type != cmTarget::SHARED_LIBRARY)
  1349. {
  1350. implib = false;
  1351. }
  1352. // Compute the full name for main target types.
  1353. const char* targetPrefix = (implib
  1354. ? this->GetProperty("IMPORT_PREFIX")
  1355. : this->GetProperty("PREFIX"));
  1356. const char* targetSuffix = (implib
  1357. ? this->GetProperty("IMPORT_SUFFIX")
  1358. : this->GetProperty("SUFFIX"));
  1359. const char* configPostfix = 0;
  1360. if(config && *config)
  1361. {
  1362. std::string configProp = cmSystemTools::UpperCase(config);
  1363. configProp += "_POSTFIX";
  1364. configPostfix = this->GetProperty(configProp.c_str());
  1365. }
  1366. const char* prefixVar = this->GetPrefixVariableInternal(type, implib);
  1367. const char* suffixVar = this->GetSuffixVariableInternal(type, implib);
  1368. const char* ll =
  1369. this->GetLinkerLanguage(
  1370. this->Makefile->GetLocalGenerator()->GetGlobalGenerator());
  1371. // first try language specific suffix
  1372. if(ll)
  1373. {
  1374. if(!targetSuffix && suffixVar && *suffixVar)
  1375. {
  1376. std::string langSuff = suffixVar + std::string("_") + ll;
  1377. targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
  1378. }
  1379. if(!targetPrefix && prefixVar && *prefixVar)
  1380. {
  1381. std::string langPrefix = prefixVar + std::string("_") + ll;
  1382. targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
  1383. }
  1384. }
  1385. // if there is no prefix on the target use the cmake definition
  1386. if(!targetPrefix && prefixVar)
  1387. {
  1388. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  1389. }
  1390. // if there is no suffix on the target use the cmake definition
  1391. if(!targetSuffix && suffixVar)
  1392. {
  1393. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  1394. }
  1395. // Begin the final name with the prefix.
  1396. outPrefix = targetPrefix?targetPrefix:"";
  1397. // Append the target name or property-specified name.
  1398. const char* outName = 0;
  1399. if(config && *config)
  1400. {
  1401. std::string configProp = cmSystemTools::UpperCase(config);
  1402. configProp += "_OUTPUT_NAME";
  1403. outName = this->GetProperty(configProp.c_str());
  1404. }
  1405. if(!outName)
  1406. {
  1407. outName = this->GetProperty("OUTPUT_NAME");
  1408. }
  1409. if(outName)
  1410. {
  1411. outBase = outName;
  1412. }
  1413. else
  1414. {
  1415. outBase = this->GetName();
  1416. }
  1417. // Append the per-configuration postfix.
  1418. outBase += configPostfix?configPostfix:"";
  1419. // Name shared libraries with their version number on some platforms.
  1420. if(const char* version = this->GetProperty("VERSION"))
  1421. {
  1422. if(type == cmTarget::SHARED_LIBRARY && !implib &&
  1423. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  1424. {
  1425. outBase += "-";
  1426. outBase += version;
  1427. }
  1428. }
  1429. // Append the suffix.
  1430. outSuffix = targetSuffix?targetSuffix:"";
  1431. }
  1432. void cmTarget::GetLibraryNames(std::string& name,
  1433. std::string& soName,
  1434. std::string& realName,
  1435. std::string& impName,
  1436. std::string& pdbName,
  1437. const char* config)
  1438. {
  1439. // Get the names based on the real type of the library.
  1440. this->GetLibraryNamesInternal(name, soName, realName, impName, pdbName,
  1441. this->GetType(), config);
  1442. }
  1443. void cmTarget::GetLibraryCleanNames(std::string& staticName,
  1444. std::string& sharedName,
  1445. std::string& sharedSOName,
  1446. std::string& sharedRealName,
  1447. std::string& importName,
  1448. std::string& pdbName,
  1449. const char* config)
  1450. {
  1451. // Get the name as if this were a static library.
  1452. std::string soName;
  1453. std::string realName;
  1454. std::string impName;
  1455. this->GetLibraryNamesInternal(staticName, soName, realName, impName,
  1456. pdbName, cmTarget::STATIC_LIBRARY, config);
  1457. // Get the names as if this were a shared library.
  1458. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  1459. {
  1460. // Since the real type is static then the user either specified
  1461. // STATIC or did not specify a type. In the former case the
  1462. // shared library will never be present. In the latter case the
  1463. // type will never be MODULE. Either way the only names that
  1464. // might have to be cleaned are the shared library names.
  1465. this->GetLibraryNamesInternal(sharedName, sharedSOName, sharedRealName,
  1466. importName, pdbName,
  1467. cmTarget::SHARED_LIBRARY, config);
  1468. }
  1469. else
  1470. {
  1471. // Use the name of the real type of the library (shared or module).
  1472. this->GetLibraryNamesInternal(sharedName, sharedSOName, sharedRealName,
  1473. importName, pdbName, this->GetType(),
  1474. config);
  1475. }
  1476. }
  1477. void cmTarget::GetLibraryNamesInternal(std::string& name,
  1478. std::string& soName,
  1479. std::string& realName,
  1480. std::string& impName,
  1481. std::string& pdbName,
  1482. TargetType type,
  1483. const char* config)
  1484. {
  1485. // Construct the name of the soname flag variable for this language.
  1486. const char* ll =
  1487. this->GetLinkerLanguage(
  1488. this->Makefile->GetLocalGenerator()->GetGlobalGenerator());
  1489. std::string sonameFlag = "CMAKE_SHARED_LIBRARY_SONAME";
  1490. if(ll)
  1491. {
  1492. sonameFlag += "_";
  1493. sonameFlag += ll;
  1494. }
  1495. sonameFlag += "_FLAG";
  1496. // Check for library version properties.
  1497. const char* version = this->GetProperty("VERSION");
  1498. const char* soversion = this->GetProperty("SOVERSION");
  1499. if((type != cmTarget::SHARED_LIBRARY && type != cmTarget::MODULE_LIBRARY) ||
  1500. !this->Makefile->GetDefinition(sonameFlag.c_str()))
  1501. {
  1502. // Versioning is supported only for shared libraries and modules,
  1503. // and then only when the platform supports an soname flag.
  1504. version = 0;
  1505. soversion = 0;
  1506. }
  1507. if(version && !soversion)
  1508. {
  1509. // The soversion must be set if the library version is set. Use
  1510. // the library version as the soversion.
  1511. soversion = version;
  1512. }
  1513. // Get the components of the library name.
  1514. std::string prefix;
  1515. std::string base;
  1516. std::string suffix;
  1517. this->GetFullNameInternal(type, config, false, prefix, base, suffix);
  1518. // The library name.
  1519. name = prefix+base+suffix;
  1520. // The library's soname.
  1521. #if defined(__APPLE__)
  1522. soName = prefix+base;
  1523. #else
  1524. soName = name;
  1525. #endif
  1526. if(soversion)
  1527. {
  1528. soName += ".";
  1529. soName += soversion;
  1530. }
  1531. #if defined(__APPLE__)
  1532. soName += suffix;
  1533. #endif
  1534. // The library's real name on disk.
  1535. #if defined(__APPLE__)
  1536. realName = prefix+base;
  1537. #else
  1538. realName = name;
  1539. #endif
  1540. if(version)
  1541. {
  1542. realName += ".";
  1543. realName += version;
  1544. }
  1545. else if(soversion)
  1546. {
  1547. realName += ".";
  1548. realName += soversion;
  1549. }
  1550. #if defined(__APPLE__)
  1551. realName += suffix;
  1552. #endif
  1553. // The import library name.
  1554. if(type == cmTarget::SHARED_LIBRARY)
  1555. {
  1556. impName = this->GetFullNameInternal(type, config, true);
  1557. }
  1558. else
  1559. {
  1560. impName = "";
  1561. }
  1562. // The program database file name.
  1563. pdbName = prefix+base+".pdb";
  1564. }
  1565. void cmTarget::GetExecutableNames(std::string& name,
  1566. std::string& realName,
  1567. std::string& pdbName,
  1568. const char* config)
  1569. {
  1570. // Get the names based on the real type of the executable.
  1571. this->GetExecutableNamesInternal(name, realName, pdbName,
  1572. this->GetType(), config);
  1573. }
  1574. void cmTarget::GetExecutableCleanNames(std::string& name,
  1575. std::string& realName,
  1576. std::string& pdbName,
  1577. const char* config)
  1578. {
  1579. // Get the name and versioned name of this executable.
  1580. this->GetExecutableNamesInternal(name, realName, pdbName,
  1581. cmTarget::EXECUTABLE, config);
  1582. }
  1583. void cmTarget::GetExecutableNamesInternal(std::string& name,
  1584. std::string& realName,
  1585. std::string& pdbName,
  1586. TargetType type,
  1587. const char* config)
  1588. {
  1589. // This versioning is supported only for executables and then only
  1590. // when the platform supports symbolic links.
  1591. #if defined(_WIN32) && !defined(__CYGWIN__)
  1592. const char* version = 0;
  1593. #else
  1594. // Check for executable version properties.
  1595. const char* version = this->GetProperty("VERSION");
  1596. if(type != cmTarget::EXECUTABLE)
  1597. {
  1598. version = 0;
  1599. }
  1600. #endif
  1601. // Get the components of the executable name.
  1602. std::string prefix;
  1603. std::string base;
  1604. std::string suffix;
  1605. this->GetFullNameInternal(type, config, false, prefix, base, suffix);
  1606. // The executable name.
  1607. name = prefix+base+suffix;
  1608. // The executable's real name on disk.
  1609. #if defined(__CYGWIN__)
  1610. realName = prefix+base;
  1611. #else
  1612. realName = name;
  1613. #endif
  1614. if(version)
  1615. {
  1616. realName += "-";
  1617. realName += version;
  1618. }
  1619. #if defined(__CYGWIN__)
  1620. realName += suffix;
  1621. #endif
  1622. // The program database file name.
  1623. pdbName = prefix+base+".pdb";
  1624. }
  1625. //----------------------------------------------------------------------------
  1626. void cmTarget::SetPropertyDefault(const char* property,
  1627. const char* default_value)
  1628. {
  1629. // Compute the name of the variable holding the default value.
  1630. std::string var = "CMAKE_";
  1631. var += property;
  1632. if(const char* value = this->Makefile->GetDefinition(var.c_str()))
  1633. {
  1634. this->SetProperty(property, value);
  1635. }
  1636. else if(default_value)
  1637. {
  1638. this->SetProperty(property, default_value);
  1639. }
  1640. }
  1641. //----------------------------------------------------------------------------
  1642. bool cmTarget::HaveBuildTreeRPATH()
  1643. {
  1644. return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
  1645. !this->LinkLibraries.empty());
  1646. }
  1647. //----------------------------------------------------------------------------
  1648. bool cmTarget::HaveInstallTreeRPATH()
  1649. {
  1650. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  1651. return install_rpath && *install_rpath;
  1652. }
  1653. //----------------------------------------------------------------------------
  1654. bool cmTarget::NeedRelinkBeforeInstall()
  1655. {
  1656. // Only executables and shared libraries can have an rpath and may
  1657. // need relinking.
  1658. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  1659. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  1660. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  1661. {
  1662. return false;
  1663. }
  1664. // If there is no install location this target will not be installed
  1665. // and therefore does not need relinking.
  1666. if(!this->GetHaveInstallRule())
  1667. {
  1668. return false;
  1669. }
  1670. // If skipping all rpaths completely then no relinking is needed.
  1671. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  1672. {
  1673. return false;
  1674. }
  1675. // If building with the install-tree rpath no relinking is needed.
  1676. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  1677. {
  1678. return false;
  1679. }
  1680. // Check for rpath support on this platform.
  1681. if(const char* ll = this->GetLinkerLanguage(
  1682. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()))
  1683. {
  1684. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1685. flagVar += ll;
  1686. flagVar += "_FLAG";
  1687. if(!this->Makefile->IsSet(flagVar.c_str()))
  1688. {
  1689. // There is no rpath support on this platform so nothing needs
  1690. // relinking.
  1691. return false;
  1692. }
  1693. }
  1694. else
  1695. {
  1696. // No linker language is known. This error will be reported by
  1697. // other code.
  1698. return false;
  1699. }
  1700. // If either a build or install tree rpath is set then the rpath
  1701. // will likely change between the build tree and install tree and
  1702. // this target must be relinked.
  1703. return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
  1704. }
  1705. //----------------------------------------------------------------------------
  1706. std::string cmTarget::GetInstallNameDirForBuildTree(const char* config)
  1707. {
  1708. // If building directly for installation then the build tree install_name
  1709. // is the same as the install tree.
  1710. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  1711. {
  1712. return GetInstallNameDirForInstallTree(config);
  1713. }
  1714. // Use the build tree directory for the target.
  1715. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  1716. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  1717. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  1718. {
  1719. std::string dir = this->GetDirectory(config);
  1720. dir += "/";
  1721. return dir;
  1722. }
  1723. else
  1724. {
  1725. return "";
  1726. }
  1727. }
  1728. //----------------------------------------------------------------------------
  1729. std::string cmTarget::GetInstallNameDirForInstallTree(const char*)
  1730. {
  1731. // Lookup the target property.
  1732. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  1733. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  1734. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  1735. install_name_dir && *install_name_dir)
  1736. {
  1737. std::string dir = install_name_dir;
  1738. dir += "/";
  1739. return dir;
  1740. }
  1741. else
  1742. {
  1743. return "";
  1744. }
  1745. }