cmCPackGenerator.cxx 57 KB

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