cmCPackGenerator.cxx 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCPackGenerator.h"
  14. #include "cmMakefile.h"
  15. #include "cmCPackLog.h"
  16. #include "cmake.h"
  17. #include "cmGlobalGenerator.h"
  18. #include "cmLocalGenerator.h"
  19. #include "cmGeneratedFileStream.h"
  20. #include "cmCPackComponentGroup.h"
  21. #include <cmsys/SystemTools.hxx>
  22. #include <cmsys/Glob.hxx>
  23. #include <memory> // auto_ptr
  24. //----------------------------------------------------------------------
  25. cmCPackGenerator::cmCPackGenerator()
  26. {
  27. this->GeneratorVerbose = false;
  28. this->MakefileMap = 0;
  29. this->Logger = 0;
  30. }
  31. //----------------------------------------------------------------------
  32. cmCPackGenerator::~cmCPackGenerator()
  33. {
  34. this->MakefileMap = 0;
  35. }
  36. //----------------------------------------------------------------------
  37. void cmCPackGeneratorProgress(const char *msg, float prog, void* ptr)
  38. {
  39. cmCPackGenerator* self = static_cast<cmCPackGenerator*>(ptr);
  40. self->DisplayVerboseOutput(msg, prog);
  41. }
  42. //----------------------------------------------------------------------
  43. void cmCPackGenerator::DisplayVerboseOutput(const char* msg,
  44. float progress)
  45. {
  46. (void)progress;
  47. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "" << msg << std::endl);
  48. }
  49. //----------------------------------------------------------------------
  50. int cmCPackGenerator::PrepareNames()
  51. {
  52. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  53. "Create temp directory." << std::endl);
  54. std::string tempDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY");
  55. tempDirectory += "/_CPack_Packages/";
  56. const char* toplevelTag = this->GetOption("CPACK_TOPLEVEL_TAG");
  57. if ( toplevelTag )
  58. {
  59. tempDirectory += toplevelTag;
  60. tempDirectory += "/";
  61. }
  62. tempDirectory += this->GetOption("CPACK_GENERATOR");
  63. std::string topDirectory = tempDirectory;
  64. this->GetOption("CPACK_PACKAGE_FILE_NAME");
  65. const char* pfname = this->GetOption("CPACK_PACKAGE_FILE_NAME");
  66. if(!pfname)
  67. {
  68. cmCPackLogger(cmCPackLog::LOG_ERROR,
  69. "CPACK_PACKAGE_FILE_NAME not specified" << std::endl);
  70. return 0;
  71. }
  72. std::string outName = pfname;
  73. tempDirectory += "/" + outName;
  74. if(!this->GetOutputExtension())
  75. {
  76. cmCPackLogger(cmCPackLog::LOG_ERROR,
  77. "No output extension specified" << std::endl);
  78. return 0;
  79. }
  80. outName += this->GetOutputExtension();
  81. const char* pdir = this->GetOption("CPACK_PACKAGE_DIRECTORY");
  82. if(!pdir)
  83. {
  84. cmCPackLogger(cmCPackLog::LOG_ERROR,
  85. "CPACK_PACKAGE_DIRECTORY not specified" << std::endl);
  86. return 0;
  87. }
  88. std::string destFile = pdir;
  89. destFile += "/" + outName;
  90. std::string outFile = topDirectory + "/" + outName;
  91. this->SetOptionIfNotSet("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str());
  92. this->SetOptionIfNotSet("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str());
  93. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_NAME", outName.c_str());
  94. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PATH", destFile.c_str());
  95. this->SetOptionIfNotSet("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
  96. outFile.c_str());
  97. this->SetOptionIfNotSet("CPACK_INSTALL_DIRECTORY", this->GetInstallPath());
  98. this->SetOptionIfNotSet("CPACK_NATIVE_INSTALL_DIRECTORY",
  99. cmsys::SystemTools::ConvertToOutputPath(this->GetInstallPath()).c_str());
  100. this->SetOptionIfNotSet("CPACK_TEMPORARY_INSTALL_DIRECTORY",
  101. tempDirectory.c_str());
  102. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  103. "Look for: CPACK_PACKAGE_DESCRIPTION_FILE" << std::endl);
  104. const char* descFileName
  105. = this->GetOption("CPACK_PACKAGE_DESCRIPTION_FILE");
  106. if ( descFileName )
  107. {
  108. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  109. "Look for: " << descFileName << std::endl);
  110. if ( !cmSystemTools::FileExists(descFileName) )
  111. {
  112. cmCPackLogger(cmCPackLog::LOG_ERROR,
  113. "Cannot find description file name: ["
  114. << descFileName << "]" << std::endl);
  115. return 0;
  116. }
  117. std::ifstream ifs(descFileName);
  118. if ( !ifs )
  119. {
  120. cmCPackLogger(cmCPackLog::LOG_ERROR,
  121. "Cannot open description file name: " << descFileName << std::endl);
  122. return 0;
  123. }
  124. cmOStringStream ostr;
  125. std::string line;
  126. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  127. "Read description file: " << descFileName << std::endl);
  128. while ( ifs && cmSystemTools::GetLineFromStream(ifs, line) )
  129. {
  130. ostr << cmSystemTools::MakeXMLSafe(line.c_str()) << std::endl;
  131. }
  132. this->SetOptionIfNotSet("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str());
  133. }
  134. if ( !this->GetOption("CPACK_PACKAGE_DESCRIPTION") )
  135. {
  136. cmCPackLogger(cmCPackLog::LOG_ERROR,
  137. "Project description not specified. Please specify "
  138. "CPACK_PACKAGE_DESCRIPTION or CPACK_PACKAGE_DESCRIPTION_FILE."
  139. << std::endl);
  140. return 0;
  141. }
  142. this->SetOptionIfNotSet("CPACK_REMOVE_TOPLEVEL_DIRECTORY", "1");
  143. return 1;
  144. }
  145. //----------------------------------------------------------------------
  146. int cmCPackGenerator::InstallProject()
  147. {
  148. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Install projects" << std::endl);
  149. this->CleanTemporaryDirectory();
  150. std::string bareTempInstallDirectory
  151. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  152. std::string tempInstallDirectoryStr = bareTempInstallDirectory;
  153. bool setDestDir = cmSystemTools::IsOn(this->GetOption("CPACK_SET_DESTDIR"));
  154. if (!setDestDir)
  155. {
  156. tempInstallDirectoryStr += this->GetPackagingInstallPrefix();
  157. }
  158. const char* tempInstallDirectory = tempInstallDirectoryStr.c_str();
  159. int res = 1;
  160. if ( !cmsys::SystemTools::MakeDirectory(bareTempInstallDirectory.c_str()))
  161. {
  162. cmCPackLogger(cmCPackLog::LOG_ERROR,
  163. "Problem creating temporary directory: "
  164. << (tempInstallDirectory ? tempInstallDirectory : "(NULL}")
  165. << std::endl);
  166. return 0;
  167. }
  168. if ( setDestDir )
  169. {
  170. std::string destDir = "DESTDIR=";
  171. destDir += tempInstallDirectory;
  172. cmSystemTools::PutEnv(destDir.c_str());
  173. }
  174. else
  175. {
  176. // Make sure there is no destdir
  177. cmSystemTools::PutEnv("DESTDIR=");
  178. }
  179. // If the CPackConfig file sets CPACK_INSTALL_COMMANDS then run them
  180. // as listed
  181. if ( !this->InstallProjectViaInstallCommands(
  182. setDestDir, tempInstallDirectory) )
  183. {
  184. return 0;
  185. }
  186. // If the CPackConfig file sets CPACK_INSTALL_SCRIPT then run them
  187. // as listed
  188. if ( !this->InstallProjectViaInstallScript(
  189. setDestDir, tempInstallDirectory) )
  190. {
  191. return 0;
  192. }
  193. // If the CPackConfig file sets CPACK_INSTALLED_DIRECTORIES
  194. // then glob it and copy it to CPACK_TEMPORARY_DIRECTORY
  195. // This is used in Source packageing
  196. if ( !this->InstallProjectViaInstalledDirectories(
  197. setDestDir, tempInstallDirectory) )
  198. {
  199. return 0;
  200. }
  201. // If the project is a CMAKE project then run pre-install
  202. // and then read the cmake_install script to run it
  203. if ( !this->InstallProjectViaInstallCMakeProjects(
  204. setDestDir, bareTempInstallDirectory.c_str()) )
  205. {
  206. return 0;
  207. }
  208. if ( setDestDir )
  209. {
  210. cmSystemTools::PutEnv("DESTDIR=");
  211. }
  212. return res;
  213. }
  214. //----------------------------------------------------------------------
  215. int cmCPackGenerator::InstallProjectViaInstallCommands(
  216. bool setDestDir, const char* tempInstallDirectory)
  217. {
  218. (void) setDestDir;
  219. const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS");
  220. if ( installCommands && *installCommands )
  221. {
  222. std::string tempInstallDirectoryEnv = "CMAKE_INSTALL_PREFIX=";
  223. tempInstallDirectoryEnv += tempInstallDirectory;
  224. cmSystemTools::PutEnv(tempInstallDirectoryEnv.c_str());
  225. std::vector<std::string> installCommandsVector;
  226. cmSystemTools::ExpandListArgument(installCommands,installCommandsVector);
  227. std::vector<std::string>::iterator it;
  228. for ( it = installCommandsVector.begin();
  229. it != installCommandsVector.end();
  230. ++it )
  231. {
  232. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << it->c_str()
  233. << std::endl);
  234. std::string output;
  235. int retVal = 1;
  236. bool resB = cmSystemTools::RunSingleCommand(it->c_str(), &output,
  237. &retVal, 0, this->GeneratorVerbose, 0);
  238. if ( !resB || retVal )
  239. {
  240. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  241. tmpFile += "/InstallOutput.log";
  242. cmGeneratedFileStream ofs(tmpFile.c_str());
  243. ofs << "# Run command: " << it->c_str() << std::endl
  244. << "# Output:" << std::endl
  245. << output.c_str() << std::endl;
  246. cmCPackLogger(cmCPackLog::LOG_ERROR,
  247. "Problem running install command: " << it->c_str() << std::endl
  248. << "Please check " << tmpFile.c_str() << " for errors"
  249. << std::endl);
  250. return 0;
  251. }
  252. }
  253. }
  254. return 1;
  255. }
  256. //----------------------------------------------------------------------
  257. int cmCPackGenerator::InstallProjectViaInstalledDirectories(
  258. bool setDestDir, const char* tempInstallDirectory)
  259. {
  260. (void)setDestDir;
  261. (void)tempInstallDirectory;
  262. std::vector<cmsys::RegularExpression> ignoreFilesRegex;
  263. const char* cpackIgnoreFiles = this->GetOption("CPACK_IGNORE_FILES");
  264. if ( cpackIgnoreFiles )
  265. {
  266. std::vector<std::string> ignoreFilesRegexString;
  267. cmSystemTools::ExpandListArgument(cpackIgnoreFiles,
  268. ignoreFilesRegexString);
  269. std::vector<std::string>::iterator it;
  270. for ( it = ignoreFilesRegexString.begin();
  271. it != ignoreFilesRegexString.end();
  272. ++it )
  273. {
  274. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  275. "Create ignore files regex for: " << it->c_str() << std::endl);
  276. ignoreFilesRegex.push_back(it->c_str());
  277. }
  278. }
  279. const char* installDirectories
  280. = this->GetOption("CPACK_INSTALLED_DIRECTORIES");
  281. if ( installDirectories && *installDirectories )
  282. {
  283. std::vector<std::string> installDirectoriesVector;
  284. cmSystemTools::ExpandListArgument(installDirectories,
  285. installDirectoriesVector);
  286. if ( installDirectoriesVector.size() % 2 != 0 )
  287. {
  288. cmCPackLogger(cmCPackLog::LOG_ERROR,
  289. "CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> and "
  290. "<subdirectory>. The <subdirectory> can be '.' to be installed in "
  291. "the toplevel directory of installation." << std::endl);
  292. return 0;
  293. }
  294. std::vector<std::string>::iterator it;
  295. const char* tempDir = tempInstallDirectory;
  296. for ( it = installDirectoriesVector.begin();
  297. it != installDirectoriesVector.end();
  298. ++it )
  299. {
  300. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  301. cmsys::Glob gl;
  302. std::string toplevel = it->c_str();
  303. it ++;
  304. std::string subdir = it->c_str();
  305. std::string findExpr = toplevel;
  306. findExpr += "/*";
  307. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  308. "- Install directory: " << toplevel << std::endl);
  309. gl.RecurseOn();
  310. if ( !gl.FindFiles(findExpr) )
  311. {
  312. cmCPackLogger(cmCPackLog::LOG_ERROR,
  313. "Cannot find any files in the installed directory" << std::endl);
  314. return 0;
  315. }
  316. std::vector<std::string>& files = gl.GetFiles();
  317. std::vector<std::string>::iterator gfit;
  318. std::vector<cmsys::RegularExpression>::iterator regIt;
  319. for ( gfit = files.begin(); gfit != files.end(); ++ gfit )
  320. {
  321. bool skip = false;
  322. std::string &inFile = *gfit;
  323. for ( regIt= ignoreFilesRegex.begin();
  324. regIt!= ignoreFilesRegex.end();
  325. ++ regIt)
  326. {
  327. if ( regIt->find(inFile.c_str()) )
  328. {
  329. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Ignore file: "
  330. << inFile.c_str() << std::endl);
  331. skip = true;
  332. }
  333. }
  334. if ( skip )
  335. {
  336. continue;
  337. }
  338. std::string filePath = tempDir;
  339. filePath += "/" + subdir + "/"
  340. + cmSystemTools::RelativePath(toplevel.c_str(), gfit->c_str());
  341. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy file: "
  342. << inFile.c_str() << " -> " << filePath.c_str() << std::endl);
  343. if ( !cmSystemTools::CopyFileIfDifferent(inFile.c_str(),
  344. filePath.c_str()) )
  345. {
  346. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying file: "
  347. << inFile.c_str() << " -> " << filePath.c_str() << std::endl);
  348. return 0;
  349. }
  350. }
  351. }
  352. }
  353. return 1;
  354. }
  355. //----------------------------------------------------------------------
  356. int cmCPackGenerator::InstallProjectViaInstallScript(
  357. bool setDestDir, const char* tempInstallDirectory)
  358. {
  359. const char* cmakeScripts
  360. = this->GetOption("CPACK_INSTALL_SCRIPT");
  361. std::string currentWorkingDirectory =
  362. cmSystemTools::GetCurrentWorkingDirectory();
  363. if ( cmakeScripts && *cmakeScripts )
  364. {
  365. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  366. "- Install scripts: " << cmakeScripts << std::endl);
  367. std::vector<std::string> cmakeScriptsVector;
  368. cmSystemTools::ExpandListArgument(cmakeScripts,
  369. cmakeScriptsVector);
  370. std::vector<std::string>::iterator it;
  371. for ( it = cmakeScriptsVector.begin();
  372. it != cmakeScriptsVector.end();
  373. ++it )
  374. {
  375. std::string installScript = it->c_str();
  376. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  377. "- Install script: " << installScript << std::endl);
  378. if ( setDestDir )
  379. {
  380. // For DESTDIR based packaging, use the *project* CMAKE_INSTALL_PREFIX
  381. // underneath the tempInstallDirectory. The value of the project's
  382. // CMAKE_INSTALL_PREFIX is sent in here as the value of the
  383. // CPACK_INSTALL_PREFIX variable.
  384. std::string dir;
  385. if (this->GetOption("CPACK_INSTALL_PREFIX"))
  386. {
  387. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  388. }
  389. this->SetOption("CMAKE_INSTALL_PREFIX", dir.c_str());
  390. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  391. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (this->SetOption)"
  392. << std::endl);
  393. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  394. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'" << std::endl);
  395. }
  396. else
  397. {
  398. this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
  399. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  400. "- Using non-DESTDIR install... (this->SetOption)" << std::endl);
  401. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  402. "- Setting CMAKE_INSTALL_PREFIX to '" << tempInstallDirectory
  403. << "'" << std::endl);
  404. }
  405. this->SetOptionIfNotSet("CMAKE_CURRENT_BINARY_DIR",
  406. tempInstallDirectory);
  407. this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR",
  408. tempInstallDirectory);
  409. int res = this->MakefileMap->ReadListFile(0, installScript.c_str());
  410. if ( cmSystemTools::GetErrorOccuredFlag() || !res )
  411. {
  412. return 0;
  413. }
  414. }
  415. }
  416. return 1;
  417. }
  418. //----------------------------------------------------------------------
  419. int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
  420. bool setDestDir, const char* baseTempInstallDirectory)
  421. {
  422. const char* cmakeProjects
  423. = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
  424. const char* cmakeGenerator
  425. = this->GetOption("CPACK_CMAKE_GENERATOR");
  426. std::string currentWorkingDirectory =
  427. cmSystemTools::GetCurrentWorkingDirectory();
  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. lg->SetGlobalGenerator(&gg);
  581. cmMakefile *mf = lg->GetMakefile();
  582. std::string realInstallDirectory = tempInstallDirectory;
  583. if ( !installSubDirectory.empty() && installSubDirectory != "/" )
  584. {
  585. realInstallDirectory += installSubDirectory;
  586. }
  587. if (componentInstall)
  588. {
  589. tempInstallDirectory += "/";
  590. tempInstallDirectory += installComponent;
  591. }
  592. if (!setDestDir)
  593. {
  594. tempInstallDirectory += this->GetPackagingInstallPrefix();
  595. }
  596. if ( setDestDir )
  597. {
  598. // For DESTDIR based packaging, use the *project* CMAKE_INSTALL_PREFIX
  599. // underneath the tempInstallDirectory. The value of the project's
  600. // CMAKE_INSTALL_PREFIX is sent in here as the value of the
  601. // CPACK_INSTALL_PREFIX variable.
  602. std::string dir;
  603. if (this->GetOption("CPACK_INSTALL_PREFIX"))
  604. {
  605. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  606. }
  607. mf->AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str());
  608. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  609. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf->AddDefinition)"
  610. << std::endl);
  611. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  612. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'"
  613. << std::endl);
  614. }
  615. else
  616. {
  617. mf->AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory.c_str());
  618. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  619. "- Using non-DESTDIR install... (mf->AddDefinition)" << std::endl);
  620. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  621. "- Setting CMAKE_INSTALL_PREFIX to '" << tempInstallDirectory
  622. << "'" << std::endl);
  623. }
  624. if ( buildConfig && *buildConfig )
  625. {
  626. mf->AddDefinition("BUILD_TYPE", buildConfig);
  627. }
  628. std::string installComponentLowerCase
  629. = cmSystemTools::LowerCase(installComponent);
  630. if ( installComponentLowerCase != "all" )
  631. {
  632. mf->AddDefinition("CMAKE_INSTALL_COMPONENT",
  633. installComponent.c_str());
  634. }
  635. // strip on TRUE, ON, 1, one or several file names, but not on
  636. // FALSE, OFF, 0 and an empty string
  637. if (!cmSystemTools::IsOff(this->GetOption("CPACK_STRIP_FILES")))
  638. {
  639. mf->AddDefinition("CMAKE_INSTALL_DO_STRIP", "1");
  640. }
  641. int res = mf->ReadListFile(0, installFile.c_str());
  642. if ( cmSystemTools::GetErrorOccuredFlag() || !res )
  643. {
  644. return 0;
  645. }
  646. }
  647. }
  648. }
  649. return 1;
  650. }
  651. //----------------------------------------------------------------------
  652. bool cmCPackGenerator::ReadListFile(const char* moduleName)
  653. {
  654. std::string fullPath = this->MakefileMap->GetModulesFile(moduleName);
  655. return this->MakefileMap->ReadListFile(0, fullPath.c_str());
  656. }
  657. //----------------------------------------------------------------------
  658. void cmCPackGenerator::SetOptionIfNotSet(const char* op,
  659. const char* value)
  660. {
  661. const char* def = this->MakefileMap->GetDefinition(op);
  662. if ( def && *def )
  663. {
  664. return;
  665. }
  666. this->SetOption(op, value);
  667. }
  668. //----------------------------------------------------------------------
  669. void cmCPackGenerator::SetOption(const char* op, const char* value)
  670. {
  671. if ( !op )
  672. {
  673. return;
  674. }
  675. if ( !value )
  676. {
  677. this->MakefileMap->RemoveDefinition(op);
  678. return;
  679. }
  680. cmCPackLogger(cmCPackLog::LOG_DEBUG, this->GetNameOfClass()
  681. << "::SetOption(" << op << ", " << value << ")" << std::endl);
  682. this->MakefileMap->AddDefinition(op, value);
  683. }
  684. //----------------------------------------------------------------------
  685. int cmCPackGenerator::DoPackage()
  686. {
  687. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  688. "Create package using " << this->Name.c_str() << std::endl);
  689. if ( !this->PrepareNames() )
  690. {
  691. return 0;
  692. }
  693. if ( cmSystemTools::IsOn(
  694. this->GetOption("CPACK_REMOVE_TOPLEVEL_DIRECTORY")) )
  695. {
  696. const char* toplevelDirectory
  697. = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  698. if ( cmSystemTools::FileExists(toplevelDirectory) )
  699. {
  700. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Remove toplevel directory: "
  701. << toplevelDirectory << std::endl);
  702. if ( !cmSystemTools::RemoveADirectory(toplevelDirectory) )
  703. {
  704. cmCPackLogger(cmCPackLog::LOG_ERROR,
  705. "Problem removing toplevel directory: "
  706. << toplevelDirectory
  707. << std::endl);
  708. return 0;
  709. }
  710. }
  711. }
  712. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  713. "About to install project " << std::endl);
  714. if ( !this->InstallProject() )
  715. {
  716. return 0;
  717. }
  718. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  719. "Done install project " << std::endl);
  720. const char* tempPackageFileName = this->GetOption(
  721. "CPACK_TEMPORARY_PACKAGE_FILE_NAME");
  722. const char* packageFileName = this->GetOption("CPACK_OUTPUT_FILE_PATH");
  723. const char* tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  724. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  725. cmsys::Glob gl;
  726. std::string findExpr = tempDirectory;
  727. findExpr += "/*";
  728. gl.RecurseOn();
  729. if ( !gl.FindFiles(findExpr) )
  730. {
  731. cmCPackLogger(cmCPackLog::LOG_ERROR,
  732. "Cannot find any files in the packaging tree" << std::endl);
  733. return 0;
  734. }
  735. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Compress package" << std::endl);
  736. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Compress files to: "
  737. << (tempPackageFileName ? tempPackageFileName : "(NULL)") << std::endl);
  738. if ( cmSystemTools::FileExists(tempPackageFileName) )
  739. {
  740. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Remove old package file"
  741. << std::endl);
  742. cmSystemTools::RemoveFile(tempPackageFileName);
  743. }
  744. if ( cmSystemTools::IsOn(this->GetOption(
  745. "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) )
  746. {
  747. tempDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  748. }
  749. // The files to be installed
  750. std::vector<std::string> files = gl.GetFiles();
  751. // For component installations, determine which files go into which
  752. // components.
  753. if (!this->Components.empty())
  754. {
  755. std::vector<std::string>::const_iterator it;
  756. for ( it = files.begin(); it != files.end(); ++ it )
  757. {
  758. std::string fileN = cmSystemTools::RelativePath(tempDirectory,
  759. it->c_str());
  760. // Determine which component we are in.
  761. std::string componentName = fileN.substr(0, fileN.find('/'));
  762. // Strip off the component part of the path.
  763. fileN = fileN.substr(fileN.find('/')+1, std::string::npos);
  764. // Add this file to the list of files for the component.
  765. this->Components[componentName].Files.push_back(fileN);
  766. }
  767. }
  768. if ( !this->CompressFiles(tempPackageFileName,
  769. tempDirectory, files) || cmSystemTools::GetErrorOccuredFlag())
  770. {
  771. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem compressing the directory"
  772. << std::endl);
  773. return 0;
  774. }
  775. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Finalize package" << std::endl);
  776. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Copy final package: "
  777. << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
  778. << " to "
  779. << (packageFileName ? packageFileName : "(NULL)")
  780. << std::endl);
  781. if ( !cmSystemTools::CopyFileIfDifferent(tempPackageFileName,
  782. packageFileName) )
  783. {
  784. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the package: "
  785. << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
  786. << " to "
  787. << (packageFileName ? packageFileName : "(NULL)")
  788. << std::endl);
  789. return 0;
  790. }
  791. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Package "
  792. << (packageFileName ? packageFileName : "(NULL)")
  793. << " generated." << std::endl);
  794. return 1;
  795. }
  796. //----------------------------------------------------------------------
  797. int cmCPackGenerator::Initialize(const char* name, cmMakefile* mf,
  798. const char* argv0)
  799. {
  800. this->MakefileMap = mf;
  801. this->Name = name;
  802. if ( !this->FindRunningCMake(argv0) )
  803. {
  804. cmCPackLogger(cmCPackLog::LOG_ERROR,
  805. "Cannot initialize the generator" << std::endl);
  806. return 0;
  807. }
  808. // set the running generator name
  809. this->SetOption("CPACK_GENERATOR", this->Name.c_str());
  810. // Load the project specific config file
  811. const char* config =
  812. this->GetOption("CPACK_PROJECT_CONFIG_FILE");
  813. if(config)
  814. {
  815. mf->ReadListFile(config);
  816. }
  817. int result = this->InitializeInternal();
  818. if (cmSystemTools::GetErrorOccuredFlag())
  819. {
  820. return 0;
  821. }
  822. // If a generator subclass did not already set this option in its
  823. // InitializeInternal implementation, and the project did not already set
  824. // it, the default value should be:
  825. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/");
  826. return result;
  827. }
  828. //----------------------------------------------------------------------
  829. int cmCPackGenerator::InitializeInternal()
  830. {
  831. return 1;
  832. }
  833. //----------------------------------------------------------------------
  834. bool cmCPackGenerator::IsSet(const char* name) const
  835. {
  836. return this->MakefileMap->IsSet(name);
  837. }
  838. //----------------------------------------------------------------------
  839. const char* cmCPackGenerator::GetOption(const char* op)
  840. {
  841. const char* ret = this->MakefileMap->GetDefinition(op);
  842. if(!ret)
  843. {
  844. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  845. "Warning, GetOption return NULL for: "
  846. << op
  847. << std::endl);
  848. }
  849. return ret;
  850. }
  851. //----------------------------------------------------------------------
  852. int cmCPackGenerator::FindRunningCMake(const char* arg0)
  853. {
  854. int found = 0;
  855. // Find our own executable.
  856. std::vector<cmStdString> failures;
  857. this->CPackSelf = arg0;
  858. cmSystemTools::ConvertToUnixSlashes(this->CPackSelf);
  859. failures.push_back(this->CPackSelf);
  860. this->CPackSelf = cmSystemTools::FindProgram(this->CPackSelf.c_str());
  861. if(!cmSystemTools::FileExists(this->CPackSelf.c_str()))
  862. {
  863. failures.push_back(this->CPackSelf);
  864. this->CPackSelf = "/usr/local/bin/ctest";
  865. }
  866. if(!cmSystemTools::FileExists(this->CPackSelf.c_str()))
  867. {
  868. failures.push_back(this->CPackSelf);
  869. cmOStringStream msg;
  870. msg << "CPack can not find the command line program ctest.\n";
  871. msg << " argv[0] = \"" << arg0 << "\"\n";
  872. msg << " Attempted paths:\n";
  873. std::vector<cmStdString>::iterator i;
  874. for(i=failures.begin(); i != failures.end(); ++i)
  875. {
  876. msg << " \"" << i->c_str() << "\"\n";
  877. }
  878. cmCPackLogger(cmCPackLog::LOG_ERROR, msg.str().c_str()
  879. << std::endl);
  880. return 0;
  881. }
  882. std::string dir;
  883. std::string file;
  884. if(cmSystemTools::SplitProgramPath(this->CPackSelf.c_str(),
  885. dir, file, true))
  886. {
  887. this->CMakeSelf = dir += "/cmake";
  888. this->CMakeSelf += cmSystemTools::GetExecutableExtension();
  889. if(cmSystemTools::FileExists(this->CMakeSelf.c_str()))
  890. {
  891. found = 1;
  892. }
  893. }
  894. if ( !found )
  895. {
  896. failures.push_back(this->CMakeSelf);
  897. #ifdef CMAKE_BUILD_DIR
  898. std::string intdir = ".";
  899. #ifdef CMAKE_INTDIR
  900. intdir = CMAKE_INTDIR;
  901. #endif
  902. this->CMakeSelf = CMAKE_BUILD_DIR;
  903. this->CMakeSelf += "/bin/";
  904. this->CMakeSelf += intdir;
  905. this->CMakeSelf += "/cmake";
  906. this->CMakeSelf += cmSystemTools::GetExecutableExtension();
  907. #endif
  908. if(!cmSystemTools::FileExists(this->CMakeSelf.c_str()))
  909. {
  910. failures.push_back(this->CMakeSelf);
  911. cmOStringStream msg;
  912. msg << "CPack can not find the command line program cmake.\n";
  913. msg << " argv[0] = \"" << arg0 << "\"\n";
  914. msg << " Attempted paths:\n";
  915. std::vector<cmStdString>::iterator i;
  916. for(i=failures.begin(); i != failures.end(); ++i)
  917. {
  918. msg << " \"" << i->c_str() << "\"\n";
  919. }
  920. cmCPackLogger(cmCPackLog::LOG_ERROR, msg.str().c_str()
  921. << std::endl);
  922. return 0;
  923. }
  924. }
  925. // do CMAKE_ROOT, look for the environment variable first
  926. std::string cMakeRoot;
  927. std::string modules;
  928. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT" << std::endl);
  929. if (getenv("CMAKE_ROOT"))
  930. {
  931. cMakeRoot = getenv("CMAKE_ROOT");
  932. modules = cMakeRoot + "/Modules/CMake.cmake";
  933. }
  934. if(modules.empty() || !cmSystemTools::FileExists(modules.c_str()))
  935. {
  936. // next try exe/..
  937. cMakeRoot = cmSystemTools::GetProgramPath(this->CMakeSelf.c_str());
  938. std::string::size_type slashPos = cMakeRoot.rfind("/");
  939. if(slashPos != std::string::npos)
  940. {
  941. cMakeRoot = cMakeRoot.substr(0, slashPos);
  942. }
  943. // is there no Modules direcory there?
  944. modules = cMakeRoot + "/Modules/CMake.cmake";
  945. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  946. << modules.c_str() << std::endl);
  947. }
  948. if (!cmSystemTools::FileExists(modules.c_str()))
  949. {
  950. // try exe/../share/cmake
  951. cMakeRoot += CMAKE_DATA_DIR;
  952. modules = cMakeRoot + "/Modules/CMake.cmake";
  953. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  954. << modules.c_str() << std::endl);
  955. }
  956. #ifdef CMAKE_ROOT_DIR
  957. if (!cmSystemTools::FileExists(modules.c_str()))
  958. {
  959. // try compiled in root directory
  960. cMakeRoot = CMAKE_ROOT_DIR;
  961. modules = cMakeRoot + "/Modules/CMake.cmake";
  962. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  963. << modules.c_str() << std::endl);
  964. }
  965. #endif
  966. #ifdef CMAKE_PREFIX
  967. if (!cmSystemTools::FileExists(modules.c_str()))
  968. {
  969. // try compiled in install prefix
  970. cMakeRoot = CMAKE_PREFIX CMAKE_DATA_DIR;
  971. modules = cMakeRoot + "/Modules/CMake.cmake";
  972. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  973. << modules.c_str() << std::endl);
  974. }
  975. #endif
  976. if (!cmSystemTools::FileExists(modules.c_str()))
  977. {
  978. // try
  979. cMakeRoot = cmSystemTools::GetProgramPath(this->CMakeSelf.c_str());
  980. cMakeRoot += CMAKE_DATA_DIR;
  981. modules = cMakeRoot + "/Modules/CMake.cmake";
  982. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  983. << modules.c_str() << std::endl);
  984. }
  985. if(!cmSystemTools::FileExists(modules.c_str()))
  986. {
  987. // next try exe
  988. cMakeRoot = cmSystemTools::GetProgramPath(this->CMakeSelf.c_str());
  989. // is there no Modules direcory there?
  990. modules = cMakeRoot + "/Modules/CMake.cmake";
  991. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  992. << modules.c_str() << std::endl);
  993. }
  994. if (!cmSystemTools::FileExists(modules.c_str()))
  995. {
  996. // couldn't find modules
  997. cmCPackLogger(cmCPackLog::LOG_ERROR,
  998. "Could not find CMAKE_ROOT !!!" << std::endl
  999. << "CMake has most likely not been installed correctly." << std::endl
  1000. <<"Modules directory not found in" << std::endl
  1001. << cMakeRoot.c_str()
  1002. << std::endl);
  1003. return 0;
  1004. }
  1005. this->CMakeRoot = cMakeRoot;
  1006. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  1007. << this->CMakeRoot.c_str() << std::endl);
  1008. this->SetOption("CMAKE_ROOT", this->CMakeRoot.c_str());
  1009. return 1;
  1010. }
  1011. //----------------------------------------------------------------------
  1012. int cmCPackGenerator::CompressFiles(const char* outFileName,
  1013. const char* toplevel, const std::vector<std::string>& files)
  1014. {
  1015. (void)outFileName;
  1016. (void)toplevel;
  1017. (void)files;
  1018. return 0;
  1019. }
  1020. //----------------------------------------------------------------------
  1021. const char* cmCPackGenerator::GetInstallPath()
  1022. {
  1023. if ( !this->InstallPath.empty() )
  1024. {
  1025. return this->InstallPath.c_str();
  1026. }
  1027. #if defined(_WIN32) && !defined(__CYGWIN__)
  1028. const char* prgfiles = cmsys::SystemTools::GetEnv("ProgramFiles");
  1029. const char* sysDrive = cmsys::SystemTools::GetEnv("SystemDrive");
  1030. if ( prgfiles )
  1031. {
  1032. this->InstallPath = prgfiles;
  1033. }
  1034. else if ( sysDrive )
  1035. {
  1036. this->InstallPath = sysDrive;
  1037. this->InstallPath += "/Program Files";
  1038. }
  1039. else
  1040. {
  1041. this->InstallPath = "c:/Program Files";
  1042. }
  1043. this->InstallPath += "/";
  1044. this->InstallPath += this->GetOption("CPACK_PACKAGE_NAME");
  1045. this->InstallPath += "-";
  1046. this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION");
  1047. #else
  1048. this->InstallPath = "/usr/local/";
  1049. #endif
  1050. return this->InstallPath.c_str();
  1051. }
  1052. //----------------------------------------------------------------------
  1053. const char* cmCPackGenerator::GetPackagingInstallPrefix()
  1054. {
  1055. cmCPackLogger(cmCPackLog::LOG_DEBUG, "GetPackagingInstallPrefix: '"
  1056. << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'" << std::endl);
  1057. return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX");
  1058. }
  1059. //----------------------------------------------------------------------
  1060. std::string cmCPackGenerator::FindTemplate(const char* name)
  1061. {
  1062. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: "
  1063. << (name ? name : "(NULL)") << std::endl);
  1064. std::string ffile = this->MakefileMap->GetModulesFile(name);
  1065. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: "
  1066. << ffile.c_str() << std::endl);
  1067. return ffile;
  1068. }
  1069. //----------------------------------------------------------------------
  1070. bool cmCPackGenerator::ConfigureString(const std::string& inString,
  1071. std::string& outString)
  1072. {
  1073. this->MakefileMap->ConfigureString(inString,
  1074. outString, true, false);
  1075. return true;
  1076. }
  1077. //----------------------------------------------------------------------
  1078. bool cmCPackGenerator::ConfigureFile(const char* inName,
  1079. const char* outName, bool copyOnly /* = false */)
  1080. {
  1081. return this->MakefileMap->ConfigureFile(inName, outName,
  1082. copyOnly, true, false) == 1;
  1083. }
  1084. //----------------------------------------------------------------------
  1085. int cmCPackGenerator::CleanTemporaryDirectory()
  1086. {
  1087. std::string tempInstallDirectoryWithPostfix
  1088. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  1089. const char* tempInstallDirectory = tempInstallDirectoryWithPostfix.c_str();
  1090. if(cmsys::SystemTools::FileExists(tempInstallDirectory))
  1091. {
  1092. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1093. "- Clean temporary : "
  1094. << tempInstallDirectory << std::endl);
  1095. if(!cmsys::SystemTools::RemoveADirectory(tempInstallDirectory))
  1096. {
  1097. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1098. "Problem removing temporary directory: " <<
  1099. tempInstallDirectory
  1100. << std::endl);
  1101. return 0;
  1102. }
  1103. }
  1104. return 1;
  1105. }
  1106. //----------------------------------------------------------------------
  1107. bool cmCPackGenerator::SupportsComponentInstallation() const
  1108. {
  1109. return false;
  1110. }
  1111. //----------------------------------------------------------------------
  1112. cmCPackInstallationType*
  1113. cmCPackGenerator::GetInstallationType(const char *projectName, const char *name)
  1114. {
  1115. (void) projectName;
  1116. bool hasInstallationType = this->InstallationTypes.count(name) != 0;
  1117. cmCPackInstallationType *installType = &this->InstallationTypes[name];
  1118. if (!hasInstallationType)
  1119. {
  1120. // Define the installation type
  1121. std::string macroPrefix = "CPACK_INSTALL_TYPE_"
  1122. + cmsys::SystemTools::UpperCase(name);
  1123. installType->Name = name;
  1124. const char* displayName
  1125. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1126. if (displayName && *displayName)
  1127. {
  1128. installType->DisplayName = displayName;
  1129. }
  1130. else
  1131. {
  1132. installType->DisplayName = installType->Name;
  1133. }
  1134. installType->Index = static_cast<unsigned>(
  1135. this->InstallationTypes.size());
  1136. }
  1137. return installType;
  1138. }
  1139. //----------------------------------------------------------------------
  1140. cmCPackComponent*
  1141. cmCPackGenerator::GetComponent(const char *projectName, const char *name)
  1142. {
  1143. bool hasComponent = this->Components.count(name) != 0;
  1144. cmCPackComponent *component = &this->Components[name];
  1145. if (!hasComponent)
  1146. {
  1147. // Define the component
  1148. std::string macroPrefix = "CPACK_COMPONENT_"
  1149. + cmsys::SystemTools::UpperCase(name);
  1150. component->Name = name;
  1151. const char* displayName
  1152. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1153. if (displayName && *displayName)
  1154. {
  1155. component->DisplayName = displayName;
  1156. }
  1157. else
  1158. {
  1159. component->DisplayName = component->Name;
  1160. }
  1161. component->IsHidden
  1162. = this->IsSet((macroPrefix + "_HIDDEN").c_str());
  1163. component->IsRequired
  1164. = this->IsSet((macroPrefix + "_REQUIRED").c_str());
  1165. component->IsDisabledByDefault
  1166. = this->IsSet((macroPrefix + "_DISABLED").c_str());
  1167. const char* groupName = this->GetOption((macroPrefix + "_GROUP").c_str());
  1168. if (groupName && *groupName)
  1169. {
  1170. component->Group = GetComponentGroup(projectName, groupName);
  1171. component->Group->Components.push_back(component);
  1172. }
  1173. else
  1174. {
  1175. component->Group = 0;
  1176. }
  1177. const char* description
  1178. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1179. if (description && *description)
  1180. {
  1181. component->Description = description;
  1182. }
  1183. // Determine the installation types.
  1184. const char *installTypes
  1185. = this->GetOption((macroPrefix + "_INSTALL_TYPES").c_str());
  1186. if (installTypes && *installTypes)
  1187. {
  1188. std::vector<std::string> installTypesVector;
  1189. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  1190. std::vector<std::string>::iterator installTypesIt;
  1191. for (installTypesIt = installTypesVector.begin();
  1192. installTypesIt != installTypesVector.end();
  1193. ++installTypesIt)
  1194. {
  1195. component->InstallationTypes.push_back(
  1196. this->GetInstallationType(projectName, installTypesIt->c_str()));
  1197. }
  1198. }
  1199. // Determine the component dependencies.
  1200. const char *depends = this->GetOption((macroPrefix + "_DEPENDS").c_str());
  1201. if (depends && *depends)
  1202. {
  1203. std::vector<std::string> dependsVector;
  1204. cmSystemTools::ExpandListArgument(depends, dependsVector);
  1205. std::vector<std::string>::iterator dependIt;
  1206. for (dependIt = dependsVector.begin();
  1207. dependIt != dependsVector.end();
  1208. ++dependIt)
  1209. {
  1210. cmCPackComponent *child = GetComponent(projectName, dependIt->c_str());
  1211. component->Dependencies.push_back(child);
  1212. child->ReverseDependencies.push_back(component);
  1213. }
  1214. }
  1215. }
  1216. return component;
  1217. }
  1218. //----------------------------------------------------------------------
  1219. cmCPackComponentGroup*
  1220. cmCPackGenerator::GetComponentGroup(const char *projectName, const char *name)
  1221. {
  1222. (void) projectName;
  1223. std::string macroPrefix = "CPACK_COMPONENT_GROUP_"
  1224. + cmsys::SystemTools::UpperCase(name);
  1225. bool hasGroup = this->ComponentGroups.count(name) != 0;
  1226. cmCPackComponentGroup *group = &this->ComponentGroups[name];
  1227. if (!hasGroup)
  1228. {
  1229. // Define the group
  1230. group->Name = name;
  1231. const char* displayName
  1232. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1233. if (displayName && *displayName)
  1234. {
  1235. group->DisplayName = displayName;
  1236. }
  1237. else
  1238. {
  1239. group->DisplayName = group->Name;
  1240. }
  1241. const char* description
  1242. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1243. if (description && *description)
  1244. {
  1245. group->Description = description;
  1246. }
  1247. group->IsBold
  1248. = this->IsSet((macroPrefix + "_BOLD_TITLE").c_str());
  1249. group->IsExpandedByDefault
  1250. = this->IsSet((macroPrefix + "_EXPANDED").c_str());
  1251. }
  1252. return group;
  1253. }