1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmGlobalUnixMakefileGenerator.cxx,v $
6 Date: $Date: 2002-10-02 21:31:59 $
7 Version: $Revision: 1.7 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
18 #include "cmGlobalUnixMakefileGenerator.h"
19 #include "cmLocalUnixMakefileGenerator.h"
20 #include "cmMakefile.h"
23 void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang
,
26 // only do for global runs
27 if (!m_CMakeInstance
->GetLocal())
31 = cmSystemTools::ConvertToOutputPath(mf
->GetDefinition("CMAKE_ROOT"));
32 // if no lang specified use CXX
37 // if CXX or C, then enable C
38 if((!this->GetLanguageEnabled("C") && lang
[0] == 'C'))
40 static char envCC
[5000];
41 if(mf
->GetDefinition("CMAKE_C_COMPILER"))
43 std::string env
= "CC=${CMAKE_C_COMPILER}";
44 mf
->ExpandVariablesInString(env
);
45 strncpy(envCC
, env
.c_str(), 4999);
49 if (m_CMakeInstance
->GetIsInTryCompile())
51 cmSystemTools::Error("This should not have happen. "
52 "If you see this message, you are probably using a "
53 "broken CMakeLists.txt file or a problematic release of "
57 std::string cmd
= root
;
58 cmd
+= "/Templates/cconfigure";
59 cmSystemTools::RunCommand(cmd
.c_str(), output
,
60 cmSystemTools::ConvertToOutputPath(
61 mf
->GetHomeOutputDirectory()).c_str());
63 std::string fpath
= mf
->GetHomeOutputDirectory();
64 fpath
+= "/CCMakeSystemConfig.cmake";
65 mf
->ReadListFile(0,fpath
.c_str());
66 this->SetLanguageEnabled("C");
67 if (!m_CMakeInstance
->GetIsInTryCompile())
69 // for old versions of CMake ListFiles
70 const char* versionValue
71 = mf
->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
72 if (!versionValue
|| atof(versionValue
) <= 1.4)
74 std::string fpath
= root
+ "/Modules/CMakeBackwardCompatibilityC.cmake";
75 mf
->ReadListFile(0,fpath
.c_str());
80 if(!this->GetLanguageEnabled("CXX") && strcmp(lang
, "CXX") == 0)
82 // see man putenv for explaination of this stupid code....
83 static char envCXX
[5000];
84 if(mf
->GetDefinition("CMAKE_CXX_COMPILER"))
86 std::string env
= "CXX=${CMAKE_CXX_COMPILER}";
87 mf
->ExpandVariablesInString(env
);
88 strncpy(envCXX
, env
.c_str(), 4999);
92 std::string cmd
= root
;
93 if (m_CMakeInstance
->GetIsInTryCompile())
95 cmSystemTools::Error("This should not have happen. "
96 "If you see this message, you are probably using a "
97 "broken CMakeLists.txt file or a problematic release of "
100 cmd
+= "/Templates/cxxconfigure";
101 cmSystemTools::RunCommand(cmd
.c_str(), output
,
102 cmSystemTools::ConvertToOutputPath(
103 mf
->GetHomeOutputDirectory()).c_str());
105 std::string fpath
= mf
->GetHomeOutputDirectory();
106 fpath
+= "/CXXCMakeSystemConfig.cmake";
107 mf
->ReadListFile(0,fpath
.c_str());
108 this->SetLanguageEnabled("CXX");
110 if (!m_CMakeInstance
->GetIsInTryCompile())
112 // for old versions of CMake ListFiles
113 const char* versionValue
114 = mf
->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
115 if (!versionValue
|| atof(versionValue
) <= 1.4)
117 fpath
= root
+ "/Modules/CMakeBackwardCompatibilityCXX.cmake";
118 mf
->ReadListFile(0,fpath
.c_str());
123 // if we are from the top, always define this
124 mf
->AddDefinition("RUN_CONFIGURE", true);
128 ///! Create a local generator appropriate to this Global Generator
129 cmLocalGenerator
*cmGlobalUnixMakefileGenerator::CreateLocalGenerator()
131 cmLocalGenerator
*lg
= new cmLocalUnixMakefileGenerator
;
132 lg
->SetGlobalGenerator(this);
136 void cmGlobalUnixMakefileGenerator::EnableLanguagesFromGenerator(
137 cmGlobalGenerator
*gen
, cmMakefile
*mf
)
139 // for UNIX we just want to read in the configured files
140 cmLocalGenerator
*lg
= this->CreateLocalGenerator();
142 // set the Start directories
143 lg
->GetMakefile()->SetStartDirectory(m_CMakeInstance
->GetStartDirectory());
144 lg
->GetMakefile()->SetStartOutputDirectory(m_CMakeInstance
->GetStartOutputDirectory());
145 lg
->GetMakefile()->MakeStartDirectoriesCurrent();
147 // if C, then enable C
148 if(gen
->GetLanguageEnabled("C"))
150 std::string fpath
= mf
->GetHomeOutputDirectory();
151 fpath
+= "/CCMakeSystemConfig.cmake";
152 lg
->GetMakefile()->ReadListFile(0,fpath
.c_str());
153 this->SetLanguageEnabled("C");
157 if(gen
->GetLanguageEnabled("CXX"))
159 std::string fpath
= mf
->GetHomeOutputDirectory();
160 fpath
+= "/CXXCMakeSystemConfig.cmake";
161 lg
->GetMakefile()->ReadListFile(0,fpath
.c_str());
162 this->SetLanguageEnabled("CXX");