cmCPackGenericGenerator.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCPackGenericGenerator.h"
  14. #include "cmMakefile.h"
  15. #include "cmCPackLog.h"
  16. #include "cmake.h"
  17. #include "cmGlobalGenerator.h"
  18. #include "cmLocalGenerator.h"
  19. #include "cmGeneratedFileStream.h"
  20. #include <cmsys/SystemTools.hxx>
  21. #include <cmsys/Glob.hxx>
  22. #include <memory> // auto_ptr
  23. //----------------------------------------------------------------------
  24. cmCPackGenericGenerator::cmCPackGenericGenerator()
  25. {
  26. this->GeneratorVerbose = false;
  27. this->MakefileMap = 0;
  28. this->Logger = 0;
  29. }
  30. //----------------------------------------------------------------------
  31. cmCPackGenericGenerator::~cmCPackGenericGenerator()
  32. {
  33. this->MakefileMap = 0;
  34. }
  35. //----------------------------------------------------------------------
  36. int cmCPackGenericGenerator::PrepareNames()
  37. {
  38. this->SetOption("CPACK_GENERATOR", this->Name.c_str());
  39. std::string tempDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY");
  40. tempDirectory += "/_CPack_Packages/";
  41. tempDirectory += this->GetOption("CPACK_GENERATOR");
  42. std::string topDirectory = tempDirectory;
  43. std::string outName = this->GetOption("CPACK_PACKAGE_FILE_NAME");
  44. tempDirectory += "/" + outName;
  45. outName += ".";
  46. outName += this->GetOutputExtension();
  47. std::string destFile = this->GetOption("CPACK_PACKAGE_DIRECTORY");
  48. destFile += "/" + outName;
  49. std::string outFile = topDirectory + "/" + outName;
  50. std::string installPrefix = tempDirectory + this->GetInstallPrefix();
  51. this->SetOption("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str());
  52. this->SetOption("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str());
  53. this->SetOption("CPACK_OUTPUT_FILE_NAME", outName.c_str());
  54. this->SetOption("CPACK_OUTPUT_FILE_PATH", destFile.c_str());
  55. this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME", outFile.c_str());
  56. this->SetOption("CPACK_INSTALL_DIRECTORY", this->GetInstallPath());
  57. this->SetOption("CPACK_NATIVE_INSTALL_DIRECTORY",
  58. cmsys::SystemTools::ConvertToOutputPath(this->GetInstallPath()).c_str());
  59. this->SetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY", installPrefix.c_str());
  60. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  61. "Look for: CPACK_PACKAGE_DESCRIPTION_FILE" << std::endl);
  62. const char* descFileName
  63. = this->GetOption("CPACK_PACKAGE_DESCRIPTION_FILE");
  64. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  65. "Look for: " << descFileName << std::endl);
  66. if ( descFileName )
  67. {
  68. if ( !cmSystemTools::FileExists(descFileName) )
  69. {
  70. cmCPackLogger(cmCPackLog::LOG_ERROR,
  71. "Cannot find description file name: " << descFileName << std::endl);
  72. return 0;
  73. }
  74. std::ifstream ifs(descFileName);
  75. if ( !ifs )
  76. {
  77. cmCPackLogger(cmCPackLog::LOG_ERROR,
  78. "Cannot open description file name: " << descFileName << std::endl);
  79. return 0;
  80. }
  81. cmOStringStream ostr;
  82. std::string line;
  83. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  84. "Read description file: " << descFileName << std::endl);
  85. while ( ifs && cmSystemTools::GetLineFromStream(ifs, line) )
  86. {
  87. ostr << cmSystemTools::MakeXMLSafe(line.c_str()) << std::endl;
  88. }
  89. this->SetOption("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str());
  90. }
  91. if ( !this->GetOption("CPACK_PACKAGE_DESCRIPTION") )
  92. {
  93. cmCPackLogger(cmCPackLog::LOG_ERROR,
  94. "Project description not specified. Please specify "
  95. "CPACK_PACKAGE_DESCRIPTION or CPACK_PACKAGE_DESCRIPTION_FILE."
  96. << std::endl);
  97. return 0;
  98. }
  99. return 1;
  100. }
  101. //----------------------------------------------------------------------
  102. int cmCPackGenericGenerator::InstallProject()
  103. {
  104. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Install projects" << std::endl);
  105. const char* tempInstallDirectory
  106. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  107. int res = 1;
  108. if ( !cmsys::SystemTools::MakeDirectory(tempInstallDirectory))
  109. {
  110. cmCPackLogger(cmCPackLog::LOG_ERROR,
  111. "Problem creating temporary directory: " << tempInstallDirectory
  112. << std::endl);
  113. return 0;
  114. }
  115. bool movable = true;
  116. if ( movable )
  117. {
  118. // Make sure there is no destdir
  119. cmSystemTools::PutEnv("DESTDIR=");
  120. }
  121. else
  122. {
  123. std::string destDir = "DESTDIR=";
  124. destDir += tempInstallDirectory;
  125. cmSystemTools::PutEnv(destDir.c_str());
  126. }
  127. const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS");
  128. if ( installCommands )
  129. {
  130. std::vector<std::string> installCommandsVector;
  131. cmSystemTools::ExpandListArgument(installCommands,installCommandsVector);
  132. std::vector<std::string>::iterator it;
  133. for ( it = installCommandsVector.begin();
  134. it != installCommandsVector.end();
  135. ++it )
  136. {
  137. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << it->c_str()
  138. << std::endl);
  139. std::string output;
  140. int retVal = 1;
  141. bool resB = cmSystemTools::RunSingleCommand(it->c_str(), &output,
  142. &retVal, 0, this->GeneratorVerbose, 0);
  143. if ( !resB || retVal )
  144. {
  145. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  146. tmpFile += "/InstallOutput.log";
  147. cmGeneratedFileStream ofs(tmpFile.c_str());
  148. ofs << "# Run command: " << it->c_str() << std::endl
  149. << "# Output:" << std::endl
  150. << output.c_str() << std::endl;
  151. cmCPackLogger(cmCPackLog::LOG_ERROR,
  152. "Problem running install command: " << it->c_str() << std::endl
  153. << "Please check " << tmpFile.c_str() << " for errors"
  154. << std::endl);
  155. res = 0;
  156. break;
  157. }
  158. }
  159. }
  160. const char* installDirectories
  161. = this->GetOption("CPACK_INSTALLED_DIRECTORIES");
  162. if ( installDirectories )
  163. {
  164. std::vector<std::string> installDirectoriesVector;
  165. cmSystemTools::ExpandListArgument(installDirectories,
  166. installDirectoriesVector);
  167. if ( installDirectoriesVector.size() % 2 != 0 )
  168. {
  169. cmCPackLogger(cmCPackLog::LOG_ERROR,
  170. "CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> and "
  171. "<subdirectory>. The <subdirectory> can be '.' to be installed in "
  172. "the toplevel directory of installation." << std::endl);
  173. return 0;
  174. }
  175. std::vector<std::string>::iterator it;
  176. const char* tempDir = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  177. for ( it = installDirectoriesVector.begin();
  178. it != installDirectoriesVector.end();
  179. ++it )
  180. {
  181. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  182. cmsys::Glob gl;
  183. std::string toplevel = it->c_str();
  184. it ++;
  185. std::string subdir = it->c_str();
  186. std::string findExpr = toplevel;
  187. findExpr += "/*";
  188. gl.RecurseOn();
  189. if ( !gl.FindFiles(findExpr) )
  190. {
  191. cmCPackLogger(cmCPackLog::LOG_ERROR,
  192. "Cannot find any files in the installed directory" << std::endl);
  193. return 0;
  194. }
  195. std::vector<std::string>& files = gl.GetFiles();
  196. std::vector<std::string>::iterator gfit;
  197. for ( gfit = files.begin(); gfit != files.end(); ++ gfit )
  198. {
  199. std::string filePath = tempDir;
  200. filePath += "/" + subdir + "/"
  201. + cmSystemTools::RelativePath(toplevel.c_str(), gfit->c_str());
  202. std::string &inFile = *gfit;
  203. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy file: "
  204. << inFile.c_str() << " -> " << filePath.c_str() << std::endl);
  205. if ( !cmSystemTools::CopyFileIfDifferent(inFile.c_str(),
  206. filePath.c_str()) )
  207. {
  208. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying file: "
  209. << inFile.c_str() << " -> " << filePath.c_str() << std::endl);
  210. }
  211. }
  212. }
  213. }
  214. const char* cmakeProjects
  215. = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
  216. if ( cmakeProjects )
  217. {
  218. std::vector<std::string> cmakeProjectsVector;
  219. cmSystemTools::ExpandListArgument(cmakeProjects,
  220. cmakeProjectsVector);
  221. std::vector<std::string>::iterator it;
  222. for ( it = cmakeProjectsVector.begin();
  223. it != cmakeProjectsVector.end();
  224. ++it )
  225. {
  226. std::string installDirectory = it->c_str();
  227. ++it;
  228. std::string installProjectName = it->c_str();
  229. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  230. "- Install project: " << installProjectName << std::endl);
  231. std::string installFile = installDirectory + "/cmake_install.cmake";
  232. cmake cm;
  233. cmGlobalGenerator gg;
  234. gg.SetCMakeInstance(&cm);
  235. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  236. lg->SetGlobalGenerator(&gg);
  237. cmMakefile *mf = lg->GetMakefile();
  238. if ( movable )
  239. {
  240. mf->AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
  241. }
  242. const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
  243. if ( buildConfig && *buildConfig )
  244. {
  245. mf->AddDefinition("BUILD_TYPE", buildConfig);
  246. }
  247. res = mf->ReadListFile(0, installFile.c_str());
  248. if ( cmSystemTools::GetErrorOccuredFlag() )
  249. {
  250. res = 0;
  251. }
  252. }
  253. }
  254. const char* binaryDirectories = this->GetOption("CPACK_BINARY_DIR");
  255. if ( binaryDirectories && !cmakeProjects )
  256. {
  257. std::vector<std::string> binaryDirectoriesVector;
  258. cmSystemTools::ExpandListArgument(binaryDirectories,
  259. binaryDirectoriesVector);
  260. std::vector<std::string>::iterator it;
  261. for ( it = binaryDirectoriesVector.begin();
  262. it != binaryDirectoriesVector.end();
  263. ++it )
  264. {
  265. std::string installFile = it->c_str();
  266. installFile += "/cmake_install.cmake";
  267. cmake cm;
  268. cmGlobalGenerator gg;
  269. gg.SetCMakeInstance(&cm);
  270. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  271. lg->SetGlobalGenerator(&gg);
  272. cmMakefile *mf = lg->GetMakefile();
  273. if ( movable )
  274. {
  275. mf->AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
  276. }
  277. const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
  278. if ( buildConfig && *buildConfig )
  279. {
  280. mf->AddDefinition("BUILD_TYPE", buildConfig);
  281. }
  282. res = mf->ReadListFile(0, installFile.c_str());
  283. if ( cmSystemTools::GetErrorOccuredFlag() )
  284. {
  285. res = 0;
  286. }
  287. }
  288. }
  289. if ( !movable )
  290. {
  291. cmSystemTools::PutEnv("DESTDIR=");
  292. }
  293. return res;
  294. }
  295. //----------------------------------------------------------------------
  296. void cmCPackGenericGenerator::SetOption(const char* op, const char* value)
  297. {
  298. if ( !op )
  299. {
  300. return;
  301. }
  302. if ( !value )
  303. {
  304. this->MakefileMap->RemoveDefinition(op);
  305. return;
  306. }
  307. cmCPackLogger(cmCPackLog::LOG_DEBUG, this->GetNameOfClass()
  308. << "::SetOption(" << op << ", " << value << ")" << std::endl);
  309. this->MakefileMap->AddDefinition(op, value);
  310. }
  311. //----------------------------------------------------------------------
  312. int cmCPackGenericGenerator::ProcessGenerator()
  313. {
  314. if ( !this->PrepareNames() )
  315. {
  316. return 0;
  317. }
  318. if ( !this->InstallProject() )
  319. {
  320. return 0;
  321. }
  322. const char* tempPackageFileName = this->GetOption(
  323. "CPACK_TEMPORARY_PACKAGE_FILE_NAME");
  324. const char* packageFileName = this->GetOption("CPACK_OUTPUT_FILE_PATH");
  325. const char* tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  326. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  327. cmsys::Glob gl;
  328. std::string findExpr = tempDirectory;
  329. findExpr += "/*";
  330. gl.RecurseOn();
  331. if ( !gl.FindFiles(findExpr) )
  332. {
  333. cmCPackLogger(cmCPackLog::LOG_ERROR,
  334. "Cannot find any files in the packaging tree" << std::endl);
  335. return 0;
  336. }
  337. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Compress package" << std::endl);
  338. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Compress files to: "
  339. << tempPackageFileName << std::endl);
  340. if ( cmSystemTools::FileExists(tempPackageFileName) )
  341. {
  342. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Remove old package file"
  343. << std::endl);
  344. cmSystemTools::RemoveFile(tempPackageFileName);
  345. }
  346. if ( cmSystemTools::IsOn(this->GetOption(
  347. "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) )
  348. {
  349. tempDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  350. }
  351. if ( !this->CompressFiles(tempPackageFileName,
  352. tempDirectory, gl.GetFiles()) )
  353. {
  354. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem compressing the directory"
  355. << std::endl);
  356. return 0;
  357. }
  358. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Finalize package" << std::endl);
  359. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Copy final package: "
  360. << tempPackageFileName << " to " << packageFileName << std::endl);
  361. if ( !cmSystemTools::CopyFileIfDifferent(tempPackageFileName,
  362. packageFileName) )
  363. {
  364. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the package: "
  365. << tempPackageFileName << " to " << packageFileName << std::endl);
  366. return 0;
  367. }
  368. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Package " << packageFileName
  369. << " generated." << std::endl);
  370. return 1;
  371. }
  372. //----------------------------------------------------------------------
  373. int cmCPackGenericGenerator::Initialize(const char* name, cmMakefile* mf)
  374. {
  375. this->MakefileMap = mf;
  376. this->Name = name;
  377. return 1;
  378. }
  379. //----------------------------------------------------------------------
  380. const char* cmCPackGenericGenerator::GetOption(const char* op)
  381. {
  382. return this->MakefileMap->GetDefinition(op);
  383. }
  384. //----------------------------------------------------------------------
  385. int cmCPackGenericGenerator::FindRunningCMake(const char* arg0)
  386. {
  387. int found = 0;
  388. // Find our own executable.
  389. std::vector<cmStdString> failures;
  390. this->CPackSelf = arg0;
  391. cmSystemTools::ConvertToUnixSlashes(this->CPackSelf);
  392. failures.push_back(this->CPackSelf);
  393. this->CPackSelf = cmSystemTools::FindProgram(this->CPackSelf.c_str());
  394. if(!cmSystemTools::FileExists(this->CPackSelf.c_str()))
  395. {
  396. failures.push_back(this->CPackSelf);
  397. this->CPackSelf = "/usr/local/bin/ctest";
  398. }
  399. if(!cmSystemTools::FileExists(this->CPackSelf.c_str()))
  400. {
  401. failures.push_back(this->CPackSelf);
  402. cmOStringStream msg;
  403. msg << "CTEST can not find the command line program ctest.\n";
  404. msg << " argv[0] = \"" << arg0 << "\"\n";
  405. msg << " Attempted paths:\n";
  406. std::vector<cmStdString>::iterator i;
  407. for(i=failures.begin(); i != failures.end(); ++i)
  408. {
  409. msg << " \"" << i->c_str() << "\"\n";
  410. }
  411. cmSystemTools::Error(msg.str().c_str());
  412. }
  413. std::string dir;
  414. std::string file;
  415. if(cmSystemTools::SplitProgramPath(this->CPackSelf.c_str(),
  416. dir, file, true))
  417. {
  418. this->CMakeSelf = dir += "/cmake";
  419. this->CMakeSelf += cmSystemTools::GetExecutableExtension();
  420. if(cmSystemTools::FileExists(this->CMakeSelf.c_str()))
  421. {
  422. found = 1;
  423. }
  424. }
  425. if ( !found )
  426. {
  427. failures.push_back(this->CMakeSelf);
  428. #ifdef CMAKE_BUILD_DIR
  429. std::string intdir = ".";
  430. #ifdef CMAKE_INTDIR
  431. intdir = CMAKE_INTDIR;
  432. #endif
  433. this->CMakeSelf = CMAKE_BUILD_DIR;
  434. this->CMakeSelf += "/bin/";
  435. this->CMakeSelf += intdir;
  436. this->CMakeSelf += "/cmake";
  437. this->CMakeSelf += cmSystemTools::GetExecutableExtension();
  438. #endif
  439. if(!cmSystemTools::FileExists(this->CMakeSelf.c_str()))
  440. {
  441. failures.push_back(this->CMakeSelf);
  442. cmOStringStream msg;
  443. msg << "CTEST can not find the command line program cmake.\n";
  444. msg << " argv[0] = \"" << arg0 << "\"\n";
  445. msg << " Attempted paths:\n";
  446. std::vector<cmStdString>::iterator i;
  447. for(i=failures.begin(); i != failures.end(); ++i)
  448. {
  449. msg << " \"" << i->c_str() << "\"\n";
  450. }
  451. cmSystemTools::Error(msg.str().c_str());
  452. }
  453. }
  454. // do CMAKE_ROOT, look for the environment variable first
  455. std::string cMakeRoot;
  456. std::string modules;
  457. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT" << std::endl);
  458. if (getenv("CMAKE_ROOT"))
  459. {
  460. cMakeRoot = getenv("CMAKE_ROOT");
  461. modules = cMakeRoot + "/Modules/CMake.cmake";
  462. }
  463. if(modules.empty() || !cmSystemTools::FileExists(modules.c_str()))
  464. {
  465. // next try exe/..
  466. cMakeRoot = cmSystemTools::GetProgramPath(this->CMakeSelf.c_str());
  467. std::string::size_type slashPos = cMakeRoot.rfind("/");
  468. if(slashPos != std::string::npos)
  469. {
  470. cMakeRoot = cMakeRoot.substr(0, slashPos);
  471. }
  472. // is there no Modules direcory there?
  473. modules = cMakeRoot + "/Modules/CMake.cmake";
  474. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  475. << modules.c_str() << std::endl);
  476. }
  477. if (!cmSystemTools::FileExists(modules.c_str()))
  478. {
  479. // try exe/../share/cmake
  480. cMakeRoot += CMAKE_DATA_DIR;
  481. modules = cMakeRoot + "/Modules/CMake.cmake";
  482. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  483. << modules.c_str() << std::endl);
  484. }
  485. #ifdef CMAKE_ROOT_DIR
  486. if (!cmSystemTools::FileExists(modules.c_str()))
  487. {
  488. // try compiled in root directory
  489. cMakeRoot = CMAKE_ROOT_DIR;
  490. modules = cMakeRoot + "/Modules/CMake.cmake";
  491. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  492. << modules.c_str() << std::endl);
  493. }
  494. #endif
  495. #ifdef CMAKE_PREFIX
  496. if (!cmSystemTools::FileExists(modules.c_str()))
  497. {
  498. // try compiled in install prefix
  499. cMakeRoot = CMAKE_PREFIX CMAKE_DATA_DIR;
  500. modules = cMakeRoot + "/Modules/CMake.cmake";
  501. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  502. << modules.c_str() << std::endl);
  503. }
  504. #endif
  505. if (!cmSystemTools::FileExists(modules.c_str()))
  506. {
  507. // try
  508. cMakeRoot = cmSystemTools::GetProgramPath(this->CMakeSelf.c_str());
  509. cMakeRoot += CMAKE_DATA_DIR;
  510. modules = cMakeRoot + "/Modules/CMake.cmake";
  511. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  512. << modules.c_str() << std::endl);
  513. }
  514. if(!cmSystemTools::FileExists(modules.c_str()))
  515. {
  516. // next try exe
  517. cMakeRoot = cmSystemTools::GetProgramPath(this->CMakeSelf.c_str());
  518. // is there no Modules direcory there?
  519. modules = cMakeRoot + "/Modules/CMake.cmake";
  520. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  521. << modules.c_str() << std::endl);
  522. }
  523. if (!cmSystemTools::FileExists(modules.c_str()))
  524. {
  525. // couldn't find modules
  526. cmSystemTools::Error("Could not find CMAKE_ROOT !!!\n"
  527. "CMake has most likely not been installed correctly.\n"
  528. "Modules directory not found in\n",
  529. cMakeRoot.c_str());
  530. return 0;
  531. }
  532. this->CMakeRoot = cMakeRoot;
  533. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  534. << this->CMakeRoot.c_str() << std::endl);
  535. this->SetOption("CMAKE_ROOT", this->CMakeRoot.c_str());
  536. return 1;
  537. }
  538. //----------------------------------------------------------------------
  539. int cmCPackGenericGenerator::CompressFiles(const char* outFileName,
  540. const char* toplevel, const std::vector<std::string>& files)
  541. {
  542. (void)outFileName;
  543. (void)toplevel;
  544. (void)files;
  545. return 0;
  546. }
  547. //----------------------------------------------------------------------
  548. const char* cmCPackGenericGenerator::GetInstallPath()
  549. {
  550. if ( !this->InstallPath.empty() )
  551. {
  552. return this->InstallPath.c_str();
  553. }
  554. #if defined(_WIN32) && !defined(__CYGWIN__)
  555. const char* prgfiles = cmsys::SystemTools::GetEnv("ProgramFiles");
  556. const char* sysDrive = cmsys::SystemTools::GetEnv("SystemDrive");
  557. if ( prgfiles )
  558. {
  559. this->InstallPath = prgfiles;
  560. }
  561. else if ( sysDrive )
  562. {
  563. this->InstallPath = sysDrive;
  564. this->InstallPath += "/Program Files";
  565. }
  566. else
  567. {
  568. this->InstallPath = "c:/Program Files";
  569. }
  570. this->InstallPath += "/";
  571. this->InstallPath += this->GetOption("CPACK_PACKAGE_NAME");
  572. this->InstallPath += "-";
  573. this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION");
  574. #else
  575. this->InstallPath = "/usr/local/";
  576. #endif
  577. return this->InstallPath.c_str();
  578. }
  579. //----------------------------------------------------------------------
  580. std::string cmCPackGenericGenerator::FindTemplate(const char* name)
  581. {
  582. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: "
  583. << name << std::endl);
  584. std::string ffile = this->MakefileMap->GetModulesFile(name);
  585. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: "
  586. << ffile.c_str() << std::endl);
  587. return ffile;
  588. }
  589. //----------------------------------------------------------------------
  590. bool cmCPackGenericGenerator::ConfigureFile(const char* inName,
  591. const char* outName)
  592. {
  593. return this->MakefileMap->ConfigureFile(inName, outName,
  594. false, true, false) == 1;
  595. }