cmCPackGenerator.cxx 57 KB

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