cmCPackGenerator.cxx 44 KB

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