cmCPackGenerator.cxx 57 KB

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