cmCPackGenerator.cxx 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  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. if (this->SupportsComponentInstallation())
  516. {
  517. // Determine the installation types for this project (if provided).
  518. std::string installTypesVar = "CPACK_"
  519. + cmSystemTools::UpperCase(installComponent) + "_INSTALL_TYPES";
  520. const char *installTypes = this->GetOption(installTypesVar.c_str());
  521. if (installTypes && *installTypes)
  522. {
  523. std::vector<std::string> installTypesVector;
  524. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  525. std::vector<std::string>::iterator installTypeIt;
  526. for (installTypeIt = installTypesVector.begin();
  527. installTypeIt != installTypesVector.end();
  528. ++installTypeIt)
  529. {
  530. this->GetInstallationType(installProjectName.c_str(),
  531. installTypeIt->c_str());
  532. }
  533. }
  534. // Determine the set of components that will be used in this project
  535. std::string componentsVar
  536. = "CPACK_COMPONENTS_" + cmSystemTools::UpperCase(installComponent);
  537. const char *components = this->GetOption(componentsVar.c_str());
  538. if (components && *components)
  539. {
  540. cmSystemTools::ExpandListArgument(components, componentsVector);
  541. std::vector<std::string>::iterator compIt;
  542. for (compIt = componentsVector.begin();
  543. compIt != componentsVector.end();
  544. ++compIt)
  545. {
  546. GetComponent(installProjectName.c_str(), compIt->c_str());
  547. }
  548. componentInstall = true;
  549. }
  550. }
  551. if (componentsVector.empty())
  552. {
  553. componentsVector.push_back(installComponent);
  554. }
  555. const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
  556. cmGlobalGenerator* globalGenerator
  557. = this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator(
  558. cmakeGenerator);
  559. // set the global flag for unix style paths on cmSystemTools as
  560. // soon as the generator is set. This allows gmake to be used
  561. // on windows.
  562. cmSystemTools::SetForceUnixPaths(globalGenerator->GetForceUnixPaths());
  563. // Does this generator require pre-install?
  564. if ( globalGenerator->GetPreinstallTargetName() )
  565. {
  566. globalGenerator->FindMakeProgram(this->MakefileMap);
  567. const char* cmakeMakeProgram
  568. = this->MakefileMap->GetDefinition("CMAKE_MAKE_PROGRAM");
  569. std::string buildCommand
  570. = globalGenerator->GenerateBuildCommand(cmakeMakeProgram,
  571. installProjectName.c_str(), 0,
  572. globalGenerator->GetPreinstallTargetName(),
  573. buildConfig, false, false);
  574. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  575. "- Install command: " << buildCommand << std::endl);
  576. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  577. "- Run preinstall target for: " << installProjectName << std::endl);
  578. std::string output;
  579. int retVal = 1;
  580. bool resB =
  581. cmSystemTools::RunSingleCommand(buildCommand.c_str(),
  582. &output,
  583. &retVal,
  584. installDirectory.c_str(),
  585. this->GeneratorVerbose, 0);
  586. if ( !resB || retVal )
  587. {
  588. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  589. tmpFile += "/PreinstallOutput.log";
  590. cmGeneratedFileStream ofs(tmpFile.c_str());
  591. ofs << "# Run command: " << buildCommand.c_str() << std::endl
  592. << "# Directory: " << installDirectory.c_str() << std::endl
  593. << "# Output:" << std::endl
  594. << output.c_str() << std::endl;
  595. cmCPackLogger(cmCPackLog::LOG_ERROR,
  596. "Problem running install command: " << buildCommand.c_str()
  597. << std::endl
  598. << "Please check " << tmpFile.c_str() << " for errors"
  599. << std::endl);
  600. return 0;
  601. }
  602. }
  603. delete globalGenerator;
  604. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  605. "- Install project: " << installProjectName << std::endl);
  606. // Run the installation for each component
  607. std::vector<std::string>::iterator componentIt;
  608. for (componentIt = componentsVector.begin();
  609. componentIt != componentsVector.end();
  610. ++componentIt)
  611. {
  612. std::string tempInstallDirectory = baseTempInstallDirectory;
  613. installComponent = *componentIt;
  614. if (componentInstall)
  615. {
  616. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  617. "- Install component: " << installComponent
  618. << std::endl);
  619. }
  620. cmake cm;
  621. cm.AddCMakePaths();
  622. cm.SetProgressCallback(cmCPackGeneratorProgress, this);
  623. cmGlobalGenerator gg;
  624. gg.SetCMakeInstance(&cm);
  625. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  626. cmMakefile *mf = lg->GetMakefile();
  627. std::string realInstallDirectory = tempInstallDirectory;
  628. if ( !installSubDirectory.empty() && installSubDirectory != "/" )
  629. {
  630. realInstallDirectory += installSubDirectory;
  631. }
  632. if (componentInstall)
  633. {
  634. tempInstallDirectory += "/";
  635. tempInstallDirectory += installComponent;
  636. }
  637. if (!setDestDir)
  638. {
  639. tempInstallDirectory += this->GetPackagingInstallPrefix();
  640. }
  641. if ( setDestDir )
  642. {
  643. // For DESTDIR based packaging, use the *project*
  644. // CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The
  645. // value of the project's CMAKE_INSTALL_PREFIX is sent in here as
  646. // the value of the CPACK_INSTALL_PREFIX variable.
  647. //
  648. // If DESTDIR has been 'internally set ON' this means that
  649. // the underlying CPack specific generator did ask for that
  650. // In this case we may override CPACK_INSTALL_PREFIX with
  651. // CPACK_PACKAGING_INSTALL_PREFIX
  652. // I know this is tricky and awkward but it's the price for
  653. // CPACK_SET_DESTDIR backward compatibility.
  654. if (cmSystemTools::IsInternallyOn(
  655. this->GetOption("CPACK_SET_DESTDIR")))
  656. {
  657. this->SetOption("CPACK_INSTALL_PREFIX",
  658. this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX"));
  659. }
  660. std::string dir;
  661. if (this->GetOption("CPACK_INSTALL_PREFIX"))
  662. {
  663. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  664. }
  665. mf->AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str());
  666. cmCPackLogger(
  667. cmCPackLog::LOG_DEBUG,
  668. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf->AddDefinition)"
  669. << std::endl);
  670. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  671. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'"
  672. << std::endl);
  673. // Make sure that DESTDIR + CPACK_INSTALL_PREFIX directory
  674. // exists:
  675. //
  676. if (cmSystemTools::StringStartsWith(dir.c_str(), "/"))
  677. {
  678. dir = tempInstallDirectory + dir;
  679. }
  680. else
  681. {
  682. dir = tempInstallDirectory + "/" + dir;
  683. }
  684. /*
  685. * We must re-set DESTDIR for each component
  686. * We must not add the CPACK_INSTALL_PREFIX part because
  687. * it will be added using the override of CMAKE_INSTALL_PREFIX
  688. * The main reason for this awkward trick is that
  689. * are using DESTDIR for 2 different reasons:
  690. * - Because it was asked by the CPack Generator or the user
  691. * using CPACK_SET_DESTDIR
  692. * - Because it was already used for component install
  693. * in order to put things in subdirs...
  694. */
  695. cmSystemTools::PutEnv((std::string("DESTDIR=")+tempInstallDirectory).c_str());
  696. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  697. "- Creating directory: '" << dir << "'" << std::endl);
  698. if ( !cmsys::SystemTools::MakeDirectory(dir.c_str()))
  699. {
  700. cmCPackLogger(cmCPackLog::LOG_ERROR,
  701. "Problem creating temporary directory: "
  702. << dir << std::endl);
  703. return 0;
  704. }
  705. }
  706. else
  707. {
  708. mf->AddDefinition("CMAKE_INSTALL_PREFIX",
  709. tempInstallDirectory.c_str());
  710. if ( !cmsys::SystemTools::MakeDirectory(
  711. tempInstallDirectory.c_str()))
  712. {
  713. cmCPackLogger(cmCPackLog::LOG_ERROR,
  714. "Problem creating temporary directory: "
  715. << tempInstallDirectory << std::endl);
  716. return 0;
  717. }
  718. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  719. "- Using non-DESTDIR install... (mf->AddDefinition)"
  720. << std::endl);
  721. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  722. "- Setting CMAKE_INSTALL_PREFIX to '"
  723. << tempInstallDirectory
  724. << "'" << std::endl);
  725. }
  726. if ( buildConfig && *buildConfig )
  727. {
  728. mf->AddDefinition("BUILD_TYPE", buildConfig);
  729. }
  730. std::string installComponentLowerCase
  731. = cmSystemTools::LowerCase(installComponent);
  732. if ( installComponentLowerCase != "all" )
  733. {
  734. mf->AddDefinition("CMAKE_INSTALL_COMPONENT",
  735. installComponent.c_str());
  736. }
  737. // strip on TRUE, ON, 1, one or several file names, but not on
  738. // FALSE, OFF, 0 and an empty string
  739. if (!cmSystemTools::IsOff(this->GetOption("CPACK_STRIP_FILES")))
  740. {
  741. mf->AddDefinition("CMAKE_INSTALL_DO_STRIP", "1");
  742. }
  743. int res = mf->ReadListFile(0, installFile.c_str());
  744. if (NULL !=mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) {
  745. if (absoluteDestFiles.length()>0) {
  746. absoluteDestFiles +=";";
  747. }
  748. absoluteDestFiles +=
  749. mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES");
  750. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  751. "Got some ABSOLUTE DESTINATION FILES: "
  752. << absoluteDestFiles << std::endl);
  753. }
  754. if ( cmSystemTools::GetErrorOccuredFlag() || !res )
  755. {
  756. return 0;
  757. }
  758. }
  759. }
  760. }
  761. this->SetOption("CPACK_ABSOLUTE_DESTINATION_FILES",
  762. absoluteDestFiles.c_str());
  763. return 1;
  764. }
  765. //----------------------------------------------------------------------
  766. bool cmCPackGenerator::ReadListFile(const char* moduleName)
  767. {
  768. std::string fullPath = this->MakefileMap->GetModulesFile(moduleName);
  769. return this->MakefileMap->ReadListFile(0, fullPath.c_str());
  770. }
  771. //----------------------------------------------------------------------
  772. void cmCPackGenerator::SetOptionIfNotSet(const char* op,
  773. const char* value)
  774. {
  775. const char* def = this->MakefileMap->GetDefinition(op);
  776. if ( def && *def )
  777. {
  778. return;
  779. }
  780. this->SetOption(op, value);
  781. }
  782. //----------------------------------------------------------------------
  783. void cmCPackGenerator::SetOption(const char* op, const char* value)
  784. {
  785. if ( !op )
  786. {
  787. return;
  788. }
  789. if ( !value )
  790. {
  791. this->MakefileMap->RemoveDefinition(op);
  792. return;
  793. }
  794. cmCPackLogger(cmCPackLog::LOG_DEBUG, this->GetNameOfClass()
  795. << "::SetOption(" << op << ", " << value << ")" << std::endl);
  796. this->MakefileMap->AddDefinition(op, value);
  797. }
  798. //----------------------------------------------------------------------
  799. int cmCPackGenerator::DoPackage()
  800. {
  801. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  802. "Create package using " << this->Name.c_str() << std::endl);
  803. if ( !this->PrepareNames() )
  804. {
  805. return 0;
  806. }
  807. if ( cmSystemTools::IsOn(
  808. this->GetOption("CPACK_REMOVE_TOPLEVEL_DIRECTORY")) )
  809. {
  810. const char* toplevelDirectory
  811. = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  812. if ( cmSystemTools::FileExists(toplevelDirectory) )
  813. {
  814. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  815. "Remove toplevel directory: "
  816. << toplevelDirectory << std::endl);
  817. if ( !cmSystemTools::RepeatedRemoveDirectory(toplevelDirectory) )
  818. {
  819. cmCPackLogger(cmCPackLog::LOG_ERROR,
  820. "Problem removing toplevel directory: "
  821. << toplevelDirectory
  822. << std::endl);
  823. return 0;
  824. }
  825. }
  826. }
  827. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  828. "About to install project " << std::endl);
  829. if ( !this->InstallProject() )
  830. {
  831. return 0;
  832. }
  833. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  834. "Done install project " << std::endl);
  835. const char* tempPackageFileName = this->GetOption(
  836. "CPACK_TEMPORARY_PACKAGE_FILE_NAME");
  837. const char* packageFileName = this->GetOption("CPACK_OUTPUT_FILE_PATH");
  838. const char* tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  839. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  840. cmsys::Glob gl;
  841. std::string findExpr = tempDirectory;
  842. findExpr += "/*";
  843. gl.RecurseOn();
  844. if ( !gl.FindFiles(findExpr) )
  845. {
  846. cmCPackLogger(cmCPackLog::LOG_ERROR,
  847. "Cannot find any files in the packaging tree" << std::endl);
  848. return 0;
  849. }
  850. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Create package" << std::endl);
  851. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Package files to: "
  852. << (tempPackageFileName ? tempPackageFileName : "(NULL)") << std::endl);
  853. if ( cmSystemTools::FileExists(tempPackageFileName) )
  854. {
  855. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Remove old package file"
  856. << std::endl);
  857. cmSystemTools::RemoveFile(tempPackageFileName);
  858. }
  859. if ( cmSystemTools::IsOn(this->GetOption(
  860. "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) )
  861. {
  862. tempDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  863. }
  864. // The files to be installed
  865. files = gl.GetFiles();
  866. // For component installations, determine which files go into which
  867. // components.
  868. if (!this->Components.empty())
  869. {
  870. std::vector<std::string>::const_iterator it;
  871. for ( it = files.begin(); it != files.end(); ++ it )
  872. {
  873. // beware we cannot just use tempDirectory as before
  874. // because some generator will "CPACK_INCLUDE_TOPLEVEL_DIRECTORY"
  875. // we really want "CPACK_TEMPORARY_DIRECTORY"
  876. std::string fileN =
  877. cmSystemTools::RelativePath(
  878. this->GetOption("CPACK_TEMPORARY_DIRECTORY"), it->c_str());
  879. // Determine which component we are in.
  880. std::string componentName = fileN.substr(0, fileN.find('/'));
  881. // Strip off the component part of the path.
  882. fileN = fileN.substr(fileN.find('/')+1, std::string::npos);
  883. // Add this file to the list of files for the component.
  884. this->Components[componentName].Files.push_back(fileN);
  885. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Adding file <"
  886. <<fileN<<"> to component <"
  887. <<componentName<<">"<<std::endl);
  888. }
  889. }
  890. packageFileNames.clear();
  891. /* Put at least one file name into the list of
  892. * wanted packageFileNames. The specific generator
  893. * may update this during PackageFiles.
  894. * (either putting several names or updating the provided one)
  895. */
  896. packageFileNames.push_back(tempPackageFileName);
  897. toplevel = tempDirectory;
  898. if ( !this->PackageFiles() || cmSystemTools::GetErrorOccuredFlag())
  899. {
  900. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem compressing the directory"
  901. << std::endl);
  902. return 0;
  903. }
  904. /*
  905. * Copy the generated packages to final destination
  906. * - there may be several of them
  907. * - the initially provided name may have changed
  908. * (because the specific generator did 'normalize' it)
  909. */
  910. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Copying final package(s) ["
  911. <<packageFileNames.size()
  912. <<"]:"<<std::endl);
  913. std::vector<std::string>::iterator it;
  914. /* now copy package one by one */
  915. for (it=packageFileNames.begin();it!=packageFileNames.end();++it)
  916. {
  917. std::string tmpPF(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"));
  918. tempPackageFileName = it->c_str();
  919. tmpPF += "/"+cmSystemTools::GetFilenameName(*it);
  920. packageFileName = tmpPF.c_str();
  921. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy final package(s): "
  922. << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
  923. << " to "
  924. << (packageFileName ? packageFileName : "(NULL)")
  925. << std::endl);
  926. if ( !cmSystemTools::CopyFileIfDifferent(tempPackageFileName,
  927. packageFileName) )
  928. {
  929. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the package: "
  930. << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
  931. << " to "
  932. << (packageFileName ? packageFileName : "(NULL)")
  933. << std::endl);
  934. return 0;
  935. }
  936. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- package: "
  937. << packageFileName
  938. << " generated." << std::endl);
  939. }
  940. return 1;
  941. }
  942. //----------------------------------------------------------------------
  943. int cmCPackGenerator::Initialize(const char* name, cmMakefile* mf)
  944. {
  945. this->MakefileMap = mf;
  946. this->Name = name;
  947. if ( !this->SetCMakeRoot() )
  948. {
  949. cmCPackLogger(cmCPackLog::LOG_ERROR,
  950. "Cannot initialize the generator" << std::endl);
  951. return 0;
  952. }
  953. // set the running generator name
  954. this->SetOption("CPACK_GENERATOR", this->Name.c_str());
  955. // Load the project specific config file
  956. const char* config =
  957. this->GetOption("CPACK_PROJECT_CONFIG_FILE");
  958. if(config)
  959. {
  960. mf->ReadListFile(config);
  961. }
  962. int result = this->InitializeInternal();
  963. if (cmSystemTools::GetErrorOccuredFlag())
  964. {
  965. return 0;
  966. }
  967. // If a generator subclass did not already set this option in its
  968. // InitializeInternal implementation, and the project did not already set
  969. // it, the default value should be:
  970. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/");
  971. return result;
  972. }
  973. //----------------------------------------------------------------------
  974. int cmCPackGenerator::InitializeInternal()
  975. {
  976. return 1;
  977. }
  978. //----------------------------------------------------------------------
  979. bool cmCPackGenerator::IsSet(const char* name) const
  980. {
  981. return this->MakefileMap->IsSet(name);
  982. }
  983. //----------------------------------------------------------------------
  984. const char* cmCPackGenerator::GetOption(const char* op)
  985. {
  986. const char* ret = this->MakefileMap->GetDefinition(op);
  987. if(!ret)
  988. {
  989. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  990. "Warning, GetOption return NULL for: "
  991. << op
  992. << std::endl);
  993. }
  994. return ret;
  995. }
  996. //----------------------------------------------------------------------
  997. int cmCPackGenerator::SetCMakeRoot()
  998. {
  999. // use the CMAKE_ROOT from cmake which should have been
  1000. // found by now
  1001. const char* root=
  1002. this->MakefileMap->GetDefinition("CMAKE_ROOT");
  1003. if(root)
  1004. {
  1005. this->CMakeRoot = root;
  1006. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  1007. << this->CMakeRoot.c_str() << std::endl);
  1008. this->SetOption("CMAKE_ROOT", this->CMakeRoot.c_str());
  1009. return 1;
  1010. }
  1011. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1012. "Could not find CMAKE_ROOT !!!"
  1013. << std::endl
  1014. << "CMake has most likely not been installed correctly."
  1015. << std::endl
  1016. <<"Modules directory not found in"
  1017. << std::endl);
  1018. return 0;
  1019. }
  1020. //----------------------------------------------------------------------
  1021. int cmCPackGenerator::PackageFiles()
  1022. {
  1023. return 0;
  1024. }
  1025. //----------------------------------------------------------------------
  1026. const char* cmCPackGenerator::GetInstallPath()
  1027. {
  1028. if ( !this->InstallPath.empty() )
  1029. {
  1030. return this->InstallPath.c_str();
  1031. }
  1032. #if defined(_WIN32) && !defined(__CYGWIN__)
  1033. const char* prgfiles = cmsys::SystemTools::GetEnv("ProgramFiles");
  1034. const char* sysDrive = cmsys::SystemTools::GetEnv("SystemDrive");
  1035. if ( prgfiles )
  1036. {
  1037. this->InstallPath = prgfiles;
  1038. }
  1039. else if ( sysDrive )
  1040. {
  1041. this->InstallPath = sysDrive;
  1042. this->InstallPath += "/Program Files";
  1043. }
  1044. else
  1045. {
  1046. this->InstallPath = "c:/Program Files";
  1047. }
  1048. this->InstallPath += "/";
  1049. this->InstallPath += this->GetOption("CPACK_PACKAGE_NAME");
  1050. this->InstallPath += "-";
  1051. this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION");
  1052. #elif defined(__HAIKU__)
  1053. BPath dir;
  1054. if (find_directory(B_COMMON_DIRECTORY, &dir) == B_OK)
  1055. {
  1056. this->InstallPath = dir.Path();
  1057. }
  1058. else
  1059. {
  1060. this->InstallPath = "/boot/common";
  1061. }
  1062. #else
  1063. this->InstallPath = "/usr/local/";
  1064. #endif
  1065. return this->InstallPath.c_str();
  1066. }
  1067. //----------------------------------------------------------------------
  1068. const char* cmCPackGenerator::GetPackagingInstallPrefix()
  1069. {
  1070. cmCPackLogger(cmCPackLog::LOG_DEBUG, "GetPackagingInstallPrefix: '"
  1071. << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'" << std::endl);
  1072. return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX");
  1073. }
  1074. //----------------------------------------------------------------------
  1075. std::string cmCPackGenerator::FindTemplate(const char* name)
  1076. {
  1077. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: "
  1078. << (name ? name : "(NULL)") << std::endl);
  1079. std::string ffile = this->MakefileMap->GetModulesFile(name);
  1080. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: "
  1081. << ffile.c_str() << std::endl);
  1082. return ffile;
  1083. }
  1084. //----------------------------------------------------------------------
  1085. bool cmCPackGenerator::ConfigureString(const std::string& inString,
  1086. std::string& outString)
  1087. {
  1088. this->MakefileMap->ConfigureString(inString,
  1089. outString, true, false);
  1090. return true;
  1091. }
  1092. //----------------------------------------------------------------------
  1093. bool cmCPackGenerator::ConfigureFile(const char* inName,
  1094. const char* outName, bool copyOnly /* = false */)
  1095. {
  1096. return this->MakefileMap->ConfigureFile(inName, outName,
  1097. copyOnly, true, false) == 1;
  1098. }
  1099. //----------------------------------------------------------------------
  1100. int cmCPackGenerator::CleanTemporaryDirectory()
  1101. {
  1102. std::string tempInstallDirectoryWithPostfix
  1103. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  1104. const char* tempInstallDirectory = tempInstallDirectoryWithPostfix.c_str();
  1105. if(cmsys::SystemTools::FileExists(tempInstallDirectory))
  1106. {
  1107. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1108. "- Clean temporary : "
  1109. << tempInstallDirectory << std::endl);
  1110. if(!cmSystemTools::RepeatedRemoveDirectory(tempInstallDirectory))
  1111. {
  1112. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1113. "Problem removing temporary directory: " <<
  1114. tempInstallDirectory
  1115. << std::endl);
  1116. return 0;
  1117. }
  1118. }
  1119. return 1;
  1120. }
  1121. //----------------------------------------------------------------------
  1122. int cmCPackGenerator::PrepareGroupingKind()
  1123. {
  1124. // The default behavior is to create 1 package by component group
  1125. // unless the user asked to put all COMPONENTS in a single package
  1126. allGroupInOne = (NULL !=
  1127. (this->GetOption(
  1128. "CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE")));
  1129. allComponentInOne = (NULL !=
  1130. (this->GetOption(
  1131. "CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE")));
  1132. ignoreComponentGroup = (NULL !=
  1133. (this->GetOption(
  1134. "CPACK_COMPONENTS_IGNORE_GROUPS")));
  1135. std::string groupingType;
  1136. // Second way to specify grouping
  1137. if (NULL != this->GetOption("CPACK_COMPONENTS_GROUPING")) {
  1138. groupingType = this->GetOption("CPACK_COMPONENTS_GROUPING");
  1139. }
  1140. if (groupingType.length()>0)
  1141. {
  1142. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "["
  1143. << this->Name << "]"
  1144. << " requested component grouping = "<< groupingType <<std::endl);
  1145. if (groupingType == "ALL_GROUP_IN_ONE")
  1146. {
  1147. allGroupInOne = true;
  1148. }
  1149. else if (groupingType == "ALL_COMPONENT_IN_ONE")
  1150. {
  1151. allComponentInOne = true;
  1152. }
  1153. else if (groupingType == "IGNORE")
  1154. {
  1155. ignoreComponentGroup = true;
  1156. }
  1157. else
  1158. {
  1159. cmCPackLogger(cmCPackLog::LOG_WARNING, "["
  1160. << this->Name << "]"
  1161. << " requested component grouping type <"<< groupingType
  1162. << "> UNKNOWN not in (ALL_GROUP_IN_ONE,"
  1163. "ALL_COMPONENT_IN_ONE,IGNORE)" <<std::endl);
  1164. }
  1165. }
  1166. // Some components were defined but NO group
  1167. // force ignoreGroups
  1168. if (this->ComponentGroups.empty() && (!this->Components.empty())
  1169. && (!ignoreComponentGroup)) {
  1170. cmCPackLogger(cmCPackLog::LOG_WARNING, "["
  1171. << this->Name << "]"
  1172. << " Some Components defined but NO component group:"
  1173. << " Ignoring component group."
  1174. << std::endl);
  1175. ignoreComponentGroup = true;
  1176. }
  1177. return 1;
  1178. }
  1179. //----------------------------------------------------------------------
  1180. bool cmCPackGenerator::SupportsComponentInstallation() const
  1181. {
  1182. return false;
  1183. }
  1184. //----------------------------------------------------------------------
  1185. cmCPackInstallationType*
  1186. cmCPackGenerator::GetInstallationType(const char *projectName,
  1187. const char *name)
  1188. {
  1189. (void) projectName;
  1190. bool hasInstallationType = this->InstallationTypes.count(name) != 0;
  1191. cmCPackInstallationType *installType = &this->InstallationTypes[name];
  1192. if (!hasInstallationType)
  1193. {
  1194. // Define the installation type
  1195. std::string macroPrefix = "CPACK_INSTALL_TYPE_"
  1196. + cmsys::SystemTools::UpperCase(name);
  1197. installType->Name = name;
  1198. const char* displayName
  1199. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1200. if (displayName && *displayName)
  1201. {
  1202. installType->DisplayName = displayName;
  1203. }
  1204. else
  1205. {
  1206. installType->DisplayName = installType->Name;
  1207. }
  1208. installType->Index = static_cast<unsigned>(
  1209. this->InstallationTypes.size());
  1210. }
  1211. return installType;
  1212. }
  1213. //----------------------------------------------------------------------
  1214. cmCPackComponent*
  1215. cmCPackGenerator::GetComponent(const char *projectName, const char *name)
  1216. {
  1217. bool hasComponent = this->Components.count(name) != 0;
  1218. cmCPackComponent *component = &this->Components[name];
  1219. if (!hasComponent)
  1220. {
  1221. // Define the component
  1222. std::string macroPrefix = "CPACK_COMPONENT_"
  1223. + cmsys::SystemTools::UpperCase(name);
  1224. component->Name = name;
  1225. const char* displayName
  1226. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1227. if (displayName && *displayName)
  1228. {
  1229. component->DisplayName = displayName;
  1230. }
  1231. else
  1232. {
  1233. component->DisplayName = component->Name;
  1234. }
  1235. component->IsHidden
  1236. = this->IsSet((macroPrefix + "_HIDDEN").c_str());
  1237. component->IsRequired
  1238. = this->IsSet((macroPrefix + "_REQUIRED").c_str());
  1239. component->IsDisabledByDefault
  1240. = this->IsSet((macroPrefix + "_DISABLED").c_str());
  1241. component->IsDownloaded
  1242. = this->IsSet((macroPrefix + "_DOWNLOADED").c_str())
  1243. || cmSystemTools::IsOn(this->GetOption("CPACK_DOWNLOAD_ALL"));
  1244. const char* archiveFile = this->GetOption((macroPrefix +
  1245. "_ARCHIVE_FILE").c_str());
  1246. if (archiveFile && *archiveFile)
  1247. {
  1248. component->ArchiveFile = archiveFile;
  1249. }
  1250. const char* groupName = this->GetOption((macroPrefix + "_GROUP").c_str());
  1251. if (groupName && *groupName)
  1252. {
  1253. component->Group = GetComponentGroup(projectName, groupName);
  1254. component->Group->Components.push_back(component);
  1255. }
  1256. else
  1257. {
  1258. component->Group = 0;
  1259. }
  1260. const char* description
  1261. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1262. if (description && *description)
  1263. {
  1264. component->Description = description;
  1265. }
  1266. // Determine the installation types.
  1267. const char *installTypes
  1268. = this->GetOption((macroPrefix + "_INSTALL_TYPES").c_str());
  1269. if (installTypes && *installTypes)
  1270. {
  1271. std::vector<std::string> installTypesVector;
  1272. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  1273. std::vector<std::string>::iterator installTypesIt;
  1274. for (installTypesIt = installTypesVector.begin();
  1275. installTypesIt != installTypesVector.end();
  1276. ++installTypesIt)
  1277. {
  1278. component->InstallationTypes.push_back(
  1279. this->GetInstallationType(projectName, installTypesIt->c_str()));
  1280. }
  1281. }
  1282. // Determine the component dependencies.
  1283. const char *depends = this->GetOption((macroPrefix + "_DEPENDS").c_str());
  1284. if (depends && *depends)
  1285. {
  1286. std::vector<std::string> dependsVector;
  1287. cmSystemTools::ExpandListArgument(depends, dependsVector);
  1288. std::vector<std::string>::iterator dependIt;
  1289. for (dependIt = dependsVector.begin();
  1290. dependIt != dependsVector.end();
  1291. ++dependIt)
  1292. {
  1293. cmCPackComponent *child = GetComponent(projectName,
  1294. dependIt->c_str());
  1295. component->Dependencies.push_back(child);
  1296. child->ReverseDependencies.push_back(component);
  1297. }
  1298. }
  1299. }
  1300. return component;
  1301. }
  1302. //----------------------------------------------------------------------
  1303. cmCPackComponentGroup*
  1304. cmCPackGenerator::GetComponentGroup(const char *projectName, const char *name)
  1305. {
  1306. (void) projectName;
  1307. std::string macroPrefix = "CPACK_COMPONENT_GROUP_"
  1308. + cmsys::SystemTools::UpperCase(name);
  1309. bool hasGroup = this->ComponentGroups.count(name) != 0;
  1310. cmCPackComponentGroup *group = &this->ComponentGroups[name];
  1311. if (!hasGroup)
  1312. {
  1313. // Define the group
  1314. group->Name = name;
  1315. const char* displayName
  1316. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1317. if (displayName && *displayName)
  1318. {
  1319. group->DisplayName = displayName;
  1320. }
  1321. else
  1322. {
  1323. group->DisplayName = group->Name;
  1324. }
  1325. const char* description
  1326. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1327. if (description && *description)
  1328. {
  1329. group->Description = description;
  1330. }
  1331. group->IsBold
  1332. = this->IsSet((macroPrefix + "_BOLD_TITLE").c_str());
  1333. group->IsExpandedByDefault
  1334. = this->IsSet((macroPrefix + "_EXPANDED").c_str());
  1335. const char* parentGroupName
  1336. = this->GetOption((macroPrefix + "_PARENT_GROUP").c_str());
  1337. if (parentGroupName && *parentGroupName)
  1338. {
  1339. group->ParentGroup = GetComponentGroup(projectName, parentGroupName);
  1340. group->ParentGroup->Subgroups.push_back(group);
  1341. }
  1342. else
  1343. {
  1344. group->ParentGroup = 0;
  1345. }
  1346. }
  1347. return group;
  1348. }