cmCPackGenerator.cxx 42 KB

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