CMakeBuildTargets.cxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #include "cmMakefile.h"
  12. #include "cmStandardIncludes.h"
  13. #include "cmMakeDepend.h"
  14. #include "cmUnixMakefileGenerator.h"
  15. #include "cmCacheManager.h"
  16. void Usage(const char* program)
  17. {
  18. std::cerr << "Usage: " << program << " CMakeLists.txt "
  19. << "-Ssource_start_directory "
  20. << "-Ooutput_start_directory "
  21. << "-Hsource_home_directory "
  22. << "-Boutput_home_directory\n"
  23. << "Where start directories are the current place in the tree,"
  24. "and the home directories are the top.\n";
  25. }
  26. // This is the main program used to gentrate makefile fragments
  27. // from CMakeLists.txt input files.
  28. int main(int ac, char** av)
  29. {
  30. if(ac < 2)
  31. {
  32. Usage(av[0]);
  33. return -1;
  34. }
  35. // Create a makefile
  36. cmMakefile mf;
  37. mf.AddDefinition("UNIX", "1");
  38. bool makeCache = false;
  39. // Parse the command line
  40. if(ac > 2)
  41. {
  42. for(int i =2; i < ac; i++)
  43. {
  44. std::string arg = av[i];
  45. // Set the start source directory with a -S dir options
  46. if(arg.find("-MakeCache",0) == 0)
  47. {
  48. makeCache = true;
  49. }
  50. // Set the start source directory with a -S dir options
  51. if(arg.find("-S",0) == 0)
  52. {
  53. std::string path = arg.substr(2);
  54. mf.SetStartDirectory(path.c_str());
  55. }
  56. // Set the start output directory with a -O dir options
  57. if(arg.find("-O",0) == 0)
  58. {
  59. std::string path = arg.substr(2);
  60. mf.SetStartOutputDirectory(path.c_str());
  61. }
  62. // Set the source home directory with a -H dir option
  63. if(arg.find("-H",0) == 0)
  64. {
  65. std::string path = arg.substr(2);
  66. mf.SetHomeDirectory(path.c_str());
  67. }
  68. // Set the output or binary directory with a -B dir option
  69. if(arg.find("-B",0) == 0)
  70. {
  71. std::string path = arg.substr(2);
  72. mf.SetHomeOutputDirectory(path.c_str());
  73. }
  74. }
  75. }
  76. // Only generate makefiles if not trying to make the cache
  77. if(!makeCache)
  78. {
  79. mf.SetMakefileGenerator(new cmUnixMakefileGenerator);
  80. }
  81. // Read and parse the input makefile
  82. mf.MakeStartDirectoriesCurrent();
  83. cmCacheManager::GetInstance()->LoadCache(&mf);
  84. if(!mf.ReadListFile(av[1]))
  85. {
  86. Usage(av[0]);
  87. return -1;
  88. }
  89. if(makeCache)
  90. {
  91. mf.GenerateCacheOnly();
  92. }
  93. else
  94. {
  95. mf.GenerateMakefile();
  96. }
  97. cmCacheManager::GetInstance()->SaveCache(&mf);
  98. if(makeCache)
  99. {
  100. cmCacheManager::GetInstance()->PrintCache(std::cout);
  101. }
  102. if(cmSystemTools::GetErrorOccuredFlag())
  103. {
  104. return -1;
  105. }
  106. return 0;
  107. }