cmCPackGenerator.cxx 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  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. destFile += "/" + outName;
  91. std::string outFile = topDirectory + "/" + outName;
  92. this->SetOptionIfNotSet("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str());
  93. this->SetOptionIfNotSet("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str());
  94. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_NAME", outName.c_str());
  95. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PATH", destFile.c_str());
  96. this->SetOptionIfNotSet("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
  97. outFile.c_str());
  98. this->SetOptionIfNotSet("CPACK_INSTALL_DIRECTORY", this->GetInstallPath());
  99. this->SetOptionIfNotSet("CPACK_NATIVE_INSTALL_DIRECTORY",
  100. cmsys::SystemTools::ConvertToOutputPath(this->GetInstallPath()).c_str());
  101. this->SetOptionIfNotSet("CPACK_TEMPORARY_INSTALL_DIRECTORY",
  102. tempDirectory.c_str());
  103. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  104. "Look for: CPACK_PACKAGE_DESCRIPTION_FILE" << std::endl);
  105. const char* descFileName
  106. = this->GetOption("CPACK_PACKAGE_DESCRIPTION_FILE");
  107. if ( descFileName )
  108. {
  109. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  110. "Look for: " << descFileName << std::endl);
  111. if ( !cmSystemTools::FileExists(descFileName) )
  112. {
  113. cmCPackLogger(cmCPackLog::LOG_ERROR,
  114. "Cannot find description file name: ["
  115. << descFileName << "]" << std::endl);
  116. return 0;
  117. }
  118. std::ifstream ifs(descFileName);
  119. if ( !ifs )
  120. {
  121. cmCPackLogger(cmCPackLog::LOG_ERROR,
  122. "Cannot open description file name: " << descFileName << std::endl);
  123. return 0;
  124. }
  125. cmOStringStream ostr;
  126. std::string line;
  127. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  128. "Read description file: " << descFileName << std::endl);
  129. while ( ifs && cmSystemTools::GetLineFromStream(ifs, line) )
  130. {
  131. ostr << cmXMLSafe(line) << std::endl;
  132. }
  133. this->SetOptionIfNotSet("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str());
  134. }
  135. if ( !this->GetOption("CPACK_PACKAGE_DESCRIPTION") )
  136. {
  137. cmCPackLogger(cmCPackLog::LOG_ERROR,
  138. "Project description not specified. Please specify "
  139. "CPACK_PACKAGE_DESCRIPTION or CPACK_PACKAGE_DESCRIPTION_FILE."
  140. << std::endl);
  141. return 0;
  142. }
  143. this->SetOptionIfNotSet("CPACK_REMOVE_TOPLEVEL_DIRECTORY", "1");
  144. return 1;
  145. }
  146. //----------------------------------------------------------------------
  147. int cmCPackGenerator::InstallProject()
  148. {
  149. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Install projects" << std::endl);
  150. this->CleanTemporaryDirectory();
  151. std::string bareTempInstallDirectory
  152. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  153. std::string tempInstallDirectoryStr = bareTempInstallDirectory;
  154. bool setDestDir = cmSystemTools::IsOn(this->GetOption("CPACK_SET_DESTDIR"));
  155. if (!setDestDir)
  156. {
  157. tempInstallDirectoryStr += this->GetPackagingInstallPrefix();
  158. }
  159. const char* tempInstallDirectory = tempInstallDirectoryStr.c_str();
  160. int res = 1;
  161. if ( !cmsys::SystemTools::MakeDirectory(bareTempInstallDirectory.c_str()))
  162. {
  163. cmCPackLogger(cmCPackLog::LOG_ERROR,
  164. "Problem creating temporary directory: "
  165. << (tempInstallDirectory ? tempInstallDirectory : "(NULL}")
  166. << std::endl);
  167. return 0;
  168. }
  169. if ( setDestDir )
  170. {
  171. std::string destDir = "DESTDIR=";
  172. destDir += tempInstallDirectory;
  173. cmSystemTools::PutEnv(destDir.c_str());
  174. }
  175. else
  176. {
  177. // Make sure there is no destdir
  178. cmSystemTools::PutEnv("DESTDIR=");
  179. }
  180. // If the CPackConfig file sets CPACK_INSTALL_COMMANDS then run them
  181. // as listed
  182. if ( !this->InstallProjectViaInstallCommands(
  183. setDestDir, tempInstallDirectory) )
  184. {
  185. return 0;
  186. }
  187. // If the CPackConfig file sets CPACK_INSTALL_SCRIPT then run them
  188. // as listed
  189. if ( !this->InstallProjectViaInstallScript(
  190. setDestDir, tempInstallDirectory) )
  191. {
  192. return 0;
  193. }
  194. // If the CPackConfig file sets CPACK_INSTALLED_DIRECTORIES
  195. // then glob it and copy it to CPACK_TEMPORARY_DIRECTORY
  196. // This is used in Source packageing
  197. if ( !this->InstallProjectViaInstalledDirectories(
  198. setDestDir, tempInstallDirectory) )
  199. {
  200. return 0;
  201. }
  202. // If the project is a CMAKE project then run pre-install
  203. // and then read the cmake_install script to run it
  204. if ( !this->InstallProjectViaInstallCMakeProjects(
  205. setDestDir, bareTempInstallDirectory.c_str()) )
  206. {
  207. return 0;
  208. }
  209. if ( setDestDir )
  210. {
  211. cmSystemTools::PutEnv("DESTDIR=");
  212. }
  213. return res;
  214. }
  215. //----------------------------------------------------------------------
  216. int cmCPackGenerator::InstallProjectViaInstallCommands(
  217. bool setDestDir, const char* tempInstallDirectory)
  218. {
  219. (void) setDestDir;
  220. const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS");
  221. if ( installCommands && *installCommands )
  222. {
  223. std::string tempInstallDirectoryEnv = "CMAKE_INSTALL_PREFIX=";
  224. tempInstallDirectoryEnv += tempInstallDirectory;
  225. cmSystemTools::PutEnv(tempInstallDirectoryEnv.c_str());
  226. std::vector<std::string> installCommandsVector;
  227. cmSystemTools::ExpandListArgument(installCommands,installCommandsVector);
  228. std::vector<std::string>::iterator it;
  229. for ( it = installCommandsVector.begin();
  230. it != installCommandsVector.end();
  231. ++it )
  232. {
  233. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << it->c_str()
  234. << std::endl);
  235. std::string output;
  236. int retVal = 1;
  237. bool resB = cmSystemTools::RunSingleCommand(it->c_str(), &output,
  238. &retVal, 0, this->GeneratorVerbose, 0);
  239. if ( !resB || retVal )
  240. {
  241. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  242. tmpFile += "/InstallOutput.log";
  243. cmGeneratedFileStream ofs(tmpFile.c_str());
  244. ofs << "# Run command: " << it->c_str() << std::endl
  245. << "# Output:" << std::endl
  246. << output.c_str() << std::endl;
  247. cmCPackLogger(cmCPackLog::LOG_ERROR,
  248. "Problem running install command: " << it->c_str() << std::endl
  249. << "Please check " << tmpFile.c_str() << " for errors"
  250. << std::endl);
  251. return 0;
  252. }
  253. }
  254. }
  255. return 1;
  256. }
  257. //----------------------------------------------------------------------
  258. int cmCPackGenerator::InstallProjectViaInstalledDirectories(
  259. bool setDestDir, const char* tempInstallDirectory)
  260. {
  261. (void)setDestDir;
  262. (void)tempInstallDirectory;
  263. std::vector<cmsys::RegularExpression> ignoreFilesRegex;
  264. const char* cpackIgnoreFiles = this->GetOption("CPACK_IGNORE_FILES");
  265. if ( cpackIgnoreFiles )
  266. {
  267. std::vector<std::string> ignoreFilesRegexString;
  268. cmSystemTools::ExpandListArgument(cpackIgnoreFiles,
  269. ignoreFilesRegexString);
  270. std::vector<std::string>::iterator it;
  271. for ( it = ignoreFilesRegexString.begin();
  272. it != ignoreFilesRegexString.end();
  273. ++it )
  274. {
  275. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  276. "Create ignore files regex for: " << it->c_str() << std::endl);
  277. ignoreFilesRegex.push_back(it->c_str());
  278. }
  279. }
  280. const char* installDirectories
  281. = this->GetOption("CPACK_INSTALLED_DIRECTORIES");
  282. if ( installDirectories && *installDirectories )
  283. {
  284. std::vector<std::string> installDirectoriesVector;
  285. cmSystemTools::ExpandListArgument(installDirectories,
  286. installDirectoriesVector);
  287. if ( installDirectoriesVector.size() % 2 != 0 )
  288. {
  289. cmCPackLogger(cmCPackLog::LOG_ERROR,
  290. "CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> and "
  291. "<subdirectory>. The <subdirectory> can be '.' to be installed in "
  292. "the toplevel directory of installation." << std::endl);
  293. return 0;
  294. }
  295. std::vector<std::string>::iterator it;
  296. const char* tempDir = tempInstallDirectory;
  297. for ( it = installDirectoriesVector.begin();
  298. it != installDirectoriesVector.end();
  299. ++it )
  300. {
  301. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  302. cmsys::Glob gl;
  303. std::string toplevel = it->c_str();
  304. it ++;
  305. std::string subdir = it->c_str();
  306. std::string findExpr = toplevel;
  307. findExpr += "/*";
  308. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  309. "- Install directory: " << toplevel << std::endl);
  310. gl.RecurseOn();
  311. if ( !gl.FindFiles(findExpr) )
  312. {
  313. cmCPackLogger(cmCPackLog::LOG_ERROR,
  314. "Cannot find any files in the installed directory" << std::endl);
  315. return 0;
  316. }
  317. std::vector<std::string>& files = gl.GetFiles();
  318. std::vector<std::string>::iterator gfit;
  319. std::vector<cmsys::RegularExpression>::iterator regIt;
  320. for ( gfit = files.begin(); gfit != files.end(); ++ gfit )
  321. {
  322. bool skip = false;
  323. std::string &inFile = *gfit;
  324. for ( regIt= ignoreFilesRegex.begin();
  325. regIt!= ignoreFilesRegex.end();
  326. ++ regIt)
  327. {
  328. if ( regIt->find(inFile.c_str()) )
  329. {
  330. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Ignore file: "
  331. << inFile.c_str() << std::endl);
  332. skip = true;
  333. }
  334. }
  335. if ( skip )
  336. {
  337. continue;
  338. }
  339. std::string filePath = tempDir;
  340. filePath += "/" + subdir + "/"
  341. + cmSystemTools::RelativePath(toplevel.c_str(), gfit->c_str());
  342. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy file: "
  343. << inFile.c_str() << " -> " << filePath.c_str() << std::endl);
  344. if ( !cmSystemTools::CopyFileIfDifferent(inFile.c_str(),
  345. filePath.c_str()) )
  346. {
  347. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying file: "
  348. << inFile.c_str() << " -> " << filePath.c_str() << std::endl);
  349. return 0;
  350. }
  351. }
  352. }
  353. }
  354. return 1;
  355. }
  356. //----------------------------------------------------------------------
  357. int cmCPackGenerator::InstallProjectViaInstallScript(
  358. bool setDestDir, const char* tempInstallDirectory)
  359. {
  360. const char* cmakeScripts
  361. = this->GetOption("CPACK_INSTALL_SCRIPT");
  362. std::string currentWorkingDirectory =
  363. cmSystemTools::GetCurrentWorkingDirectory();
  364. if ( cmakeScripts && *cmakeScripts )
  365. {
  366. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  367. "- Install scripts: " << cmakeScripts << std::endl);
  368. std::vector<std::string> cmakeScriptsVector;
  369. cmSystemTools::ExpandListArgument(cmakeScripts,
  370. cmakeScriptsVector);
  371. std::vector<std::string>::iterator it;
  372. for ( it = cmakeScriptsVector.begin();
  373. it != cmakeScriptsVector.end();
  374. ++it )
  375. {
  376. std::string installScript = it->c_str();
  377. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  378. "- Install script: " << installScript << std::endl);
  379. if ( setDestDir )
  380. {
  381. // For DESTDIR based packaging, use the *project* CMAKE_INSTALL_PREFIX
  382. // underneath the tempInstallDirectory. The value of the project's
  383. // CMAKE_INSTALL_PREFIX is sent in here as the value of the
  384. // CPACK_INSTALL_PREFIX variable.
  385. std::string dir;
  386. if (this->GetOption("CPACK_INSTALL_PREFIX"))
  387. {
  388. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  389. }
  390. this->SetOption("CMAKE_INSTALL_PREFIX", dir.c_str());
  391. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  392. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (this->SetOption)"
  393. << std::endl);
  394. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  395. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'" << std::endl);
  396. }
  397. else
  398. {
  399. this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
  400. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  401. "- Using non-DESTDIR install... (this->SetOption)" << std::endl);
  402. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  403. "- Setting CMAKE_INSTALL_PREFIX to '" << tempInstallDirectory
  404. << "'" << std::endl);
  405. }
  406. this->SetOptionIfNotSet("CMAKE_CURRENT_BINARY_DIR",
  407. tempInstallDirectory);
  408. this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR",
  409. tempInstallDirectory);
  410. int res = this->MakefileMap->ReadListFile(0, installScript.c_str());
  411. if ( cmSystemTools::GetErrorOccuredFlag() || !res )
  412. {
  413. return 0;
  414. }
  415. }
  416. }
  417. return 1;
  418. }
  419. //----------------------------------------------------------------------
  420. int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
  421. bool setDestDir, const char* baseTempInstallDirectory)
  422. {
  423. const char* cmakeProjects
  424. = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
  425. const char* cmakeGenerator
  426. = this->GetOption("CPACK_CMAKE_GENERATOR");
  427. std::string currentWorkingDirectory =
  428. cmSystemTools::GetCurrentWorkingDirectory();
  429. if ( cmakeProjects && *cmakeProjects )
  430. {
  431. if ( !cmakeGenerator )
  432. {
  433. cmCPackLogger(cmCPackLog::LOG_ERROR,
  434. "CPACK_INSTALL_CMAKE_PROJECTS is specified, but "
  435. "CPACK_CMAKE_GENERATOR is not. CPACK_CMAKE_GENERATOR "
  436. "is required to install the project."
  437. << std::endl);
  438. return 0;
  439. }
  440. std::vector<std::string> cmakeProjectsVector;
  441. cmSystemTools::ExpandListArgument(cmakeProjects,
  442. cmakeProjectsVector);
  443. std::vector<std::string>::iterator it;
  444. for ( it = cmakeProjectsVector.begin();
  445. it != cmakeProjectsVector.end();
  446. ++it )
  447. {
  448. if ( it+1 == cmakeProjectsVector.end() ||
  449. it+2 == cmakeProjectsVector.end() ||
  450. it+3 == cmakeProjectsVector.end() )
  451. {
  452. cmCPackLogger(cmCPackLog::LOG_ERROR,
  453. "Not enough items on list: CPACK_INSTALL_CMAKE_PROJECTS. "
  454. "CPACK_INSTALL_CMAKE_PROJECTS should hold quadruplet of install "
  455. "directory, install project name, install component, and install "
  456. "subdirectory."
  457. << std::endl);
  458. return 0;
  459. }
  460. std::string installDirectory = it->c_str();
  461. ++it;
  462. std::string installProjectName = it->c_str();
  463. ++it;
  464. std::string installComponent = it->c_str();
  465. ++it;
  466. std::string installSubDirectory = it->c_str();
  467. std::string installFile = installDirectory + "/cmake_install.cmake";
  468. std::vector<std::string> componentsVector;
  469. bool componentInstall = false;
  470. if (this->SupportsComponentInstallation())
  471. {
  472. // Determine the installation types for this project (if provided).
  473. std::string installTypesVar = "CPACK_"
  474. + cmSystemTools::UpperCase(installComponent) + "_INSTALL_TYPES";
  475. const char *installTypes = this->GetOption(installTypesVar.c_str());
  476. if (installTypes && *installTypes)
  477. {
  478. std::vector<std::string> installTypesVector;
  479. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  480. std::vector<std::string>::iterator installTypeIt;
  481. for (installTypeIt = installTypesVector.begin();
  482. installTypeIt != installTypesVector.end();
  483. ++installTypeIt)
  484. {
  485. this->GetInstallationType(installProjectName.c_str(),
  486. installTypeIt->c_str());
  487. }
  488. }
  489. // Determine the set of components that will be used in this project
  490. std::string componentsVar
  491. = "CPACK_COMPONENTS_" + cmSystemTools::UpperCase(installComponent);
  492. const char *components = this->GetOption(componentsVar.c_str());
  493. if (components && *components)
  494. {
  495. cmSystemTools::ExpandListArgument(components, componentsVector);
  496. std::vector<std::string>::iterator compIt;
  497. for (compIt = componentsVector.begin();
  498. compIt != componentsVector.end();
  499. ++compIt)
  500. {
  501. GetComponent(installProjectName.c_str(), compIt->c_str());
  502. }
  503. componentInstall = true;
  504. }
  505. }
  506. if (componentsVector.empty())
  507. {
  508. componentsVector.push_back(installComponent);
  509. }
  510. const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
  511. cmGlobalGenerator* globalGenerator
  512. = this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator(
  513. cmakeGenerator);
  514. // set the global flag for unix style paths on cmSystemTools as
  515. // soon as the generator is set. This allows gmake to be used
  516. // on windows.
  517. cmSystemTools::SetForceUnixPaths(globalGenerator->GetForceUnixPaths());
  518. // Does this generator require pre-install?
  519. if ( globalGenerator->GetPreinstallTargetName() )
  520. {
  521. globalGenerator->FindMakeProgram(this->MakefileMap);
  522. const char* cmakeMakeProgram
  523. = this->MakefileMap->GetDefinition("CMAKE_MAKE_PROGRAM");
  524. std::string buildCommand
  525. = globalGenerator->GenerateBuildCommand(cmakeMakeProgram,
  526. installProjectName.c_str(), 0,
  527. globalGenerator->GetPreinstallTargetName(),
  528. buildConfig, false, false);
  529. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  530. "- Install command: " << buildCommand << std::endl);
  531. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  532. "- Run preinstall target for: " << installProjectName << std::endl);
  533. std::string output;
  534. int retVal = 1;
  535. bool resB =
  536. cmSystemTools::RunSingleCommand(buildCommand.c_str(),
  537. &output,
  538. &retVal,
  539. installDirectory.c_str(),
  540. this->GeneratorVerbose, 0);
  541. if ( !resB || retVal )
  542. {
  543. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  544. tmpFile += "/PreinstallOutput.log";
  545. cmGeneratedFileStream ofs(tmpFile.c_str());
  546. ofs << "# Run command: " << buildCommand.c_str() << std::endl
  547. << "# Directory: " << installDirectory.c_str() << std::endl
  548. << "# Output:" << std::endl
  549. << output.c_str() << std::endl;
  550. cmCPackLogger(cmCPackLog::LOG_ERROR,
  551. "Problem running install command: " << buildCommand.c_str()
  552. << std::endl
  553. << "Please check " << tmpFile.c_str() << " for errors"
  554. << std::endl);
  555. return 0;
  556. }
  557. }
  558. delete globalGenerator;
  559. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  560. "- Install project: " << installProjectName << std::endl);
  561. // Run the installation for each component
  562. std::vector<std::string>::iterator componentIt;
  563. for (componentIt = componentsVector.begin();
  564. componentIt != componentsVector.end();
  565. ++componentIt)
  566. {
  567. std::string tempInstallDirectory = baseTempInstallDirectory;
  568. installComponent = *componentIt;
  569. if (componentInstall)
  570. {
  571. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  572. "- Install component: " << installComponent
  573. << std::endl);
  574. }
  575. cmake cm;
  576. cm.AddCMakePaths();
  577. cm.SetProgressCallback(cmCPackGeneratorProgress, this);
  578. cmGlobalGenerator gg;
  579. gg.SetCMakeInstance(&cm);
  580. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  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. #elif defined(__HAIKU__)
  945. BPath dir;
  946. if (find_directory(B_COMMON_DIRECTORY, &dir) == B_OK)
  947. {
  948. this->InstallPath = dir.Path();
  949. }
  950. else
  951. {
  952. this->InstallPath = "/boot/common";
  953. }
  954. #else
  955. this->InstallPath = "/usr/local/";
  956. #endif
  957. return this->InstallPath.c_str();
  958. }
  959. //----------------------------------------------------------------------
  960. const char* cmCPackGenerator::GetPackagingInstallPrefix()
  961. {
  962. cmCPackLogger(cmCPackLog::LOG_DEBUG, "GetPackagingInstallPrefix: '"
  963. << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'" << std::endl);
  964. return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX");
  965. }
  966. //----------------------------------------------------------------------
  967. std::string cmCPackGenerator::FindTemplate(const char* name)
  968. {
  969. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: "
  970. << (name ? name : "(NULL)") << std::endl);
  971. std::string ffile = this->MakefileMap->GetModulesFile(name);
  972. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: "
  973. << ffile.c_str() << std::endl);
  974. return ffile;
  975. }
  976. //----------------------------------------------------------------------
  977. bool cmCPackGenerator::ConfigureString(const std::string& inString,
  978. std::string& outString)
  979. {
  980. this->MakefileMap->ConfigureString(inString,
  981. outString, true, false);
  982. return true;
  983. }
  984. //----------------------------------------------------------------------
  985. bool cmCPackGenerator::ConfigureFile(const char* inName,
  986. const char* outName, bool copyOnly /* = false */)
  987. {
  988. return this->MakefileMap->ConfigureFile(inName, outName,
  989. copyOnly, true, false) == 1;
  990. }
  991. //----------------------------------------------------------------------
  992. int cmCPackGenerator::CleanTemporaryDirectory()
  993. {
  994. std::string tempInstallDirectoryWithPostfix
  995. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  996. const char* tempInstallDirectory = tempInstallDirectoryWithPostfix.c_str();
  997. if(cmsys::SystemTools::FileExists(tempInstallDirectory))
  998. {
  999. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1000. "- Clean temporary : "
  1001. << tempInstallDirectory << std::endl);
  1002. if(!cmsys::SystemTools::RemoveADirectory(tempInstallDirectory))
  1003. {
  1004. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1005. "Problem removing temporary directory: " <<
  1006. tempInstallDirectory
  1007. << std::endl);
  1008. return 0;
  1009. }
  1010. }
  1011. return 1;
  1012. }
  1013. //----------------------------------------------------------------------
  1014. bool cmCPackGenerator::SupportsComponentInstallation() const
  1015. {
  1016. return false;
  1017. }
  1018. //----------------------------------------------------------------------
  1019. cmCPackInstallationType*
  1020. cmCPackGenerator::GetInstallationType(const char *projectName,
  1021. const char *name)
  1022. {
  1023. (void) projectName;
  1024. bool hasInstallationType = this->InstallationTypes.count(name) != 0;
  1025. cmCPackInstallationType *installType = &this->InstallationTypes[name];
  1026. if (!hasInstallationType)
  1027. {
  1028. // Define the installation type
  1029. std::string macroPrefix = "CPACK_INSTALL_TYPE_"
  1030. + cmsys::SystemTools::UpperCase(name);
  1031. installType->Name = name;
  1032. const char* displayName
  1033. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1034. if (displayName && *displayName)
  1035. {
  1036. installType->DisplayName = displayName;
  1037. }
  1038. else
  1039. {
  1040. installType->DisplayName = installType->Name;
  1041. }
  1042. installType->Index = static_cast<unsigned>(
  1043. this->InstallationTypes.size());
  1044. }
  1045. return installType;
  1046. }
  1047. //----------------------------------------------------------------------
  1048. cmCPackComponent*
  1049. cmCPackGenerator::GetComponent(const char *projectName, const char *name)
  1050. {
  1051. bool hasComponent = this->Components.count(name) != 0;
  1052. cmCPackComponent *component = &this->Components[name];
  1053. if (!hasComponent)
  1054. {
  1055. // Define the component
  1056. std::string macroPrefix = "CPACK_COMPONENT_"
  1057. + cmsys::SystemTools::UpperCase(name);
  1058. component->Name = name;
  1059. const char* displayName
  1060. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1061. if (displayName && *displayName)
  1062. {
  1063. component->DisplayName = displayName;
  1064. }
  1065. else
  1066. {
  1067. component->DisplayName = component->Name;
  1068. }
  1069. component->IsHidden
  1070. = this->IsSet((macroPrefix + "_HIDDEN").c_str());
  1071. component->IsRequired
  1072. = this->IsSet((macroPrefix + "_REQUIRED").c_str());
  1073. component->IsDisabledByDefault
  1074. = this->IsSet((macroPrefix + "_DISABLED").c_str());
  1075. component->IsDownloaded
  1076. = this->IsSet((macroPrefix + "_DOWNLOADED").c_str())
  1077. || cmSystemTools::IsOn(this->GetOption("CPACK_DOWNLOAD_ALL"));
  1078. const char* archiveFile = this->GetOption((macroPrefix +
  1079. "_ARCHIVE_FILE").c_str());
  1080. if (archiveFile && *archiveFile)
  1081. {
  1082. component->ArchiveFile = archiveFile;
  1083. }
  1084. const char* groupName = this->GetOption((macroPrefix + "_GROUP").c_str());
  1085. if (groupName && *groupName)
  1086. {
  1087. component->Group = GetComponentGroup(projectName, groupName);
  1088. component->Group->Components.push_back(component);
  1089. }
  1090. else
  1091. {
  1092. component->Group = 0;
  1093. }
  1094. const char* description
  1095. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1096. if (description && *description)
  1097. {
  1098. component->Description = description;
  1099. }
  1100. // Determine the installation types.
  1101. const char *installTypes
  1102. = this->GetOption((macroPrefix + "_INSTALL_TYPES").c_str());
  1103. if (installTypes && *installTypes)
  1104. {
  1105. std::vector<std::string> installTypesVector;
  1106. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  1107. std::vector<std::string>::iterator installTypesIt;
  1108. for (installTypesIt = installTypesVector.begin();
  1109. installTypesIt != installTypesVector.end();
  1110. ++installTypesIt)
  1111. {
  1112. component->InstallationTypes.push_back(
  1113. this->GetInstallationType(projectName, installTypesIt->c_str()));
  1114. }
  1115. }
  1116. // Determine the component dependencies.
  1117. const char *depends = this->GetOption((macroPrefix + "_DEPENDS").c_str());
  1118. if (depends && *depends)
  1119. {
  1120. std::vector<std::string> dependsVector;
  1121. cmSystemTools::ExpandListArgument(depends, dependsVector);
  1122. std::vector<std::string>::iterator dependIt;
  1123. for (dependIt = dependsVector.begin();
  1124. dependIt != dependsVector.end();
  1125. ++dependIt)
  1126. {
  1127. cmCPackComponent *child = GetComponent(projectName,
  1128. dependIt->c_str());
  1129. component->Dependencies.push_back(child);
  1130. child->ReverseDependencies.push_back(component);
  1131. }
  1132. }
  1133. }
  1134. return component;
  1135. }
  1136. //----------------------------------------------------------------------
  1137. cmCPackComponentGroup*
  1138. cmCPackGenerator::GetComponentGroup(const char *projectName, const char *name)
  1139. {
  1140. (void) projectName;
  1141. std::string macroPrefix = "CPACK_COMPONENT_GROUP_"
  1142. + cmsys::SystemTools::UpperCase(name);
  1143. bool hasGroup = this->ComponentGroups.count(name) != 0;
  1144. cmCPackComponentGroup *group = &this->ComponentGroups[name];
  1145. if (!hasGroup)
  1146. {
  1147. // Define the group
  1148. group->Name = name;
  1149. const char* displayName
  1150. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1151. if (displayName && *displayName)
  1152. {
  1153. group->DisplayName = displayName;
  1154. }
  1155. else
  1156. {
  1157. group->DisplayName = group->Name;
  1158. }
  1159. const char* description
  1160. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1161. if (description && *description)
  1162. {
  1163. group->Description = description;
  1164. }
  1165. group->IsBold
  1166. = this->IsSet((macroPrefix + "_BOLD_TITLE").c_str());
  1167. group->IsExpandedByDefault
  1168. = this->IsSet((macroPrefix + "_EXPANDED").c_str());
  1169. const char* parentGroupName
  1170. = this->GetOption((macroPrefix + "_PARENT_GROUP").c_str());
  1171. if (parentGroupName && *parentGroupName)
  1172. {
  1173. group->ParentGroup = GetComponentGroup(projectName, parentGroupName);
  1174. group->ParentGroup->Subgroups.push_back(group);
  1175. }
  1176. else
  1177. {
  1178. group->ParentGroup = 0;
  1179. }
  1180. }
  1181. return group;
  1182. }