cmCPackGenerator.cxx 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  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 "cmCPackGenerator.h"
  11. #include "cmMakefile.h"
  12. #include "cmCPackLog.h"
  13. #include "cmake.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmLocalGenerator.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmCPackComponentGroup.h"
  18. #include "cmXMLSafe.h"
  19. #include <cmsys/SystemTools.hxx>
  20. #include <cmsys/Glob.hxx>
  21. #include <memory> // auto_ptr
  22. #if defined(__HAIKU__)
  23. #include <StorageKit.h>
  24. #endif
  25. //----------------------------------------------------------------------
  26. cmCPackGenerator::cmCPackGenerator()
  27. {
  28. this->GeneratorVerbose = false;
  29. this->MakefileMap = 0;
  30. this->Logger = 0;
  31. }
  32. //----------------------------------------------------------------------
  33. cmCPackGenerator::~cmCPackGenerator()
  34. {
  35. this->MakefileMap = 0;
  36. }
  37. //----------------------------------------------------------------------
  38. void cmCPackGeneratorProgress(const char *msg, float prog, void* ptr)
  39. {
  40. cmCPackGenerator* self = static_cast<cmCPackGenerator*>(ptr);
  41. self->DisplayVerboseOutput(msg, prog);
  42. }
  43. //----------------------------------------------------------------------
  44. void cmCPackGenerator::DisplayVerboseOutput(const char* msg,
  45. float progress)
  46. {
  47. (void)progress;
  48. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "" << msg << std::endl);
  49. }
  50. //----------------------------------------------------------------------
  51. int cmCPackGenerator::PrepareNames()
  52. {
  53. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  54. "Create temp directory." << std::endl);
  55. std::string tempDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY");
  56. tempDirectory += "/_CPack_Packages/";
  57. const char* toplevelTag = this->GetOption("CPACK_TOPLEVEL_TAG");
  58. if ( toplevelTag )
  59. {
  60. tempDirectory += toplevelTag;
  61. tempDirectory += "/";
  62. }
  63. tempDirectory += this->GetOption("CPACK_GENERATOR");
  64. std::string topDirectory = tempDirectory;
  65. this->GetOption("CPACK_PACKAGE_FILE_NAME");
  66. const char* pfname = this->GetOption("CPACK_PACKAGE_FILE_NAME");
  67. if(!pfname)
  68. {
  69. cmCPackLogger(cmCPackLog::LOG_ERROR,
  70. "CPACK_PACKAGE_FILE_NAME not specified" << std::endl);
  71. return 0;
  72. }
  73. std::string outName = pfname;
  74. tempDirectory += "/" + outName;
  75. if(!this->GetOutputExtension())
  76. {
  77. cmCPackLogger(cmCPackLog::LOG_ERROR,
  78. "No output extension specified" << std::endl);
  79. return 0;
  80. }
  81. outName += this->GetOutputExtension();
  82. const char* pdir = this->GetOption("CPACK_PACKAGE_DIRECTORY");
  83. if(!pdir)
  84. {
  85. cmCPackLogger(cmCPackLog::LOG_ERROR,
  86. "CPACK_PACKAGE_DIRECTORY not specified" << std::endl);
  87. return 0;
  88. }
  89. std::string destFile = pdir;
  90. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PREFIX", destFile.c_str());
  91. destFile += "/" + outName;
  92. std::string outFile = topDirectory + "/" + outName;
  93. this->SetOptionIfNotSet("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str());
  94. this->SetOptionIfNotSet("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str());
  95. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_NAME", outName.c_str());
  96. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PATH", destFile.c_str());
  97. this->SetOptionIfNotSet("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
  98. outFile.c_str());
  99. this->SetOptionIfNotSet("CPACK_INSTALL_DIRECTORY", this->GetInstallPath());
  100. this->SetOptionIfNotSet("CPACK_NATIVE_INSTALL_DIRECTORY",
  101. cmsys::SystemTools::ConvertToOutputPath(this->GetInstallPath()).c_str());
  102. this->SetOptionIfNotSet("CPACK_TEMPORARY_INSTALL_DIRECTORY",
  103. tempDirectory.c_str());
  104. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  105. "Look for: CPACK_PACKAGE_DESCRIPTION_FILE" << std::endl);
  106. const char* descFileName
  107. = this->GetOption("CPACK_PACKAGE_DESCRIPTION_FILE");
  108. if ( descFileName )
  109. {
  110. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  111. "Look for: " << descFileName << std::endl);
  112. if ( !cmSystemTools::FileExists(descFileName) )
  113. {
  114. cmCPackLogger(cmCPackLog::LOG_ERROR,
  115. "Cannot find description file name: ["
  116. << descFileName << "]" << std::endl);
  117. return 0;
  118. }
  119. std::ifstream ifs(descFileName);
  120. if ( !ifs )
  121. {
  122. cmCPackLogger(cmCPackLog::LOG_ERROR,
  123. "Cannot open description file name: " << descFileName << std::endl);
  124. return 0;
  125. }
  126. cmOStringStream ostr;
  127. std::string line;
  128. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  129. "Read description file: " << descFileName << std::endl);
  130. while ( ifs && cmSystemTools::GetLineFromStream(ifs, line) )
  131. {
  132. ostr << cmXMLSafe(line) << std::endl;
  133. }
  134. this->SetOptionIfNotSet("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str());
  135. }
  136. if ( !this->GetOption("CPACK_PACKAGE_DESCRIPTION") )
  137. {
  138. cmCPackLogger(cmCPackLog::LOG_ERROR,
  139. "Project description not specified. Please specify "
  140. "CPACK_PACKAGE_DESCRIPTION or CPACK_PACKAGE_DESCRIPTION_FILE."
  141. << std::endl);
  142. return 0;
  143. }
  144. this->SetOptionIfNotSet("CPACK_REMOVE_TOPLEVEL_DIRECTORY", "1");
  145. return 1;
  146. }
  147. //----------------------------------------------------------------------
  148. int cmCPackGenerator::InstallProject()
  149. {
  150. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Install projects" << std::endl);
  151. this->CleanTemporaryDirectory();
  152. std::string bareTempInstallDirectory
  153. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  154. std::string tempInstallDirectoryStr = bareTempInstallDirectory;
  155. bool setDestDir = cmSystemTools::IsOn(this->GetOption("CPACK_SET_DESTDIR"))
  156. | cmSystemTools::IsInternallyOn(this->GetOption("CPACK_SET_DESTDIR"));
  157. if (!setDestDir)
  158. {
  159. tempInstallDirectoryStr += this->GetPackagingInstallPrefix();
  160. }
  161. const char* tempInstallDirectory = tempInstallDirectoryStr.c_str();
  162. int res = 1;
  163. if ( !cmsys::SystemTools::MakeDirectory(bareTempInstallDirectory.c_str()))
  164. {
  165. cmCPackLogger(cmCPackLog::LOG_ERROR,
  166. "Problem creating temporary directory: "
  167. << (tempInstallDirectory ? tempInstallDirectory : "(NULL}")
  168. << std::endl);
  169. return 0;
  170. }
  171. if ( setDestDir )
  172. {
  173. std::string destDir = "DESTDIR=";
  174. destDir += tempInstallDirectory;
  175. cmSystemTools::PutEnv(destDir.c_str());
  176. }
  177. else
  178. {
  179. // Make sure there is no destdir
  180. cmSystemTools::PutEnv("DESTDIR=");
  181. }
  182. // If the CPackConfig file sets CPACK_INSTALL_COMMANDS then run them
  183. // as listed
  184. if ( !this->InstallProjectViaInstallCommands(
  185. setDestDir, tempInstallDirectory) )
  186. {
  187. return 0;
  188. }
  189. // If the CPackConfig file sets CPACK_INSTALL_SCRIPT then run them
  190. // as listed
  191. if ( !this->InstallProjectViaInstallScript(
  192. setDestDir, tempInstallDirectory) )
  193. {
  194. return 0;
  195. }
  196. // If the CPackConfig file sets CPACK_INSTALLED_DIRECTORIES
  197. // then glob it and copy it to CPACK_TEMPORARY_DIRECTORY
  198. // This is used in Source packageing
  199. if ( !this->InstallProjectViaInstalledDirectories(
  200. setDestDir, tempInstallDirectory) )
  201. {
  202. return 0;
  203. }
  204. // If the project is a CMAKE project then run pre-install
  205. // and then read the cmake_install script to run it
  206. if ( !this->InstallProjectViaInstallCMakeProjects(
  207. setDestDir, bareTempInstallDirectory.c_str()) )
  208. {
  209. return 0;
  210. }
  211. if ( setDestDir )
  212. {
  213. cmSystemTools::PutEnv("DESTDIR=");
  214. }
  215. return res;
  216. }
  217. //----------------------------------------------------------------------
  218. int cmCPackGenerator::InstallProjectViaInstallCommands(
  219. bool setDestDir, const char* tempInstallDirectory)
  220. {
  221. (void) setDestDir;
  222. const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS");
  223. if ( installCommands && *installCommands )
  224. {
  225. std::string tempInstallDirectoryEnv = "CMAKE_INSTALL_PREFIX=";
  226. tempInstallDirectoryEnv += tempInstallDirectory;
  227. cmSystemTools::PutEnv(tempInstallDirectoryEnv.c_str());
  228. std::vector<std::string> installCommandsVector;
  229. cmSystemTools::ExpandListArgument(installCommands,installCommandsVector);
  230. std::vector<std::string>::iterator it;
  231. for ( it = installCommandsVector.begin();
  232. it != installCommandsVector.end();
  233. ++it )
  234. {
  235. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << it->c_str()
  236. << std::endl);
  237. std::string output;
  238. int retVal = 1;
  239. bool resB = cmSystemTools::RunSingleCommand(it->c_str(), &output,
  240. &retVal, 0, this->GeneratorVerbose, 0);
  241. if ( !resB || retVal )
  242. {
  243. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  244. tmpFile += "/InstallOutput.log";
  245. cmGeneratedFileStream ofs(tmpFile.c_str());
  246. ofs << "# Run command: " << it->c_str() << std::endl
  247. << "# Output:" << std::endl
  248. << output.c_str() << std::endl;
  249. cmCPackLogger(cmCPackLog::LOG_ERROR,
  250. "Problem running install command: " << it->c_str() << std::endl
  251. << "Please check " << tmpFile.c_str() << " for errors"
  252. << std::endl);
  253. return 0;
  254. }
  255. }
  256. }
  257. return 1;
  258. }
  259. //----------------------------------------------------------------------
  260. int cmCPackGenerator::InstallProjectViaInstalledDirectories(
  261. bool setDestDir, const char* tempInstallDirectory)
  262. {
  263. (void)setDestDir;
  264. (void)tempInstallDirectory;
  265. std::vector<cmsys::RegularExpression> ignoreFilesRegex;
  266. const char* cpackIgnoreFiles = this->GetOption("CPACK_IGNORE_FILES");
  267. if ( cpackIgnoreFiles )
  268. {
  269. std::vector<std::string> ignoreFilesRegexString;
  270. cmSystemTools::ExpandListArgument(cpackIgnoreFiles,
  271. ignoreFilesRegexString);
  272. std::vector<std::string>::iterator it;
  273. for ( it = ignoreFilesRegexString.begin();
  274. it != ignoreFilesRegexString.end();
  275. ++it )
  276. {
  277. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  278. "Create ignore files regex for: " << it->c_str() << std::endl);
  279. ignoreFilesRegex.push_back(it->c_str());
  280. }
  281. }
  282. const char* installDirectories
  283. = this->GetOption("CPACK_INSTALLED_DIRECTORIES");
  284. if ( installDirectories && *installDirectories )
  285. {
  286. std::vector<std::string> installDirectoriesVector;
  287. cmSystemTools::ExpandListArgument(installDirectories,
  288. installDirectoriesVector);
  289. if ( installDirectoriesVector.size() % 2 != 0 )
  290. {
  291. cmCPackLogger(cmCPackLog::LOG_ERROR,
  292. "CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> and "
  293. "<subdirectory>. The <subdirectory> can be '.' to be installed in "
  294. "the toplevel directory of installation." << std::endl);
  295. return 0;
  296. }
  297. std::vector<std::string>::iterator it;
  298. const char* tempDir = tempInstallDirectory;
  299. for ( it = installDirectoriesVector.begin();
  300. it != installDirectoriesVector.end();
  301. ++it )
  302. {
  303. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  304. cmsys::Glob gl;
  305. std::string top = it->c_str();
  306. it ++;
  307. std::string subdir = it->c_str();
  308. std::string findExpr = top;
  309. findExpr += "/*";
  310. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  311. "- Install directory: " << top << std::endl);
  312. gl.RecurseOn();
  313. if ( !gl.FindFiles(findExpr) )
  314. {
  315. cmCPackLogger(cmCPackLog::LOG_ERROR,
  316. "Cannot find any files in the installed directory" << std::endl);
  317. return 0;
  318. }
  319. files = gl.GetFiles();
  320. std::vector<std::string>::iterator gfit;
  321. std::vector<cmsys::RegularExpression>::iterator regIt;
  322. for ( gfit = files.begin(); gfit != files.end(); ++ gfit )
  323. {
  324. bool skip = false;
  325. std::string &inFile = *gfit;
  326. for ( regIt= ignoreFilesRegex.begin();
  327. regIt!= ignoreFilesRegex.end();
  328. ++ regIt)
  329. {
  330. if ( regIt->find(inFile.c_str()) )
  331. {
  332. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Ignore file: "
  333. << inFile.c_str() << std::endl);
  334. skip = true;
  335. }
  336. }
  337. if ( skip )
  338. {
  339. continue;
  340. }
  341. std::string filePath = tempDir;
  342. filePath += "/" + subdir + "/"
  343. + cmSystemTools::RelativePath(top.c_str(), gfit->c_str());
  344. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy file: "
  345. << inFile.c_str() << " -> " << filePath.c_str() << std::endl);
  346. if ( !cmSystemTools::CopyFileIfDifferent(inFile.c_str(),
  347. filePath.c_str()) )
  348. {
  349. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying file: "
  350. << inFile.c_str() << " -> " << filePath.c_str() << std::endl);
  351. return 0;
  352. }
  353. }
  354. }
  355. }
  356. return 1;
  357. }
  358. //----------------------------------------------------------------------
  359. int cmCPackGenerator::InstallProjectViaInstallScript(
  360. bool setDestDir, const char* tempInstallDirectory)
  361. {
  362. const char* cmakeScripts
  363. = this->GetOption("CPACK_INSTALL_SCRIPT");
  364. if ( cmakeScripts && *cmakeScripts )
  365. {
  366. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  367. "- Install scripts: " << cmakeScripts << std::endl);
  368. std::vector<std::string> cmakeScriptsVector;
  369. cmSystemTools::ExpandListArgument(cmakeScripts,
  370. cmakeScriptsVector);
  371. std::vector<std::string>::iterator it;
  372. for ( it = cmakeScriptsVector.begin();
  373. it != cmakeScriptsVector.end();
  374. ++it )
  375. {
  376. std::string installScript = it->c_str();
  377. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  378. "- Install script: " << installScript << std::endl);
  379. if ( setDestDir )
  380. {
  381. // For DESTDIR based packaging, use the *project* CMAKE_INSTALL_PREFIX
  382. // underneath the tempInstallDirectory. The value of the project's
  383. // CMAKE_INSTALL_PREFIX is sent in here as the value of the
  384. // CPACK_INSTALL_PREFIX variable.
  385. std::string dir;
  386. if (this->GetOption("CPACK_INSTALL_PREFIX"))
  387. {
  388. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  389. }
  390. this->SetOption("CMAKE_INSTALL_PREFIX", dir.c_str());
  391. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  392. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (this->SetOption)"
  393. << std::endl);
  394. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  395. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'" << std::endl);
  396. }
  397. else
  398. {
  399. this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
  400. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  401. "- Using non-DESTDIR install... (this->SetOption)" << std::endl);
  402. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  403. "- Setting CMAKE_INSTALL_PREFIX to '" << tempInstallDirectory
  404. << "'" << std::endl);
  405. }
  406. this->SetOptionIfNotSet("CMAKE_CURRENT_BINARY_DIR",
  407. tempInstallDirectory);
  408. this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR",
  409. tempInstallDirectory);
  410. int res = this->MakefileMap->ReadListFile(0, installScript.c_str());
  411. if ( cmSystemTools::GetErrorOccuredFlag() || !res )
  412. {
  413. return 0;
  414. }
  415. }
  416. }
  417. return 1;
  418. }
  419. //----------------------------------------------------------------------
  420. int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
  421. bool setDestDir, const char* baseTempInstallDirectory)
  422. {
  423. const char* cmakeProjects
  424. = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
  425. const char* cmakeGenerator
  426. = this->GetOption("CPACK_CMAKE_GENERATOR");
  427. if ( cmakeProjects && *cmakeProjects )
  428. {
  429. if ( !cmakeGenerator )
  430. {
  431. cmCPackLogger(cmCPackLog::LOG_ERROR,
  432. "CPACK_INSTALL_CMAKE_PROJECTS is specified, but "
  433. "CPACK_CMAKE_GENERATOR is not. CPACK_CMAKE_GENERATOR "
  434. "is required to install the project."
  435. << std::endl);
  436. return 0;
  437. }
  438. std::vector<std::string> cmakeProjectsVector;
  439. cmSystemTools::ExpandListArgument(cmakeProjects,
  440. cmakeProjectsVector);
  441. std::vector<std::string>::iterator it;
  442. for ( it = cmakeProjectsVector.begin();
  443. it != cmakeProjectsVector.end();
  444. ++it )
  445. {
  446. if ( it+1 == cmakeProjectsVector.end() ||
  447. it+2 == cmakeProjectsVector.end() ||
  448. it+3 == cmakeProjectsVector.end() )
  449. {
  450. cmCPackLogger(cmCPackLog::LOG_ERROR,
  451. "Not enough items on list: CPACK_INSTALL_CMAKE_PROJECTS. "
  452. "CPACK_INSTALL_CMAKE_PROJECTS should hold quadruplet of install "
  453. "directory, install project name, install component, and install "
  454. "subdirectory."
  455. << std::endl);
  456. return 0;
  457. }
  458. std::string installDirectory = it->c_str();
  459. ++it;
  460. std::string installProjectName = it->c_str();
  461. ++it;
  462. std::string installComponent = it->c_str();
  463. ++it;
  464. std::string installSubDirectory = it->c_str();
  465. std::string installFile = installDirectory + "/cmake_install.cmake";
  466. std::vector<std::string> componentsVector;
  467. bool componentInstall = false;
  468. if (this->SupportsComponentInstallation())
  469. {
  470. // Determine the installation types for this project (if provided).
  471. std::string installTypesVar = "CPACK_"
  472. + cmSystemTools::UpperCase(installComponent) + "_INSTALL_TYPES";
  473. const char *installTypes = this->GetOption(installTypesVar.c_str());
  474. if (installTypes && *installTypes)
  475. {
  476. std::vector<std::string> installTypesVector;
  477. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  478. std::vector<std::string>::iterator installTypeIt;
  479. for (installTypeIt = installTypesVector.begin();
  480. installTypeIt != installTypesVector.end();
  481. ++installTypeIt)
  482. {
  483. this->GetInstallationType(installProjectName.c_str(),
  484. installTypeIt->c_str());
  485. }
  486. }
  487. // Determine the set of components that will be used in this project
  488. std::string componentsVar
  489. = "CPACK_COMPONENTS_" + cmSystemTools::UpperCase(installComponent);
  490. const char *components = this->GetOption(componentsVar.c_str());
  491. if (components && *components)
  492. {
  493. cmSystemTools::ExpandListArgument(components, componentsVector);
  494. std::vector<std::string>::iterator compIt;
  495. for (compIt = componentsVector.begin();
  496. compIt != componentsVector.end();
  497. ++compIt)
  498. {
  499. GetComponent(installProjectName.c_str(), compIt->c_str());
  500. }
  501. componentInstall = true;
  502. }
  503. }
  504. if (componentsVector.empty())
  505. {
  506. componentsVector.push_back(installComponent);
  507. }
  508. const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
  509. cmGlobalGenerator* globalGenerator
  510. = this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator(
  511. cmakeGenerator);
  512. // set the global flag for unix style paths on cmSystemTools as
  513. // soon as the generator is set. This allows gmake to be used
  514. // on windows.
  515. cmSystemTools::SetForceUnixPaths(globalGenerator->GetForceUnixPaths());
  516. // Does this generator require pre-install?
  517. if ( globalGenerator->GetPreinstallTargetName() )
  518. {
  519. globalGenerator->FindMakeProgram(this->MakefileMap);
  520. const char* cmakeMakeProgram
  521. = this->MakefileMap->GetDefinition("CMAKE_MAKE_PROGRAM");
  522. std::string buildCommand
  523. = globalGenerator->GenerateBuildCommand(cmakeMakeProgram,
  524. installProjectName.c_str(), 0,
  525. globalGenerator->GetPreinstallTargetName(),
  526. buildConfig, false, false);
  527. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  528. "- Install command: " << buildCommand << std::endl);
  529. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  530. "- Run preinstall target for: " << installProjectName << std::endl);
  531. std::string output;
  532. int retVal = 1;
  533. bool resB =
  534. cmSystemTools::RunSingleCommand(buildCommand.c_str(),
  535. &output,
  536. &retVal,
  537. installDirectory.c_str(),
  538. this->GeneratorVerbose, 0);
  539. if ( !resB || retVal )
  540. {
  541. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  542. tmpFile += "/PreinstallOutput.log";
  543. cmGeneratedFileStream ofs(tmpFile.c_str());
  544. ofs << "# Run command: " << buildCommand.c_str() << std::endl
  545. << "# Directory: " << installDirectory.c_str() << std::endl
  546. << "# Output:" << std::endl
  547. << output.c_str() << std::endl;
  548. cmCPackLogger(cmCPackLog::LOG_ERROR,
  549. "Problem running install command: " << buildCommand.c_str()
  550. << std::endl
  551. << "Please check " << tmpFile.c_str() << " for errors"
  552. << std::endl);
  553. return 0;
  554. }
  555. }
  556. delete globalGenerator;
  557. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  558. "- Install project: " << installProjectName << std::endl);
  559. // Run the installation for each component
  560. std::vector<std::string>::iterator componentIt;
  561. for (componentIt = componentsVector.begin();
  562. componentIt != componentsVector.end();
  563. ++componentIt)
  564. {
  565. std::string tempInstallDirectory = baseTempInstallDirectory;
  566. installComponent = *componentIt;
  567. if (componentInstall)
  568. {
  569. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  570. "- Install component: " << installComponent
  571. << std::endl);
  572. }
  573. cmake cm;
  574. cm.AddCMakePaths();
  575. cm.SetProgressCallback(cmCPackGeneratorProgress, this);
  576. cmGlobalGenerator gg;
  577. gg.SetCMakeInstance(&cm);
  578. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  579. cmMakefile *mf = lg->GetMakefile();
  580. std::string realInstallDirectory = tempInstallDirectory;
  581. if ( !installSubDirectory.empty() && installSubDirectory != "/" )
  582. {
  583. realInstallDirectory += installSubDirectory;
  584. }
  585. if (componentInstall)
  586. {
  587. tempInstallDirectory += "/";
  588. tempInstallDirectory += installComponent;
  589. }
  590. if (!setDestDir)
  591. {
  592. tempInstallDirectory += this->GetPackagingInstallPrefix();
  593. }
  594. if ( setDestDir )
  595. {
  596. // For DESTDIR based packaging, use the *project*
  597. // CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The
  598. // value of the project's CMAKE_INSTALL_PREFIX is sent in here as
  599. // the value of the CPACK_INSTALL_PREFIX variable.
  600. //
  601. // If DESTDIR has been 'internally set ON' this means that
  602. // the underlying CPack specific generator did ask for that
  603. // In this case we may overrode CPACK_INSTALL_PREFIX with
  604. // CPACK_PACKAGING_INSTALL_PREFIX
  605. // I know this is tricky and awkward but it's the price for
  606. // CPACK_SET_DESTDIR backward compatibility.
  607. if (cmSystemTools::IsInternallyOn(this->GetOption("CPACK_SET_DESTDIR")))
  608. {
  609. this->SetOption("CPACK_INSTALL_PREFIX",this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX"));
  610. }
  611. std::string dir;
  612. if (this->GetOption("CPACK_INSTALL_PREFIX"))
  613. {
  614. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  615. }
  616. mf->AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str());
  617. cmCPackLogger(
  618. cmCPackLog::LOG_DEBUG,
  619. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf->AddDefinition)"
  620. << std::endl);
  621. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  622. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'"
  623. << std::endl);
  624. // Make sure that DESTDIR + CPACK_INSTALL_PREFIX directory
  625. // exists:
  626. //
  627. if (cmSystemTools::StringStartsWith(dir.c_str(), "/"))
  628. {
  629. dir = tempInstallDirectory + dir;
  630. }
  631. else
  632. {
  633. dir = tempInstallDirectory + "/" + dir;
  634. }
  635. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  636. "- Creating directory: '" << dir << "'" << std::endl);
  637. if ( !cmsys::SystemTools::MakeDirectory(dir.c_str()))
  638. {
  639. cmCPackLogger(cmCPackLog::LOG_ERROR,
  640. "Problem creating temporary directory: "
  641. << dir << std::endl);
  642. return 0;
  643. }
  644. }
  645. else
  646. {
  647. mf->AddDefinition("CMAKE_INSTALL_PREFIX",
  648. tempInstallDirectory.c_str());
  649. if ( !cmsys::SystemTools::MakeDirectory(
  650. tempInstallDirectory.c_str()))
  651. {
  652. cmCPackLogger(cmCPackLog::LOG_ERROR,
  653. "Problem creating temporary directory: "
  654. << tempInstallDirectory << std::endl);
  655. return 0;
  656. }
  657. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  658. "- Using non-DESTDIR install... (mf->AddDefinition)"
  659. << std::endl);
  660. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  661. "- Setting CMAKE_INSTALL_PREFIX to '"
  662. << tempInstallDirectory
  663. << "'" << std::endl);
  664. }
  665. if ( buildConfig && *buildConfig )
  666. {
  667. mf->AddDefinition("BUILD_TYPE", buildConfig);
  668. }
  669. std::string installComponentLowerCase
  670. = cmSystemTools::LowerCase(installComponent);
  671. if ( installComponentLowerCase != "all" )
  672. {
  673. mf->AddDefinition("CMAKE_INSTALL_COMPONENT",
  674. installComponent.c_str());
  675. }
  676. // strip on TRUE, ON, 1, one or several file names, but not on
  677. // FALSE, OFF, 0 and an empty string
  678. if (!cmSystemTools::IsOff(this->GetOption("CPACK_STRIP_FILES")))
  679. {
  680. mf->AddDefinition("CMAKE_INSTALL_DO_STRIP", "1");
  681. }
  682. int res = mf->ReadListFile(0, installFile.c_str());
  683. if ( cmSystemTools::GetErrorOccuredFlag() || !res )
  684. {
  685. return 0;
  686. }
  687. }
  688. }
  689. }
  690. return 1;
  691. }
  692. //----------------------------------------------------------------------
  693. bool cmCPackGenerator::ReadListFile(const char* moduleName)
  694. {
  695. std::string fullPath = this->MakefileMap->GetModulesFile(moduleName);
  696. return this->MakefileMap->ReadListFile(0, fullPath.c_str());
  697. }
  698. //----------------------------------------------------------------------
  699. void cmCPackGenerator::SetOptionIfNotSet(const char* op,
  700. const char* value)
  701. {
  702. const char* def = this->MakefileMap->GetDefinition(op);
  703. if ( def && *def )
  704. {
  705. return;
  706. }
  707. this->SetOption(op, value);
  708. }
  709. //----------------------------------------------------------------------
  710. void cmCPackGenerator::SetOption(const char* op, const char* value)
  711. {
  712. if ( !op )
  713. {
  714. return;
  715. }
  716. if ( !value )
  717. {
  718. this->MakefileMap->RemoveDefinition(op);
  719. return;
  720. }
  721. cmCPackLogger(cmCPackLog::LOG_DEBUG, this->GetNameOfClass()
  722. << "::SetOption(" << op << ", " << value << ")" << std::endl);
  723. this->MakefileMap->AddDefinition(op, value);
  724. }
  725. //----------------------------------------------------------------------
  726. int cmCPackGenerator::DoPackage()
  727. {
  728. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  729. "Create package using " << this->Name.c_str() << std::endl);
  730. if ( !this->PrepareNames() )
  731. {
  732. return 0;
  733. }
  734. if ( cmSystemTools::IsOn(
  735. this->GetOption("CPACK_REMOVE_TOPLEVEL_DIRECTORY")) )
  736. {
  737. const char* toplevelDirectory
  738. = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  739. if ( cmSystemTools::FileExists(toplevelDirectory) )
  740. {
  741. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  742. "Remove toplevel directory: "
  743. << toplevelDirectory << std::endl);
  744. if ( !cmSystemTools::RepeatedRemoveDirectory(toplevelDirectory) )
  745. {
  746. cmCPackLogger(cmCPackLog::LOG_ERROR,
  747. "Problem removing toplevel directory: "
  748. << toplevelDirectory
  749. << std::endl);
  750. return 0;
  751. }
  752. }
  753. }
  754. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  755. "About to install project " << std::endl);
  756. if ( !this->InstallProject() )
  757. {
  758. return 0;
  759. }
  760. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  761. "Done install project " << std::endl);
  762. const char* tempPackageFileName = this->GetOption(
  763. "CPACK_TEMPORARY_PACKAGE_FILE_NAME");
  764. const char* packageFileName = this->GetOption("CPACK_OUTPUT_FILE_PATH");
  765. const char* tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  766. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  767. cmsys::Glob gl;
  768. std::string findExpr = tempDirectory;
  769. findExpr += "/*";
  770. gl.RecurseOn();
  771. if ( !gl.FindFiles(findExpr) )
  772. {
  773. cmCPackLogger(cmCPackLog::LOG_ERROR,
  774. "Cannot find any files in the packaging tree" << std::endl);
  775. return 0;
  776. }
  777. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Compress package" << std::endl);
  778. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Compress files to: "
  779. << (tempPackageFileName ? tempPackageFileName : "(NULL)") << std::endl);
  780. if ( cmSystemTools::FileExists(tempPackageFileName) )
  781. {
  782. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Remove old package file"
  783. << std::endl);
  784. cmSystemTools::RemoveFile(tempPackageFileName);
  785. }
  786. if ( cmSystemTools::IsOn(this->GetOption(
  787. "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) )
  788. {
  789. tempDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  790. }
  791. // The files to be installed
  792. files = gl.GetFiles();
  793. // For component installations, determine which files go into which
  794. // components.
  795. if (!this->Components.empty())
  796. {
  797. std::vector<std::string>::const_iterator it;
  798. for ( it = files.begin(); it != files.end(); ++ it )
  799. {
  800. std::string fileN = cmSystemTools::RelativePath(tempDirectory,
  801. it->c_str());
  802. // Determine which component we are in.
  803. std::string componentName = fileN.substr(0, fileN.find('/'));
  804. // Strip off the component part of the path.
  805. fileN = fileN.substr(fileN.find('/')+1, std::string::npos);
  806. // Add this file to the list of files for the component.
  807. this->Components[componentName].Files.push_back(fileN);
  808. }
  809. }
  810. packageFileNames.clear();
  811. /* Put at least one file name into the list of
  812. * wanted packageFileNames. The specific generator
  813. * may update this during PackageFiles.
  814. * (either putting several names or updating the provided one)
  815. */
  816. packageFileNames.push_back(tempPackageFileName);
  817. toplevel = tempDirectory;
  818. if ( !this->PackageFiles() || cmSystemTools::GetErrorOccuredFlag())
  819. {
  820. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem compressing the directory"
  821. << std::endl);
  822. return 0;
  823. }
  824. /*
  825. * Copy the generated packages to final destination
  826. * - there may be several of them
  827. * - the initially provided name may have changed
  828. * (because the specific generator did 'normalize' it)
  829. */
  830. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Copying final package(s) ["
  831. <<packageFileNames.size()
  832. <<"]:"<<std::endl);
  833. std::vector<std::string>::iterator it;
  834. /* now copy package one by one */
  835. for (it=packageFileNames.begin();it!=packageFileNames.end();++it)
  836. {
  837. std::string tmpPF(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"));
  838. tempPackageFileName = it->c_str();
  839. tmpPF += "/"+cmSystemTools::GetFilenameName(*it);
  840. packageFileName = tmpPF.c_str();
  841. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy final package(s): "
  842. << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
  843. << " to "
  844. << (packageFileName ? packageFileName : "(NULL)")
  845. << std::endl);
  846. if ( !cmSystemTools::CopyFileIfDifferent(tempPackageFileName,
  847. packageFileName) )
  848. {
  849. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the package: "
  850. << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
  851. << " to "
  852. << (packageFileName ? packageFileName : "(NULL)")
  853. << std::endl);
  854. return 0;
  855. }
  856. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- package: "
  857. << packageFileName
  858. << " generated." << std::endl);
  859. }
  860. return 1;
  861. }
  862. //----------------------------------------------------------------------
  863. int cmCPackGenerator::Initialize(const char* name, cmMakefile* mf)
  864. {
  865. this->MakefileMap = mf;
  866. this->Name = name;
  867. if ( !this->SetCMakeRoot() )
  868. {
  869. cmCPackLogger(cmCPackLog::LOG_ERROR,
  870. "Cannot initialize the generator" << std::endl);
  871. return 0;
  872. }
  873. // set the running generator name
  874. this->SetOption("CPACK_GENERATOR", this->Name.c_str());
  875. // Load the project specific config file
  876. const char* config =
  877. this->GetOption("CPACK_PROJECT_CONFIG_FILE");
  878. if(config)
  879. {
  880. mf->ReadListFile(config);
  881. }
  882. int result = this->InitializeInternal();
  883. if (cmSystemTools::GetErrorOccuredFlag())
  884. {
  885. return 0;
  886. }
  887. // If a generator subclass did not already set this option in its
  888. // InitializeInternal implementation, and the project did not already set
  889. // it, the default value should be:
  890. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/");
  891. return result;
  892. }
  893. //----------------------------------------------------------------------
  894. int cmCPackGenerator::InitializeInternal()
  895. {
  896. return 1;
  897. }
  898. //----------------------------------------------------------------------
  899. bool cmCPackGenerator::IsSet(const char* name) const
  900. {
  901. return this->MakefileMap->IsSet(name);
  902. }
  903. //----------------------------------------------------------------------
  904. const char* cmCPackGenerator::GetOption(const char* op)
  905. {
  906. const char* ret = this->MakefileMap->GetDefinition(op);
  907. if(!ret)
  908. {
  909. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  910. "Warning, GetOption return NULL for: "
  911. << op
  912. << std::endl);
  913. }
  914. return ret;
  915. }
  916. //----------------------------------------------------------------------
  917. int cmCPackGenerator::SetCMakeRoot()
  918. {
  919. // use the CMAKE_ROOT from cmake which should have been
  920. // found by now
  921. const char* root=
  922. this->MakefileMap->GetDefinition("CMAKE_ROOT");
  923. if(root)
  924. {
  925. this->CMakeRoot = root;
  926. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  927. << this->CMakeRoot.c_str() << std::endl);
  928. this->SetOption("CMAKE_ROOT", this->CMakeRoot.c_str());
  929. return 1;
  930. }
  931. cmCPackLogger(cmCPackLog::LOG_ERROR,
  932. "Could not find CMAKE_ROOT !!!"
  933. << std::endl
  934. << "CMake has most likely not been installed correctly."
  935. << std::endl
  936. <<"Modules directory not found in"
  937. << std::endl);
  938. return 0;
  939. }
  940. //----------------------------------------------------------------------
  941. int cmCPackGenerator::PackageFiles()
  942. {
  943. return 0;
  944. }
  945. //----------------------------------------------------------------------
  946. const char* cmCPackGenerator::GetInstallPath()
  947. {
  948. if ( !this->InstallPath.empty() )
  949. {
  950. return this->InstallPath.c_str();
  951. }
  952. #if defined(_WIN32) && !defined(__CYGWIN__)
  953. const char* prgfiles = cmsys::SystemTools::GetEnv("ProgramFiles");
  954. const char* sysDrive = cmsys::SystemTools::GetEnv("SystemDrive");
  955. if ( prgfiles )
  956. {
  957. this->InstallPath = prgfiles;
  958. }
  959. else if ( sysDrive )
  960. {
  961. this->InstallPath = sysDrive;
  962. this->InstallPath += "/Program Files";
  963. }
  964. else
  965. {
  966. this->InstallPath = "c:/Program Files";
  967. }
  968. this->InstallPath += "/";
  969. this->InstallPath += this->GetOption("CPACK_PACKAGE_NAME");
  970. this->InstallPath += "-";
  971. this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION");
  972. #elif defined(__HAIKU__)
  973. BPath dir;
  974. if (find_directory(B_COMMON_DIRECTORY, &dir) == B_OK)
  975. {
  976. this->InstallPath = dir.Path();
  977. }
  978. else
  979. {
  980. this->InstallPath = "/boot/common";
  981. }
  982. #else
  983. this->InstallPath = "/usr/local/";
  984. #endif
  985. return this->InstallPath.c_str();
  986. }
  987. //----------------------------------------------------------------------
  988. const char* cmCPackGenerator::GetPackagingInstallPrefix()
  989. {
  990. cmCPackLogger(cmCPackLog::LOG_DEBUG, "GetPackagingInstallPrefix: '"
  991. << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'" << std::endl);
  992. return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX");
  993. }
  994. //----------------------------------------------------------------------
  995. std::string cmCPackGenerator::FindTemplate(const char* name)
  996. {
  997. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: "
  998. << (name ? name : "(NULL)") << std::endl);
  999. std::string ffile = this->MakefileMap->GetModulesFile(name);
  1000. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: "
  1001. << ffile.c_str() << std::endl);
  1002. return ffile;
  1003. }
  1004. //----------------------------------------------------------------------
  1005. bool cmCPackGenerator::ConfigureString(const std::string& inString,
  1006. std::string& outString)
  1007. {
  1008. this->MakefileMap->ConfigureString(inString,
  1009. outString, true, false);
  1010. return true;
  1011. }
  1012. //----------------------------------------------------------------------
  1013. bool cmCPackGenerator::ConfigureFile(const char* inName,
  1014. const char* outName, bool copyOnly /* = false */)
  1015. {
  1016. return this->MakefileMap->ConfigureFile(inName, outName,
  1017. copyOnly, true, false) == 1;
  1018. }
  1019. //----------------------------------------------------------------------
  1020. int cmCPackGenerator::CleanTemporaryDirectory()
  1021. {
  1022. std::string tempInstallDirectoryWithPostfix
  1023. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  1024. const char* tempInstallDirectory = tempInstallDirectoryWithPostfix.c_str();
  1025. if(cmsys::SystemTools::FileExists(tempInstallDirectory))
  1026. {
  1027. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1028. "- Clean temporary : "
  1029. << tempInstallDirectory << std::endl);
  1030. if(!cmSystemTools::RepeatedRemoveDirectory(tempInstallDirectory))
  1031. {
  1032. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1033. "Problem removing temporary directory: " <<
  1034. tempInstallDirectory
  1035. << std::endl);
  1036. return 0;
  1037. }
  1038. }
  1039. return 1;
  1040. }
  1041. //----------------------------------------------------------------------
  1042. bool cmCPackGenerator::SupportsComponentInstallation() const
  1043. {
  1044. return false;
  1045. }
  1046. //----------------------------------------------------------------------
  1047. cmCPackInstallationType*
  1048. cmCPackGenerator::GetInstallationType(const char *projectName,
  1049. const char *name)
  1050. {
  1051. (void) projectName;
  1052. bool hasInstallationType = this->InstallationTypes.count(name) != 0;
  1053. cmCPackInstallationType *installType = &this->InstallationTypes[name];
  1054. if (!hasInstallationType)
  1055. {
  1056. // Define the installation type
  1057. std::string macroPrefix = "CPACK_INSTALL_TYPE_"
  1058. + cmsys::SystemTools::UpperCase(name);
  1059. installType->Name = name;
  1060. const char* displayName
  1061. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1062. if (displayName && *displayName)
  1063. {
  1064. installType->DisplayName = displayName;
  1065. }
  1066. else
  1067. {
  1068. installType->DisplayName = installType->Name;
  1069. }
  1070. installType->Index = static_cast<unsigned>(
  1071. this->InstallationTypes.size());
  1072. }
  1073. return installType;
  1074. }
  1075. //----------------------------------------------------------------------
  1076. cmCPackComponent*
  1077. cmCPackGenerator::GetComponent(const char *projectName, const char *name)
  1078. {
  1079. bool hasComponent = this->Components.count(name) != 0;
  1080. cmCPackComponent *component = &this->Components[name];
  1081. if (!hasComponent)
  1082. {
  1083. // Define the component
  1084. std::string macroPrefix = "CPACK_COMPONENT_"
  1085. + cmsys::SystemTools::UpperCase(name);
  1086. component->Name = name;
  1087. const char* displayName
  1088. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1089. if (displayName && *displayName)
  1090. {
  1091. component->DisplayName = displayName;
  1092. }
  1093. else
  1094. {
  1095. component->DisplayName = component->Name;
  1096. }
  1097. component->IsHidden
  1098. = this->IsSet((macroPrefix + "_HIDDEN").c_str());
  1099. component->IsRequired
  1100. = this->IsSet((macroPrefix + "_REQUIRED").c_str());
  1101. component->IsDisabledByDefault
  1102. = this->IsSet((macroPrefix + "_DISABLED").c_str());
  1103. component->IsDownloaded
  1104. = this->IsSet((macroPrefix + "_DOWNLOADED").c_str())
  1105. || cmSystemTools::IsOn(this->GetOption("CPACK_DOWNLOAD_ALL"));
  1106. const char* archiveFile = this->GetOption((macroPrefix +
  1107. "_ARCHIVE_FILE").c_str());
  1108. if (archiveFile && *archiveFile)
  1109. {
  1110. component->ArchiveFile = archiveFile;
  1111. }
  1112. const char* groupName = this->GetOption((macroPrefix + "_GROUP").c_str());
  1113. if (groupName && *groupName)
  1114. {
  1115. component->Group = GetComponentGroup(projectName, groupName);
  1116. component->Group->Components.push_back(component);
  1117. }
  1118. else
  1119. {
  1120. component->Group = 0;
  1121. }
  1122. const char* description
  1123. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1124. if (description && *description)
  1125. {
  1126. component->Description = description;
  1127. }
  1128. // Determine the installation types.
  1129. const char *installTypes
  1130. = this->GetOption((macroPrefix + "_INSTALL_TYPES").c_str());
  1131. if (installTypes && *installTypes)
  1132. {
  1133. std::vector<std::string> installTypesVector;
  1134. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  1135. std::vector<std::string>::iterator installTypesIt;
  1136. for (installTypesIt = installTypesVector.begin();
  1137. installTypesIt != installTypesVector.end();
  1138. ++installTypesIt)
  1139. {
  1140. component->InstallationTypes.push_back(
  1141. this->GetInstallationType(projectName, installTypesIt->c_str()));
  1142. }
  1143. }
  1144. // Determine the component dependencies.
  1145. const char *depends = this->GetOption((macroPrefix + "_DEPENDS").c_str());
  1146. if (depends && *depends)
  1147. {
  1148. std::vector<std::string> dependsVector;
  1149. cmSystemTools::ExpandListArgument(depends, dependsVector);
  1150. std::vector<std::string>::iterator dependIt;
  1151. for (dependIt = dependsVector.begin();
  1152. dependIt != dependsVector.end();
  1153. ++dependIt)
  1154. {
  1155. cmCPackComponent *child = GetComponent(projectName,
  1156. dependIt->c_str());
  1157. component->Dependencies.push_back(child);
  1158. child->ReverseDependencies.push_back(component);
  1159. }
  1160. }
  1161. }
  1162. return component;
  1163. }
  1164. //----------------------------------------------------------------------
  1165. cmCPackComponentGroup*
  1166. cmCPackGenerator::GetComponentGroup(const char *projectName, const char *name)
  1167. {
  1168. (void) projectName;
  1169. std::string macroPrefix = "CPACK_COMPONENT_GROUP_"
  1170. + cmsys::SystemTools::UpperCase(name);
  1171. bool hasGroup = this->ComponentGroups.count(name) != 0;
  1172. cmCPackComponentGroup *group = &this->ComponentGroups[name];
  1173. if (!hasGroup)
  1174. {
  1175. // Define the group
  1176. group->Name = name;
  1177. const char* displayName
  1178. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1179. if (displayName && *displayName)
  1180. {
  1181. group->DisplayName = displayName;
  1182. }
  1183. else
  1184. {
  1185. group->DisplayName = group->Name;
  1186. }
  1187. const char* description
  1188. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1189. if (description && *description)
  1190. {
  1191. group->Description = description;
  1192. }
  1193. group->IsBold
  1194. = this->IsSet((macroPrefix + "_BOLD_TITLE").c_str());
  1195. group->IsExpandedByDefault
  1196. = this->IsSet((macroPrefix + "_EXPANDED").c_str());
  1197. const char* parentGroupName
  1198. = this->GetOption((macroPrefix + "_PARENT_GROUP").c_str());
  1199. if (parentGroupName && *parentGroupName)
  1200. {
  1201. group->ParentGroup = GetComponentGroup(projectName, parentGroupName);
  1202. group->ParentGroup->Subgroups.push_back(group);
  1203. }
  1204. else
  1205. {
  1206. group->ParentGroup = 0;
  1207. }
  1208. }
  1209. return group;
  1210. }