cmCPackGenerator.cxx 43 KB

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