cmCPackGenerator.cxx 45 KB

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