cmProjectCommand.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "cmProjectCommand.h"
  11. // cmProjectCommand
  12. bool cmProjectCommand
  13. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  14. {
  15. if(args.size() < 1 )
  16. {
  17. this->SetError("PROJECT called with incorrect number of arguments");
  18. return false;
  19. }
  20. this->Makefile->SetProjectName(args[0].c_str());
  21. std::string bindir = args[0];
  22. bindir += "_BINARY_DIR";
  23. std::string srcdir = args[0];
  24. srcdir += "_SOURCE_DIR";
  25. this->Makefile->AddCacheDefinition
  26. (bindir.c_str(),
  27. this->Makefile->GetCurrentOutputDirectory(),
  28. "Value Computed by CMake", cmCacheManager::STATIC);
  29. this->Makefile->AddCacheDefinition
  30. (srcdir.c_str(),
  31. this->Makefile->GetCurrentDirectory(),
  32. "Value Computed by CMake", cmCacheManager::STATIC);
  33. bindir = "PROJECT_BINARY_DIR";
  34. srcdir = "PROJECT_SOURCE_DIR";
  35. this->Makefile->AddDefinition(bindir.c_str(),
  36. this->Makefile->GetCurrentOutputDirectory());
  37. this->Makefile->AddDefinition(srcdir.c_str(),
  38. this->Makefile->GetCurrentDirectory());
  39. this->Makefile->AddDefinition("PROJECT_NAME", args[0].c_str());
  40. // Set the CMAKE_PROJECT_NAME variable to be the highest-level
  41. // project name in the tree. If there are two project commands
  42. // in the same CMakeLists.txt file, and it is the top level
  43. // CMakeLists.txt file, then go with the last one, so that
  44. // CMAKE_PROJECT_NAME will match PROJECT_NAME, and cmake --build
  45. // will work.
  46. if(!this->Makefile->GetDefinition("CMAKE_PROJECT_NAME")
  47. || (this->Makefile->GetLocalGenerator()->GetParent() == 0) )
  48. {
  49. this->Makefile->AddDefinition("CMAKE_PROJECT_NAME", args[0].c_str());
  50. this->Makefile->AddCacheDefinition
  51. ("CMAKE_PROJECT_NAME",
  52. args[0].c_str(),
  53. "Value Computed by CMake", cmCacheManager::STATIC);
  54. }
  55. std::vector<std::string> languages;
  56. if(args.size() > 1)
  57. {
  58. for(size_t i =1; i < args.size(); ++i)
  59. {
  60. languages.push_back(args[i]);
  61. }
  62. }
  63. else
  64. {
  65. // if no language is specified do c and c++
  66. languages.push_back("C");
  67. languages.push_back("CXX");
  68. }
  69. this->Makefile->EnableLanguage(languages, false);
  70. std::string extraInclude = "CMAKE_PROJECT_" + args[0] + "_INCLUDE";
  71. const char* include = this->Makefile->GetDefinition(extraInclude.c_str());
  72. if(include)
  73. {
  74. std::string fullFilePath;
  75. bool readit =
  76. this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(),
  77. include);
  78. if(!readit && !cmSystemTools::GetFatalErrorOccured())
  79. {
  80. std::string m =
  81. "could not find file:\n"
  82. " ";
  83. m += include;
  84. this->SetError(m.c_str());
  85. return false;
  86. }
  87. }
  88. return true;
  89. }