cmLocalGenerator.cxx 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmLocalGenerator.h"
  11. #include "cmComputeLinkInformation.h"
  12. #include "cmGeneratedFileStream.h"
  13. #include "cmGlobalGenerator.h"
  14. #include "cmInstallGenerator.h"
  15. #include "cmInstallFilesGenerator.h"
  16. #include "cmInstallScriptGenerator.h"
  17. #include "cmInstallTargetGenerator.h"
  18. #include "cmMakefile.h"
  19. #include "cmSourceFile.h"
  20. #include "cmTest.h"
  21. #include "cmTestGenerator.h"
  22. #include "cmCustomCommandGenerator.h"
  23. #include "cmVersion.h"
  24. #include "cmake.h"
  25. #include "cmAlgorithms.h"
  26. #if defined(CMAKE_BUILD_WITH_CMAKE)
  27. # define CM_LG_ENCODE_OBJECT_NAMES
  28. # include <cmsys/MD5.h>
  29. #endif
  30. #include <cmsys/System.h>
  31. #include <ctype.h> // for isalpha
  32. #include <assert.h>
  33. #if defined(__HAIKU__)
  34. #include <FindDirectory.h>
  35. #include <StorageDefs.h>
  36. #endif
  37. cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg,
  38. cmLocalGenerator* parent,
  39. cmState::Snapshot snapshot)
  40. : cmOutputConverter(snapshot), StateSnapshot(snapshot)
  41. {
  42. assert(snapshot.IsValid());
  43. this->GlobalGenerator = gg;
  44. this->Parent = parent;
  45. if (parent)
  46. {
  47. parent->AddChild(this);
  48. }
  49. this->Makefile = new cmMakefile(this);
  50. this->EmitUniversalBinaryFlags = true;
  51. this->BackwardsCompatibility = 0;
  52. this->BackwardsCompatibilityFinal = false;
  53. }
  54. cmLocalGenerator::~cmLocalGenerator()
  55. {
  56. delete this->Makefile;
  57. }
  58. void cmLocalGenerator::IssueMessage(cmake::MessageType t,
  59. std::string const& text) const
  60. {
  61. cmListFileContext lfc;
  62. lfc.FilePath = this->StateSnapshot.GetCurrentSourceDirectory();
  63. lfc.FilePath += "/CMakeLists.txt";
  64. if(!this->GlobalGenerator->GetCMakeInstance()->GetIsInTryCompile())
  65. {
  66. cmOutputConverter converter(this->StateSnapshot);
  67. lfc.FilePath = converter.Convert(lfc.FilePath, cmLocalGenerator::HOME);
  68. }
  69. lfc.Line = 0;
  70. this->GlobalGenerator->GetCMakeInstance()->IssueMessage(t, text, lfc);
  71. }
  72. //----------------------------------------------------------------------------
  73. void cmLocalGenerator::ComputeObjectMaxPath()
  74. {
  75. // Choose a maximum object file name length.
  76. #if defined(_WIN32) || defined(__CYGWIN__)
  77. this->ObjectPathMax = 250;
  78. #else
  79. this->ObjectPathMax = 1000;
  80. #endif
  81. const char* plen = this->Makefile->GetDefinition("CMAKE_OBJECT_PATH_MAX");
  82. if(plen && *plen)
  83. {
  84. unsigned int pmax;
  85. if(sscanf(plen, "%u", &pmax) == 1)
  86. {
  87. if(pmax >= 128)
  88. {
  89. this->ObjectPathMax = pmax;
  90. }
  91. else
  92. {
  93. std::ostringstream w;
  94. w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
  95. << ", which is less than the minimum of 128. "
  96. << "The value will be ignored.";
  97. this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  98. }
  99. }
  100. else
  101. {
  102. std::ostringstream w;
  103. w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
  104. << "\", which fails to parse as a positive integer. "
  105. << "The value will be ignored.";
  106. this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  107. }
  108. }
  109. this->ObjectMaxPathViolations.clear();
  110. }
  111. void cmLocalGenerator::TraceDependencies()
  112. {
  113. std::vector<std::string> configs;
  114. this->Makefile->GetConfigurations(configs);
  115. if (configs.empty())
  116. {
  117. configs.push_back("");
  118. }
  119. for(std::vector<std::string>::const_iterator ci = configs.begin();
  120. ci != configs.end(); ++ci)
  121. {
  122. this->GlobalGenerator->CreateEvaluationSourceFiles(*ci);
  123. }
  124. // Generate the rule files for each target.
  125. cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets();
  126. for(cmGeneratorTargetsType::iterator t = targets.begin();
  127. t != targets.end(); ++t)
  128. {
  129. if (t->second->Target->IsImported()
  130. || t->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  131. {
  132. continue;
  133. }
  134. t->second->TraceDependencies();
  135. }
  136. }
  137. void cmLocalGenerator::GenerateTestFiles()
  138. {
  139. if ( !this->Makefile->IsOn("CMAKE_TESTING_ENABLED") )
  140. {
  141. return;
  142. }
  143. // Compute the set of configurations.
  144. std::vector<std::string> configurationTypes;
  145. const std::string& config =
  146. this->Makefile->GetConfigurations(configurationTypes, false);
  147. std::string file = this->StateSnapshot.GetCurrentBinaryDirectory();
  148. file += "/";
  149. file += "CTestTestfile.cmake";
  150. cmGeneratedFileStream fout(file.c_str());
  151. fout.SetCopyIfDifferent(true);
  152. fout << "# CMake generated Testfile for " << std::endl
  153. << "# Source directory: "
  154. << this->StateSnapshot.GetCurrentSourceDirectory() << std::endl
  155. << "# Build directory: "
  156. << this->StateSnapshot.GetCurrentBinaryDirectory() << std::endl
  157. << "# " << std::endl
  158. << "# This file includes the relevant testing commands "
  159. << "required for " << std::endl
  160. << "# testing this directory and lists subdirectories to "
  161. << "be tested as well." << std::endl;
  162. const char* testIncludeFile =
  163. this->Makefile->GetProperty("TEST_INCLUDE_FILE");
  164. if ( testIncludeFile )
  165. {
  166. fout << "include(\"" << testIncludeFile << "\")" << std::endl;
  167. }
  168. // Ask each test generator to write its code.
  169. std::vector<cmTestGenerator*> const&
  170. testers = this->Makefile->GetTestGenerators();
  171. for(std::vector<cmTestGenerator*>::const_iterator gi = testers.begin();
  172. gi != testers.end(); ++gi)
  173. {
  174. (*gi)->Generate(fout, config, configurationTypes);
  175. }
  176. if (!this->Children.empty())
  177. {
  178. size_t i;
  179. for(i = 0; i < this->Children.size(); ++i)
  180. {
  181. // TODO: Use add_subdirectory instead?
  182. fout << "subdirs(";
  183. std::string outP =
  184. this->Children[i]->GetMakefile()->GetCurrentBinaryDirectory();
  185. fout << this->Convert(outP,START_OUTPUT);
  186. fout << ")" << std::endl;
  187. }
  188. }
  189. }
  190. //----------------------------------------------------------------------------
  191. void cmLocalGenerator::GenerateInstallRules()
  192. {
  193. // Compute the install prefix.
  194. const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
  195. #if defined(_WIN32) && !defined(__CYGWIN__)
  196. std::string prefix_win32;
  197. if(!prefix)
  198. {
  199. if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32))
  200. {
  201. prefix_win32 = "C:";
  202. }
  203. const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
  204. if(project_name && project_name[0])
  205. {
  206. prefix_win32 += "/Program Files/";
  207. prefix_win32 += project_name;
  208. }
  209. else
  210. {
  211. prefix_win32 += "/InstalledCMakeProject";
  212. }
  213. prefix = prefix_win32.c_str();
  214. }
  215. #elif defined(__HAIKU__)
  216. char dir[B_PATH_NAME_LENGTH];
  217. if (!prefix)
  218. {
  219. if (find_directory(B_SYSTEM_DIRECTORY, -1, false, dir, sizeof(dir))
  220. == B_OK)
  221. {
  222. prefix = dir;
  223. }
  224. else
  225. {
  226. prefix = "/boot/system";
  227. }
  228. }
  229. #else
  230. if (!prefix)
  231. {
  232. prefix = "/usr/local";
  233. }
  234. #endif
  235. if (const char *stagingPrefix
  236. = this->Makefile->GetDefinition("CMAKE_STAGING_PREFIX"))
  237. {
  238. prefix = stagingPrefix;
  239. }
  240. // Compute the set of configurations.
  241. std::vector<std::string> configurationTypes;
  242. const std::string& config =
  243. this->Makefile->GetConfigurations(configurationTypes, false);
  244. // Choose a default install configuration.
  245. std::string default_config = config;
  246. const char* default_order[] = {"RELEASE", "MINSIZEREL",
  247. "RELWITHDEBINFO", "DEBUG", 0};
  248. for(const char** c = default_order; *c && default_config.empty(); ++c)
  249. {
  250. for(std::vector<std::string>::iterator i = configurationTypes.begin();
  251. i != configurationTypes.end(); ++i)
  252. {
  253. if(cmSystemTools::UpperCase(*i) == *c)
  254. {
  255. default_config = *i;
  256. }
  257. }
  258. }
  259. if(default_config.empty() && !configurationTypes.empty())
  260. {
  261. default_config = configurationTypes[0];
  262. }
  263. // Create the install script file.
  264. std::string file = this->StateSnapshot.GetCurrentBinaryDirectory();
  265. std::string homedir = this->GetState()->GetBinaryDirectory();
  266. int toplevel_install = 0;
  267. if (file == homedir)
  268. {
  269. toplevel_install = 1;
  270. }
  271. file += "/cmake_install.cmake";
  272. cmGeneratedFileStream fout(file.c_str());
  273. fout.SetCopyIfDifferent(true);
  274. // Write the header.
  275. fout << "# Install script for directory: "
  276. << this->StateSnapshot.GetCurrentSourceDirectory()
  277. << std::endl << std::endl;
  278. fout << "# Set the install prefix" << std::endl
  279. << "if(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
  280. << " set(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
  281. << "endif()" << std::endl
  282. << "string(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
  283. << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
  284. << std::endl;
  285. // Write support code for generating per-configuration install rules.
  286. fout <<
  287. "# Set the install configuration name.\n"
  288. "if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
  289. " if(BUILD_TYPE)\n"
  290. " string(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
  291. " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
  292. " else()\n"
  293. " set(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
  294. " endif()\n"
  295. " message(STATUS \"Install configuration: "
  296. "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
  297. "endif()\n"
  298. "\n";
  299. // Write support code for dealing with component-specific installs.
  300. fout <<
  301. "# Set the component getting installed.\n"
  302. "if(NOT CMAKE_INSTALL_COMPONENT)\n"
  303. " if(COMPONENT)\n"
  304. " message(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
  305. " set(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
  306. " else()\n"
  307. " set(CMAKE_INSTALL_COMPONENT)\n"
  308. " endif()\n"
  309. "endif()\n"
  310. "\n";
  311. // Copy user-specified install options to the install code.
  312. if(const char* so_no_exe =
  313. this->Makefile->GetDefinition("CMAKE_INSTALL_SO_NO_EXE"))
  314. {
  315. fout <<
  316. "# Install shared libraries without execute permission?\n"
  317. "if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
  318. " set(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe << "\")\n"
  319. "endif()\n"
  320. "\n";
  321. }
  322. // Ask each install generator to write its code.
  323. std::vector<cmInstallGenerator*> const& installers =
  324. this->Makefile->GetInstallGenerators();
  325. for(std::vector<cmInstallGenerator*>::const_iterator
  326. gi = installers.begin();
  327. gi != installers.end(); ++gi)
  328. {
  329. (*gi)->Generate(fout, config, configurationTypes);
  330. }
  331. // Write rules from old-style specification stored in targets.
  332. this->GenerateTargetInstallRules(fout, config, configurationTypes);
  333. // Include install scripts from subdirectories.
  334. if(!this->Children.empty())
  335. {
  336. fout << "if(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
  337. fout << " # Include the install script for each subdirectory.\n";
  338. for(std::vector<cmLocalGenerator*>::const_iterator
  339. ci = this->Children.begin(); ci != this->Children.end(); ++ci)
  340. {
  341. if(!(*ci)->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  342. {
  343. std::string odir = (*ci)->GetMakefile()->GetCurrentBinaryDirectory();
  344. cmSystemTools::ConvertToUnixSlashes(odir);
  345. fout << " include(\"" << odir
  346. << "/cmake_install.cmake\")" << std::endl;
  347. }
  348. }
  349. fout << "\n";
  350. fout << "endif()\n\n";
  351. }
  352. // Record the install manifest.
  353. if ( toplevel_install )
  354. {
  355. fout <<
  356. "if(CMAKE_INSTALL_COMPONENT)\n"
  357. " set(CMAKE_INSTALL_MANIFEST \"install_manifest_"
  358. "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
  359. "else()\n"
  360. " set(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
  361. "endif()\n"
  362. "\n"
  363. "string(REPLACE \";\" \"\\n\" CMAKE_INSTALL_MANIFEST_CONTENT\n"
  364. " \"${CMAKE_INSTALL_MANIFEST_FILES}\")\n"
  365. "file(WRITE \"" << homedir << "/${CMAKE_INSTALL_MANIFEST}\"\n"
  366. " \"${CMAKE_INSTALL_MANIFEST_CONTENT}\")\n";
  367. }
  368. }
  369. //----------------------------------------------------------------------------
  370. void cmLocalGenerator::GenerateTargetManifest()
  371. {
  372. // Collect the set of configuration types.
  373. std::vector<std::string> configNames;
  374. this->Makefile->GetConfigurations(configNames);
  375. if(configNames.empty())
  376. {
  377. configNames.push_back("");
  378. }
  379. // Add our targets to the manifest for each configuration.
  380. cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets();
  381. for(cmGeneratorTargetsType::iterator t = targets.begin();
  382. t != targets.end(); ++t)
  383. {
  384. cmGeneratorTarget& target = *t->second;
  385. if (target.Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  386. {
  387. continue;
  388. }
  389. if (target.Target->IsImported())
  390. {
  391. continue;
  392. }
  393. for(std::vector<std::string>::iterator ci = configNames.begin();
  394. ci != configNames.end(); ++ci)
  395. {
  396. const char* config = ci->c_str();
  397. target.GenerateTargetManifest(config);
  398. }
  399. }
  400. }
  401. cmState* cmLocalGenerator::GetState() const
  402. {
  403. return this->GlobalGenerator->GetCMakeInstance()->GetState();
  404. }
  405. cmState::Snapshot cmLocalGenerator::GetStateSnapshot() const
  406. {
  407. return this->StateSnapshot;
  408. }
  409. void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
  410. const std::string& lang,
  411. cmSourceFile& source,
  412. cmGeneratorTarget& target)
  413. {
  414. std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname));
  415. objectDir = this->Convert(objectDir,START_OUTPUT,SHELL);
  416. std::string objectFile = this->Convert(ofname,START_OUTPUT,SHELL);
  417. std::string sourceFile =
  418. this->ConvertToOutputFormat(source.GetFullPath(), SHELL);
  419. std::string varString = "CMAKE_";
  420. varString += lang;
  421. varString += "_COMPILE_OBJECT";
  422. std::vector<std::string> rules;
  423. rules.push_back(this->Makefile->GetRequiredDefinition(varString));
  424. varString = "CMAKE_";
  425. varString += lang;
  426. varString += "_FLAGS";
  427. std::string flags;
  428. flags += this->Makefile->GetSafeDefinition(varString);
  429. flags += " ";
  430. {
  431. std::vector<std::string> includes;
  432. this->GetIncludeDirectories(includes, &target, lang);
  433. flags += this->GetIncludeFlags(includes, &target, lang);
  434. }
  435. flags += this->Makefile->GetDefineFlags();
  436. // Construct the command lines.
  437. cmCustomCommandLines commandLines;
  438. std::vector<std::string> commands;
  439. cmSystemTools::ExpandList(rules, commands);
  440. cmLocalGenerator::RuleVariables vars;
  441. vars.Language = lang.c_str();
  442. vars.Source = sourceFile.c_str();
  443. vars.Object = objectFile.c_str();
  444. vars.ObjectDir = objectDir.c_str();
  445. vars.Flags = flags.c_str();
  446. for(std::vector<std::string>::iterator i = commands.begin();
  447. i != commands.end(); ++i)
  448. {
  449. // Expand the full command line string.
  450. this->ExpandRuleVariables(*i, vars);
  451. // Parse the string to get the custom command line.
  452. cmCustomCommandLine commandLine;
  453. std::vector<std::string> cmd = cmSystemTools::ParseArguments(i->c_str());
  454. commandLine.insert(commandLine.end(), cmd.begin(), cmd.end());
  455. // Store this command line.
  456. commandLines.push_back(commandLine);
  457. }
  458. // Check for extra object-file dependencies.
  459. std::vector<std::string> depends;
  460. const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
  461. if(additionalDeps)
  462. {
  463. cmSystemTools::ExpandListArgument(additionalDeps, depends);
  464. }
  465. // Generate a meaningful comment for the command.
  466. std::string comment = "Building ";
  467. comment += lang;
  468. comment += " object ";
  469. comment += this->Convert(ofname, START_OUTPUT);
  470. // Add the custom command to build the object file.
  471. this->Makefile->AddCustomCommandToOutput(
  472. ofname,
  473. depends,
  474. source.GetFullPath(),
  475. commandLines,
  476. comment.c_str(),
  477. this->StateSnapshot.GetCurrentBinaryDirectory()
  478. );
  479. }
  480. void cmLocalGenerator::AddBuildTargetRule(const std::string& llang,
  481. cmGeneratorTarget& target)
  482. {
  483. std::string objs;
  484. std::vector<std::string> objVector;
  485. std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  486. // Add all the sources outputs to the depends of the target
  487. std::vector<cmSourceFile*> classes;
  488. target.GetSourceFiles(classes, config);
  489. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  490. i != classes.end(); ++i)
  491. {
  492. cmSourceFile* sf = *i;
  493. if(!sf->GetCustomCommand() &&
  494. !sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  495. !sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  496. {
  497. std::string dir_max;
  498. dir_max += this->StateSnapshot.GetCurrentBinaryDirectory();
  499. dir_max += "/";
  500. std::string obj = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
  501. if(!obj.empty())
  502. {
  503. std::string ofname = this->StateSnapshot.GetCurrentBinaryDirectory();
  504. ofname += "/";
  505. ofname += obj;
  506. objVector.push_back(ofname);
  507. this->AddCustomCommandToCreateObject(ofname.c_str(),
  508. llang, *(*i), target);
  509. objs += this->Convert(ofname,START_OUTPUT,SHELL);
  510. objs += " ";
  511. }
  512. }
  513. }
  514. std::string createRule = target.GetCreateRuleVariable(llang, config);
  515. bool useWatcomQuote = this->Makefile->IsOn(createRule+"_USE_WATCOM_QUOTE");
  516. std::string targetName = target.Target->GetFullName();
  517. // Executable :
  518. // Shared Library:
  519. // Static Library:
  520. // Shared Module:
  521. std::string linkLibs; // should be set
  522. std::string frameworkPath;
  523. std::string linkPath;
  524. std::string flags; // should be set
  525. std::string linkFlags; // should be set
  526. this->GetTargetFlags(linkLibs, frameworkPath, linkPath, flags, linkFlags,
  527. &target, useWatcomQuote);
  528. linkLibs = frameworkPath + linkPath + linkLibs;
  529. cmLocalGenerator::RuleVariables vars;
  530. vars.Language = llang.c_str();
  531. vars.Objects = objs.c_str();
  532. vars.ObjectDir = ".";
  533. vars.Target = targetName.c_str();
  534. vars.LinkLibraries = linkLibs.c_str();
  535. vars.Flags = flags.c_str();
  536. vars.LinkFlags = linkFlags.c_str();
  537. std::string langFlags;
  538. this->AddLanguageFlags(langFlags, llang, "");
  539. this->AddArchitectureFlags(langFlags, &target, llang, "");
  540. vars.LanguageCompileFlags = langFlags.c_str();
  541. cmCustomCommandLines commandLines;
  542. std::vector<std::string> rules;
  543. rules.push_back(this->Makefile->GetRequiredDefinition(createRule));
  544. std::vector<std::string> commands;
  545. cmSystemTools::ExpandList(rules, commands);
  546. for(std::vector<std::string>::iterator i = commands.begin();
  547. i != commands.end(); ++i)
  548. {
  549. // Expand the full command line string.
  550. this->ExpandRuleVariables(*i, vars);
  551. // Parse the string to get the custom command line.
  552. cmCustomCommandLine commandLine;
  553. std::vector<std::string> cmd = cmSystemTools::ParseArguments(i->c_str());
  554. commandLine.insert(commandLine.end(), cmd.begin(), cmd.end());
  555. // Store this command line.
  556. commandLines.push_back(commandLine);
  557. }
  558. std::string targetFullPath = target.Target->GetFullPath();
  559. // Generate a meaningful comment for the command.
  560. std::string comment = "Linking ";
  561. comment += llang;
  562. comment += " target ";
  563. comment += this->Convert(targetFullPath, START_OUTPUT);
  564. this->Makefile->AddCustomCommandToOutput(
  565. targetFullPath,
  566. objVector,
  567. "",
  568. commandLines,
  569. comment.c_str(),
  570. this->StateSnapshot.GetCurrentBinaryDirectory()
  571. );
  572. this->Makefile->GetSource(targetFullPath);
  573. target.Target->AddSource(targetFullPath);
  574. }
  575. void cmLocalGenerator
  576. ::CreateCustomTargetsAndCommands(std::set<std::string> const& lang)
  577. {
  578. cmGeneratorTargetsType tgts = this->Makefile->GetGeneratorTargets();
  579. for(cmGeneratorTargetsType::iterator l = tgts.begin();
  580. l != tgts.end(); l++)
  581. {
  582. if (l->first->IsImported())
  583. {
  584. continue;
  585. }
  586. cmGeneratorTarget& target = *l->second;
  587. switch(target.GetType())
  588. {
  589. case cmTarget::STATIC_LIBRARY:
  590. case cmTarget::SHARED_LIBRARY:
  591. case cmTarget::MODULE_LIBRARY:
  592. case cmTarget::EXECUTABLE:
  593. {
  594. std::string llang = target.Target->GetLinkerLanguage();
  595. if(llang.empty())
  596. {
  597. cmSystemTools::Error
  598. ("CMake can not determine linker language for target: ",
  599. target.Target->GetName().c_str());
  600. return;
  601. }
  602. // if the language is not in the set lang then create custom
  603. // commands to build the target
  604. if(lang.count(llang) == 0)
  605. {
  606. this->AddBuildTargetRule(llang, target);
  607. }
  608. }
  609. break;
  610. default:
  611. break;
  612. }
  613. }
  614. }
  615. // List of variables that are replaced when
  616. // rules are expanced. These variables are
  617. // replaced in the form <var> with GetSafeDefinition(var).
  618. // ${LANG} is replaced in the variable first with all enabled
  619. // languages.
  620. static const char* ruleReplaceVars[] =
  621. {
  622. "CMAKE_${LANG}_COMPILER",
  623. "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
  624. "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
  625. "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
  626. "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
  627. "CMAKE_${LANG}_LINK_FLAGS",
  628. "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
  629. "CMAKE_${LANG}_ARCHIVE",
  630. "CMAKE_AR",
  631. "CMAKE_CURRENT_SOURCE_DIR",
  632. "CMAKE_CURRENT_BINARY_DIR",
  633. "CMAKE_RANLIB",
  634. "CMAKE_LINKER",
  635. "CMAKE_CL_SHOWINCLUDES_PREFIX",
  636. 0
  637. };
  638. std::string
  639. cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
  640. const RuleVariables& replaceValues)
  641. {
  642. if(replaceValues.LinkFlags)
  643. {
  644. if(variable == "LINK_FLAGS")
  645. {
  646. return replaceValues.LinkFlags;
  647. }
  648. }
  649. if(replaceValues.Flags)
  650. {
  651. if(variable == "FLAGS")
  652. {
  653. return replaceValues.Flags;
  654. }
  655. }
  656. if(replaceValues.Source)
  657. {
  658. if(variable == "SOURCE")
  659. {
  660. return replaceValues.Source;
  661. }
  662. }
  663. if(replaceValues.PreprocessedSource)
  664. {
  665. if(variable == "PREPROCESSED_SOURCE")
  666. {
  667. return replaceValues.PreprocessedSource;
  668. }
  669. }
  670. if(replaceValues.AssemblySource)
  671. {
  672. if(variable == "ASSEMBLY_SOURCE")
  673. {
  674. return replaceValues.AssemblySource;
  675. }
  676. }
  677. if(replaceValues.Object)
  678. {
  679. if(variable == "OBJECT")
  680. {
  681. return replaceValues.Object;
  682. }
  683. }
  684. if(replaceValues.ObjectDir)
  685. {
  686. if(variable == "OBJECT_DIR")
  687. {
  688. return replaceValues.ObjectDir;
  689. }
  690. }
  691. if(replaceValues.ObjectFileDir)
  692. {
  693. if(variable == "OBJECT_FILE_DIR")
  694. {
  695. return replaceValues.ObjectFileDir;
  696. }
  697. }
  698. if(replaceValues.Objects)
  699. {
  700. if(variable == "OBJECTS")
  701. {
  702. return replaceValues.Objects;
  703. }
  704. }
  705. if(replaceValues.ObjectsQuoted)
  706. {
  707. if(variable == "OBJECTS_QUOTED")
  708. {
  709. return replaceValues.ObjectsQuoted;
  710. }
  711. }
  712. if(replaceValues.Defines && variable == "DEFINES")
  713. {
  714. return replaceValues.Defines;
  715. }
  716. if(replaceValues.TargetPDB )
  717. {
  718. if(variable == "TARGET_PDB")
  719. {
  720. return replaceValues.TargetPDB;
  721. }
  722. }
  723. if(replaceValues.TargetCompilePDB)
  724. {
  725. if(variable == "TARGET_COMPILE_PDB")
  726. {
  727. return replaceValues.TargetCompilePDB;
  728. }
  729. }
  730. if(replaceValues.DependencyFile )
  731. {
  732. if(variable == "DEP_FILE")
  733. {
  734. return replaceValues.DependencyFile;
  735. }
  736. }
  737. if(replaceValues.Target)
  738. {
  739. if(variable == "TARGET_QUOTED")
  740. {
  741. std::string targetQuoted = replaceValues.Target;
  742. if(!targetQuoted.empty() && targetQuoted[0] != '\"')
  743. {
  744. targetQuoted = '\"';
  745. targetQuoted += replaceValues.Target;
  746. targetQuoted += '\"';
  747. }
  748. return targetQuoted;
  749. }
  750. if(variable == "TARGET_UNQUOTED")
  751. {
  752. std::string unquoted = replaceValues.Target;
  753. std::string::size_type sz = unquoted.size();
  754. if(sz > 2 && unquoted[0] == '\"' && unquoted[sz-1] == '\"')
  755. {
  756. unquoted = unquoted.substr(1, sz-2);
  757. }
  758. return unquoted;
  759. }
  760. if(replaceValues.LanguageCompileFlags)
  761. {
  762. if(variable == "LANGUAGE_COMPILE_FLAGS")
  763. {
  764. return replaceValues.LanguageCompileFlags;
  765. }
  766. }
  767. if(replaceValues.Target)
  768. {
  769. if(variable == "TARGET")
  770. {
  771. return replaceValues.Target;
  772. }
  773. }
  774. if(variable == "TARGET_IMPLIB")
  775. {
  776. return this->TargetImplib;
  777. }
  778. if(variable == "TARGET_VERSION_MAJOR")
  779. {
  780. if(replaceValues.TargetVersionMajor)
  781. {
  782. return replaceValues.TargetVersionMajor;
  783. }
  784. else
  785. {
  786. return "0";
  787. }
  788. }
  789. if(variable == "TARGET_VERSION_MINOR")
  790. {
  791. if(replaceValues.TargetVersionMinor)
  792. {
  793. return replaceValues.TargetVersionMinor;
  794. }
  795. else
  796. {
  797. return "0";
  798. }
  799. }
  800. if(replaceValues.Target)
  801. {
  802. if(variable == "TARGET_BASE")
  803. {
  804. // Strip the last extension off the target name.
  805. std::string targetBase = replaceValues.Target;
  806. std::string::size_type pos = targetBase.rfind(".");
  807. if(pos != targetBase.npos)
  808. {
  809. return targetBase.substr(0, pos);
  810. }
  811. else
  812. {
  813. return targetBase;
  814. }
  815. }
  816. }
  817. }
  818. if(variable == "TARGET_SONAME" || variable == "SONAME_FLAG" ||
  819. variable == "TARGET_INSTALLNAME_DIR")
  820. {
  821. // All these variables depend on TargetSOName
  822. if(replaceValues.TargetSOName)
  823. {
  824. if(variable == "TARGET_SONAME")
  825. {
  826. return replaceValues.TargetSOName;
  827. }
  828. if(variable == "SONAME_FLAG" && replaceValues.SONameFlag)
  829. {
  830. return replaceValues.SONameFlag;
  831. }
  832. if(replaceValues.TargetInstallNameDir &&
  833. variable == "TARGET_INSTALLNAME_DIR")
  834. {
  835. return replaceValues.TargetInstallNameDir;
  836. }
  837. }
  838. return "";
  839. }
  840. if(replaceValues.LinkLibraries)
  841. {
  842. if(variable == "LINK_LIBRARIES")
  843. {
  844. return replaceValues.LinkLibraries;
  845. }
  846. }
  847. if(replaceValues.Language)
  848. {
  849. if(variable == "LANGUAGE")
  850. {
  851. return replaceValues.Language;
  852. }
  853. }
  854. if(replaceValues.CMTarget)
  855. {
  856. if(variable == "TARGET_NAME")
  857. {
  858. return replaceValues.CMTarget->GetName();
  859. }
  860. if(variable == "TARGET_TYPE")
  861. {
  862. return cmTarget::GetTargetTypeName(replaceValues.CMTarget->GetType());
  863. }
  864. }
  865. if(replaceValues.Output)
  866. {
  867. if(variable == "OUTPUT")
  868. {
  869. return replaceValues.Output;
  870. }
  871. }
  872. if(variable == "CMAKE_COMMAND")
  873. {
  874. return this->Convert(cmSystemTools::GetCMakeCommand(), FULL, SHELL);
  875. }
  876. std::vector<std::string> enabledLanguages =
  877. this->GetState()->GetEnabledLanguages();
  878. // loop over language specific replace variables
  879. int pos = 0;
  880. while(ruleReplaceVars[pos])
  881. {
  882. for(std::vector<std::string>::iterator i = enabledLanguages.begin();
  883. i != enabledLanguages.end(); ++i)
  884. {
  885. const char* lang = i->c_str();
  886. std::string actualReplace = ruleReplaceVars[pos];
  887. // If this is the compiler then look for the extra variable
  888. // _COMPILER_ARG1 which must be the first argument to the compiler
  889. const char* compilerArg1 = 0;
  890. const char* compilerTarget = 0;
  891. const char* compilerOptionTarget = 0;
  892. const char* compilerExternalToolchain = 0;
  893. const char* compilerOptionExternalToolchain = 0;
  894. const char* compilerSysroot = 0;
  895. const char* compilerOptionSysroot = 0;
  896. if(actualReplace == "CMAKE_${LANG}_COMPILER")
  897. {
  898. std::string arg1 = actualReplace + "_ARG1";
  899. cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
  900. compilerArg1 = this->Makefile->GetDefinition(arg1);
  901. compilerTarget
  902. = this->Makefile->GetDefinition(
  903. std::string("CMAKE_") + lang + "_COMPILER_TARGET");
  904. compilerOptionTarget
  905. = this->Makefile->GetDefinition(
  906. std::string("CMAKE_") + lang +
  907. "_COMPILE_OPTIONS_TARGET");
  908. compilerExternalToolchain
  909. = this->Makefile->GetDefinition(
  910. std::string("CMAKE_") + lang +
  911. "_COMPILER_EXTERNAL_TOOLCHAIN");
  912. compilerOptionExternalToolchain
  913. = this->Makefile->GetDefinition(
  914. std::string("CMAKE_") + lang +
  915. "_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN");
  916. compilerSysroot
  917. = this->Makefile->GetDefinition("CMAKE_SYSROOT");
  918. compilerOptionSysroot
  919. = this->Makefile->GetDefinition(
  920. std::string("CMAKE_") + lang +
  921. "_COMPILE_OPTIONS_SYSROOT");
  922. }
  923. if(actualReplace.find("${LANG}") != actualReplace.npos)
  924. {
  925. cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
  926. }
  927. if(actualReplace == variable)
  928. {
  929. std::string replace =
  930. this->Makefile->GetSafeDefinition(variable);
  931. // if the variable is not a FLAG then treat it like a path
  932. if(variable.find("_FLAG") == variable.npos)
  933. {
  934. std::string ret = this->ConvertToOutputForExisting(replace);
  935. // if there is a required first argument to the compiler add it
  936. // to the compiler string
  937. if(compilerArg1)
  938. {
  939. ret += " ";
  940. ret += compilerArg1;
  941. }
  942. if (compilerTarget && compilerOptionTarget)
  943. {
  944. ret += " ";
  945. ret += compilerOptionTarget;
  946. ret += compilerTarget;
  947. }
  948. if (compilerExternalToolchain && compilerOptionExternalToolchain)
  949. {
  950. ret += " ";
  951. ret += compilerOptionExternalToolchain;
  952. ret += this->EscapeForShell(compilerExternalToolchain, true);
  953. }
  954. if (compilerSysroot && compilerOptionSysroot)
  955. {
  956. ret += " ";
  957. ret += compilerOptionSysroot;
  958. ret += this->EscapeForShell(compilerSysroot, true);
  959. }
  960. return ret;
  961. }
  962. return replace;
  963. }
  964. }
  965. pos++;
  966. }
  967. return variable;
  968. }
  969. void
  970. cmLocalGenerator::ExpandRuleVariables(std::string& s,
  971. const RuleVariables& replaceValues)
  972. {
  973. if(replaceValues.RuleLauncher)
  974. {
  975. this->InsertRuleLauncher(s, replaceValues.CMTarget,
  976. replaceValues.RuleLauncher);
  977. }
  978. std::string::size_type start = s.find('<');
  979. // no variables to expand
  980. if(start == s.npos)
  981. {
  982. return;
  983. }
  984. std::string::size_type pos = 0;
  985. std::string expandedInput;
  986. while(start != s.npos && start < s.size()-2)
  987. {
  988. std::string::size_type end = s.find('>', start);
  989. // if we find a < with no > we are done
  990. if(end == s.npos)
  991. {
  992. return;
  993. }
  994. char c = s[start+1];
  995. // if the next char after the < is not A-Za-z then
  996. // skip it and try to find the next < in the string
  997. if(!isalpha(c))
  998. {
  999. start = s.find('<', start+1);
  1000. }
  1001. else
  1002. {
  1003. // extract the var
  1004. std::string var = s.substr(start+1, end - start-1);
  1005. std::string replace = this->ExpandRuleVariable(var,
  1006. replaceValues);
  1007. expandedInput += s.substr(pos, start-pos);
  1008. expandedInput += replace;
  1009. // move to next one
  1010. start = s.find('<', start+var.size()+2);
  1011. pos = end+1;
  1012. }
  1013. }
  1014. // add the rest of the input
  1015. expandedInput += s.substr(pos, s.size()-pos);
  1016. s = expandedInput;
  1017. }
  1018. //----------------------------------------------------------------------------
  1019. const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target,
  1020. const std::string& prop)
  1021. {
  1022. if(target)
  1023. {
  1024. return target->GetProperty(prop);
  1025. }
  1026. else
  1027. {
  1028. return this->Makefile->GetProperty(prop);
  1029. }
  1030. }
  1031. //----------------------------------------------------------------------------
  1032. void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target,
  1033. const std::string& prop)
  1034. {
  1035. if(const char* val = this->GetRuleLauncher(target, prop))
  1036. {
  1037. std::ostringstream wrapped;
  1038. wrapped << val << " " << s;
  1039. s = wrapped.str();
  1040. }
  1041. }
  1042. //----------------------------------------------------------------------------
  1043. std::string
  1044. cmLocalGenerator::ConvertToIncludeReference(std::string const& path,
  1045. OutputFormat format,
  1046. bool forceFullPaths)
  1047. {
  1048. return this->ConvertToOutputForExisting(
  1049. path, forceFullPaths? FULL : START_OUTPUT, format);
  1050. }
  1051. //----------------------------------------------------------------------------
  1052. std::string cmLocalGenerator::GetIncludeFlags(
  1053. const std::vector<std::string> &includes,
  1054. cmGeneratorTarget* target,
  1055. const std::string& lang,
  1056. bool forceFullPaths,
  1057. bool forResponseFile,
  1058. const std::string& config)
  1059. {
  1060. if(lang.empty())
  1061. {
  1062. return "";
  1063. }
  1064. OutputFormat shellFormat = forResponseFile? RESPONSE : SHELL;
  1065. std::ostringstream includeFlags;
  1066. std::string flagVar = "CMAKE_INCLUDE_FLAG_";
  1067. flagVar += lang;
  1068. const char* includeFlag =
  1069. this->Makefile->GetSafeDefinition(flagVar);
  1070. flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
  1071. flagVar += lang;
  1072. const char* sep = this->Makefile->GetDefinition(flagVar);
  1073. bool quotePaths = false;
  1074. if(this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
  1075. {
  1076. quotePaths = true;
  1077. }
  1078. bool repeatFlag = true;
  1079. // should the include flag be repeated like ie. -IA -IB
  1080. if(!sep)
  1081. {
  1082. sep = " ";
  1083. }
  1084. else
  1085. {
  1086. // if there is a separator then the flag is not repeated but is only
  1087. // given once i.e. -classpath a:b:c
  1088. repeatFlag = false;
  1089. }
  1090. // Support special system include flag if it is available and the
  1091. // normal flag is repeated for each directory.
  1092. std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
  1093. sysFlagVar += lang;
  1094. const char* sysIncludeFlag = 0;
  1095. if(repeatFlag)
  1096. {
  1097. sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar);
  1098. }
  1099. std::string fwSearchFlagVar = "CMAKE_";
  1100. fwSearchFlagVar += lang;
  1101. fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
  1102. const char* fwSearchFlag =
  1103. this->Makefile->GetDefinition(fwSearchFlagVar);
  1104. std::string sysFwSearchFlagVar = "CMAKE_";
  1105. sysFwSearchFlagVar += lang;
  1106. sysFwSearchFlagVar += "_SYSTEM_FRAMEWORK_SEARCH_FLAG";
  1107. const char* sysFwSearchFlag =
  1108. this->Makefile->GetDefinition(sysFwSearchFlagVar);
  1109. bool flagUsed = false;
  1110. std::set<std::string> emitted;
  1111. #ifdef __APPLE__
  1112. emitted.insert("/System/Library/Frameworks");
  1113. #endif
  1114. std::vector<std::string>::const_iterator i;
  1115. for(i = includes.begin(); i != includes.end(); ++i)
  1116. {
  1117. if(fwSearchFlag && *fwSearchFlag && this->Makefile->IsOn("APPLE")
  1118. && cmSystemTools::IsPathToFramework(i->c_str()))
  1119. {
  1120. std::string frameworkDir = *i;
  1121. frameworkDir += "/../";
  1122. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
  1123. if(emitted.insert(frameworkDir).second)
  1124. {
  1125. if (sysFwSearchFlag && target &&
  1126. target->IsSystemIncludeDirectory(*i, config))
  1127. {
  1128. includeFlags << sysFwSearchFlag;
  1129. }
  1130. else
  1131. {
  1132. includeFlags << fwSearchFlag;
  1133. }
  1134. includeFlags << this->ConvertToOutputFormat(frameworkDir, shellFormat)
  1135. << " ";
  1136. }
  1137. continue;
  1138. }
  1139. if(!flagUsed || repeatFlag)
  1140. {
  1141. if(sysIncludeFlag && target &&
  1142. target->IsSystemIncludeDirectory(*i, config))
  1143. {
  1144. includeFlags << sysIncludeFlag;
  1145. }
  1146. else
  1147. {
  1148. includeFlags << includeFlag;
  1149. }
  1150. flagUsed = true;
  1151. }
  1152. std::string includePath =
  1153. this->ConvertToIncludeReference(*i, shellFormat, forceFullPaths);
  1154. if(quotePaths && !includePath.empty() && includePath[0] != '\"')
  1155. {
  1156. includeFlags << "\"";
  1157. }
  1158. includeFlags << includePath;
  1159. if(quotePaths && !includePath.empty() && includePath[0] != '\"')
  1160. {
  1161. includeFlags << "\"";
  1162. }
  1163. includeFlags << sep;
  1164. }
  1165. std::string flags = includeFlags.str();
  1166. // remove trailing separators
  1167. if((sep[0] != ' ') && !flags.empty() && flags[flags.size()-1] == sep[0])
  1168. {
  1169. flags[flags.size()-1] = ' ';
  1170. }
  1171. return flags;
  1172. }
  1173. //----------------------------------------------------------------------------
  1174. void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines,
  1175. cmTarget const* target,
  1176. const std::string& config,
  1177. const std::string& lang)
  1178. {
  1179. std::vector<std::string> targetDefines;
  1180. target->GetCompileDefinitions(targetDefines, config, lang);
  1181. this->AppendDefines(defines, targetDefines);
  1182. }
  1183. //----------------------------------------------------------------------------
  1184. void cmLocalGenerator::AddCompileOptions(
  1185. std::string& flags, cmTarget* target,
  1186. const std::string& lang, const std::string& config
  1187. )
  1188. {
  1189. std::string langFlagRegexVar = std::string("CMAKE_")+lang+"_FLAG_REGEX";
  1190. if(const char* langFlagRegexStr =
  1191. this->Makefile->GetDefinition(langFlagRegexVar))
  1192. {
  1193. // Filter flags acceptable to this language.
  1194. cmsys::RegularExpression r(langFlagRegexStr);
  1195. std::vector<std::string> opts;
  1196. if(const char* targetFlags = target->GetProperty("COMPILE_FLAGS"))
  1197. {
  1198. cmSystemTools::ParseWindowsCommandLine(targetFlags, opts);
  1199. }
  1200. target->GetCompileOptions(opts, config, lang);
  1201. for(std::vector<std::string>::const_iterator i = opts.begin();
  1202. i != opts.end(); ++i)
  1203. {
  1204. if(r.find(i->c_str()))
  1205. {
  1206. // (Re-)Escape this flag. COMPILE_FLAGS were already parsed
  1207. // as a command line above, and COMPILE_OPTIONS are escaped.
  1208. this->AppendFlagEscape(flags, *i);
  1209. }
  1210. }
  1211. }
  1212. else
  1213. {
  1214. // Use all flags.
  1215. if(const char* targetFlags = target->GetProperty("COMPILE_FLAGS"))
  1216. {
  1217. // COMPILE_FLAGS are not escaped for historical reasons.
  1218. this->AppendFlags(flags, targetFlags);
  1219. }
  1220. std::vector<std::string> opts;
  1221. target->GetCompileOptions(opts, config, lang);
  1222. for(std::vector<std::string>::const_iterator i = opts.begin();
  1223. i != opts.end(); ++i)
  1224. {
  1225. // COMPILE_OPTIONS are escaped.
  1226. this->AppendFlagEscape(flags, *i);
  1227. }
  1228. }
  1229. std::vector<std::string> features;
  1230. target->GetCompileFeatures(features, config);
  1231. for(std::vector<std::string>::const_iterator it = features.begin();
  1232. it != features.end(); ++it)
  1233. {
  1234. if (!this->Makefile->AddRequiredTargetFeature(target, *it))
  1235. {
  1236. return;
  1237. }
  1238. }
  1239. for(std::map<std::string, std::string>::const_iterator it
  1240. = target->GetMaxLanguageStandards().begin();
  1241. it != target->GetMaxLanguageStandards().end(); ++it)
  1242. {
  1243. const char* standard = target->GetProperty(it->first + "_STANDARD");
  1244. if(!standard)
  1245. {
  1246. continue;
  1247. }
  1248. if (this->Makefile->IsLaterStandard(it->first, standard, it->second))
  1249. {
  1250. std::ostringstream e;
  1251. e << "The COMPILE_FEATURES property of target \""
  1252. << target->GetName() << "\" was evaluated when computing the link "
  1253. "implementation, and the \"" << it->first << "_STANDARD\" was \""
  1254. << it->second << "\" for that computation. Computing the "
  1255. "COMPILE_FEATURES based on the link implementation resulted in a "
  1256. "higher \"" << it->first << "_STANDARD\" \"" << standard << "\". "
  1257. "This is not permitted. The COMPILE_FEATURES may not both depend on "
  1258. "and be depended on by the link implementation." << std::endl;
  1259. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  1260. return;
  1261. }
  1262. }
  1263. this->AddCompilerRequirementFlag(flags, target, lang);
  1264. }
  1265. //----------------------------------------------------------------------------
  1266. void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
  1267. cmGeneratorTarget* target,
  1268. const std::string& lang,
  1269. const std::string& config,
  1270. bool stripImplicitInclDirs
  1271. )
  1272. {
  1273. // Need to decide whether to automatically include the source and
  1274. // binary directories at the beginning of the include path.
  1275. bool includeSourceDir = false;
  1276. bool includeBinaryDir = false;
  1277. // When automatic include directories are requested for a build then
  1278. // include the source and binary directories at the beginning of the
  1279. // include path to approximate include file behavior for an
  1280. // in-source build. This does not account for the case of a source
  1281. // file in a subdirectory of the current source directory but we
  1282. // cannot fix this because not all native build tools support
  1283. // per-source-file include paths.
  1284. if(this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
  1285. {
  1286. includeSourceDir = true;
  1287. includeBinaryDir = true;
  1288. }
  1289. // Do not repeat an include path.
  1290. std::set<std::string> emitted;
  1291. // Store the automatic include paths.
  1292. if(includeBinaryDir)
  1293. {
  1294. if(emitted.find(
  1295. this->StateSnapshot.GetCurrentBinaryDirectory()) == emitted.end())
  1296. {
  1297. dirs.push_back(this->StateSnapshot.GetCurrentBinaryDirectory());
  1298. emitted.insert(this->StateSnapshot.GetCurrentBinaryDirectory());
  1299. }
  1300. }
  1301. if(includeSourceDir)
  1302. {
  1303. if(emitted.find(
  1304. this->StateSnapshot.GetCurrentSourceDirectory()) == emitted.end())
  1305. {
  1306. dirs.push_back(this->StateSnapshot.GetCurrentSourceDirectory());
  1307. emitted.insert(this->StateSnapshot.GetCurrentSourceDirectory());
  1308. }
  1309. }
  1310. if(!target)
  1311. {
  1312. return;
  1313. }
  1314. std::string rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
  1315. std::vector<std::string> implicitDirs;
  1316. // Load implicit include directories for this language.
  1317. std::string impDirVar = "CMAKE_";
  1318. impDirVar += lang;
  1319. impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES";
  1320. if(const char* value = this->Makefile->GetDefinition(impDirVar))
  1321. {
  1322. std::vector<std::string> impDirVec;
  1323. cmSystemTools::ExpandListArgument(value, impDirVec);
  1324. for(std::vector<std::string>::const_iterator i = impDirVec.begin();
  1325. i != impDirVec.end(); ++i)
  1326. {
  1327. std::string d = rootPath + *i;
  1328. cmSystemTools::ConvertToUnixSlashes(d);
  1329. emitted.insert(d);
  1330. if (!stripImplicitInclDirs)
  1331. {
  1332. implicitDirs.push_back(*i);
  1333. }
  1334. }
  1335. }
  1336. // Get the target-specific include directories.
  1337. std::vector<std::string> includes;
  1338. includes = target->GetIncludeDirectories(config, lang);
  1339. // Support putting all the in-project include directories first if
  1340. // it is requested by the project.
  1341. if(this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
  1342. {
  1343. const char* topSourceDir = this->GetState()->GetSourceDirectory();
  1344. const char* topBinaryDir = this->GetState()->GetBinaryDirectory();
  1345. for(std::vector<std::string>::const_iterator i = includes.begin();
  1346. i != includes.end(); ++i)
  1347. {
  1348. // Emit this directory only if it is a subdirectory of the
  1349. // top-level source or binary tree.
  1350. if(cmSystemTools::ComparePath(*i, topSourceDir) ||
  1351. cmSystemTools::ComparePath(*i, topBinaryDir) ||
  1352. cmSystemTools::IsSubDirectory(*i, topSourceDir) ||
  1353. cmSystemTools::IsSubDirectory(*i, topBinaryDir))
  1354. {
  1355. if(emitted.insert(*i).second)
  1356. {
  1357. dirs.push_back(*i);
  1358. }
  1359. }
  1360. }
  1361. }
  1362. // Construct the final ordered include directory list.
  1363. for(std::vector<std::string>::const_iterator i = includes.begin();
  1364. i != includes.end(); ++i)
  1365. {
  1366. if(emitted.insert(*i).second)
  1367. {
  1368. dirs.push_back(*i);
  1369. }
  1370. }
  1371. for(std::vector<std::string>::const_iterator i = implicitDirs.begin();
  1372. i != implicitDirs.end(); ++i)
  1373. {
  1374. if(std::find(includes.begin(), includes.end(), *i) != includes.end())
  1375. {
  1376. dirs.push_back(*i);
  1377. }
  1378. }
  1379. }
  1380. void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
  1381. std::string const& config,
  1382. cmTarget* target)
  1383. {
  1384. this->AppendFlags(flags,
  1385. this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS"));
  1386. if(!config.empty())
  1387. {
  1388. std::string name = "CMAKE_STATIC_LINKER_FLAGS_" + config;
  1389. this->AppendFlags(flags, this->Makefile->GetSafeDefinition(name));
  1390. }
  1391. this->AppendFlags(flags, target->GetProperty("STATIC_LIBRARY_FLAGS"));
  1392. if(!config.empty())
  1393. {
  1394. std::string name = "STATIC_LIBRARY_FLAGS_" + config;
  1395. this->AppendFlags(flags, target->GetProperty(name));
  1396. }
  1397. }
  1398. void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
  1399. std::string& flags,
  1400. std::string& linkFlags,
  1401. std::string& frameworkPath,
  1402. std::string& linkPath,
  1403. cmGeneratorTarget* target,
  1404. bool useWatcomQuote)
  1405. {
  1406. std::string buildType =
  1407. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1408. buildType = cmSystemTools::UpperCase(buildType);
  1409. const char* libraryLinkVariable =
  1410. "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
  1411. switch(target->GetType())
  1412. {
  1413. case cmTarget::STATIC_LIBRARY:
  1414. this->GetStaticLibraryFlags(linkFlags, buildType, target->Target);
  1415. break;
  1416. case cmTarget::MODULE_LIBRARY:
  1417. libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
  1418. case cmTarget::SHARED_LIBRARY:
  1419. {
  1420. linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
  1421. linkFlags += " ";
  1422. if(!buildType.empty())
  1423. {
  1424. std::string build = libraryLinkVariable;
  1425. build += "_";
  1426. build += buildType;
  1427. linkFlags += this->Makefile->GetSafeDefinition(build);
  1428. linkFlags += " ";
  1429. }
  1430. if(this->Makefile->IsOn("WIN32") &&
  1431. !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
  1432. {
  1433. std::vector<cmSourceFile*> sources;
  1434. target->GetSourceFiles(sources, buildType);
  1435. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1436. i != sources.end(); ++i)
  1437. {
  1438. cmSourceFile* sf = *i;
  1439. if(sf->GetExtension() == "def")
  1440. {
  1441. linkFlags +=
  1442. this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1443. linkFlags += this->Convert(sf->GetFullPath(),
  1444. FULL, SHELL);
  1445. linkFlags += " ";
  1446. }
  1447. }
  1448. }
  1449. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  1450. if(targetLinkFlags)
  1451. {
  1452. linkFlags += targetLinkFlags;
  1453. linkFlags += " ";
  1454. }
  1455. if(!buildType.empty())
  1456. {
  1457. std::string configLinkFlags = "LINK_FLAGS_";
  1458. configLinkFlags += buildType;
  1459. targetLinkFlags = target->GetProperty(configLinkFlags);
  1460. if(targetLinkFlags)
  1461. {
  1462. linkFlags += targetLinkFlags;
  1463. linkFlags += " ";
  1464. }
  1465. }
  1466. this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
  1467. *target, false, false, useWatcomQuote);
  1468. }
  1469. break;
  1470. case cmTarget::EXECUTABLE:
  1471. {
  1472. linkFlags +=
  1473. this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1474. linkFlags += " ";
  1475. if(!buildType.empty())
  1476. {
  1477. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1478. build += buildType;
  1479. linkFlags += this->Makefile->GetSafeDefinition(build);
  1480. linkFlags += " ";
  1481. }
  1482. std::string linkLanguage = target->Target->GetLinkerLanguage(buildType);
  1483. if(linkLanguage.empty())
  1484. {
  1485. cmSystemTools::Error
  1486. ("CMake can not determine linker language for target: ",
  1487. target->Target->GetName().c_str());
  1488. return;
  1489. }
  1490. this->AddLanguageFlags(flags, linkLanguage, buildType);
  1491. this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
  1492. *target, false, false, useWatcomQuote);
  1493. if(cmSystemTools::IsOn
  1494. (this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1495. {
  1496. std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_")
  1497. + linkLanguage + std::string("_FLAGS");
  1498. linkFlags += this->Makefile->GetSafeDefinition(sFlagVar);
  1499. linkFlags += " ";
  1500. }
  1501. if ( target->GetPropertyAsBool("WIN32_EXECUTABLE") )
  1502. {
  1503. linkFlags +=
  1504. this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1505. linkFlags += " ";
  1506. }
  1507. else
  1508. {
  1509. linkFlags +=
  1510. this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1511. linkFlags += " ";
  1512. }
  1513. if (target->Target->IsExecutableWithExports())
  1514. {
  1515. std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
  1516. exportFlagVar += linkLanguage;
  1517. exportFlagVar += "_FLAG";
  1518. linkFlags +=
  1519. this->Makefile->GetSafeDefinition(exportFlagVar);
  1520. linkFlags += " ";
  1521. }
  1522. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  1523. if(targetLinkFlags)
  1524. {
  1525. linkFlags += targetLinkFlags;
  1526. linkFlags += " ";
  1527. }
  1528. if(!buildType.empty())
  1529. {
  1530. std::string configLinkFlags = "LINK_FLAGS_";
  1531. configLinkFlags += buildType;
  1532. targetLinkFlags = target->GetProperty(configLinkFlags);
  1533. if(targetLinkFlags)
  1534. {
  1535. linkFlags += targetLinkFlags;
  1536. linkFlags += " ";
  1537. }
  1538. }
  1539. }
  1540. break;
  1541. default:
  1542. break;
  1543. }
  1544. }
  1545. std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib,
  1546. OutputFormat format)
  1547. {
  1548. #if defined(_WIN32) && !defined(__CYGWIN__)
  1549. // Work-ardound command line parsing limitations in MSVC 6.0
  1550. if(this->Makefile->IsOn("MSVC60"))
  1551. {
  1552. // Search for the last space.
  1553. std::string::size_type pos = lib.rfind(' ');
  1554. if(pos != lib.npos)
  1555. {
  1556. // Find the slash after the last space, if any.
  1557. pos = lib.find('/', pos);
  1558. // Convert the portion of the path with a space to a short path.
  1559. std::string sp;
  1560. if(cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp))
  1561. {
  1562. // Append the rest of the path with no space.
  1563. sp += lib.substr(pos);
  1564. // Convert to an output path.
  1565. return this->Convert(sp.c_str(), NONE, format);
  1566. }
  1567. }
  1568. }
  1569. #endif
  1570. // Normal behavior.
  1571. return this->Convert(lib, START_OUTPUT, format);
  1572. }
  1573. /**
  1574. * Output the linking rules on a command line. For executables,
  1575. * targetLibrary should be a NULL pointer. For libraries, it should point
  1576. * to the name of the library. This will not link a library against itself.
  1577. */
  1578. void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
  1579. std::string& frameworkPath,
  1580. std::string& linkPath,
  1581. cmGeneratorTarget &tgt,
  1582. bool relink,
  1583. bool forResponseFile,
  1584. bool useWatcomQuote)
  1585. {
  1586. OutputFormat shellFormat = (forResponseFile) ? RESPONSE :
  1587. ((useWatcomQuote) ? WATCOMQUOTE : SHELL);
  1588. bool escapeAllowMakeVars = !forResponseFile;
  1589. std::ostringstream fout;
  1590. std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1591. cmComputeLinkInformation* pcli = tgt.Target->GetLinkInformation(config);
  1592. if(!pcli)
  1593. {
  1594. return;
  1595. }
  1596. cmComputeLinkInformation& cli = *pcli;
  1597. // Collect library linking flags command line options.
  1598. std::string linkLibs;
  1599. std::string linkLanguage = cli.GetLinkLanguage();
  1600. std::string libPathFlag =
  1601. this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
  1602. std::string libPathTerminator =
  1603. this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
  1604. // Flags to link an executable to shared libraries.
  1605. std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
  1606. linkFlagsVar += linkLanguage;
  1607. linkFlagsVar += "_FLAGS";
  1608. if( tgt.GetType() == cmTarget::EXECUTABLE )
  1609. {
  1610. linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar);
  1611. linkLibs += " ";
  1612. }
  1613. // Append the framework search path flags.
  1614. std::string fwSearchFlagVar = "CMAKE_";
  1615. fwSearchFlagVar += linkLanguage;
  1616. fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
  1617. const char* fwSearchFlag =
  1618. this->Makefile->GetDefinition(fwSearchFlagVar);
  1619. if(fwSearchFlag && *fwSearchFlag)
  1620. {
  1621. std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
  1622. for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
  1623. fdi != fwDirs.end(); ++fdi)
  1624. {
  1625. frameworkPath += fwSearchFlag;
  1626. frameworkPath += this->Convert(*fdi, NONE, shellFormat);
  1627. frameworkPath += " ";
  1628. }
  1629. }
  1630. // Append the library search path flags.
  1631. std::vector<std::string> const& libDirs = cli.GetDirectories();
  1632. for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
  1633. libDir != libDirs.end(); ++libDir)
  1634. {
  1635. std::string libpath = this->ConvertToOutputForExisting(*libDir,
  1636. START_OUTPUT,
  1637. shellFormat);
  1638. linkPath += " " + libPathFlag;
  1639. linkPath += libpath;
  1640. linkPath += libPathTerminator;
  1641. linkPath += " ";
  1642. }
  1643. // Append the link items.
  1644. typedef cmComputeLinkInformation::ItemVector ItemVector;
  1645. ItemVector const& items = cli.GetItems();
  1646. for(ItemVector::const_iterator li = items.begin(); li != items.end(); ++li)
  1647. {
  1648. if(li->Target && li->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  1649. {
  1650. continue;
  1651. }
  1652. if(li->IsPath)
  1653. {
  1654. linkLibs += this->ConvertToLinkReference(li->Value, shellFormat);
  1655. }
  1656. else
  1657. {
  1658. linkLibs += li->Value;
  1659. }
  1660. linkLibs += " ";
  1661. }
  1662. // Write the library flags to the build rule.
  1663. fout << linkLibs;
  1664. // Check what kind of rpath flags to use.
  1665. if(cli.GetRuntimeSep().empty())
  1666. {
  1667. // Each rpath entry gets its own option ("-R a -R b -R c")
  1668. std::vector<std::string> runtimeDirs;
  1669. cli.GetRPath(runtimeDirs, relink);
  1670. std::string rpath;
  1671. for(std::vector<std::string>::iterator ri = runtimeDirs.begin();
  1672. ri != runtimeDirs.end(); ++ri)
  1673. {
  1674. rpath += cli.GetRuntimeFlag();
  1675. rpath += this->Convert(*ri, NONE, shellFormat);
  1676. rpath += " ";
  1677. }
  1678. fout << rpath;
  1679. }
  1680. else
  1681. {
  1682. // All rpath entries are combined ("-Wl,-rpath,a:b:c").
  1683. std::string rpath = cli.GetRPathString(relink);
  1684. // Store the rpath option in the stream.
  1685. if(!rpath.empty())
  1686. {
  1687. fout << cli.GetRuntimeFlag();
  1688. fout << this->EscapeForShell(rpath, escapeAllowMakeVars);
  1689. fout << " ";
  1690. }
  1691. }
  1692. // Add the linker runtime search path if any.
  1693. std::string rpath_link = cli.GetRPathLinkString();
  1694. if(!cli.GetRPathLinkFlag().empty() && !rpath_link.empty())
  1695. {
  1696. fout << cli.GetRPathLinkFlag();
  1697. fout << this->EscapeForShell(rpath_link, escapeAllowMakeVars);
  1698. fout << " ";
  1699. }
  1700. // Add standard libraries for this language.
  1701. std::string standardLibsVar = "CMAKE_";
  1702. standardLibsVar += cli.GetLinkLanguage();
  1703. standardLibsVar += "_STANDARD_LIBRARIES";
  1704. if(const char* stdLibs =
  1705. this->Makefile->GetDefinition(standardLibsVar))
  1706. {
  1707. fout << stdLibs << " ";
  1708. }
  1709. linkLibraries = fout.str();
  1710. }
  1711. //----------------------------------------------------------------------------
  1712. void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
  1713. cmGeneratorTarget const* target,
  1714. const std::string& lang,
  1715. const std::string& config)
  1716. {
  1717. // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone):
  1718. if(!this->Makefile->IsOn("APPLE"))
  1719. {
  1720. return;
  1721. }
  1722. if(this->EmitUniversalBinaryFlags)
  1723. {
  1724. std::vector<std::string> archs;
  1725. target->GetAppleArchs(config, archs);
  1726. const char* sysroot = this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
  1727. if(sysroot && sysroot[0] == '/' && !sysroot[1])
  1728. { sysroot = 0; }
  1729. std::string sysrootFlagVar =
  1730. std::string("CMAKE_") + lang + "_SYSROOT_FLAG";
  1731. const char* sysrootFlag =
  1732. this->Makefile->GetDefinition(sysrootFlagVar);
  1733. const char* deploymentTarget =
  1734. this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
  1735. std::string deploymentTargetFlagVar =
  1736. std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG";
  1737. const char* deploymentTargetFlag =
  1738. this->Makefile->GetDefinition(deploymentTargetFlagVar);
  1739. if(!archs.empty() && !lang.empty() && (lang[0] =='C' || lang[0] == 'F'))
  1740. {
  1741. for(std::vector<std::string>::iterator i = archs.begin();
  1742. i != archs.end(); ++i)
  1743. {
  1744. flags += " -arch ";
  1745. flags += *i;
  1746. }
  1747. }
  1748. if(sysrootFlag && *sysrootFlag && sysroot && *sysroot)
  1749. {
  1750. flags += " ";
  1751. flags += sysrootFlag;
  1752. flags += " ";
  1753. flags += this->Convert(sysroot, NONE, SHELL);
  1754. }
  1755. if (deploymentTargetFlag && *deploymentTargetFlag &&
  1756. deploymentTarget && *deploymentTarget)
  1757. {
  1758. flags += " ";
  1759. flags += deploymentTargetFlag;
  1760. flags += deploymentTarget;
  1761. }
  1762. }
  1763. }
  1764. //----------------------------------------------------------------------------
  1765. void cmLocalGenerator::AddLanguageFlags(std::string& flags,
  1766. const std::string& lang,
  1767. const std::string& config)
  1768. {
  1769. // Add language-specific flags.
  1770. std::string flagsVar = "CMAKE_";
  1771. flagsVar += lang;
  1772. flagsVar += "_FLAGS";
  1773. this->AddConfigVariableFlags(flags, flagsVar, config);
  1774. }
  1775. //----------------------------------------------------------------------------
  1776. bool cmLocalGenerator::GetRealDependency(const std::string& inName,
  1777. const std::string& config,
  1778. std::string& dep)
  1779. {
  1780. // Older CMake code may specify the dependency using the target
  1781. // output file rather than the target name. Such code would have
  1782. // been written before there was support for target properties that
  1783. // modify the name so stripping down to just the file name should
  1784. // produce the target name in this case.
  1785. std::string name = cmSystemTools::GetFilenameName(inName);
  1786. // If the input name is the empty string, there is no real
  1787. // dependency. Short-circuit the other checks:
  1788. if(name == "")
  1789. {
  1790. return false;
  1791. }
  1792. if(cmSystemTools::GetFilenameLastExtension(name) == ".exe")
  1793. {
  1794. name = cmSystemTools::GetFilenameWithoutLastExtension(name);
  1795. }
  1796. // Look for a CMake target with the given name.
  1797. if(cmTarget* target = this->Makefile->FindTargetToUse(name))
  1798. {
  1799. // make sure it is not just a coincidence that the target name
  1800. // found is part of the inName
  1801. if(cmSystemTools::FileIsFullPath(inName.c_str()))
  1802. {
  1803. std::string tLocation;
  1804. if(target->GetType() >= cmTarget::EXECUTABLE &&
  1805. target->GetType() <= cmTarget::MODULE_LIBRARY)
  1806. {
  1807. tLocation = target->GetLocation(config);
  1808. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1809. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  1810. }
  1811. std::string depLocation = cmSystemTools::GetFilenamePath(
  1812. std::string(inName));
  1813. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  1814. if(depLocation != tLocation)
  1815. {
  1816. // it is a full path to a depend that has the same name
  1817. // as a target but is in a different location so do not use
  1818. // the target as the depend
  1819. dep = inName;
  1820. return true;
  1821. }
  1822. }
  1823. switch (target->GetType())
  1824. {
  1825. case cmTarget::EXECUTABLE:
  1826. case cmTarget::STATIC_LIBRARY:
  1827. case cmTarget::SHARED_LIBRARY:
  1828. case cmTarget::MODULE_LIBRARY:
  1829. case cmTarget::UNKNOWN_LIBRARY:
  1830. dep = target->GetLocation(config);
  1831. return true;
  1832. case cmTarget::OBJECT_LIBRARY:
  1833. // An object library has no single file on which to depend.
  1834. // This was listed to get the target-level dependency.
  1835. return false;
  1836. case cmTarget::INTERFACE_LIBRARY:
  1837. // An interface library has no file on which to depend.
  1838. // This was listed to get the target-level dependency.
  1839. return false;
  1840. case cmTarget::UTILITY:
  1841. case cmTarget::GLOBAL_TARGET:
  1842. // A utility target has no file on which to depend. This was listed
  1843. // only to get the target-level dependency.
  1844. return false;
  1845. }
  1846. }
  1847. // The name was not that of a CMake target. It must name a file.
  1848. if(cmSystemTools::FileIsFullPath(inName.c_str()))
  1849. {
  1850. // This is a full path. Return it as given.
  1851. dep = inName;
  1852. return true;
  1853. }
  1854. // Check for a source file in this directory that matches the
  1855. // dependency.
  1856. if(cmSourceFile* sf = this->Makefile->GetSource(inName))
  1857. {
  1858. dep = sf->GetFullPath();
  1859. return true;
  1860. }
  1861. // Treat the name as relative to the source directory in which it
  1862. // was given.
  1863. dep = this->StateSnapshot.GetCurrentSourceDirectory();
  1864. dep += "/";
  1865. dep += inName;
  1866. return true;
  1867. }
  1868. //----------------------------------------------------------------------------
  1869. void cmLocalGenerator::AddSharedFlags(std::string& flags,
  1870. const std::string& lang,
  1871. bool shared)
  1872. {
  1873. std::string flagsVar;
  1874. // Add flags for dealing with shared libraries for this language.
  1875. if(shared)
  1876. {
  1877. flagsVar = "CMAKE_SHARED_LIBRARY_";
  1878. flagsVar += lang;
  1879. flagsVar += "_FLAGS";
  1880. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  1881. }
  1882. }
  1883. //----------------------------------------------------------------------------
  1884. void cmLocalGenerator::
  1885. AddCompilerRequirementFlag(std::string &flags, cmTarget const* target,
  1886. const std::string& lang)
  1887. {
  1888. if (lang.empty())
  1889. {
  1890. return;
  1891. }
  1892. const char* defaultStd
  1893. = this->Makefile->GetDefinition("CMAKE_" + lang + "_STANDARD_DEFAULT");
  1894. if (!defaultStd || !*defaultStd)
  1895. {
  1896. // This compiler has no notion of language standard levels.
  1897. return;
  1898. }
  1899. std::string stdProp = lang + "_STANDARD";
  1900. const char *standardProp = target->GetProperty(stdProp);
  1901. if (!standardProp)
  1902. {
  1903. return;
  1904. }
  1905. std::string extProp = lang + "_EXTENSIONS";
  1906. std::string type = "EXTENSION";
  1907. bool ext = true;
  1908. if (const char* extPropValue = target->GetProperty(extProp))
  1909. {
  1910. if (cmSystemTools::IsOff(extPropValue))
  1911. {
  1912. ext = false;
  1913. type = "STANDARD";
  1914. }
  1915. }
  1916. if (target->GetPropertyAsBool(lang + "_STANDARD_REQUIRED"))
  1917. {
  1918. std::string option_flag =
  1919. "CMAKE_" + lang + standardProp
  1920. + "_" + type + "_COMPILE_OPTION";
  1921. const char *opt = target->GetMakefile()->GetDefinition(option_flag);
  1922. if (!opt)
  1923. {
  1924. std::ostringstream e;
  1925. e << "Target \"" << target->GetName() << "\" requires the language "
  1926. "dialect \"" << lang << standardProp << "\" "
  1927. << (ext ? "(with compiler extensions)" : "") << ", but CMake "
  1928. "does not know the compile flags to use to enable it.";
  1929. this->IssueMessage(cmake::FATAL_ERROR, e.str());
  1930. }
  1931. else
  1932. {
  1933. this->AppendFlagEscape(flags, opt);
  1934. }
  1935. return;
  1936. }
  1937. static std::map<std::string, std::vector<std::string> > langStdMap;
  1938. if (langStdMap.empty())
  1939. {
  1940. // Maintain sorted order, most recent first.
  1941. langStdMap["CXX"].push_back("14");
  1942. langStdMap["CXX"].push_back("11");
  1943. langStdMap["CXX"].push_back("98");
  1944. langStdMap["C"].push_back("11");
  1945. langStdMap["C"].push_back("99");
  1946. langStdMap["C"].push_back("90");
  1947. }
  1948. std::string standard(standardProp);
  1949. std::vector<std::string>& stds = langStdMap[lang];
  1950. std::vector<std::string>::const_iterator stdIt =
  1951. std::find(stds.begin(), stds.end(), standard);
  1952. if (stdIt == stds.end())
  1953. {
  1954. std::string e =
  1955. lang + "_STANDARD is set to invalid value '" + standard + "'";
  1956. this->GetGlobalGenerator()->GetCMakeInstance()
  1957. ->IssueMessage(cmake::FATAL_ERROR, e, target->GetBacktrace());
  1958. return;
  1959. }
  1960. std::vector<std::string>::const_iterator defaultStdIt =
  1961. std::find(stds.begin(), stds.end(), defaultStd);
  1962. if (defaultStdIt == stds.end())
  1963. {
  1964. std::string e =
  1965. "CMAKE_" + lang + "_STANDARD_DEFAULT is set to invalid value '" +
  1966. std::string(defaultStd) + "'";
  1967. this->IssueMessage(cmake::INTERNAL_ERROR, e);
  1968. return;
  1969. }
  1970. // Greater or equal because the standards are stored in
  1971. // backward chronological order.
  1972. if (stdIt >= defaultStdIt)
  1973. {
  1974. std::string option_flag =
  1975. "CMAKE_" + lang + *stdIt
  1976. + "_" + type + "_COMPILE_OPTION";
  1977. const char *opt =
  1978. target->GetMakefile()->GetRequiredDefinition(option_flag);
  1979. this->AppendFlagEscape(flags, opt);
  1980. return;
  1981. }
  1982. for ( ; stdIt < defaultStdIt; ++stdIt)
  1983. {
  1984. std::string option_flag =
  1985. "CMAKE_" + lang + *stdIt
  1986. + "_" + type + "_COMPILE_OPTION";
  1987. if (const char *opt = target->GetMakefile()->GetDefinition(option_flag))
  1988. {
  1989. this->AppendFlagEscape(flags, opt);
  1990. return;
  1991. }
  1992. }
  1993. }
  1994. static void AddVisibilityCompileOption(std::string &flags,
  1995. cmTarget const* target,
  1996. cmLocalGenerator *lg,
  1997. const std::string& lang,
  1998. std::string* warnCMP0063)
  1999. {
  2000. std::string l(lang);
  2001. std::string compileOption = "CMAKE_" + l + "_COMPILE_OPTIONS_VISIBILITY";
  2002. const char *opt = lg->GetMakefile()->GetDefinition(compileOption);
  2003. if (!opt)
  2004. {
  2005. return;
  2006. }
  2007. std::string flagDefine = l + "_VISIBILITY_PRESET";
  2008. const char *prop = target->GetProperty(flagDefine);
  2009. if (!prop)
  2010. {
  2011. return;
  2012. }
  2013. if (warnCMP0063)
  2014. {
  2015. *warnCMP0063 += " " + flagDefine + "\n";
  2016. return;
  2017. }
  2018. if (strcmp(prop, "hidden") != 0
  2019. && strcmp(prop, "default") != 0
  2020. && strcmp(prop, "protected") != 0
  2021. && strcmp(prop, "internal") != 0 )
  2022. {
  2023. std::ostringstream e;
  2024. e << "Target " << target->GetName() << " uses unsupported value \""
  2025. << prop << "\" for " << flagDefine << ".";
  2026. cmSystemTools::Error(e.str().c_str());
  2027. return;
  2028. }
  2029. std::string option = std::string(opt) + prop;
  2030. lg->AppendFlags(flags, option);
  2031. }
  2032. static void AddInlineVisibilityCompileOption(std::string &flags,
  2033. cmTarget const* target,
  2034. cmLocalGenerator *lg,
  2035. std::string* warnCMP0063)
  2036. {
  2037. std::string compileOption
  2038. = "CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN";
  2039. const char *opt = lg->GetMakefile()->GetDefinition(compileOption);
  2040. if (!opt)
  2041. {
  2042. return;
  2043. }
  2044. bool prop = target->GetPropertyAsBool("VISIBILITY_INLINES_HIDDEN");
  2045. if (!prop)
  2046. {
  2047. return;
  2048. }
  2049. if (warnCMP0063)
  2050. {
  2051. *warnCMP0063 += " VISIBILITY_INLINES_HIDDEN\n";
  2052. return;
  2053. }
  2054. lg->AppendFlags(flags, opt);
  2055. }
  2056. //----------------------------------------------------------------------------
  2057. void cmLocalGenerator
  2058. ::AddVisibilityPresetFlags(std::string &flags, cmTarget const* target,
  2059. const std::string& lang)
  2060. {
  2061. if (lang.empty())
  2062. {
  2063. return;
  2064. }
  2065. std::string warnCMP0063;
  2066. std::string *pWarnCMP0063 = 0;
  2067. if (target->GetType() != cmTarget::SHARED_LIBRARY &&
  2068. target->GetType() != cmTarget::MODULE_LIBRARY &&
  2069. !target->IsExecutableWithExports())
  2070. {
  2071. switch (target->GetPolicyStatusCMP0063())
  2072. {
  2073. case cmPolicies::OLD:
  2074. return;
  2075. case cmPolicies::WARN:
  2076. pWarnCMP0063 = &warnCMP0063;
  2077. break;
  2078. default:
  2079. break;
  2080. }
  2081. }
  2082. AddVisibilityCompileOption(flags, target, this, lang, pWarnCMP0063);
  2083. if(lang == "CXX")
  2084. {
  2085. AddInlineVisibilityCompileOption(flags, target, this, pWarnCMP0063);
  2086. }
  2087. if (!warnCMP0063.empty() &&
  2088. this->WarnCMP0063.insert(target).second)
  2089. {
  2090. std::ostringstream w;
  2091. w <<
  2092. cmPolicies::GetPolicyWarning(cmPolicies::CMP0063) << "\n"
  2093. "Target \"" << target->GetName() << "\" of "
  2094. "type \"" << cmTarget::GetTargetTypeName(target->GetType()) << "\" "
  2095. "has the following visibility properties set for " << lang << ":\n" <<
  2096. warnCMP0063 <<
  2097. "For compatibility CMake is not honoring them for this target.";
  2098. target->GetMakefile()->GetCMakeInstance()
  2099. ->IssueMessage(cmake::AUTHOR_WARNING, w.str(), target->GetBacktrace());
  2100. }
  2101. }
  2102. //----------------------------------------------------------------------------
  2103. void cmLocalGenerator::AddCMP0018Flags(std::string &flags,
  2104. cmTarget const* target,
  2105. std::string const& lang,
  2106. const std::string& config)
  2107. {
  2108. int targetType = target->GetType();
  2109. bool shared = ((targetType == cmTarget::SHARED_LIBRARY) ||
  2110. (targetType == cmTarget::MODULE_LIBRARY));
  2111. if (this->GetShouldUseOldFlags(shared, lang))
  2112. {
  2113. this->AddSharedFlags(flags, lang, shared);
  2114. }
  2115. else
  2116. {
  2117. if (target->GetType() == cmTarget::OBJECT_LIBRARY)
  2118. {
  2119. if (target->GetPropertyAsBool("POSITION_INDEPENDENT_CODE"))
  2120. {
  2121. this->AddPositionIndependentFlags(flags, lang, targetType);
  2122. }
  2123. return;
  2124. }
  2125. if (target->GetLinkInterfaceDependentBoolProperty(
  2126. "POSITION_INDEPENDENT_CODE",
  2127. config))
  2128. {
  2129. this->AddPositionIndependentFlags(flags, lang, targetType);
  2130. }
  2131. if (shared)
  2132. {
  2133. this->AppendFeatureOptions(flags, lang, "DLL");
  2134. }
  2135. }
  2136. }
  2137. //----------------------------------------------------------------------------
  2138. bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
  2139. const std::string &lang) const
  2140. {
  2141. std::string originalFlags =
  2142. this->GlobalGenerator->GetSharedLibFlagsForLanguage(lang);
  2143. if (shared)
  2144. {
  2145. std::string flagsVar = "CMAKE_SHARED_LIBRARY_";
  2146. flagsVar += lang;
  2147. flagsVar += "_FLAGS";
  2148. const char* flags =
  2149. this->Makefile->GetSafeDefinition(flagsVar);
  2150. if (flags && flags != originalFlags)
  2151. {
  2152. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0018))
  2153. {
  2154. case cmPolicies::WARN:
  2155. {
  2156. std::ostringstream e;
  2157. e << "Variable " << flagsVar << " has been modified. CMake "
  2158. "will ignore the POSITION_INDEPENDENT_CODE target property for "
  2159. "shared libraries and will use the " << flagsVar << " variable "
  2160. "instead. This may cause errors if the original content of "
  2161. << flagsVar << " was removed.\n"
  2162. << cmPolicies::GetPolicyWarning(cmPolicies::CMP0018);
  2163. this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  2164. // fall through to OLD behaviour
  2165. }
  2166. case cmPolicies::OLD:
  2167. return true;
  2168. case cmPolicies::REQUIRED_IF_USED:
  2169. case cmPolicies::REQUIRED_ALWAYS:
  2170. case cmPolicies::NEW:
  2171. return false;
  2172. }
  2173. }
  2174. }
  2175. return false;
  2176. }
  2177. //----------------------------------------------------------------------------
  2178. void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
  2179. std::string const& lang,
  2180. int targetType)
  2181. {
  2182. const char* picFlags = 0;
  2183. if(targetType == cmTarget::EXECUTABLE)
  2184. {
  2185. std::string flagsVar = "CMAKE_";
  2186. flagsVar += lang;
  2187. flagsVar += "_COMPILE_OPTIONS_PIE";
  2188. picFlags = this->Makefile->GetSafeDefinition(flagsVar);
  2189. }
  2190. if (!picFlags)
  2191. {
  2192. std::string flagsVar = "CMAKE_";
  2193. flagsVar += lang;
  2194. flagsVar += "_COMPILE_OPTIONS_PIC";
  2195. picFlags = this->Makefile->GetSafeDefinition(flagsVar);
  2196. }
  2197. if (picFlags)
  2198. {
  2199. std::vector<std::string> options;
  2200. cmSystemTools::ExpandListArgument(picFlags, options);
  2201. for(std::vector<std::string>::const_iterator oi = options.begin();
  2202. oi != options.end(); ++oi)
  2203. {
  2204. this->AppendFlagEscape(flags, *oi);
  2205. }
  2206. }
  2207. }
  2208. //----------------------------------------------------------------------------
  2209. void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
  2210. const std::string& var,
  2211. const std::string& config)
  2212. {
  2213. // Add the flags from the variable itself.
  2214. std::string flagsVar = var;
  2215. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  2216. // Add the flags from the build-type specific variable.
  2217. if(!config.empty())
  2218. {
  2219. flagsVar += "_";
  2220. flagsVar += cmSystemTools::UpperCase(config);
  2221. this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar));
  2222. }
  2223. }
  2224. //----------------------------------------------------------------------------
  2225. void cmLocalGenerator::AppendFlags(std::string& flags,
  2226. const std::string& newFlags)
  2227. {
  2228. if(!newFlags.empty())
  2229. {
  2230. if(!flags.empty())
  2231. {
  2232. flags += " ";
  2233. }
  2234. flags += newFlags;
  2235. }
  2236. }
  2237. //----------------------------------------------------------------------------
  2238. void cmLocalGenerator::AppendFlags(std::string& flags,
  2239. const char* newFlags)
  2240. {
  2241. if(newFlags && *newFlags)
  2242. {
  2243. this->AppendFlags(flags, std::string(newFlags));
  2244. }
  2245. }
  2246. //----------------------------------------------------------------------------
  2247. void cmLocalGenerator::AppendFlagEscape(std::string& flags,
  2248. const std::string& rawFlag)
  2249. {
  2250. this->AppendFlags(flags, this->EscapeForShell(rawFlag));
  2251. }
  2252. //----------------------------------------------------------------------------
  2253. void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
  2254. const char* defines_list)
  2255. {
  2256. // Short-circuit if there are no definitions.
  2257. if(!defines_list)
  2258. {
  2259. return;
  2260. }
  2261. // Expand the list of definitions.
  2262. std::vector<std::string> defines_vec;
  2263. cmSystemTools::ExpandListArgument(defines_list, defines_vec);
  2264. this->AppendDefines(defines, defines_vec);
  2265. }
  2266. //----------------------------------------------------------------------------
  2267. void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
  2268. const std::vector<std::string> &defines_vec)
  2269. {
  2270. for(std::vector<std::string>::const_iterator di = defines_vec.begin();
  2271. di != defines_vec.end(); ++di)
  2272. {
  2273. // Skip unsupported definitions.
  2274. if(!this->CheckDefinition(*di))
  2275. {
  2276. continue;
  2277. }
  2278. defines.insert(*di);
  2279. }
  2280. }
  2281. //----------------------------------------------------------------------------
  2282. void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
  2283. std::string &definesString,
  2284. const std::string& lang)
  2285. {
  2286. // Lookup the define flag for the current language.
  2287. std::string dflag = "-D";
  2288. if(!lang.empty())
  2289. {
  2290. std::string defineFlagVar = "CMAKE_";
  2291. defineFlagVar += lang;
  2292. defineFlagVar += "_DEFINE_FLAG";
  2293. const char* df = this->Makefile->GetDefinition(defineFlagVar);
  2294. if(df && *df)
  2295. {
  2296. dflag = df;
  2297. }
  2298. }
  2299. std::set<std::string>::const_iterator defineIt = defines.begin();
  2300. const std::set<std::string>::const_iterator defineEnd = defines.end();
  2301. const char* itemSeparator = definesString.empty() ? "" : " ";
  2302. for( ; defineIt != defineEnd; ++defineIt)
  2303. {
  2304. // Append the definition with proper escaping.
  2305. std::string def = dflag;
  2306. if(this->GetState()->UseWatcomWMake())
  2307. {
  2308. // The Watcom compiler does its own command line parsing instead
  2309. // of using the windows shell rules. Definitions are one of
  2310. // -DNAME
  2311. // -DNAME=<cpp-token>
  2312. // -DNAME="c-string with spaces and other characters(?@#$)"
  2313. //
  2314. // Watcom will properly parse each of these cases from the
  2315. // command line without any escapes. However we still have to
  2316. // get the '$' and '#' characters through WMake as '$$' and
  2317. // '$#'.
  2318. for(const char* c = defineIt->c_str(); *c; ++c)
  2319. {
  2320. if(*c == '$' || *c == '#')
  2321. {
  2322. def += '$';
  2323. }
  2324. def += *c;
  2325. }
  2326. }
  2327. else
  2328. {
  2329. // Make the definition appear properly on the command line. Use
  2330. // -DNAME="value" instead of -D"NAME=value" to help VS6 parser.
  2331. std::string::size_type eq = defineIt->find("=");
  2332. def += defineIt->substr(0, eq);
  2333. if(eq != defineIt->npos)
  2334. {
  2335. def += "=";
  2336. def += this->EscapeForShell(defineIt->c_str() + eq + 1, true);
  2337. }
  2338. }
  2339. definesString += itemSeparator;
  2340. itemSeparator = " ";
  2341. definesString += def;
  2342. }
  2343. }
  2344. //----------------------------------------------------------------------------
  2345. void cmLocalGenerator::AppendFeatureOptions(
  2346. std::string& flags, const std::string& lang, const char* feature)
  2347. {
  2348. std::string optVar = "CMAKE_";
  2349. optVar += lang;
  2350. optVar += "_COMPILE_OPTIONS_";
  2351. optVar += feature;
  2352. if(const char* optionList = this->Makefile->GetDefinition(optVar))
  2353. {
  2354. std::vector<std::string> options;
  2355. cmSystemTools::ExpandListArgument(optionList, options);
  2356. for(std::vector<std::string>::const_iterator oi = options.begin();
  2357. oi != options.end(); ++oi)
  2358. {
  2359. this->AppendFlagEscape(flags, *oi);
  2360. }
  2361. }
  2362. }
  2363. //----------------------------------------------------------------------------
  2364. const char* cmLocalGenerator::GetFeature(const std::string& feature,
  2365. const std::string& config)
  2366. {
  2367. // TODO: Define accumulation policy for features (prepend, append, replace).
  2368. // Currently we always replace.
  2369. if(!config.empty())
  2370. {
  2371. std::string featureConfig = feature;
  2372. featureConfig += "_";
  2373. featureConfig += cmSystemTools::UpperCase(config);
  2374. if(const char* value = this->Makefile->GetProperty(featureConfig))
  2375. {
  2376. return value;
  2377. }
  2378. }
  2379. if(const char* value = this->Makefile->GetProperty(feature))
  2380. {
  2381. return value;
  2382. }
  2383. if(cmLocalGenerator* parent = this->GetParent())
  2384. {
  2385. return parent->GetFeature(feature, config);
  2386. }
  2387. return 0;
  2388. }
  2389. //----------------------------------------------------------------------------
  2390. std::string
  2391. cmLocalGenerator::ConstructComment(cmCustomCommandGenerator const& ccg,
  2392. const char* default_comment)
  2393. {
  2394. // Check for a comment provided with the command.
  2395. if(ccg.GetComment())
  2396. {
  2397. return ccg.GetComment();
  2398. }
  2399. // Construct a reasonable default comment if possible.
  2400. if(!ccg.GetOutputs().empty())
  2401. {
  2402. std::string comment;
  2403. comment = "Generating ";
  2404. const char* sep = "";
  2405. for(std::vector<std::string>::const_iterator o = ccg.GetOutputs().begin();
  2406. o != ccg.GetOutputs().end(); ++o)
  2407. {
  2408. comment += sep;
  2409. comment += this->Convert(*o, cmLocalGenerator::START_OUTPUT);
  2410. sep = ", ";
  2411. }
  2412. return comment;
  2413. }
  2414. // Otherwise use the provided default.
  2415. return default_comment;
  2416. }
  2417. //----------------------------------------------------------------------------
  2418. class cmInstallTargetGeneratorLocal: public cmInstallTargetGenerator
  2419. {
  2420. public:
  2421. cmInstallTargetGeneratorLocal(cmTarget& t, const char* dest, bool implib):
  2422. cmInstallTargetGenerator(
  2423. t, dest, implib, "", std::vector<std::string>(), "Unspecified",
  2424. cmInstallGenerator::SelectMessageLevel(t.GetMakefile()),
  2425. false) {}
  2426. };
  2427. //----------------------------------------------------------------------------
  2428. void
  2429. cmLocalGenerator
  2430. ::GenerateTargetInstallRules(
  2431. std::ostream& os, const std::string& config,
  2432. std::vector<std::string> const& configurationTypes)
  2433. {
  2434. // Convert the old-style install specification from each target to
  2435. // an install generator and run it.
  2436. cmTargets& tgts = this->Makefile->GetTargets();
  2437. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  2438. {
  2439. if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  2440. {
  2441. continue;
  2442. }
  2443. // Include the user-specified pre-install script for this target.
  2444. if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
  2445. {
  2446. cmInstallScriptGenerator g(preinstall, false, 0);
  2447. g.Generate(os, config, configurationTypes);
  2448. }
  2449. // Install this target if a destination is given.
  2450. if(l->second.GetInstallPath() != "")
  2451. {
  2452. // Compute the full install destination. Note that converting
  2453. // to unix slashes also removes any trailing slash.
  2454. // We also skip over the leading slash given by the user.
  2455. std::string destination = l->second.GetInstallPath().substr(1);
  2456. cmSystemTools::ConvertToUnixSlashes(destination);
  2457. if(destination.empty())
  2458. {
  2459. destination = ".";
  2460. }
  2461. // Generate the proper install generator for this target type.
  2462. switch(l->second.GetType())
  2463. {
  2464. case cmTarget::EXECUTABLE:
  2465. case cmTarget::STATIC_LIBRARY:
  2466. case cmTarget::MODULE_LIBRARY:
  2467. {
  2468. // Use a target install generator.
  2469. cmInstallTargetGeneratorLocal
  2470. g(l->second, destination.c_str(), false);
  2471. g.Generate(os, config, configurationTypes);
  2472. }
  2473. break;
  2474. case cmTarget::SHARED_LIBRARY:
  2475. {
  2476. #if defined(_WIN32) || defined(__CYGWIN__)
  2477. // Special code to handle DLL. Install the import library
  2478. // to the normal destination and the DLL to the runtime
  2479. // destination.
  2480. cmInstallTargetGeneratorLocal
  2481. g1(l->second, destination.c_str(), true);
  2482. g1.Generate(os, config, configurationTypes);
  2483. // We also skip over the leading slash given by the user.
  2484. destination = l->second.GetRuntimeInstallPath().substr(1);
  2485. cmSystemTools::ConvertToUnixSlashes(destination);
  2486. cmInstallTargetGeneratorLocal
  2487. g2(l->second, destination.c_str(), false);
  2488. g2.Generate(os, config, configurationTypes);
  2489. #else
  2490. // Use a target install generator.
  2491. cmInstallTargetGeneratorLocal
  2492. g(l->second, destination.c_str(), false);
  2493. g.Generate(os, config, configurationTypes);
  2494. #endif
  2495. }
  2496. break;
  2497. default:
  2498. break;
  2499. }
  2500. }
  2501. // Include the user-specified post-install script for this target.
  2502. if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
  2503. {
  2504. cmInstallScriptGenerator g(postinstall, false, 0);
  2505. g.Generate(os, config, configurationTypes);
  2506. }
  2507. }
  2508. }
  2509. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2510. static std::string cmLocalGeneratorMD5(const char* input)
  2511. {
  2512. char md5out[32];
  2513. cmsysMD5* md5 = cmsysMD5_New();
  2514. cmsysMD5_Initialize(md5);
  2515. cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
  2516. cmsysMD5_FinalizeHex(md5, md5out);
  2517. cmsysMD5_Delete(md5);
  2518. return std::string(md5out, 32);
  2519. }
  2520. static bool
  2521. cmLocalGeneratorShortenObjectName(std::string& objName,
  2522. std::string::size_type max_len)
  2523. {
  2524. // Replace the beginning of the path portion of the object name with
  2525. // its own md5 sum.
  2526. std::string::size_type pos = objName.find('/', objName.size()-max_len+32);
  2527. if(pos != objName.npos)
  2528. {
  2529. std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
  2530. md5name += objName.substr(pos);
  2531. objName = md5name;
  2532. // The object name is now short enough.
  2533. return true;
  2534. }
  2535. else
  2536. {
  2537. // The object name could not be shortened enough.
  2538. return false;
  2539. }
  2540. }
  2541. static
  2542. bool cmLocalGeneratorCheckObjectName(std::string& objName,
  2543. std::string::size_type dir_len,
  2544. std::string::size_type max_total_len)
  2545. {
  2546. // Enforce the maximum file name length if possible.
  2547. std::string::size_type max_obj_len = max_total_len;
  2548. if(dir_len < max_total_len)
  2549. {
  2550. max_obj_len = max_total_len - dir_len;
  2551. if(objName.size() > max_obj_len)
  2552. {
  2553. // The current object file name is too long. Try to shorten it.
  2554. return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
  2555. }
  2556. else
  2557. {
  2558. // The object file name is short enough.
  2559. return true;
  2560. }
  2561. }
  2562. else
  2563. {
  2564. // The build directory in which the object will be stored is
  2565. // already too deep.
  2566. return false;
  2567. }
  2568. }
  2569. #endif
  2570. //----------------------------------------------------------------------------
  2571. std::string&
  2572. cmLocalGenerator
  2573. ::CreateSafeUniqueObjectFileName(const std::string& sin,
  2574. std::string const& dir_max)
  2575. {
  2576. // Look for an existing mapped name for this object file.
  2577. std::map<std::string,std::string>::iterator it =
  2578. this->UniqueObjectNamesMap.find(sin);
  2579. // If no entry exists create one.
  2580. if(it == this->UniqueObjectNamesMap.end())
  2581. {
  2582. // Start with the original name.
  2583. std::string ssin = sin;
  2584. // Avoid full paths by removing leading slashes.
  2585. ssin.erase(0, ssin.find_first_not_of("/"));
  2586. // Avoid full paths by removing colons.
  2587. cmSystemTools::ReplaceString(ssin, ":", "_");
  2588. // Avoid relative paths that go up the tree.
  2589. cmSystemTools::ReplaceString(ssin, "../", "__/");
  2590. // Avoid spaces.
  2591. cmSystemTools::ReplaceString(ssin, " ", "_");
  2592. // Mangle the name if necessary.
  2593. if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
  2594. {
  2595. bool done;
  2596. int cc = 0;
  2597. char rpstr[100];
  2598. sprintf(rpstr, "_p_");
  2599. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2600. std::string sssin = sin;
  2601. do
  2602. {
  2603. done = true;
  2604. for ( it = this->UniqueObjectNamesMap.begin();
  2605. it != this->UniqueObjectNamesMap.end();
  2606. ++ it )
  2607. {
  2608. if ( it->second == ssin )
  2609. {
  2610. done = false;
  2611. }
  2612. }
  2613. if ( done )
  2614. {
  2615. break;
  2616. }
  2617. sssin = ssin;
  2618. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2619. sprintf(rpstr, "_p%d_", cc++);
  2620. }
  2621. while ( !done );
  2622. }
  2623. #if defined(CM_LG_ENCODE_OBJECT_NAMES)
  2624. if(!cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
  2625. this->ObjectPathMax))
  2626. {
  2627. // Warn if this is the first time the path has been seen.
  2628. if(this->ObjectMaxPathViolations.insert(dir_max).second)
  2629. {
  2630. std::ostringstream m;
  2631. m << "The object file directory\n"
  2632. << " " << dir_max << "\n"
  2633. << "has " << dir_max.size() << " characters. "
  2634. << "The maximum full path to an object file is "
  2635. << this->ObjectPathMax << " characters "
  2636. << "(see CMAKE_OBJECT_PATH_MAX). "
  2637. << "Object file\n"
  2638. << " " << ssin << "\n"
  2639. << "cannot be safely placed under this directory. "
  2640. << "The build may not work correctly.";
  2641. this->IssueMessage(cmake::WARNING, m.str());
  2642. }
  2643. }
  2644. #else
  2645. (void)dir_max;
  2646. #endif
  2647. // Insert the newly mapped object file name.
  2648. std::map<std::string, std::string>::value_type e(sin, ssin);
  2649. it = this->UniqueObjectNamesMap.insert(e).first;
  2650. }
  2651. // Return the map entry.
  2652. return it->second;
  2653. }
  2654. //----------------------------------------------------------------------------
  2655. void cmLocalGenerator::ComputeObjectFilenames(
  2656. std::map<cmSourceFile const*, std::string>&,
  2657. cmGeneratorTarget const*)
  2658. {
  2659. }
  2660. bool cmLocalGenerator::IsWindowsShell() const
  2661. {
  2662. return this->GetState()->UseWindowsShell();
  2663. }
  2664. bool cmLocalGenerator::IsWatcomWMake() const
  2665. {
  2666. return this->GetState()->UseWatcomWMake();
  2667. }
  2668. bool cmLocalGenerator::IsMinGWMake() const
  2669. {
  2670. return this->GetState()->UseMinGWMake();
  2671. }
  2672. bool cmLocalGenerator::IsNMake() const
  2673. {
  2674. return this->GetState()->UseNMake();
  2675. }
  2676. //----------------------------------------------------------------------------
  2677. std::string
  2678. cmLocalGenerator
  2679. ::GetObjectFileNameWithoutTarget(const cmSourceFile& source,
  2680. std::string const& dir_max,
  2681. bool* hasSourceExtension)
  2682. {
  2683. // Construct the object file name using the full path to the source
  2684. // file which is its only unique identification.
  2685. const char* fullPath = source.GetFullPath().c_str();
  2686. // Try referencing the source relative to the source tree.
  2687. std::string relFromSource = this->Convert(fullPath, START);
  2688. assert(!relFromSource.empty());
  2689. bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
  2690. bool subSource = relSource && relFromSource[0] != '.';
  2691. // Try referencing the source relative to the binary tree.
  2692. std::string relFromBinary = this->Convert(fullPath, START_OUTPUT);
  2693. assert(!relFromBinary.empty());
  2694. bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
  2695. bool subBinary = relBinary && relFromBinary[0] != '.';
  2696. // Select a nice-looking reference to the source file to construct
  2697. // the object file name.
  2698. std::string objectName;
  2699. if((relSource && !relBinary) || (subSource && !subBinary))
  2700. {
  2701. objectName = relFromSource;
  2702. }
  2703. else if((relBinary && !relSource) || (subBinary && !subSource))
  2704. {
  2705. objectName = relFromBinary;
  2706. }
  2707. else if(relFromBinary.length() < relFromSource.length())
  2708. {
  2709. objectName = relFromBinary;
  2710. }
  2711. else
  2712. {
  2713. objectName = relFromSource;
  2714. }
  2715. // if it is still a full path check for the try compile case
  2716. // try compile never have in source sources, and should not
  2717. // have conflicting source file names in the same target
  2718. if(cmSystemTools::FileIsFullPath(objectName.c_str()))
  2719. {
  2720. if(this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
  2721. {
  2722. objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
  2723. }
  2724. }
  2725. // Replace the original source file extension with the object file
  2726. // extension.
  2727. bool keptSourceExtension = true;
  2728. if(!source.GetPropertyAsBool("KEEP_EXTENSION"))
  2729. {
  2730. // Decide whether this language wants to replace the source
  2731. // extension with the object extension. For CMake 2.4
  2732. // compatibility do this by default.
  2733. bool replaceExt = this->NeedBackwardsCompatibility_2_4();
  2734. if(!replaceExt)
  2735. {
  2736. std::string lang = source.GetLanguage();
  2737. if(!lang.empty())
  2738. {
  2739. std::string repVar = "CMAKE_";
  2740. repVar += lang;
  2741. repVar += "_OUTPUT_EXTENSION_REPLACE";
  2742. replaceExt = this->Makefile->IsOn(repVar);
  2743. }
  2744. }
  2745. // Remove the source extension if it is to be replaced.
  2746. if(replaceExt)
  2747. {
  2748. keptSourceExtension = false;
  2749. std::string::size_type dot_pos = objectName.rfind(".");
  2750. if(dot_pos != std::string::npos)
  2751. {
  2752. objectName = objectName.substr(0, dot_pos);
  2753. }
  2754. }
  2755. // Store the new extension.
  2756. objectName +=
  2757. this->GlobalGenerator->GetLanguageOutputExtension(source);
  2758. }
  2759. if(hasSourceExtension)
  2760. {
  2761. *hasSourceExtension = keptSourceExtension;
  2762. }
  2763. // Convert to a safe name.
  2764. return this->CreateSafeUniqueObjectFileName(objectName, dir_max);
  2765. }
  2766. //----------------------------------------------------------------------------
  2767. std::string
  2768. cmLocalGenerator
  2769. ::GetSourceFileLanguage(const cmSourceFile& source)
  2770. {
  2771. return source.GetLanguage();
  2772. }
  2773. //----------------------------------------------------------------------------
  2774. std::string
  2775. cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
  2776. {
  2777. cmSystemTools::Error("GetTargetDirectory"
  2778. " called on cmLocalGenerator");
  2779. return "";
  2780. }
  2781. //----------------------------------------------------------------------------
  2782. cmIML_INT_uint64_t cmLocalGenerator::GetBackwardsCompatibility()
  2783. {
  2784. // The computed version may change until the project is fully
  2785. // configured.
  2786. if(!this->BackwardsCompatibilityFinal)
  2787. {
  2788. unsigned int major = 0;
  2789. unsigned int minor = 0;
  2790. unsigned int patch = 0;
  2791. if(const char* value
  2792. = this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"))
  2793. {
  2794. switch(sscanf(value, "%u.%u.%u", &major, &minor, &patch))
  2795. {
  2796. case 2: patch = 0; break;
  2797. case 1: minor = 0; patch = 0; break;
  2798. default: break;
  2799. }
  2800. }
  2801. this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
  2802. this->BackwardsCompatibilityFinal = this->Makefile->IsConfigured();
  2803. }
  2804. return this->BackwardsCompatibility;
  2805. }
  2806. //----------------------------------------------------------------------------
  2807. bool cmLocalGenerator::NeedBackwardsCompatibility_2_4()
  2808. {
  2809. // Check the policy to decide whether to pay attention to this
  2810. // variable.
  2811. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0001))
  2812. {
  2813. case cmPolicies::WARN:
  2814. // WARN is just OLD without warning because user code does not
  2815. // always affect whether this check is done.
  2816. case cmPolicies::OLD:
  2817. // Old behavior is to check the variable.
  2818. break;
  2819. case cmPolicies::NEW:
  2820. // New behavior is to ignore the variable.
  2821. return false;
  2822. case cmPolicies::REQUIRED_IF_USED:
  2823. case cmPolicies::REQUIRED_ALWAYS:
  2824. // This will never be the case because the only way to require
  2825. // the setting is to require the user to specify version policy
  2826. // 2.6 or higher. Once we add that requirement then this whole
  2827. // method can be removed anyway.
  2828. return false;
  2829. }
  2830. // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
  2831. // equal to or lower than the given version.
  2832. cmIML_INT_uint64_t actual_compat = this->GetBackwardsCompatibility();
  2833. return (actual_compat &&
  2834. actual_compat <= CMake_VERSION_ENCODE(2, 4, 255));
  2835. }
  2836. //----------------------------------------------------------------------------
  2837. bool cmLocalGenerator::CheckDefinition(std::string const& define) const
  2838. {
  2839. // Many compilers do not support -DNAME(arg)=sdf so we disable it.
  2840. std::string::size_type pos = define.find_first_of("(=");
  2841. if (pos != std::string::npos)
  2842. {
  2843. if (define[pos] == '(')
  2844. {
  2845. std::ostringstream e;
  2846. e << "WARNING: Function-style preprocessor definitions may not be "
  2847. << "passed on the compiler command line because many compilers "
  2848. << "do not support it.\n"
  2849. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2850. << "Consider defining the macro in a (configured) header file.\n";
  2851. cmSystemTools::Message(e.str().c_str());
  2852. return false;
  2853. }
  2854. }
  2855. // Many compilers do not support # in the value so we disable it.
  2856. if(define.find_first_of("#") != define.npos)
  2857. {
  2858. std::ostringstream e;
  2859. e << "WARNING: Preprocessor definitions containing '#' may not be "
  2860. << "passed on the compiler command line because many compilers "
  2861. << "do not support it.\n"
  2862. << "CMake is dropping a preprocessor definition: " << define << "\n"
  2863. << "Consider defining the macro in a (configured) header file.\n";
  2864. cmSystemTools::Message(e.str().c_str());
  2865. return false;
  2866. }
  2867. // Assume it is supported.
  2868. return true;
  2869. }
  2870. //----------------------------------------------------------------------------
  2871. static void cmLGInfoProp(cmMakefile* mf, cmTarget* target,
  2872. const std::string& prop)
  2873. {
  2874. if(const char* val = target->GetProperty(prop))
  2875. {
  2876. mf->AddDefinition(prop, val);
  2877. }
  2878. }
  2879. //----------------------------------------------------------------------------
  2880. void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
  2881. const std::string& targetName,
  2882. const char* fname)
  2883. {
  2884. // Find the Info.plist template.
  2885. const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
  2886. std::string inFile = (in && *in)? in : "MacOSXBundleInfo.plist.in";
  2887. if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
  2888. {
  2889. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2890. if(!inMod.empty())
  2891. {
  2892. inFile = inMod;
  2893. }
  2894. }
  2895. if(!cmSystemTools::FileExists(inFile.c_str(), true))
  2896. {
  2897. std::ostringstream e;
  2898. e << "Target " << target->GetName() << " Info.plist template \""
  2899. << inFile << "\" could not be found.";
  2900. cmSystemTools::Error(e.str().c_str());
  2901. return;
  2902. }
  2903. // Convert target properties to variables in an isolated makefile
  2904. // scope to configure the file. If properties are set they will
  2905. // override user make variables. If not the configuration will fall
  2906. // back to the directory-level values set by the user.
  2907. cmMakefile* mf = this->Makefile;
  2908. mf->PushScope();
  2909. mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName.c_str());
  2910. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING");
  2911. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE");
  2912. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
  2913. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
  2914. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_NAME");
  2915. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
  2916. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
  2917. cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
  2918. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2919. mf->PopScope();
  2920. }
  2921. //----------------------------------------------------------------------------
  2922. void cmLocalGenerator::GenerateFrameworkInfoPList(cmTarget* target,
  2923. const std::string& targetName,
  2924. const char* fname)
  2925. {
  2926. // Find the Info.plist template.
  2927. const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
  2928. std::string inFile = (in && *in)? in : "MacOSXFrameworkInfo.plist.in";
  2929. if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
  2930. {
  2931. std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
  2932. if(!inMod.empty())
  2933. {
  2934. inFile = inMod;
  2935. }
  2936. }
  2937. if(!cmSystemTools::FileExists(inFile.c_str(), true))
  2938. {
  2939. std::ostringstream e;
  2940. e << "Target " << target->GetName() << " Info.plist template \""
  2941. << inFile << "\" could not be found.";
  2942. cmSystemTools::Error(e.str().c_str());
  2943. return;
  2944. }
  2945. // Convert target properties to variables in an isolated makefile
  2946. // scope to configure the file. If properties are set they will
  2947. // override user make variables. If not the configuration will fall
  2948. // back to the directory-level values set by the user.
  2949. cmMakefile* mf = this->Makefile;
  2950. mf->PushScope();
  2951. mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName.c_str());
  2952. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE");
  2953. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
  2954. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
  2955. cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
  2956. mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
  2957. mf->PopScope();
  2958. }