cmCPackGenerator.cxx 50 KB

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