cmCPackGenerator.cxx 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  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. if ( cmakeScripts && *cmakeScripts )
  363. {
  364. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  365. "- Install scripts: " << cmakeScripts << std::endl);
  366. std::vector<std::string> cmakeScriptsVector;
  367. cmSystemTools::ExpandListArgument(cmakeScripts,
  368. cmakeScriptsVector);
  369. std::vector<std::string>::iterator it;
  370. for ( it = cmakeScriptsVector.begin();
  371. it != cmakeScriptsVector.end();
  372. ++it )
  373. {
  374. std::string installScript = it->c_str();
  375. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  376. "- Install script: " << installScript << std::endl);
  377. if ( setDestDir )
  378. {
  379. // For DESTDIR based packaging, use the *project* CMAKE_INSTALL_PREFIX
  380. // underneath the tempInstallDirectory. The value of the project's
  381. // CMAKE_INSTALL_PREFIX is sent in here as the value of the
  382. // CPACK_INSTALL_PREFIX variable.
  383. std::string dir;
  384. if (this->GetOption("CPACK_INSTALL_PREFIX"))
  385. {
  386. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  387. }
  388. this->SetOption("CMAKE_INSTALL_PREFIX", dir.c_str());
  389. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  390. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (this->SetOption)"
  391. << std::endl);
  392. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  393. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'" << std::endl);
  394. }
  395. else
  396. {
  397. this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
  398. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  399. "- Using non-DESTDIR install... (this->SetOption)" << std::endl);
  400. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  401. "- Setting CMAKE_INSTALL_PREFIX to '" << tempInstallDirectory
  402. << "'" << std::endl);
  403. }
  404. this->SetOptionIfNotSet("CMAKE_CURRENT_BINARY_DIR",
  405. tempInstallDirectory);
  406. this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR",
  407. tempInstallDirectory);
  408. int res = this->MakefileMap->ReadListFile(0, installScript.c_str());
  409. if ( cmSystemTools::GetErrorOccuredFlag() || !res )
  410. {
  411. return 0;
  412. }
  413. }
  414. }
  415. return 1;
  416. }
  417. //----------------------------------------------------------------------
  418. int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
  419. bool setDestDir, const char* baseTempInstallDirectory)
  420. {
  421. const char* cmakeProjects
  422. = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
  423. const char* cmakeGenerator
  424. = this->GetOption("CPACK_CMAKE_GENERATOR");
  425. if ( cmakeProjects && *cmakeProjects )
  426. {
  427. if ( !cmakeGenerator )
  428. {
  429. cmCPackLogger(cmCPackLog::LOG_ERROR,
  430. "CPACK_INSTALL_CMAKE_PROJECTS is specified, but "
  431. "CPACK_CMAKE_GENERATOR is not. CPACK_CMAKE_GENERATOR "
  432. "is required to install the project."
  433. << std::endl);
  434. return 0;
  435. }
  436. std::vector<std::string> cmakeProjectsVector;
  437. cmSystemTools::ExpandListArgument(cmakeProjects,
  438. cmakeProjectsVector);
  439. std::vector<std::string>::iterator it;
  440. for ( it = cmakeProjectsVector.begin();
  441. it != cmakeProjectsVector.end();
  442. ++it )
  443. {
  444. if ( it+1 == cmakeProjectsVector.end() ||
  445. it+2 == cmakeProjectsVector.end() ||
  446. it+3 == cmakeProjectsVector.end() )
  447. {
  448. cmCPackLogger(cmCPackLog::LOG_ERROR,
  449. "Not enough items on list: CPACK_INSTALL_CMAKE_PROJECTS. "
  450. "CPACK_INSTALL_CMAKE_PROJECTS should hold quadruplet of install "
  451. "directory, install project name, install component, and install "
  452. "subdirectory."
  453. << std::endl);
  454. return 0;
  455. }
  456. std::string installDirectory = it->c_str();
  457. ++it;
  458. std::string installProjectName = it->c_str();
  459. ++it;
  460. std::string installComponent = it->c_str();
  461. ++it;
  462. std::string installSubDirectory = it->c_str();
  463. std::string installFile = installDirectory + "/cmake_install.cmake";
  464. std::vector<std::string> componentsVector;
  465. bool componentInstall = false;
  466. if (this->SupportsComponentInstallation())
  467. {
  468. // Determine the installation types for this project (if provided).
  469. std::string installTypesVar = "CPACK_"
  470. + cmSystemTools::UpperCase(installComponent) + "_INSTALL_TYPES";
  471. const char *installTypes = this->GetOption(installTypesVar.c_str());
  472. if (installTypes && *installTypes)
  473. {
  474. std::vector<std::string> installTypesVector;
  475. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  476. std::vector<std::string>::iterator installTypeIt;
  477. for (installTypeIt = installTypesVector.begin();
  478. installTypeIt != installTypesVector.end();
  479. ++installTypeIt)
  480. {
  481. this->GetInstallationType(installProjectName.c_str(),
  482. installTypeIt->c_str());
  483. }
  484. }
  485. // Determine the set of components that will be used in this project
  486. std::string componentsVar
  487. = "CPACK_COMPONENTS_" + cmSystemTools::UpperCase(installComponent);
  488. const char *components = this->GetOption(componentsVar.c_str());
  489. if (components && *components)
  490. {
  491. cmSystemTools::ExpandListArgument(components, componentsVector);
  492. std::vector<std::string>::iterator compIt;
  493. for (compIt = componentsVector.begin();
  494. compIt != componentsVector.end();
  495. ++compIt)
  496. {
  497. GetComponent(installProjectName.c_str(), compIt->c_str());
  498. }
  499. componentInstall = true;
  500. }
  501. }
  502. if (componentsVector.empty())
  503. {
  504. componentsVector.push_back(installComponent);
  505. }
  506. const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
  507. cmGlobalGenerator* globalGenerator
  508. = this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator(
  509. cmakeGenerator);
  510. // set the global flag for unix style paths on cmSystemTools as
  511. // soon as the generator is set. This allows gmake to be used
  512. // on windows.
  513. cmSystemTools::SetForceUnixPaths(globalGenerator->GetForceUnixPaths());
  514. // Does this generator require pre-install?
  515. if ( globalGenerator->GetPreinstallTargetName() )
  516. {
  517. globalGenerator->FindMakeProgram(this->MakefileMap);
  518. const char* cmakeMakeProgram
  519. = this->MakefileMap->GetDefinition("CMAKE_MAKE_PROGRAM");
  520. std::string buildCommand
  521. = globalGenerator->GenerateBuildCommand(cmakeMakeProgram,
  522. installProjectName.c_str(), 0,
  523. globalGenerator->GetPreinstallTargetName(),
  524. buildConfig, false, false);
  525. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  526. "- Install command: " << buildCommand << std::endl);
  527. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  528. "- Run preinstall target for: " << installProjectName << std::endl);
  529. std::string output;
  530. int retVal = 1;
  531. bool resB =
  532. cmSystemTools::RunSingleCommand(buildCommand.c_str(),
  533. &output,
  534. &retVal,
  535. installDirectory.c_str(),
  536. this->GeneratorVerbose, 0);
  537. if ( !resB || retVal )
  538. {
  539. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  540. tmpFile += "/PreinstallOutput.log";
  541. cmGeneratedFileStream ofs(tmpFile.c_str());
  542. ofs << "# Run command: " << buildCommand.c_str() << std::endl
  543. << "# Directory: " << installDirectory.c_str() << std::endl
  544. << "# Output:" << std::endl
  545. << output.c_str() << std::endl;
  546. cmCPackLogger(cmCPackLog::LOG_ERROR,
  547. "Problem running install command: " << buildCommand.c_str()
  548. << std::endl
  549. << "Please check " << tmpFile.c_str() << " for errors"
  550. << std::endl);
  551. return 0;
  552. }
  553. }
  554. delete globalGenerator;
  555. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  556. "- Install project: " << installProjectName << std::endl);
  557. // Run the installation for each component
  558. std::vector<std::string>::iterator componentIt;
  559. for (componentIt = componentsVector.begin();
  560. componentIt != componentsVector.end();
  561. ++componentIt)
  562. {
  563. std::string tempInstallDirectory = baseTempInstallDirectory;
  564. installComponent = *componentIt;
  565. if (componentInstall)
  566. {
  567. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  568. "- Install component: " << installComponent
  569. << std::endl);
  570. }
  571. cmake cm;
  572. cm.AddCMakePaths();
  573. cm.SetProgressCallback(cmCPackGeneratorProgress, this);
  574. cmGlobalGenerator gg;
  575. gg.SetCMakeInstance(&cm);
  576. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  577. cmMakefile *mf = lg->GetMakefile();
  578. std::string realInstallDirectory = tempInstallDirectory;
  579. if ( !installSubDirectory.empty() && installSubDirectory != "/" )
  580. {
  581. realInstallDirectory += installSubDirectory;
  582. }
  583. if (componentInstall)
  584. {
  585. tempInstallDirectory += "/";
  586. tempInstallDirectory += installComponent;
  587. }
  588. if (!setDestDir)
  589. {
  590. tempInstallDirectory += this->GetPackagingInstallPrefix();
  591. }
  592. if ( setDestDir )
  593. {
  594. // For DESTDIR based packaging, use the *project*
  595. // CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The
  596. // value of the project's CMAKE_INSTALL_PREFIX is sent in here as
  597. // the value of the CPACK_INSTALL_PREFIX variable.
  598. //
  599. std::string dir;
  600. if (this->GetOption("CPACK_INSTALL_PREFIX"))
  601. {
  602. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  603. }
  604. mf->AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str());
  605. cmCPackLogger(
  606. cmCPackLog::LOG_DEBUG,
  607. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf->AddDefinition)"
  608. << std::endl);
  609. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  610. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'"
  611. << std::endl);
  612. // Make sure that DESTDIR + CPACK_INSTALL_PREFIX directory
  613. // exists:
  614. //
  615. if (cmSystemTools::StringStartsWith(dir.c_str(), "/"))
  616. {
  617. dir = tempInstallDirectory + dir;
  618. }
  619. else
  620. {
  621. dir = tempInstallDirectory + "/" + dir;
  622. }
  623. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  624. "- Creating directory: '" << dir << "'" << std::endl);
  625. if ( !cmsys::SystemTools::MakeDirectory(dir.c_str()))
  626. {
  627. cmCPackLogger(cmCPackLog::LOG_ERROR,
  628. "Problem creating temporary directory: "
  629. << dir << std::endl);
  630. return 0;
  631. }
  632. }
  633. else
  634. {
  635. mf->AddDefinition("CMAKE_INSTALL_PREFIX",
  636. tempInstallDirectory.c_str());
  637. if ( !cmsys::SystemTools::MakeDirectory(
  638. tempInstallDirectory.c_str()))
  639. {
  640. cmCPackLogger(cmCPackLog::LOG_ERROR,
  641. "Problem creating temporary directory: "
  642. << tempInstallDirectory << std::endl);
  643. return 0;
  644. }
  645. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  646. "- Using non-DESTDIR install... (mf->AddDefinition)"
  647. << std::endl);
  648. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  649. "- Setting CMAKE_INSTALL_PREFIX to '"
  650. << tempInstallDirectory
  651. << "'" << std::endl);
  652. }
  653. if ( buildConfig && *buildConfig )
  654. {
  655. mf->AddDefinition("BUILD_TYPE", buildConfig);
  656. }
  657. std::string installComponentLowerCase
  658. = cmSystemTools::LowerCase(installComponent);
  659. if ( installComponentLowerCase != "all" )
  660. {
  661. mf->AddDefinition("CMAKE_INSTALL_COMPONENT",
  662. installComponent.c_str());
  663. }
  664. // strip on TRUE, ON, 1, one or several file names, but not on
  665. // FALSE, OFF, 0 and an empty string
  666. if (!cmSystemTools::IsOff(this->GetOption("CPACK_STRIP_FILES")))
  667. {
  668. mf->AddDefinition("CMAKE_INSTALL_DO_STRIP", "1");
  669. }
  670. int res = mf->ReadListFile(0, installFile.c_str());
  671. if ( cmSystemTools::GetErrorOccuredFlag() || !res )
  672. {
  673. return 0;
  674. }
  675. }
  676. }
  677. }
  678. return 1;
  679. }
  680. //----------------------------------------------------------------------
  681. bool cmCPackGenerator::ReadListFile(const char* moduleName)
  682. {
  683. std::string fullPath = this->MakefileMap->GetModulesFile(moduleName);
  684. return this->MakefileMap->ReadListFile(0, fullPath.c_str());
  685. }
  686. //----------------------------------------------------------------------
  687. void cmCPackGenerator::SetOptionIfNotSet(const char* op,
  688. const char* value)
  689. {
  690. const char* def = this->MakefileMap->GetDefinition(op);
  691. if ( def && *def )
  692. {
  693. return;
  694. }
  695. this->SetOption(op, value);
  696. }
  697. //----------------------------------------------------------------------
  698. void cmCPackGenerator::SetOption(const char* op, const char* value)
  699. {
  700. if ( !op )
  701. {
  702. return;
  703. }
  704. if ( !value )
  705. {
  706. this->MakefileMap->RemoveDefinition(op);
  707. return;
  708. }
  709. cmCPackLogger(cmCPackLog::LOG_DEBUG, this->GetNameOfClass()
  710. << "::SetOption(" << op << ", " << value << ")" << std::endl);
  711. this->MakefileMap->AddDefinition(op, value);
  712. }
  713. //----------------------------------------------------------------------
  714. int cmCPackGenerator::DoPackage()
  715. {
  716. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  717. "Create package using " << this->Name.c_str() << std::endl);
  718. if ( !this->PrepareNames() )
  719. {
  720. return 0;
  721. }
  722. if ( cmSystemTools::IsOn(
  723. this->GetOption("CPACK_REMOVE_TOPLEVEL_DIRECTORY")) )
  724. {
  725. const char* toplevelDirectory
  726. = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  727. if ( cmSystemTools::FileExists(toplevelDirectory) )
  728. {
  729. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  730. "Remove toplevel directory: "
  731. << toplevelDirectory << std::endl);
  732. if ( !cmSystemTools::RemoveADirectory(toplevelDirectory) )
  733. {
  734. cmCPackLogger(cmCPackLog::LOG_ERROR,
  735. "Problem removing toplevel directory: "
  736. << toplevelDirectory
  737. << std::endl);
  738. return 0;
  739. }
  740. }
  741. }
  742. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  743. "About to install project " << std::endl);
  744. if ( !this->InstallProject() )
  745. {
  746. return 0;
  747. }
  748. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  749. "Done install project " << std::endl);
  750. const char* tempPackageFileName = this->GetOption(
  751. "CPACK_TEMPORARY_PACKAGE_FILE_NAME");
  752. const char* packageFileName = this->GetOption("CPACK_OUTPUT_FILE_PATH");
  753. const char* tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  754. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  755. cmsys::Glob gl;
  756. std::string findExpr = tempDirectory;
  757. findExpr += "/*";
  758. gl.RecurseOn();
  759. if ( !gl.FindFiles(findExpr) )
  760. {
  761. cmCPackLogger(cmCPackLog::LOG_ERROR,
  762. "Cannot find any files in the packaging tree" << std::endl);
  763. return 0;
  764. }
  765. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Compress package" << std::endl);
  766. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Compress files to: "
  767. << (tempPackageFileName ? tempPackageFileName : "(NULL)") << std::endl);
  768. if ( cmSystemTools::FileExists(tempPackageFileName) )
  769. {
  770. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Remove old package file"
  771. << std::endl);
  772. cmSystemTools::RemoveFile(tempPackageFileName);
  773. }
  774. if ( cmSystemTools::IsOn(this->GetOption(
  775. "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) )
  776. {
  777. tempDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  778. }
  779. // The files to be installed
  780. std::vector<std::string> files = gl.GetFiles();
  781. // For component installations, determine which files go into which
  782. // components.
  783. if (!this->Components.empty())
  784. {
  785. std::vector<std::string>::const_iterator it;
  786. for ( it = files.begin(); it != files.end(); ++ it )
  787. {
  788. std::string fileN = cmSystemTools::RelativePath(tempDirectory,
  789. it->c_str());
  790. // Determine which component we are in.
  791. std::string componentName = fileN.substr(0, fileN.find('/'));
  792. // Strip off the component part of the path.
  793. fileN = fileN.substr(fileN.find('/')+1, std::string::npos);
  794. // Add this file to the list of files for the component.
  795. this->Components[componentName].Files.push_back(fileN);
  796. }
  797. }
  798. if ( !this->CompressFiles(tempPackageFileName,
  799. tempDirectory, files) || cmSystemTools::GetErrorOccuredFlag())
  800. {
  801. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem compressing the directory"
  802. << std::endl);
  803. return 0;
  804. }
  805. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Finalize package" << std::endl);
  806. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Copy final package: "
  807. << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
  808. << " to "
  809. << (packageFileName ? packageFileName : "(NULL)")
  810. << std::endl);
  811. if ( !cmSystemTools::CopyFileIfDifferent(tempPackageFileName,
  812. packageFileName) )
  813. {
  814. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the package: "
  815. << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
  816. << " to "
  817. << (packageFileName ? packageFileName : "(NULL)")
  818. << std::endl);
  819. return 0;
  820. }
  821. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Package "
  822. << (packageFileName ? packageFileName : "(NULL)")
  823. << " generated." << std::endl);
  824. return 1;
  825. }
  826. //----------------------------------------------------------------------
  827. int cmCPackGenerator::Initialize(const char* name, cmMakefile* mf)
  828. {
  829. this->MakefileMap = mf;
  830. this->Name = name;
  831. if ( !this->SetCMakeRoot() )
  832. {
  833. cmCPackLogger(cmCPackLog::LOG_ERROR,
  834. "Cannot initialize the generator" << std::endl);
  835. return 0;
  836. }
  837. // set the running generator name
  838. this->SetOption("CPACK_GENERATOR", this->Name.c_str());
  839. // Load the project specific config file
  840. const char* config =
  841. this->GetOption("CPACK_PROJECT_CONFIG_FILE");
  842. if(config)
  843. {
  844. mf->ReadListFile(config);
  845. }
  846. int result = this->InitializeInternal();
  847. if (cmSystemTools::GetErrorOccuredFlag())
  848. {
  849. return 0;
  850. }
  851. // If a generator subclass did not already set this option in its
  852. // InitializeInternal implementation, and the project did not already set
  853. // it, the default value should be:
  854. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/");
  855. return result;
  856. }
  857. //----------------------------------------------------------------------
  858. int cmCPackGenerator::InitializeInternal()
  859. {
  860. return 1;
  861. }
  862. //----------------------------------------------------------------------
  863. bool cmCPackGenerator::IsSet(const char* name) const
  864. {
  865. return this->MakefileMap->IsSet(name);
  866. }
  867. //----------------------------------------------------------------------
  868. const char* cmCPackGenerator::GetOption(const char* op)
  869. {
  870. const char* ret = this->MakefileMap->GetDefinition(op);
  871. if(!ret)
  872. {
  873. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  874. "Warning, GetOption return NULL for: "
  875. << op
  876. << std::endl);
  877. }
  878. return ret;
  879. }
  880. //----------------------------------------------------------------------
  881. int cmCPackGenerator::SetCMakeRoot()
  882. {
  883. // use the CMAKE_ROOT from cmake which should have been
  884. // found by now
  885. const char* root=
  886. this->MakefileMap->GetDefinition("CMAKE_ROOT");
  887. if(root)
  888. {
  889. this->CMakeRoot = root;
  890. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  891. << this->CMakeRoot.c_str() << std::endl);
  892. this->SetOption("CMAKE_ROOT", this->CMakeRoot.c_str());
  893. return 1;
  894. }
  895. cmCPackLogger(cmCPackLog::LOG_ERROR,
  896. "Could not find CMAKE_ROOT !!!"
  897. << std::endl
  898. << "CMake has most likely not been installed correctly."
  899. << std::endl
  900. <<"Modules directory not found in"
  901. << std::endl);
  902. return 0;
  903. }
  904. //----------------------------------------------------------------------
  905. int cmCPackGenerator::CompressFiles(const char* outFileName,
  906. const char* toplevel, const std::vector<std::string>& files)
  907. {
  908. (void)outFileName;
  909. (void)toplevel;
  910. (void)files;
  911. return 0;
  912. }
  913. //----------------------------------------------------------------------
  914. const char* cmCPackGenerator::GetInstallPath()
  915. {
  916. if ( !this->InstallPath.empty() )
  917. {
  918. return this->InstallPath.c_str();
  919. }
  920. #if defined(_WIN32) && !defined(__CYGWIN__)
  921. const char* prgfiles = cmsys::SystemTools::GetEnv("ProgramFiles");
  922. const char* sysDrive = cmsys::SystemTools::GetEnv("SystemDrive");
  923. if ( prgfiles )
  924. {
  925. this->InstallPath = prgfiles;
  926. }
  927. else if ( sysDrive )
  928. {
  929. this->InstallPath = sysDrive;
  930. this->InstallPath += "/Program Files";
  931. }
  932. else
  933. {
  934. this->InstallPath = "c:/Program Files";
  935. }
  936. this->InstallPath += "/";
  937. this->InstallPath += this->GetOption("CPACK_PACKAGE_NAME");
  938. this->InstallPath += "-";
  939. this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION");
  940. #elif defined(__HAIKU__)
  941. BPath dir;
  942. if (find_directory(B_COMMON_DIRECTORY, &dir) == B_OK)
  943. {
  944. this->InstallPath = dir.Path();
  945. }
  946. else
  947. {
  948. this->InstallPath = "/boot/common";
  949. }
  950. #else
  951. this->InstallPath = "/usr/local/";
  952. #endif
  953. return this->InstallPath.c_str();
  954. }
  955. //----------------------------------------------------------------------
  956. const char* cmCPackGenerator::GetPackagingInstallPrefix()
  957. {
  958. cmCPackLogger(cmCPackLog::LOG_DEBUG, "GetPackagingInstallPrefix: '"
  959. << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'" << std::endl);
  960. return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX");
  961. }
  962. //----------------------------------------------------------------------
  963. std::string cmCPackGenerator::FindTemplate(const char* name)
  964. {
  965. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: "
  966. << (name ? name : "(NULL)") << std::endl);
  967. std::string ffile = this->MakefileMap->GetModulesFile(name);
  968. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: "
  969. << ffile.c_str() << std::endl);
  970. return ffile;
  971. }
  972. //----------------------------------------------------------------------
  973. bool cmCPackGenerator::ConfigureString(const std::string& inString,
  974. std::string& outString)
  975. {
  976. this->MakefileMap->ConfigureString(inString,
  977. outString, true, false);
  978. return true;
  979. }
  980. //----------------------------------------------------------------------
  981. bool cmCPackGenerator::ConfigureFile(const char* inName,
  982. const char* outName, bool copyOnly /* = false */)
  983. {
  984. return this->MakefileMap->ConfigureFile(inName, outName,
  985. copyOnly, true, false) == 1;
  986. }
  987. //----------------------------------------------------------------------
  988. int cmCPackGenerator::CleanTemporaryDirectory()
  989. {
  990. std::string tempInstallDirectoryWithPostfix
  991. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  992. const char* tempInstallDirectory = tempInstallDirectoryWithPostfix.c_str();
  993. if(cmsys::SystemTools::FileExists(tempInstallDirectory))
  994. {
  995. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  996. "- Clean temporary : "
  997. << tempInstallDirectory << std::endl);
  998. if(!cmsys::SystemTools::RemoveADirectory(tempInstallDirectory))
  999. {
  1000. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1001. "Problem removing temporary directory: " <<
  1002. tempInstallDirectory
  1003. << std::endl);
  1004. return 0;
  1005. }
  1006. }
  1007. return 1;
  1008. }
  1009. //----------------------------------------------------------------------
  1010. bool cmCPackGenerator::SupportsComponentInstallation() const
  1011. {
  1012. return false;
  1013. }
  1014. //----------------------------------------------------------------------
  1015. cmCPackInstallationType*
  1016. cmCPackGenerator::GetInstallationType(const char *projectName,
  1017. const char *name)
  1018. {
  1019. (void) projectName;
  1020. bool hasInstallationType = this->InstallationTypes.count(name) != 0;
  1021. cmCPackInstallationType *installType = &this->InstallationTypes[name];
  1022. if (!hasInstallationType)
  1023. {
  1024. // Define the installation type
  1025. std::string macroPrefix = "CPACK_INSTALL_TYPE_"
  1026. + cmsys::SystemTools::UpperCase(name);
  1027. installType->Name = name;
  1028. const char* displayName
  1029. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1030. if (displayName && *displayName)
  1031. {
  1032. installType->DisplayName = displayName;
  1033. }
  1034. else
  1035. {
  1036. installType->DisplayName = installType->Name;
  1037. }
  1038. installType->Index = static_cast<unsigned>(
  1039. this->InstallationTypes.size());
  1040. }
  1041. return installType;
  1042. }
  1043. //----------------------------------------------------------------------
  1044. cmCPackComponent*
  1045. cmCPackGenerator::GetComponent(const char *projectName, const char *name)
  1046. {
  1047. bool hasComponent = this->Components.count(name) != 0;
  1048. cmCPackComponent *component = &this->Components[name];
  1049. if (!hasComponent)
  1050. {
  1051. // Define the component
  1052. std::string macroPrefix = "CPACK_COMPONENT_"
  1053. + cmsys::SystemTools::UpperCase(name);
  1054. component->Name = name;
  1055. const char* displayName
  1056. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1057. if (displayName && *displayName)
  1058. {
  1059. component->DisplayName = displayName;
  1060. }
  1061. else
  1062. {
  1063. component->DisplayName = component->Name;
  1064. }
  1065. component->IsHidden
  1066. = this->IsSet((macroPrefix + "_HIDDEN").c_str());
  1067. component->IsRequired
  1068. = this->IsSet((macroPrefix + "_REQUIRED").c_str());
  1069. component->IsDisabledByDefault
  1070. = this->IsSet((macroPrefix + "_DISABLED").c_str());
  1071. component->IsDownloaded
  1072. = this->IsSet((macroPrefix + "_DOWNLOADED").c_str())
  1073. || cmSystemTools::IsOn(this->GetOption("CPACK_DOWNLOAD_ALL"));
  1074. const char* archiveFile = this->GetOption((macroPrefix +
  1075. "_ARCHIVE_FILE").c_str());
  1076. if (archiveFile && *archiveFile)
  1077. {
  1078. component->ArchiveFile = archiveFile;
  1079. }
  1080. const char* groupName = this->GetOption((macroPrefix + "_GROUP").c_str());
  1081. if (groupName && *groupName)
  1082. {
  1083. component->Group = GetComponentGroup(projectName, groupName);
  1084. component->Group->Components.push_back(component);
  1085. }
  1086. else
  1087. {
  1088. component->Group = 0;
  1089. }
  1090. const char* description
  1091. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1092. if (description && *description)
  1093. {
  1094. component->Description = description;
  1095. }
  1096. // Determine the installation types.
  1097. const char *installTypes
  1098. = this->GetOption((macroPrefix + "_INSTALL_TYPES").c_str());
  1099. if (installTypes && *installTypes)
  1100. {
  1101. std::vector<std::string> installTypesVector;
  1102. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  1103. std::vector<std::string>::iterator installTypesIt;
  1104. for (installTypesIt = installTypesVector.begin();
  1105. installTypesIt != installTypesVector.end();
  1106. ++installTypesIt)
  1107. {
  1108. component->InstallationTypes.push_back(
  1109. this->GetInstallationType(projectName, installTypesIt->c_str()));
  1110. }
  1111. }
  1112. // Determine the component dependencies.
  1113. const char *depends = this->GetOption((macroPrefix + "_DEPENDS").c_str());
  1114. if (depends && *depends)
  1115. {
  1116. std::vector<std::string> dependsVector;
  1117. cmSystemTools::ExpandListArgument(depends, dependsVector);
  1118. std::vector<std::string>::iterator dependIt;
  1119. for (dependIt = dependsVector.begin();
  1120. dependIt != dependsVector.end();
  1121. ++dependIt)
  1122. {
  1123. cmCPackComponent *child = GetComponent(projectName,
  1124. dependIt->c_str());
  1125. component->Dependencies.push_back(child);
  1126. child->ReverseDependencies.push_back(component);
  1127. }
  1128. }
  1129. }
  1130. return component;
  1131. }
  1132. //----------------------------------------------------------------------
  1133. cmCPackComponentGroup*
  1134. cmCPackGenerator::GetComponentGroup(const char *projectName, const char *name)
  1135. {
  1136. (void) projectName;
  1137. std::string macroPrefix = "CPACK_COMPONENT_GROUP_"
  1138. + cmsys::SystemTools::UpperCase(name);
  1139. bool hasGroup = this->ComponentGroups.count(name) != 0;
  1140. cmCPackComponentGroup *group = &this->ComponentGroups[name];
  1141. if (!hasGroup)
  1142. {
  1143. // Define the group
  1144. group->Name = name;
  1145. const char* displayName
  1146. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1147. if (displayName && *displayName)
  1148. {
  1149. group->DisplayName = displayName;
  1150. }
  1151. else
  1152. {
  1153. group->DisplayName = group->Name;
  1154. }
  1155. const char* description
  1156. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1157. if (description && *description)
  1158. {
  1159. group->Description = description;
  1160. }
  1161. group->IsBold
  1162. = this->IsSet((macroPrefix + "_BOLD_TITLE").c_str());
  1163. group->IsExpandedByDefault
  1164. = this->IsSet((macroPrefix + "_EXPANDED").c_str());
  1165. const char* parentGroupName
  1166. = this->GetOption((macroPrefix + "_PARENT_GROUP").c_str());
  1167. if (parentGroupName && *parentGroupName)
  1168. {
  1169. group->ParentGroup = GetComponentGroup(projectName, parentGroupName);
  1170. group->ParentGroup->Subgroups.push_back(group);
  1171. }
  1172. else
  1173. {
  1174. group->ParentGroup = 0;
  1175. }
  1176. }
  1177. return group;
  1178. }