summaryrefslogtreecommitdiff
path: root/Source/cmGlobalUnixMakefileGenerator.cxx
blob: d6082c7dc70c93887d55e3f2c39ee43430aeb178 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include "cmGlobalUnixMakefileGenerator.h"
#include "cmLocalUnixMakefileGenerator.h"
#include "cmMakefile.h"
#include "cmake.h"

void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang, 
                                                   cmMakefile *mf)
{
  bool isLocal = m_CMakeInstance->GetLocal();
  // if no lang specified use CXX
  if(!lang )
    {
    lang = "CXX";
    }
  //std::string root 
  //  = cmSystemTools::ConvertToOutputPath(mf->GetDefinition("CMAKE_ROOT"));
  std::string root = mf->GetDefinition("CMAKE_ROOT");
  std::string rootBin = mf->GetHomeOutputDirectory();
  if(m_ConfiguredFilesPath.size())
    {
    rootBin = m_ConfiguredFilesPath;
    }
  bool needCBackwards = false;
  bool needCXXBackwards = false;
  
  // check for a C compiler and configure it
  if(!isLocal &&
     !this->GetLanguageEnabled("C") && 
     lang[0] == 'C')
    {
    if (m_CMakeInstance->GetIsInTryCompile())
      {
      cmSystemTools::Error("This should not have happen. "
                           "If you see this message, you are probably using a "
                           "broken CMakeLists.txt file or a problematic release of "
                           "CMake");
      }
    needCBackwards = true;
    // Read the DetermineSystem file
    std::string systemFile = root;
    systemFile += "/Modules/CMakeDetermineSystem.cmake";
    mf->ReadListFile(0, systemFile.c_str());
    // read determine C compiler
    std::string determineCFile = root;
    determineCFile += "/Modules/CMakeDetermineCCompiler.cmake";
    mf->ReadListFile(0,determineCFile.c_str());
    this->SetLanguageEnabled("C");
    } 
  
  // check for a CXX compiler and configure it
  if(!isLocal &&
     !this->GetLanguageEnabled("CXX") &&
     strcmp(lang, "CXX") == 0)
    {
    needCXXBackwards = true;
    std::string determineCFile = root;
    determineCFile += "/Modules/CMakeDetermineCXXCompiler.cmake";
    mf->ReadListFile(0,determineCFile.c_str());
    this->SetLanguageEnabled("CXX");
    }
 
    
  std::string fpath = rootBin;
  if(!mf->GetDefinition("CMAKE_SYSTEM_LOADED"))
    {
    fpath += "/CMakeSystem.cmake";
    mf->ReadListFile(0,fpath.c_str());
    }
  // if C,  then enable C
  if(lang[0] == 'C' && !mf->GetDefinition("CMAKE_C_COMPILER_LOADED"))
    {
    fpath = rootBin;
    fpath += "/CMakeCCompiler.cmake";
    mf->ReadListFile(0,fpath.c_str());
    }
  if(strcmp(lang, "CXX") == 0 && !mf->GetDefinition("CMAKE_CXX_COMPILER_LOADED"))
    {
    fpath = rootBin;
    fpath += "/CMakeCXXCompiler.cmake";
    mf->ReadListFile(0,fpath.c_str());
    }
  if(!mf->GetDefinition("CMAKE_SYSTEM_SPECIFIC_INFORMATION_LOADED"))
    {
    fpath = root;
    fpath += "/Modules/CMakeSystemSpecificInformation.cmake";
    mf->ReadListFile(0,fpath.c_str());
    }
  
  if(!isLocal)
    {
    // At this point we should have enough info for a try compile
    // which is used in the backward stuff
    if(needCBackwards)
      {
      if (!m_CMakeInstance->GetIsInTryCompile())
        {
        // for old versions of CMake ListFiles
        const char* versionValue
          = mf->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
        if (!versionValue || atof(versionValue) <= 1.4)
          {
          std::string ifpath = root + "/Modules/CMakeBackwardCompatibilityC.cmake";
          mf->ReadListFile(0,ifpath.c_str()); 
          }
        }
      }
    if(needCXXBackwards)
      {
      if (!m_CMakeInstance->GetIsInTryCompile())
        {
        // for old versions of CMake ListFiles
        const char* versionValue
          = mf->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
        if (!versionValue || atof(versionValue) <= 1.4)
          {
          std::string fpath = root + "/Modules/CMakeBackwardCompatibilityCXX.cmake";
          mf->ReadListFile(0,fpath.c_str()); 
          }
        }
      }
    // if we are from the top, always define this
    mf->AddDefinition("RUN_CONFIGURE", true);
    }
}

///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *cmGlobalUnixMakefileGenerator::CreateLocalGenerator()
{
  cmLocalGenerator *lg = new cmLocalUnixMakefileGenerator;
  lg->SetGlobalGenerator(this);
  return lg;
}

void cmGlobalUnixMakefileGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen)
{
  this->SetConfiguredFilesPath(gen->GetCMakeInstance()->GetHomeOutputDirectory());
  // if C,  then enable C
  if(gen->GetLanguageEnabled("C"))
    {
    this->SetLanguageEnabled("C");
    }
  
  // if CXX 
  if(gen->GetLanguageEnabled("CXX"))
    {
    this->SetLanguageEnabled("CXX");
    }
}