packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmProjectCommand.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmProjectCommand.h"
13
14 // cmProjectCommand
15 bool cmProjectCommand
16 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
17 {
18   if(args.size() < 1 )
19     {
20     this->SetError("PROJECT called with incorrect number of arguments");
21     return false;
22     }
23   this->Makefile->SetProjectName(args[0].c_str());
24
25   std::string bindir = args[0];
26   bindir += "_BINARY_DIR";
27   std::string srcdir = args[0];
28   srcdir += "_SOURCE_DIR";
29
30   this->Makefile->AddCacheDefinition
31     (bindir.c_str(),
32      this->Makefile->GetCurrentOutputDirectory(),
33      "Value Computed by CMake", cmCacheManager::STATIC);
34   this->Makefile->AddCacheDefinition
35     (srcdir.c_str(),
36      this->Makefile->GetCurrentDirectory(),
37      "Value Computed by CMake", cmCacheManager::STATIC);
38
39   bindir = "PROJECT_BINARY_DIR";
40   srcdir = "PROJECT_SOURCE_DIR";
41
42   this->Makefile->AddDefinition(bindir.c_str(),
43           this->Makefile->GetCurrentOutputDirectory());
44   this->Makefile->AddDefinition(srcdir.c_str(),
45           this->Makefile->GetCurrentDirectory());
46
47   this->Makefile->AddDefinition("PROJECT_NAME", args[0].c_str());
48
49   // Set the CMAKE_PROJECT_NAME variable to be the highest-level
50   // project name in the tree. If there are two project commands
51   // in the same CMakeLists.txt file, and it is the top level
52   // CMakeLists.txt file, then go with the last one, so that
53   // CMAKE_PROJECT_NAME will match PROJECT_NAME, and cmake --build
54   // will work.
55   if(!this->Makefile->GetDefinition("CMAKE_PROJECT_NAME")
56      || (this->Makefile->GetLocalGenerator()->GetParent() == 0) )
57     {
58     this->Makefile->AddDefinition("CMAKE_PROJECT_NAME", args[0].c_str());
59     this->Makefile->AddCacheDefinition
60       ("CMAKE_PROJECT_NAME",
61        args[0].c_str(),
62        "Value Computed by CMake", cmCacheManager::STATIC);
63     }
64
65   std::vector<std::string> languages;
66   if(args.size() > 1)
67     {
68     for(size_t i =1; i < args.size(); ++i)
69       {
70       languages.push_back(args[i]);
71       }
72     }
73   else
74     {
75     // if no language is specified do c and c++
76     languages.push_back("C");
77     languages.push_back("CXX");
78     }
79   this->Makefile->EnableLanguage(languages, false);
80   std::string extraInclude = "CMAKE_PROJECT_" + args[0] + "_INCLUDE";
81   const char* include = this->Makefile->GetDefinition(extraInclude.c_str());
82   if(include)
83     {
84     std::string fullFilePath;
85     bool readit =
86       this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(),
87                                     include);
88     if(!readit && !cmSystemTools::GetFatalErrorOccured())
89       {
90       std::string m =
91         "could not find file:\n"
92         "  ";
93       m += include;
94       this->SetError(m.c_str());
95       return false;
96       }
97     }
98   return true;
99 }
100