CMakeBuildTargets.cxx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2001 Insight Consortium
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. * Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. * Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. * The name of the Insight Consortium, nor the names of any consortium members,
  17. nor of any contributors, may be used to endorse or promote products derived
  18. from this software without specific prior written permission.
  19. * Modified source versions must be plainly marked as such, and must not be
  20. misrepresented as being the original software.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
  25. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. =========================================================================*/
  32. #include "cmMakefile.h"
  33. #include "cmStandardIncludes.h"
  34. #include "cmMakeDepend.h"
  35. #include "cmUnixMakefileGenerator.h"
  36. #include "cmCacheManager.h"
  37. void Usage(const char* program)
  38. {
  39. std::cerr << "Usage: " << program << " CMakeLists.txt "
  40. << "-Ssource_start_directory "
  41. << "-Ooutput_start_directory "
  42. << "-Hsource_home_directory "
  43. << "-Boutput_home_directory\n"
  44. << "Where start directories are the current place in the tree,"
  45. "and the home directories are the top.\n";
  46. }
  47. // This is the main program used to gentrate makefile fragments
  48. // from CMakeLists.txt input files.
  49. int main(int ac, char** av)
  50. {
  51. if(ac < 2)
  52. {
  53. Usage(av[0]);
  54. return -1;
  55. }
  56. // Create a makefile
  57. cmMakefile mf;
  58. mf.AddDefinition("UNIX", "1");
  59. bool makeCache = false;
  60. // Parse the command line
  61. if(ac > 2)
  62. {
  63. for(int i =2; i < ac; i++)
  64. {
  65. std::string arg = av[i];
  66. // Set the start source directory with a -S dir options
  67. if(arg.find("-MakeCache",0) == 0)
  68. {
  69. makeCache = true;
  70. }
  71. // Set the start source directory with a -S dir options
  72. if(arg.find("-S",0) == 0)
  73. {
  74. std::string path = arg.substr(2);
  75. mf.SetStartDirectory(path.c_str());
  76. }
  77. // Set the start output directory with a -O dir options
  78. if(arg.find("-O",0) == 0)
  79. {
  80. std::string path = arg.substr(2);
  81. mf.SetStartOutputDirectory(path.c_str());
  82. }
  83. // Set the source home directory with a -H dir option
  84. if(arg.find("-H",0) == 0)
  85. {
  86. std::string path = arg.substr(2);
  87. mf.SetHomeDirectory(path.c_str());
  88. }
  89. // Set the output or binary directory with a -B dir option
  90. if(arg.find("-B",0) == 0)
  91. {
  92. std::string path = arg.substr(2);
  93. mf.SetHomeOutputDirectory(path.c_str());
  94. }
  95. }
  96. }
  97. // Only generate makefiles if not trying to make the cache
  98. if(!makeCache)
  99. {
  100. mf.SetMakefileGenerator(new cmUnixMakefileGenerator);
  101. }
  102. // Read and parse the input makefile
  103. mf.MakeStartDirectoriesCurrent();
  104. cmCacheManager::GetInstance()->LoadCache(&mf);
  105. if(!mf.ReadListFile(av[1]))
  106. {
  107. Usage(av[0]);
  108. return -1;
  109. }
  110. if(makeCache)
  111. {
  112. mf.GenerateCacheOnly();
  113. }
  114. else
  115. {
  116. mf.GenerateMakefile();
  117. }
  118. cmCacheManager::GetInstance()->SaveCache(&mf);
  119. if(makeCache)
  120. {
  121. cmCacheManager::GetInstance()->PrintCache(std::cout);
  122. }
  123. if(cmSystemTools::GetErrorOccuredFlag())
  124. {
  125. return -1;
  126. }
  127. return 0;
  128. }