cmCPackGenerator.cxx 54 KB

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