cmCPackGenerator.cxx 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684
  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->IsSet("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::string buildCommand
  598. = globalGenerator->GenerateBuildCommand(cmakeMakeProgram,
  599. installProjectName.c_str(), 0, 0,
  600. globalGenerator->GetPreinstallTargetName(),
  601. buildConfig, false, false);
  602. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  603. "- Install command: " << buildCommand << std::endl);
  604. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  605. "- Run preinstall target for: " << installProjectName << std::endl);
  606. std::string output;
  607. int retVal = 1;
  608. bool resB =
  609. cmSystemTools::RunSingleCommand(buildCommand.c_str(),
  610. &output,
  611. &retVal,
  612. installDirectory.c_str(),
  613. this->GeneratorVerbose, 0);
  614. if ( !resB || retVal )
  615. {
  616. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  617. tmpFile += "/PreinstallOutput.log";
  618. cmGeneratedFileStream ofs(tmpFile.c_str());
  619. ofs << "# Run command: " << buildCommand.c_str() << std::endl
  620. << "# Directory: " << installDirectory.c_str() << std::endl
  621. << "# Output:" << std::endl
  622. << output.c_str() << std::endl;
  623. cmCPackLogger(cmCPackLog::LOG_ERROR,
  624. "Problem running install command: " << buildCommand.c_str()
  625. << std::endl
  626. << "Please check " << tmpFile.c_str() << " for errors"
  627. << std::endl);
  628. return 0;
  629. }
  630. }
  631. delete globalGenerator;
  632. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  633. "- Install project: " << installProjectName << std::endl);
  634. // Run the installation for each component
  635. std::vector<std::string>::iterator componentIt;
  636. for (componentIt = componentsVector.begin();
  637. componentIt != componentsVector.end();
  638. ++componentIt)
  639. {
  640. std::string tempInstallDirectory = baseTempInstallDirectory;
  641. installComponent = *componentIt;
  642. if (componentInstall)
  643. {
  644. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  645. "- Install component: " << installComponent
  646. << std::endl);
  647. }
  648. cmake cm;
  649. cm.AddCMakePaths();
  650. cm.SetProgressCallback(cmCPackGeneratorProgress, this);
  651. cmGlobalGenerator gg;
  652. gg.SetCMakeInstance(&cm);
  653. cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  654. cmMakefile *mf = lg->GetMakefile();
  655. std::string realInstallDirectory = tempInstallDirectory;
  656. if ( !installSubDirectory.empty() && installSubDirectory != "/" )
  657. {
  658. realInstallDirectory += installSubDirectory;
  659. }
  660. if (componentInstall)
  661. {
  662. tempInstallDirectory += "/";
  663. // Some CPack generators would rather chose
  664. // the local installation directory suffix.
  665. // Some (e.g. RPM) use
  666. // one install directory for each component **GROUP**
  667. // instead of the default
  668. // one install directory for each component.
  669. tempInstallDirectory +=
  670. GetComponentInstallDirNameSuffix(installComponent);
  671. if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY"))
  672. {
  673. tempInstallDirectory += "/";
  674. tempInstallDirectory += this->GetOption("CPACK_PACKAGE_FILE_NAME");
  675. }
  676. }
  677. if (!setDestDir)
  678. {
  679. tempInstallDirectory += this->GetPackagingInstallPrefix();
  680. }
  681. if ( setDestDir )
  682. {
  683. // For DESTDIR based packaging, use the *project*
  684. // CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The
  685. // value of the project's CMAKE_INSTALL_PREFIX is sent in here as
  686. // the value of the CPACK_INSTALL_PREFIX variable.
  687. //
  688. // If DESTDIR has been 'internally set ON' this means that
  689. // the underlying CPack specific generator did ask for that
  690. // In this case we may override CPACK_INSTALL_PREFIX with
  691. // CPACK_PACKAGING_INSTALL_PREFIX
  692. // I know this is tricky and awkward but it's the price for
  693. // CPACK_SET_DESTDIR backward compatibility.
  694. if (cmSystemTools::IsInternallyOn(
  695. this->GetOption("CPACK_SET_DESTDIR")))
  696. {
  697. this->SetOption("CPACK_INSTALL_PREFIX",
  698. this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX"));
  699. }
  700. std::string dir;
  701. if (this->GetOption("CPACK_INSTALL_PREFIX"))
  702. {
  703. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  704. }
  705. mf->AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str());
  706. cmCPackLogger(
  707. cmCPackLog::LOG_DEBUG,
  708. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf->AddDefinition)"
  709. << std::endl);
  710. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  711. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'"
  712. << std::endl);
  713. // Make sure that DESTDIR + CPACK_INSTALL_PREFIX directory
  714. // exists:
  715. //
  716. if (cmSystemTools::StringStartsWith(dir.c_str(), "/"))
  717. {
  718. dir = tempInstallDirectory + dir;
  719. }
  720. else
  721. {
  722. dir = tempInstallDirectory + "/" + dir;
  723. }
  724. /*
  725. * We must re-set DESTDIR for each component
  726. * We must not add the CPACK_INSTALL_PREFIX part because
  727. * it will be added using the override of CMAKE_INSTALL_PREFIX
  728. * The main reason for this awkward trick is that
  729. * are using DESTDIR for 2 different reasons:
  730. * - Because it was asked by the CPack Generator or the user
  731. * using CPACK_SET_DESTDIR
  732. * - Because it was already used for component install
  733. * in order to put things in subdirs...
  734. */
  735. cmSystemTools::PutEnv(
  736. (std::string("DESTDIR=")+tempInstallDirectory).c_str()
  737. );
  738. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  739. "- Creating directory: '" << dir << "'" << std::endl);
  740. if ( !cmsys::SystemTools::MakeDirectory(dir.c_str()))
  741. {
  742. cmCPackLogger(cmCPackLog::LOG_ERROR,
  743. "Problem creating temporary directory: "
  744. << dir << std::endl);
  745. return 0;
  746. }
  747. }
  748. else
  749. {
  750. mf->AddDefinition("CMAKE_INSTALL_PREFIX",
  751. tempInstallDirectory.c_str());
  752. if ( !cmsys::SystemTools::MakeDirectory(
  753. tempInstallDirectory.c_str()))
  754. {
  755. cmCPackLogger(cmCPackLog::LOG_ERROR,
  756. "Problem creating temporary directory: "
  757. << tempInstallDirectory << std::endl);
  758. return 0;
  759. }
  760. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  761. "- Using non-DESTDIR install... (mf->AddDefinition)"
  762. << std::endl);
  763. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  764. "- Setting CMAKE_INSTALL_PREFIX to '"
  765. << tempInstallDirectory
  766. << "'" << std::endl);
  767. }
  768. if ( buildConfig && *buildConfig )
  769. {
  770. mf->AddDefinition("BUILD_TYPE", buildConfig);
  771. }
  772. std::string installComponentLowerCase
  773. = cmSystemTools::LowerCase(installComponent);
  774. if ( installComponentLowerCase != "all" )
  775. {
  776. mf->AddDefinition("CMAKE_INSTALL_COMPONENT",
  777. installComponent.c_str());
  778. }
  779. // strip on TRUE, ON, 1, one or several file names, but not on
  780. // FALSE, OFF, 0 and an empty string
  781. if (!cmSystemTools::IsOff(this->GetOption("CPACK_STRIP_FILES")))
  782. {
  783. mf->AddDefinition("CMAKE_INSTALL_DO_STRIP", "1");
  784. }
  785. // Remember the list of files before installation
  786. // of the current component (if we are in component install)
  787. const char* InstallPrefix = tempInstallDirectory.c_str();
  788. std::vector<std::string> filesBefore;
  789. std::string findExpr(InstallPrefix);
  790. if (componentInstall)
  791. {
  792. cmsys::Glob glB;
  793. findExpr += "/*";
  794. glB.RecurseOn();
  795. glB.FindFiles(findExpr);
  796. filesBefore = glB.GetFiles();
  797. std::sort(filesBefore.begin(),filesBefore.end());
  798. }
  799. // If CPack was asked to warn on ABSOLUTE INSTALL DESTINATION
  800. // then forward request to cmake_install.cmake script
  801. if (this->IsOn("CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION"))
  802. {
  803. mf->AddDefinition("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION",
  804. "1");
  805. }
  806. // If current CPack generator does support
  807. // ABSOLUTE INSTALL DESTINATION or CPack has been asked for
  808. // then ask cmake_install.cmake script to error out
  809. // as soon as it occurs (before installing file)
  810. if (!SupportsAbsoluteDestination() ||
  811. this->IsOn("CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION"))
  812. {
  813. mf->AddDefinition("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION",
  814. "1");
  815. }
  816. // do installation
  817. int res = mf->ReadListFile(0, installFile.c_str());
  818. // forward definition of CMAKE_ABSOLUTE_DESTINATION_FILES
  819. // to CPack (may be used by generators like CPack RPM or DEB)
  820. // in order to transparently handle ABSOLUTE PATH
  821. if (mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES"))
  822. {
  823. mf->AddDefinition("CPACK_ABSOLUTE_DESTINATION_FILES",
  824. mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES"));
  825. }
  826. // Now rebuild the list of files after installation
  827. // of the current component (if we are in component install)
  828. if (componentInstall)
  829. {
  830. cmsys::Glob glA;
  831. glA.RecurseOn();
  832. glA.FindFiles(findExpr);
  833. std::vector<std::string> filesAfter = glA.GetFiles();
  834. std::sort(filesAfter.begin(),filesAfter.end());
  835. std::vector<std::string>::iterator diff;
  836. std::vector<std::string> result(filesAfter.size());
  837. diff = std::set_difference (
  838. filesAfter.begin(),filesAfter.end(),
  839. filesBefore.begin(),filesBefore.end(),
  840. result.begin());
  841. std::vector<std::string>::iterator fit;
  842. std::string localFileName;
  843. // Populate the File field of each component
  844. for (fit=result.begin();fit!=diff;++fit)
  845. {
  846. localFileName =
  847. cmSystemTools::RelativePath(InstallPrefix, fit->c_str());
  848. localFileName =
  849. localFileName.substr(localFileName.find_first_not_of('/'),
  850. std::string::npos);
  851. Components[installComponent].Files.push_back(localFileName);
  852. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Adding file <"
  853. <<localFileName<<"> to component <"
  854. <<installComponent<<">"<<std::endl);
  855. }
  856. }
  857. if (NULL !=mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) {
  858. if (absoluteDestFiles.length()>0) {
  859. absoluteDestFiles +=";";
  860. }
  861. absoluteDestFiles +=
  862. mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES");
  863. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  864. "Got some ABSOLUTE DESTINATION FILES: "
  865. << absoluteDestFiles << std::endl);
  866. // define component specific var
  867. if (componentInstall)
  868. {
  869. std::string absoluteDestFileComponent =
  870. std::string("CPACK_ABSOLUTE_DESTINATION_FILES")
  871. + "_" + GetComponentInstallDirNameSuffix(installComponent);
  872. if (NULL != this->GetOption(absoluteDestFileComponent.c_str()))
  873. {
  874. std::string absoluteDestFilesListComponent =
  875. this->GetOption(absoluteDestFileComponent.c_str());
  876. absoluteDestFilesListComponent +=";";
  877. absoluteDestFilesListComponent +=
  878. mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES");
  879. this->SetOption(absoluteDestFileComponent.c_str(),
  880. absoluteDestFilesListComponent.c_str());
  881. }
  882. else
  883. {
  884. this->SetOption(absoluteDestFileComponent.c_str(),
  885. mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"));
  886. }
  887. }
  888. }
  889. if ( cmSystemTools::GetErrorOccuredFlag() || !res )
  890. {
  891. return 0;
  892. }
  893. }
  894. }
  895. }
  896. this->SetOption("CPACK_ABSOLUTE_DESTINATION_FILES",
  897. absoluteDestFiles.c_str());
  898. return 1;
  899. }
  900. //----------------------------------------------------------------------
  901. bool cmCPackGenerator::ReadListFile(const char* moduleName)
  902. {
  903. bool retval;
  904. std::string fullPath = this->MakefileMap->GetModulesFile(moduleName);
  905. retval = this->MakefileMap->ReadListFile(0, fullPath.c_str());
  906. // include FATAL_ERROR and ERROR in the return status
  907. retval = retval && (! cmSystemTools::GetErrorOccuredFlag());
  908. return retval;
  909. }
  910. //----------------------------------------------------------------------
  911. void cmCPackGenerator::SetOptionIfNotSet(const char* op,
  912. const char* value)
  913. {
  914. const char* def = this->MakefileMap->GetDefinition(op);
  915. if ( def && *def )
  916. {
  917. return;
  918. }
  919. this->SetOption(op, value);
  920. }
  921. //----------------------------------------------------------------------
  922. void cmCPackGenerator::SetOption(const char* op, const char* value)
  923. {
  924. if ( !op )
  925. {
  926. return;
  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);
  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 char* name, cmMakefile* mf)
  1067. {
  1068. this->MakefileMap = mf;
  1069. this->Name = name;
  1070. if ( !this->SetCMakeRoot() )
  1071. {
  1072. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1073. "Cannot initialize the generator" << std::endl);
  1074. return 0;
  1075. }
  1076. // set the running generator name
  1077. this->SetOption("CPACK_GENERATOR", this->Name.c_str());
  1078. // Load the project specific config file
  1079. const char* config =
  1080. this->GetOption("CPACK_PROJECT_CONFIG_FILE");
  1081. if(config)
  1082. {
  1083. mf->ReadListFile(config);
  1084. }
  1085. int result = this->InitializeInternal();
  1086. if (cmSystemTools::GetErrorOccuredFlag())
  1087. {
  1088. return 0;
  1089. }
  1090. // If a generator subclass did not already set this option in its
  1091. // InitializeInternal implementation, and the project did not already set
  1092. // it, the default value should be:
  1093. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/");
  1094. return result;
  1095. }
  1096. //----------------------------------------------------------------------
  1097. int cmCPackGenerator::InitializeInternal()
  1098. {
  1099. return 1;
  1100. }
  1101. //----------------------------------------------------------------------
  1102. bool cmCPackGenerator::IsSet(const char* name) const
  1103. {
  1104. return this->MakefileMap->IsSet(name);
  1105. }
  1106. //----------------------------------------------------------------------
  1107. bool cmCPackGenerator::IsOn(const char* name) const
  1108. {
  1109. return cmSystemTools::IsOn(GetOption(name));
  1110. }
  1111. //----------------------------------------------------------------------
  1112. const char* cmCPackGenerator::GetOption(const char* op) const
  1113. {
  1114. const char* ret = this->MakefileMap->GetDefinition(op);
  1115. if(!ret)
  1116. {
  1117. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1118. "Warning, GetOption return NULL for: "
  1119. << op
  1120. << std::endl);
  1121. }
  1122. return ret;
  1123. }
  1124. //----------------------------------------------------------------------
  1125. int cmCPackGenerator::SetCMakeRoot()
  1126. {
  1127. // use the CMAKE_ROOT from cmake which should have been
  1128. // found by now
  1129. const char* root=
  1130. this->MakefileMap->GetDefinition("CMAKE_ROOT");
  1131. if(root)
  1132. {
  1133. this->CMakeRoot = root;
  1134. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  1135. << this->CMakeRoot.c_str() << std::endl);
  1136. this->SetOption("CMAKE_ROOT", this->CMakeRoot.c_str());
  1137. return 1;
  1138. }
  1139. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1140. "Could not find CMAKE_ROOT !!!"
  1141. << std::endl
  1142. << "CMake has most likely not been installed correctly."
  1143. << std::endl
  1144. <<"Modules directory not found in"
  1145. << std::endl);
  1146. return 0;
  1147. }
  1148. //----------------------------------------------------------------------
  1149. int cmCPackGenerator::PackageFiles()
  1150. {
  1151. return 0;
  1152. }
  1153. //----------------------------------------------------------------------
  1154. const char* cmCPackGenerator::GetInstallPath()
  1155. {
  1156. if ( !this->InstallPath.empty() )
  1157. {
  1158. return this->InstallPath.c_str();
  1159. }
  1160. #if defined(_WIN32) && !defined(__CYGWIN__)
  1161. const char* prgfiles = cmsys::SystemTools::GetEnv("ProgramFiles");
  1162. const char* sysDrive = cmsys::SystemTools::GetEnv("SystemDrive");
  1163. if ( prgfiles )
  1164. {
  1165. this->InstallPath = prgfiles;
  1166. }
  1167. else if ( sysDrive )
  1168. {
  1169. this->InstallPath = sysDrive;
  1170. this->InstallPath += "/Program Files";
  1171. }
  1172. else
  1173. {
  1174. this->InstallPath = "c:/Program Files";
  1175. }
  1176. this->InstallPath += "/";
  1177. this->InstallPath += this->GetOption("CPACK_PACKAGE_NAME");
  1178. this->InstallPath += "-";
  1179. this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION");
  1180. #elif defined(__HAIKU__)
  1181. char dir[B_PATH_NAME_LENGTH];
  1182. if (find_directory(B_SYSTEM_DIRECTORY, -1, false, dir, sizeof(dir)) == B_OK)
  1183. {
  1184. this->InstallPath = dir;
  1185. }
  1186. else
  1187. {
  1188. this->InstallPath = "/boot/system";
  1189. }
  1190. #else
  1191. this->InstallPath = "/usr/local/";
  1192. #endif
  1193. return this->InstallPath.c_str();
  1194. }
  1195. //----------------------------------------------------------------------
  1196. const char* cmCPackGenerator::GetPackagingInstallPrefix()
  1197. {
  1198. cmCPackLogger(cmCPackLog::LOG_DEBUG, "GetPackagingInstallPrefix: '"
  1199. << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'" << std::endl);
  1200. return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX");
  1201. }
  1202. //----------------------------------------------------------------------
  1203. std::string cmCPackGenerator::FindTemplate(const char* name)
  1204. {
  1205. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: "
  1206. << (name ? name : "(NULL)") << std::endl);
  1207. std::string ffile = this->MakefileMap->GetModulesFile(name);
  1208. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: "
  1209. << ffile.c_str() << std::endl);
  1210. return ffile;
  1211. }
  1212. //----------------------------------------------------------------------
  1213. bool cmCPackGenerator::ConfigureString(const std::string& inString,
  1214. std::string& outString)
  1215. {
  1216. this->MakefileMap->ConfigureString(inString,
  1217. outString, true, false);
  1218. return true;
  1219. }
  1220. //----------------------------------------------------------------------
  1221. bool cmCPackGenerator::ConfigureFile(const char* inName,
  1222. const char* outName, bool copyOnly /* = false */)
  1223. {
  1224. return this->MakefileMap->ConfigureFile(inName, outName,
  1225. copyOnly, true, false) == 1;
  1226. }
  1227. //----------------------------------------------------------------------
  1228. int cmCPackGenerator::CleanTemporaryDirectory()
  1229. {
  1230. std::string tempInstallDirectoryWithPostfix
  1231. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  1232. const char* tempInstallDirectory = tempInstallDirectoryWithPostfix.c_str();
  1233. if(cmsys::SystemTools::FileExists(tempInstallDirectory))
  1234. {
  1235. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1236. "- Clean temporary : "
  1237. << tempInstallDirectory << std::endl);
  1238. if(!cmSystemTools::RepeatedRemoveDirectory(tempInstallDirectory))
  1239. {
  1240. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1241. "Problem removing temporary directory: " <<
  1242. tempInstallDirectory
  1243. << std::endl);
  1244. return 0;
  1245. }
  1246. }
  1247. return 1;
  1248. }
  1249. //----------------------------------------------------------------------
  1250. int cmCPackGenerator::PrepareGroupingKind()
  1251. {
  1252. // find a component package method specified by the user
  1253. ComponentPackageMethod method = UNKNOWN_COMPONENT_PACKAGE_METHOD;
  1254. if(this->GetOption("CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE"))
  1255. {
  1256. method = ONE_PACKAGE;
  1257. }
  1258. if(this->GetOption("CPACK_COMPONENTS_IGNORE_GROUPS"))
  1259. {
  1260. method = ONE_PACKAGE_PER_COMPONENT;
  1261. }
  1262. if(this->GetOption("CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP"))
  1263. {
  1264. method = ONE_PACKAGE_PER_GROUP;
  1265. }
  1266. std::string groupingType;
  1267. // Second way to specify grouping
  1268. if (NULL != this->GetOption("CPACK_COMPONENTS_GROUPING")) {
  1269. groupingType = this->GetOption("CPACK_COMPONENTS_GROUPING");
  1270. }
  1271. if (groupingType.length()>0)
  1272. {
  1273. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "["
  1274. << this->Name << "]"
  1275. << " requested component grouping = "<< groupingType <<std::endl);
  1276. if (groupingType == "ALL_COMPONENTS_IN_ONE")
  1277. {
  1278. method = ONE_PACKAGE;
  1279. }
  1280. else if (groupingType == "IGNORE")
  1281. {
  1282. method = ONE_PACKAGE_PER_COMPONENT;
  1283. }
  1284. else if (groupingType == "ONE_PER_GROUP")
  1285. {
  1286. method = ONE_PACKAGE_PER_GROUP;
  1287. }
  1288. else
  1289. {
  1290. cmCPackLogger(cmCPackLog::LOG_WARNING, "["
  1291. << this->Name << "]"
  1292. << " requested component grouping type <"<< groupingType
  1293. << "> UNKNOWN not in (ALL_COMPONENTS_IN_ONE,IGNORE,ONE_PER_GROUP)"
  1294. << std::endl);
  1295. }
  1296. }
  1297. // Some components were defined but NO group
  1298. // fallback to default if not group based
  1299. if(method == ONE_PACKAGE_PER_GROUP &&
  1300. this->ComponentGroups.empty() && !this->Components.empty())
  1301. {
  1302. if(componentPackageMethod == ONE_PACKAGE)
  1303. {
  1304. method = ONE_PACKAGE;
  1305. }
  1306. else
  1307. {
  1308. method = ONE_PACKAGE_PER_COMPONENT;
  1309. }
  1310. cmCPackLogger(cmCPackLog::LOG_WARNING, "["
  1311. << this->Name << "]"
  1312. << " One package per component group requested, "
  1313. << "but NO component groups exist: Ignoring component group."
  1314. << std::endl);
  1315. }
  1316. // if user specified packaging method, override the default packaging method
  1317. if(method != UNKNOWN_COMPONENT_PACKAGE_METHOD)
  1318. {
  1319. componentPackageMethod = method;
  1320. }
  1321. const char* method_names[] =
  1322. {
  1323. "ALL_COMPONENTS_IN_ONE",
  1324. "IGNORE_GROUPS",
  1325. "ONE_PER_GROUP"
  1326. };
  1327. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "["
  1328. << this->Name << "]"
  1329. << " requested component grouping = "
  1330. << method_names[componentPackageMethod]
  1331. << std::endl);
  1332. return 1;
  1333. }
  1334. //----------------------------------------------------------------------
  1335. std::string cmCPackGenerator::GetComponentInstallDirNameSuffix(
  1336. const std::string& componentName) {
  1337. return componentName;
  1338. }
  1339. //----------------------------------------------------------------------
  1340. std::string cmCPackGenerator::GetComponentPackageFileName(
  1341. const std::string& initialPackageFileName,
  1342. const std::string& groupOrComponentName,
  1343. bool isGroupName) {
  1344. /*
  1345. * the default behavior is to use the
  1346. * component [group] name as a suffix
  1347. */
  1348. std::string suffix="-"+groupOrComponentName;
  1349. /* check if we should use DISPLAY name */
  1350. std::string dispNameVar = "CPACK_"+Name+"_USE_DISPLAY_NAME_IN_FILENAME";
  1351. if (IsOn(dispNameVar.c_str()))
  1352. {
  1353. /* the component Group case */
  1354. if (isGroupName)
  1355. {
  1356. std::string groupDispVar = "CPACK_COMPONENT_GROUP_"
  1357. + cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME";
  1358. const char* groupDispName = GetOption(groupDispVar.c_str());
  1359. if (groupDispName)
  1360. {
  1361. suffix = "-"+std::string(groupDispName);
  1362. }
  1363. }
  1364. /* the [single] component case */
  1365. else
  1366. {
  1367. std::string dispVar = "CPACK_COMPONENT_"
  1368. + cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME";
  1369. const char* dispName = GetOption(dispVar.c_str());
  1370. if(dispName)
  1371. {
  1372. suffix = "-"+std::string(dispName);
  1373. }
  1374. }
  1375. }
  1376. return initialPackageFileName + suffix;
  1377. }
  1378. //----------------------------------------------------------------------
  1379. enum cmCPackGenerator::CPackSetDestdirSupport
  1380. cmCPackGenerator::SupportsSetDestdir() const
  1381. {
  1382. return cmCPackGenerator::SETDESTDIR_SUPPORTED;
  1383. }
  1384. //----------------------------------------------------------------------
  1385. bool cmCPackGenerator::SupportsAbsoluteDestination() const
  1386. {
  1387. return true;
  1388. }
  1389. //----------------------------------------------------------------------
  1390. bool cmCPackGenerator::SupportsComponentInstallation() const
  1391. {
  1392. return false;
  1393. }
  1394. //----------------------------------------------------------------------
  1395. bool cmCPackGenerator::WantsComponentInstallation() const
  1396. {
  1397. return (!IsOn("CPACK_MONOLITHIC_INSTALL") & SupportsComponentInstallation());
  1398. }
  1399. //----------------------------------------------------------------------
  1400. cmCPackInstallationType*
  1401. cmCPackGenerator::GetInstallationType(const char *projectName,
  1402. const char *name)
  1403. {
  1404. (void) projectName;
  1405. bool hasInstallationType = this->InstallationTypes.count(name) != 0;
  1406. cmCPackInstallationType *installType = &this->InstallationTypes[name];
  1407. if (!hasInstallationType)
  1408. {
  1409. // Define the installation type
  1410. std::string macroPrefix = "CPACK_INSTALL_TYPE_"
  1411. + cmsys::SystemTools::UpperCase(name);
  1412. installType->Name = name;
  1413. const char* displayName
  1414. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1415. if (displayName && *displayName)
  1416. {
  1417. installType->DisplayName = displayName;
  1418. }
  1419. else
  1420. {
  1421. installType->DisplayName = installType->Name;
  1422. }
  1423. installType->Index = static_cast<unsigned>(
  1424. this->InstallationTypes.size());
  1425. }
  1426. return installType;
  1427. }
  1428. //----------------------------------------------------------------------
  1429. cmCPackComponent*
  1430. cmCPackGenerator::GetComponent(const char *projectName, const char *name)
  1431. {
  1432. bool hasComponent = this->Components.count(name) != 0;
  1433. cmCPackComponent *component = &this->Components[name];
  1434. if (!hasComponent)
  1435. {
  1436. // Define the component
  1437. std::string macroPrefix = "CPACK_COMPONENT_"
  1438. + cmsys::SystemTools::UpperCase(name);
  1439. component->Name = name;
  1440. const char* displayName
  1441. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1442. if (displayName && *displayName)
  1443. {
  1444. component->DisplayName = displayName;
  1445. }
  1446. else
  1447. {
  1448. component->DisplayName = component->Name;
  1449. }
  1450. component->IsHidden
  1451. = this->IsSet((macroPrefix + "_HIDDEN").c_str());
  1452. component->IsRequired
  1453. = this->IsSet((macroPrefix + "_REQUIRED").c_str());
  1454. component->IsDisabledByDefault
  1455. = this->IsSet((macroPrefix + "_DISABLED").c_str());
  1456. component->IsDownloaded
  1457. = this->IsSet((macroPrefix + "_DOWNLOADED").c_str())
  1458. || cmSystemTools::IsOn(this->GetOption("CPACK_DOWNLOAD_ALL"));
  1459. const char* archiveFile = this->GetOption((macroPrefix +
  1460. "_ARCHIVE_FILE").c_str());
  1461. if (archiveFile && *archiveFile)
  1462. {
  1463. component->ArchiveFile = archiveFile;
  1464. }
  1465. const char* groupName = this->GetOption((macroPrefix + "_GROUP").c_str());
  1466. if (groupName && *groupName)
  1467. {
  1468. component->Group = GetComponentGroup(projectName, groupName);
  1469. component->Group->Components.push_back(component);
  1470. }
  1471. else
  1472. {
  1473. component->Group = 0;
  1474. }
  1475. const char* description
  1476. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1477. if (description && *description)
  1478. {
  1479. component->Description = description;
  1480. }
  1481. // Determine the installation types.
  1482. const char *installTypes
  1483. = this->GetOption((macroPrefix + "_INSTALL_TYPES").c_str());
  1484. if (installTypes && *installTypes)
  1485. {
  1486. std::vector<std::string> installTypesVector;
  1487. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  1488. std::vector<std::string>::iterator installTypesIt;
  1489. for (installTypesIt = installTypesVector.begin();
  1490. installTypesIt != installTypesVector.end();
  1491. ++installTypesIt)
  1492. {
  1493. component->InstallationTypes.push_back(
  1494. this->GetInstallationType(projectName, installTypesIt->c_str()));
  1495. }
  1496. }
  1497. // Determine the component dependencies.
  1498. const char *depends = this->GetOption((macroPrefix + "_DEPENDS").c_str());
  1499. if (depends && *depends)
  1500. {
  1501. std::vector<std::string> dependsVector;
  1502. cmSystemTools::ExpandListArgument(depends, dependsVector);
  1503. std::vector<std::string>::iterator dependIt;
  1504. for (dependIt = dependsVector.begin();
  1505. dependIt != dependsVector.end();
  1506. ++dependIt)
  1507. {
  1508. cmCPackComponent *child = GetComponent(projectName,
  1509. dependIt->c_str());
  1510. component->Dependencies.push_back(child);
  1511. child->ReverseDependencies.push_back(component);
  1512. }
  1513. }
  1514. }
  1515. return component;
  1516. }
  1517. //----------------------------------------------------------------------
  1518. cmCPackComponentGroup*
  1519. cmCPackGenerator::GetComponentGroup(const char *projectName, const char *name)
  1520. {
  1521. (void) projectName;
  1522. std::string macroPrefix = "CPACK_COMPONENT_GROUP_"
  1523. + cmsys::SystemTools::UpperCase(name);
  1524. bool hasGroup = this->ComponentGroups.count(name) != 0;
  1525. cmCPackComponentGroup *group = &this->ComponentGroups[name];
  1526. if (!hasGroup)
  1527. {
  1528. // Define the group
  1529. group->Name = name;
  1530. const char* displayName
  1531. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1532. if (displayName && *displayName)
  1533. {
  1534. group->DisplayName = displayName;
  1535. }
  1536. else
  1537. {
  1538. group->DisplayName = group->Name;
  1539. }
  1540. const char* description
  1541. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1542. if (description && *description)
  1543. {
  1544. group->Description = description;
  1545. }
  1546. group->IsBold
  1547. = this->IsSet((macroPrefix + "_BOLD_TITLE").c_str());
  1548. group->IsExpandedByDefault
  1549. = this->IsSet((macroPrefix + "_EXPANDED").c_str());
  1550. const char* parentGroupName
  1551. = this->GetOption((macroPrefix + "_PARENT_GROUP").c_str());
  1552. if (parentGroupName && *parentGroupName)
  1553. {
  1554. group->ParentGroup = GetComponentGroup(projectName, parentGroupName);
  1555. group->ParentGroup->Subgroups.push_back(group);
  1556. }
  1557. else
  1558. {
  1559. group->ParentGroup = 0;
  1560. }
  1561. }
  1562. return group;
  1563. }