cmCPackGenerator.cxx 54 KB

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