cmCPackGenerator.cxx 58 KB

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