cmCPackIFWGenerator.cxx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  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 "cmCPackIFWGenerator.h"
  11. #include "cmGlobalGenerator.h"
  12. #include "cmLocalGenerator.h"
  13. #include "cmSystemTools.h"
  14. #include "cmMakefile.h"
  15. #include "cmGeneratedFileStream.h"
  16. #include "cmCPackLog.h"
  17. #include "cmCPackComponentGroup.h"
  18. #include <cmsys/SystemTools.hxx>
  19. #include <cmsys/Glob.hxx>
  20. #include <cmsys/Directory.hxx>
  21. #include <cmsys/RegularExpression.hxx>
  22. #include <cmXMLSafe.h>
  23. //----------------------------------------------------------------------
  24. cmCPackIFWGenerator::cmCPackIFWGenerator()
  25. {
  26. }
  27. //----------------------------------------------------------------------
  28. cmCPackIFWGenerator::~cmCPackIFWGenerator()
  29. {
  30. }
  31. //----------------------------------------------------------------------
  32. int cmCPackIFWGenerator::PackageFiles()
  33. {
  34. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Configuration" << std::endl);
  35. if (!IfwCreateConfigFile())
  36. {
  37. cmCPackLogger(cmCPackLog::LOG_ERROR,
  38. "CPack error: Could not create IFW \"config.xml\" file."
  39. << std::endl);
  40. return false;
  41. }
  42. if (Components.empty() && !IfwCreatePackageFile())
  43. {
  44. cmCPackLogger(cmCPackLog::LOG_ERROR,
  45. "CPack error: Could not create IFW "
  46. "\"root/meta/package.xml\" file."
  47. << std::endl);
  48. return false;
  49. }
  50. std::string ifwTLD = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  51. std::string ifwTmpFile = ifwTLD;
  52. ifwTmpFile += "/IFWOutput.log";
  53. std::set<std::string> ifwDependsComponents;
  54. std::string ifwBinaryComponents;
  55. std::string ifwDownloadedComponents;
  56. // Create groups meta information
  57. std::map<std::string, cmCPackComponentGroup>::iterator groupIt;
  58. for(groupIt = this->ComponentGroups.begin();
  59. groupIt != this->ComponentGroups.end();
  60. ++groupIt
  61. )
  62. {
  63. std::string macroPrefix = "CPACK_IFW_COMPONENT_GROUP_"
  64. + cmsys::SystemTools::UpperCase(groupIt->second.Name);
  65. std::string groupId = IfwGetGroupId(&groupIt->second);
  66. if(!ifwBinaryComponents.empty()) ifwBinaryComponents += ",";
  67. ifwBinaryComponents += groupId;
  68. std::string pkgMetaDir = this->toplevel + "/packages/"
  69. + groupId
  70. + "/meta";
  71. std::string pkgXmlFileName = pkgMetaDir
  72. + "/package.xml";
  73. cmGeneratedFileStream pkgXml(pkgXmlFileName.data());
  74. pkgXml << "<?xml version=\"1.0\"?>" << std::endl;
  75. pkgXml << "<Package>" << std::endl;
  76. pkgXml << " <DisplayName>" << groupIt->second.DisplayName
  77. << "</DisplayName>" << std::endl;
  78. pkgXml << " <Description>" << groupIt->second.Description
  79. << "</Description>" << std::endl;
  80. pkgXml << " <Name>" << groupId << "</Name>" << std::endl;
  81. // Version
  82. const char* ifwPackageVersion = this->GetOption("CPACK_PACKAGE_VERSION");
  83. const char* ifwGroupVersion = this->GetOption(macroPrefix + "_VERSION");
  84. pkgXml << " <Version>"
  85. << (ifwGroupVersion ? ifwGroupVersion : ifwPackageVersion)
  86. << "</Version>" << std::endl;
  87. pkgXml << " <ReleaseDate>" << IfwCreateCurrentDate()
  88. << "</ReleaseDate>" << std::endl;
  89. // Licenses
  90. std::vector<std::string> licenses;
  91. if(IfwParseLicenses(licenses, macroPrefix + "_LICENSES", pkgMetaDir))
  92. {
  93. pkgXml << " <Licenses>" << std::endl;
  94. for(size_t i = 0; i < licenses.size(); i += 2)
  95. {
  96. pkgXml << " <License "
  97. << "name=\"" << licenses[i] << "\" "
  98. << "file=\"" << licenses[i + 1] << "\" "
  99. << "/>" <<std::endl;
  100. }
  101. pkgXml << " </Licenses>" << std::endl;
  102. }
  103. // Priority
  104. if(const char* ifwGroupPriority =
  105. this->GetOption(macroPrefix + "_PRIORITY"))
  106. {
  107. pkgXml << " <SortingPriority>" << ifwGroupPriority
  108. << "</SortingPriority>" << std::endl;
  109. }
  110. pkgXml << "</Package>" << std::endl;
  111. }
  112. // Create components meta information
  113. std::map<std::string, cmCPackComponent>::iterator compIt;
  114. for (compIt = this->Components.begin();
  115. compIt != this->Components.end();
  116. ++compIt)
  117. {
  118. // Component id
  119. std::string ifwCompId = IfwGetComponentId(&compIt->second);
  120. std::string pkgMetaDir = this->toplevel + "/"
  121. + GetComponentInstallDirNamePrefix(compIt->second.Name)
  122. + ifwCompId + "/meta";
  123. std::string pkgXmlFileName = pkgMetaDir + "/package.xml";
  124. cmGeneratedFileStream pkgXml(pkgXmlFileName.data());
  125. // Check IFW version for component
  126. std::string macroPrefix = "CPACK_IFW_COMPONENT_"
  127. + cmsys::SystemTools::UpperCase(compIt->second.Name);
  128. pkgXml << "<?xml version=\"1.0\"?>" << std::endl;
  129. pkgXml << "<Package>" << std::endl;
  130. pkgXml << " <DisplayName>" << compIt->second.DisplayName
  131. << "</DisplayName>" << std::endl;
  132. pkgXml << " <Description>" << compIt->second.Description
  133. << "</Description>" << std::endl;
  134. pkgXml << " <Name>" << ifwCompId << "</Name>" << std::endl;
  135. // Version
  136. const char* ifwPackageVersion = this->GetOption("CPACK_PACKAGE_VERSION");
  137. const char* ifwCompVersion =
  138. this->GetOption(macroPrefix + "_VERSION");
  139. pkgXml << " <Version>"
  140. << (ifwCompVersion ? ifwCompVersion : ifwPackageVersion)
  141. << "</Version>" << std::endl;
  142. pkgXml << " <ReleaseDate>" << IfwCreateCurrentDate()
  143. << "</ReleaseDate>" << std::endl;
  144. // Script
  145. const char* ifwCompScript =
  146. this->GetOption(macroPrefix + "_SCRIPT");
  147. if (ifwCompScript)
  148. {
  149. // Copy file
  150. std::string ifwCompScriptFile = pkgMetaDir + "/operations.qs";
  151. cmsys::SystemTools::CopyFileIfDifferent(ifwCompScript,
  152. ifwCompScriptFile.data());
  153. pkgXml << " <Script>" << "operations.qs" << "</Script>" << std::endl;
  154. }
  155. // Check dependencies
  156. std::set<std::string> compDepSet;
  157. // CMake dependencies
  158. if (!compIt->second.Dependencies.empty())
  159. {
  160. std::vector<cmCPackComponent *>::iterator depCompIt;
  161. for(depCompIt = compIt->second.Dependencies.begin();
  162. depCompIt != compIt->second.Dependencies.end();
  163. ++depCompIt)
  164. {
  165. compDepSet.insert(IfwGetComponentId(*depCompIt));
  166. }
  167. }
  168. // QtIFW dependencies
  169. if(const char *ifwCompDepsStr = this->GetOption(macroPrefix + "_DEPENDS"))
  170. {
  171. std::vector<std::string> ifwCompDepsVector;
  172. cmSystemTools::ExpandListArgument(ifwCompDepsStr,
  173. ifwCompDepsVector);
  174. for(std::vector<std::string>::iterator
  175. depCompIt = ifwCompDepsVector.begin();
  176. depCompIt != ifwCompDepsVector.end(); ++depCompIt)
  177. {
  178. compDepSet.insert(*depCompIt);
  179. ifwDependsComponents.insert(*depCompIt);
  180. }
  181. }
  182. // Write dependencies
  183. if (!compDepSet.empty())
  184. {
  185. pkgXml << " <Dependencies>";
  186. std::set<std::string>::iterator it = compDepSet.begin();
  187. pkgXml << *it;
  188. ++it;
  189. while(it != compDepSet.end())
  190. {
  191. pkgXml << "," << *it;
  192. ++it;
  193. }
  194. pkgXml << "</Dependencies>" << std::endl;
  195. }
  196. // Licenses
  197. std::vector<std::string> licenses;
  198. if(IfwParseLicenses(licenses, macroPrefix + "_LICENSES", pkgMetaDir))
  199. {
  200. pkgXml << " <Licenses>" << std::endl;
  201. for(size_t i = 0; i < licenses.size(); i += 2)
  202. {
  203. pkgXml << " <License "
  204. << "name=\"" << licenses[i] << "\" "
  205. << "file=\"" << licenses[i + 1] << "\" "
  206. << "/>" <<std::endl;
  207. }
  208. pkgXml << " </Licenses>" << std::endl;
  209. }
  210. // TODO: Check how enable virtual component (now it's allways disabled)
  211. if (compIt->second.IsRequired) {
  212. pkgXml << " <ForcedInstallation>true</ForcedInstallation>"
  213. << std::endl;
  214. } else if (compIt->second.IsDisabledByDefault) {
  215. pkgXml << " <Default>false</Default>" << std::endl;
  216. } else if (compIt->second.IsHidden) {
  217. pkgXml << " <Virtual>true</Virtual>" << std::endl;
  218. } else {
  219. pkgXml << " <Default>true</Default>" << std::endl;
  220. }
  221. // Priority
  222. if(const char* ifwCompPriority =
  223. this->GetOption(macroPrefix + "_PRIORITY"))
  224. {
  225. pkgXml << " <SortingPriority>" << ifwCompPriority
  226. << "</SortingPriority>" << std::endl;
  227. }
  228. pkgXml << "</Package>" << std::endl;
  229. // Downloaded
  230. if (compIt->second.IsDownloaded)
  231. {
  232. if (!ifwDownloadedComponents.empty()) ifwDownloadedComponents += ",";
  233. ifwDownloadedComponents += ifwCompId;
  234. }
  235. else
  236. {
  237. if (!ifwBinaryComponents.empty()) ifwBinaryComponents += ",";
  238. ifwBinaryComponents += ifwCompId;
  239. }
  240. }
  241. // Run repogen
  242. if (!ifwDownloadSite.empty())
  243. {
  244. std::string ifwCmd = ifwRepoGen;
  245. ifwCmd += " -c " + this->toplevel + "/config/config.xml";
  246. ifwCmd += " -p " + this->toplevel + "/packages";
  247. if(!ifwPkgsDirsVector.empty())
  248. {
  249. for(std::vector<std::string>::iterator it = ifwPkgsDirsVector.begin();
  250. it != ifwPkgsDirsVector.end(); ++it)
  251. {
  252. ifwCmd += " -p " + *it;
  253. }
  254. }
  255. if (!ifwOnlineOnly && !ifwDownloadedComponents.empty()) {
  256. ifwCmd += " -i " + ifwDownloadedComponents;
  257. }
  258. ifwCmd += " " + this->toplevel + "/repository";
  259. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << ifwCmd
  260. << std::endl);
  261. std::string output;
  262. int retVal = 1;
  263. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  264. "- Generate repository" << std::endl);
  265. bool res = cmSystemTools::RunSingleCommand(
  266. ifwCmd.c_str(), &output, &retVal, 0, this->GeneratorVerbose, 0);
  267. if ( !res || retVal )
  268. {
  269. cmGeneratedFileStream ofs(ifwTmpFile.c_str());
  270. ofs << "# Run command: " << ifwCmd << std::endl
  271. << "# Output:" << std::endl
  272. << output << std::endl;
  273. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running IFW command: "
  274. << ifwCmd << std::endl
  275. << "Please check " << ifwTmpFile << " for errors"
  276. << std::endl);
  277. return 0;
  278. }
  279. }
  280. // Run binary creator
  281. {
  282. std::string ifwCmd = ifwBinCreator;
  283. ifwCmd += " -c " + this->toplevel + "/config/config.xml";
  284. ifwCmd += " -p " + this->toplevel + "/packages";
  285. if(!ifwPkgsDirsVector.empty())
  286. {
  287. for(std::vector<std::string>::iterator it = ifwPkgsDirsVector.begin();
  288. it != ifwPkgsDirsVector.end(); ++it)
  289. {
  290. ifwCmd += " -p " + *it;
  291. }
  292. }
  293. if (ifwOnlineOnly)
  294. {
  295. ifwCmd += " --online-only";
  296. }
  297. else if (!ifwDownloadedComponents.empty() && !ifwDownloadSite.empty())
  298. {
  299. ifwCmd += " -e " + ifwDownloadedComponents;
  300. }
  301. else if (!ifwDependsComponents.empty())
  302. {
  303. ifwCmd += " -i ";
  304. std::set<std::string>::iterator it = ifwDependsComponents.begin();
  305. ifwCmd += *it;
  306. ++it;
  307. while(it != ifwDependsComponents.end())
  308. {
  309. ifwCmd += "," + (*it);
  310. ++it;
  311. }
  312. ifwCmd += "," + ifwBinaryComponents;
  313. }
  314. // TODO: set correct name for multipackages
  315. if (this->packageFileNames.size() > 0)
  316. {
  317. ifwCmd += " " + packageFileNames[0];
  318. }
  319. else
  320. {
  321. ifwCmd += " installer";
  322. }
  323. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << ifwCmd
  324. << std::endl);
  325. std::string output;
  326. int retVal = 1;
  327. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Generate package" << std::endl);
  328. bool res = cmSystemTools::RunSingleCommand(
  329. ifwCmd.c_str(), &output, &retVal, 0, this->GeneratorVerbose, 0);
  330. if ( !res || retVal )
  331. {
  332. cmGeneratedFileStream ofs(ifwTmpFile.c_str());
  333. ofs << "# Run command: " << ifwCmd << std::endl
  334. << "# Output:" << std::endl
  335. << output << std::endl;
  336. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running IFW command: "
  337. << ifwCmd << std::endl
  338. << "Please check " << ifwTmpFile << " for errors"
  339. << std::endl);
  340. return 0;
  341. }
  342. }
  343. return 1;
  344. }
  345. //----------------------------------------------------------------------
  346. const char *cmCPackIFWGenerator::GetPackagingInstallPrefix()
  347. {
  348. const char *defPrefix = cmCPackGenerator::GetPackagingInstallPrefix();
  349. std::string tmpPref = defPrefix ? defPrefix : "";
  350. if(this->Components.empty())
  351. {
  352. tmpPref += "packages/root/data";
  353. }
  354. this->SetOption("CPACK_IFW_PACKAGING_INSTALL_PREFIX", tmpPref.c_str());
  355. return this->GetOption("CPACK_IFW_PACKAGING_INSTALL_PREFIX");
  356. }
  357. //----------------------------------------------------------------------
  358. const char *cmCPackIFWGenerator::GetOutputExtension()
  359. {
  360. const char *suffix = this->GetOption("CMAKE_EXECUTABLE_SUFFIX");
  361. return suffix ? suffix : "";
  362. }
  363. //----------------------------------------------------------------------
  364. std::string cmCPackIFWGenerator::IfwGetGroupId(cmCPackComponentGroup *group)
  365. {
  366. std::string ifwGroupId;
  367. std::string ifwGroupName;
  368. std::list<cmCPackComponentGroup*> groups;
  369. while(group)
  370. {
  371. groups.push_front(group);
  372. group = group->ParentGroup;
  373. }
  374. std::list<cmCPackComponentGroup*>::iterator it = groups.begin();
  375. if(it != groups.end())
  376. {
  377. ifwGroupId = IfwGetGroupName(*it);
  378. ++it;
  379. }
  380. while(it != groups.end())
  381. {
  382. ifwGroupName = IfwGetGroupName(*it);
  383. if(ifwResolveDuplicateNames)
  384. {
  385. if(ifwGroupName.substr(0, ifwGroupId.size()) == ifwGroupId)
  386. {
  387. ifwGroupId = ifwGroupName;
  388. ++it;
  389. continue;
  390. }
  391. }
  392. ifwGroupId += "." + ifwGroupName;
  393. ++it;
  394. }
  395. return ifwGroupId;
  396. }
  397. //----------------------------------------------------------------------
  398. std::string cmCPackIFWGenerator::IfwGetComponentId(cmCPackComponent *component)
  399. {
  400. std::string ifwCompId;
  401. if(component) {
  402. ifwCompId = IfwGetGroupId(component->Group);
  403. if(!ifwCompId.empty()) ifwCompId += ".";
  404. std::string ifwCompName = IfwGetComponentName(component);
  405. if(ifwResolveDuplicateNames &&
  406. (ifwCompName.substr(0, ifwCompId.size()) == ifwCompId))
  407. {
  408. ifwCompId = ifwCompName;
  409. }
  410. else
  411. {
  412. ifwCompId += ifwCompName;
  413. }
  414. }
  415. return ifwCompId;
  416. }
  417. //----------------------------------------------------------------------
  418. std::string cmCPackIFWGenerator::IfwGetGroupName(cmCPackComponentGroup *group)
  419. {
  420. std::string ifwGroupName = group->Name;
  421. if(const char* name =
  422. this->GetOption("CPACK_IFW_COMPONENT_GROUP_"
  423. + cmsys::SystemTools::UpperCase(group->Name) + "_NAME"))
  424. {
  425. ifwGroupName = name;
  426. }
  427. return ifwGroupName;
  428. }
  429. //----------------------------------------------------------------------
  430. std::string
  431. cmCPackIFWGenerator::IfwGetComponentName(cmCPackComponent *component)
  432. {
  433. return IfwGetComponentName(component->Name);
  434. }
  435. //----------------------------------------------------------------------
  436. std::string
  437. cmCPackIFWGenerator::IfwGetComponentName(const std::string &componentName)
  438. {
  439. std::string ifwCompName = componentName;
  440. if(const char* name =
  441. this->GetOption("CPACK_IFW_COMPONENT_"
  442. + cmsys::SystemTools::UpperCase(componentName) + "_NAME"))
  443. {
  444. ifwCompName = name;
  445. }
  446. return ifwCompName;
  447. }
  448. //----------------------------------------------------------------------
  449. int cmCPackIFWGenerator::InitializeInternal()
  450. {
  451. // Search Qt Installer Framework tools
  452. if(!this->IsOn("CPACK_IFW_BINARYCREATOR_EXECUTABLE_FOUND") ||
  453. !this->IsOn("CPACK_IFW_REPOGEN_EXECUTABLE_FOUND"))
  454. {
  455. this->ReadListFile("CPackIFW.cmake");
  456. }
  457. // Look 'binarycreator' executable (needs)
  458. if(this->IsOn("CPACK_IFW_BINARYCREATOR_EXECUTABLE_FOUND"))
  459. {
  460. const char *ifwBinCreatorStr =
  461. this->GetOption("CPACK_IFW_BINARYCREATOR_EXECUTABLE");
  462. ifwBinCreator = ifwBinCreatorStr ? ifwBinCreatorStr : "";
  463. }
  464. else
  465. {
  466. ifwBinCreator = "";
  467. }
  468. if (ifwBinCreator.empty())
  469. {
  470. cmCPackLogger(cmCPackLog::LOG_ERROR,
  471. "Cannot find QtIFW compiler \"binarycreator\": "
  472. "likely it is not installed, or not in your PATH"
  473. << std::endl);
  474. return 0;
  475. }
  476. // Look 'repogen' executable (optional)
  477. if(this->IsOn("CPACK_IFW_REPOGEN_EXECUTABLE_FOUND"))
  478. {
  479. const char *ifwRepoGenStr =
  480. this->GetOption("CPACK_IFW_REPOGEN_EXECUTABLE");
  481. ifwRepoGen = ifwRepoGenStr ? ifwRepoGenStr : "";
  482. }
  483. else
  484. {
  485. ifwRepoGen = "";
  486. }
  487. // // Variables that Change Behavior
  488. // Resolve duplicate names
  489. ifwResolveDuplicateNames = this->IsOn("CPACK_IFW_RESOLVE_DUPLICATE_NAMES");
  490. // Additional packages dirs
  491. ifwPkgsDirsVector.clear();
  492. if(const char* dirs = this->GetOption("CPACK_IFW_PACKAGES_DIRECTORIES"))
  493. {
  494. cmSystemTools::ExpandListArgument(dirs,
  495. ifwPkgsDirsVector);
  496. }
  497. // Remote repository
  498. if (const char *site = this->GetOption("CPACK_DOWNLOAD_SITE"))
  499. {
  500. ifwDownloadSite = site;
  501. }
  502. ifwOnlineOnly = this->IsOn("CPACK_DOWNLOAD_ALL") ? true : false;
  503. if (!ifwDownloadSite.empty() && ifwRepoGen.empty()) {
  504. cmCPackLogger(cmCPackLog::LOG_ERROR,
  505. "Cannot find QtIFW repository generator \"repogen\": "
  506. "likely it is not installed, or not in your PATH"
  507. << std::endl);
  508. return 0;
  509. }
  510. return this->Superclass::InitializeInternal();
  511. }
  512. //----------------------------------------------------------------------
  513. std::string
  514. cmCPackIFWGenerator::GetComponentInstallDirNamePrefix(
  515. const std::string& /*componentName*/)
  516. {
  517. return "packages/";
  518. }
  519. //----------------------------------------------------------------------
  520. std::string
  521. cmCPackIFWGenerator::GetComponentInstallDirNameSuffix(
  522. const std::string& componentName)
  523. {
  524. std::map<std::string, cmCPackComponent>::iterator
  525. compIt = this->Components.find(componentName);
  526. cmCPackComponent *comp =
  527. compIt != this->Components.end() ? &compIt->second : 0;
  528. const std::string prefix = GetComponentInstallDirNamePrefix(componentName);
  529. const std::string suffix = "/data";
  530. if (componentPackageMethod == ONE_PACKAGE_PER_COMPONENT) {
  531. return prefix + IfwGetComponentId(comp) + suffix;
  532. }
  533. if (componentPackageMethod == ONE_PACKAGE) {
  534. return std::string(prefix + "ALL_COMPONENTS_IN_ONE" + suffix);
  535. }
  536. return prefix + IfwGetComponentId(comp) + suffix;
  537. }
  538. //----------------------------------------------------------------------
  539. bool cmCPackIFWGenerator::GetListOfSubdirectories(
  540. const char* topdir, std::vector<std::string>& dirs)
  541. {
  542. cmsys::Directory dir;
  543. dir.Load(topdir);
  544. size_t fileNum;
  545. for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum)
  546. {
  547. if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".") &&
  548. strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".."))
  549. {
  550. cmsys_stl::string fullPath = topdir;
  551. fullPath += "/";
  552. fullPath += dir.GetFile(static_cast<unsigned long>(fileNum));
  553. if(cmsys::SystemTools::FileIsDirectory(fullPath.c_str()) &&
  554. !cmsys::SystemTools::FileIsSymlink(fullPath.c_str()))
  555. {
  556. if (!this->GetListOfSubdirectories(fullPath.c_str(), dirs))
  557. {
  558. return false;
  559. }
  560. }
  561. }
  562. }
  563. dirs.push_back(topdir);
  564. return true;
  565. }
  566. //----------------------------------------------------------------------
  567. enum cmCPackGenerator::CPackSetDestdirSupport
  568. cmCPackIFWGenerator::SupportsSetDestdir() const
  569. {
  570. return cmCPackGenerator::SETDESTDIR_SHOULD_NOT_BE_USED;
  571. }
  572. //----------------------------------------------------------------------
  573. bool cmCPackIFWGenerator::SupportsAbsoluteDestination() const
  574. {
  575. return false;
  576. }
  577. //----------------------------------------------------------------------
  578. bool cmCPackIFWGenerator::SupportsComponentInstallation() const
  579. {
  580. return true;
  581. }
  582. //----------------------------------------------------------------------
  583. int cmCPackIFWGenerator::IfwCreateConfigFile()
  584. {
  585. cmGeneratedFileStream cfg((this->toplevel + "/config/config.xml").data());
  586. std::string ifwPkgName;
  587. if (const char *name = this->GetOption("CPACK_PACKAGE_NAME"))
  588. {
  589. ifwPkgName = name;
  590. }
  591. else
  592. {
  593. ifwPkgName = "Your package";
  594. }
  595. std::string ifwPkgDescription;
  596. if (const char *name = this->GetOption("CPACK_PACKAGE_DESCRIPTION_SUMMARY"))
  597. {
  598. ifwPkgDescription = name;
  599. }
  600. else
  601. {
  602. ifwPkgDescription = "Your package description";
  603. }
  604. std::string ifwPkgVersion;
  605. if (const char *version = this->GetOption("CPACK_PACKAGE_VERSION"))
  606. {
  607. ifwPkgVersion = version;
  608. }
  609. else
  610. {
  611. ifwPkgVersion = "1.0.0";
  612. }
  613. const char *ifwPkgInstDir =
  614. this->GetOption("CPACK_PACKAGE_INSTALL_DIRECTORY");
  615. const char *ifwTargetDir =
  616. this->GetOption("CPACK_IFW_TARGET_DIRECTORY");
  617. const char *ifwAdminTargetDir =
  618. this->GetOption("CPACK_IFW_ADMIN_TARGET_DIRECTORY");
  619. cfg << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
  620. cfg << "<Installer>" << std::endl;
  621. cfg << " <Name>" << cmXMLSafe(ifwPkgName).str() << "</Name>" << std::endl;
  622. cfg << " <Version>" << ifwPkgVersion << "</Version>" << std::endl;
  623. cfg << " <Title>" << cmXMLSafe(ifwPkgDescription).str() << "</Title>"
  624. << std::endl;
  625. // Default target directory for installation
  626. if (ifwTargetDir)
  627. {
  628. cfg << " <TargetDir>" << ifwTargetDir << "</TargetDir>" << std::endl;
  629. }
  630. else if (ifwPkgInstDir)
  631. {
  632. cfg << " <TargetDir>@ApplicationsDir@/" << ifwPkgInstDir
  633. << "</TargetDir>" << std::endl;
  634. }
  635. else
  636. {
  637. cfg << " <TargetDir>@RootDir@/usr/local</TargetDir>" << std::endl;
  638. }
  639. // Default target directory for installation with administrator rights
  640. if (ifwAdminTargetDir)
  641. {
  642. cfg << " <AdminTargetDir>" << ifwAdminTargetDir
  643. << "</AdminTargetDir>" << std::endl;
  644. }
  645. if (!ifwDownloadSite.empty())
  646. {
  647. cfg << " <RemoteRepositories>" << std::endl;
  648. cfg << " <Repository>" << std::endl;
  649. cfg << " <Url>" << ifwDownloadSite << "</Url>" << std::endl;
  650. // These properties can now be set from "cpack_configure_downloads"
  651. // <Enabled>1</Enabled>
  652. // <Username>user</Username>
  653. // <Password>password</Password>
  654. // <DisplayName>Example repository</DisplayName>
  655. cfg << " </Repository>" << std::endl;
  656. cfg << " </RemoteRepositories>" << std::endl;
  657. }
  658. // CPack IFW default policy
  659. cfg << " <!-- CPack IFW default policy -->" << std::endl;
  660. cfg << " <AllowNonAsciiCharacters>true</AllowNonAsciiCharacters>"
  661. << std::endl;
  662. cfg << " <AllowSpaceInPath>true</AllowSpaceInPath>" << std::endl;
  663. cfg << "</Installer>" << std::endl;
  664. return 1;
  665. }
  666. //----------------------------------------------------------------------
  667. // Create default package file
  668. int cmCPackIFWGenerator::IfwCreatePackageFile()
  669. {
  670. std::string ifwPkgName;
  671. if (const char *name = this->GetOption("CPACK_PACKAGE_NAME"))
  672. {
  673. ifwPkgName = name;
  674. }
  675. else
  676. {
  677. ifwPkgName = "Your package";
  678. }
  679. std::string ifwPkgDescription;
  680. if (const char *name = this->GetOption("CPACK_PACKAGE_DESCRIPTION_SUMMARY"))
  681. {
  682. ifwPkgDescription = name;
  683. }
  684. else
  685. {
  686. ifwPkgDescription = "Your package description";
  687. }
  688. cmGeneratedFileStream
  689. pkgXml((this->toplevel + "/packages/root/meta/package.xml").data());
  690. pkgXml << "<?xml version=\"1.0\"?>" << std::endl;
  691. pkgXml << "<Package>" << std::endl;
  692. pkgXml << " <DisplayName>" << ifwPkgName << "</DisplayName>" << std::endl;
  693. pkgXml << " <Description>" << ifwPkgDescription
  694. << "</Description>" << std::endl;
  695. pkgXml << " <Name>" << "root" << "</Name>" << std::endl;
  696. pkgXml << " <Version>" << this->GetOption("CPACK_PACKAGE_VERSION")
  697. << "</Version>" << std::endl;
  698. pkgXml << " <ReleaseDate>" << IfwCreateCurrentDate() << "</ReleaseDate>"
  699. << std::endl;
  700. pkgXml << " <ForcedInstallation>true</ForcedInstallation>" << std::endl;
  701. pkgXml << " <Default>true</Default>" << std::endl;
  702. pkgXml << "</Package>" << std::endl;
  703. return 1;
  704. }
  705. //----------------------------------------------------------------------
  706. std::string cmCPackIFWGenerator::IfwCreateCurrentDate()
  707. {
  708. time_t rawtime;
  709. struct tm * timeinfo;
  710. char buffer[80];
  711. time (&rawtime);
  712. timeinfo = localtime(&rawtime);
  713. strftime(buffer, 80, "%Y-%m-%d", timeinfo);
  714. return buffer;
  715. }
  716. //----------------------------------------------------------------------
  717. bool cmCPackIFWGenerator::IfwParseLicenses(std::vector<std::string> &licenses,
  718. const std::string &variable,
  719. const std::string &metaDir)
  720. {
  721. if (const char *option = this->GetOption(variable))
  722. {
  723. if(!licenses.empty()) licenses.clear();
  724. cmSystemTools::ExpandListArgument( option, licenses );
  725. }
  726. else
  727. {
  728. return false;
  729. }
  730. if ( licenses.size() % 2 != 0 )
  731. {
  732. cmCPackLogger(cmCPackLog::LOG_ERROR, variable
  733. << " should contain pairs of <display_name> and <file_path>."
  734. << std::endl);
  735. return false;
  736. }
  737. for(size_t i = 1; i < licenses.size(); i += 2)
  738. {
  739. std::string name = cmSystemTools::GetFilenameName(licenses[i]);
  740. std::string path = metaDir + "/" + name;
  741. cmsys::SystemTools::CopyFileIfDifferent(licenses[i].data(), path.data());
  742. licenses[i] = name;
  743. }
  744. return licenses.size() > 1;
  745. }