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
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Insight Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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)
{
// only do for global runs
if (!m_CMakeInstance->GetLocal())
{
std::string output;
std::string root
= cmSystemTools::ConvertToOutputPath(mf->GetDefinition("CMAKE_ROOT"));
// if no lang specified use CXX
if(!lang )
{
lang = "CXX";
}
// if CXX or C, then enable C
if((!this->GetLanguageEnabled("C") && lang[0] == 'C'))
{
static char envCC[5000];
if(mf->GetDefinition("CMAKE_C_COMPILER"))
{
#if !defined(_WIN32) && defined(__COMO__)
std::string env = "${CMAKE_C_COMPILER}";
mf->ExpandVariablesInString(env);
strncpy(envCC, env.c_str(), 4999);
envCC[4999] = 0;
setenv("CC", envCC, 1);
#else
std::string env = "CC=${CMAKE_C_COMPILER}";
mf->ExpandVariablesInString(env);
strncpy(envCC, env.c_str(), 4999);
envCC[4999] = 0;
putenv(envCC);
#endif
}
std::string cmd = root;
cmd += "/Templates/cconfigure";
cmSystemTools::RunCommand(cmd.c_str(), output,
cmSystemTools::ConvertToOutputPath(mf->GetHomeOutputDirectory()).c_str());
std::string fpath = mf->GetHomeOutputDirectory();
fpath += "/CCMakeSystemConfig.cmake";
mf->ReadListFile(0,fpath.c_str());
this->SetLanguageEnabled("C");
}
// if CXX
if(!this->GetLanguageEnabled("CXX") && strcmp(lang, "CXX") == 0)
{
// see man putenv for explaination of this stupid code....
static char envCXX[5000];
if(mf->GetDefinition("CMAKE_CXX_COMPILER"))
{
#if !defined(_WIN32) && defined(__COMO__)
std::string env = "${CMAKE_CXX_COMPILER}";
mf->ExpandVariablesInString(env);
strncpy(envCXX, env.c_str(), 4999);
envCXX[4999] = 0;
setenv("CXX", envCXX, 1);
#else
std::string env = "CXX=${CMAKE_CXX_COMPILER}";
mf->ExpandVariablesInString(env);
strncpy(envCXX, env.c_str(), 4999);
envCXX[4999] = 0;
putenv(envCXX);
#endif
}
std::string cmd = root;
cmd += "/Templates/cxxconfigure";
cmSystemTools::RunCommand(cmd.c_str(), output,
cmSystemTools::ConvertToOutputPath(mf->GetHomeOutputDirectory()).c_str());
std::string fpath = mf->GetHomeOutputDirectory();
fpath += "/CXXCMakeSystemConfig.cmake";
mf->ReadListFile(0,fpath.c_str());
this->SetLanguageEnabled("CXX");
// for old versions of CMake ListFiles
if (!m_CMakeInstance->GetIsInTryCompile())
{
const char* versionValue
= mf->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
if (!versionValue || atof(versionValue) <= 1.4)
{
fpath = root + "/Modules/TestForANSIStreamHeaders.cmake";
mf->ReadListFile(NULL,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, cmMakefile *mf)
{
// for UNIX we just want to read in the configured files
cmLocalGenerator *lg = this->CreateLocalGenerator();
// set the Start directories
lg->GetMakefile()->SetStartDirectory(m_CMakeInstance->GetStartDirectory());
lg->GetMakefile()->SetStartOutputDirectory(m_CMakeInstance->GetStartOutputDirectory());
lg->GetMakefile()->MakeStartDirectoriesCurrent();
// if C, then enable C
if(gen->GetLanguageEnabled("C"))
{
std::string fpath = mf->GetHomeOutputDirectory();
fpath += "/CCMakeSystemConfig.cmake";
lg->GetMakefile()->ReadListFile(0,fpath.c_str());
this->SetLanguageEnabled("C");
}
// if CXX
if(gen->GetLanguageEnabled("CXX"))
{
std::string fpath = mf->GetHomeOutputDirectory();
fpath += "/CXXCMakeSystemConfig.cmake";
lg->GetMakefile()->ReadListFile(0,fpath.c_str());
this->SetLanguageEnabled("CXX");
}
delete lg;
}
|