CMake/Source/cmGlobalUnixMakefileGenerat...

166 lines
5.7 KiB
C++
Raw Normal View History

2002-08-31 00:01:48 +04:00
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
2002-08-31 00:01:48 +04:00
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.
2002-08-31 00:01:48 +04:00
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.
=========================================================================*/
2002-08-31 00:01:48 +04:00
#include "cmGlobalUnixMakefileGenerator.h"
#include "cmLocalUnixMakefileGenerator.h"
#include "cmMakefile.h"
2002-09-06 21:06:23 +04:00
#include "cmake.h"
2002-08-31 00:01:48 +04:00
void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang,
cmMakefile *mf)
{
2002-09-13 18:42:50 +04:00
// only do for global runs
if (!m_CMakeInstance->GetLocal())
2002-08-31 00:01:48 +04:00
{
2002-09-13 18:42:50 +04:00
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'))
2002-08-31 00:01:48 +04:00
{
2002-09-06 21:06:23 +04:00
static char envCC[5000];
if(mf->GetDefinition("CMAKE_C_COMPILER"))
{
std::string env = "CC=${CMAKE_C_COMPILER}";
mf->ExpandVariablesInString(env);
strncpy(envCC, env.c_str(), 4999);
envCC[4999] = 0;
putenv(envCC);
}
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");
}
std::string cmd = root;
cmd += "/Templates/cconfigure";
cmSystemTools::RunCommand(cmd.c_str(), output,
cmSystemTools::ConvertToOutputPath(
mf->GetHomeOutputDirectory()).c_str());
2002-09-13 18:42:50 +04:00
std::string fpath = mf->GetHomeOutputDirectory();
fpath += "/CCMakeSystemConfig.cmake";
mf->ReadListFile(0,fpath.c_str());
this->SetLanguageEnabled("C");
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)
{
2002-10-17 18:51:23 +04:00
std::string ifpath = root + "/Modules/CMakeBackwardCompatibilityC.cmake";
mf->ReadListFile(0,ifpath.c_str());
}
}
2002-09-13 18:42:50 +04:00
}
// 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"))
2002-09-06 21:06:23 +04:00
{
2002-09-13 18:42:50 +04:00
std::string env = "CXX=${CMAKE_CXX_COMPILER}";
mf->ExpandVariablesInString(env);
strncpy(envCXX, env.c_str(), 4999);
envCXX[4999] = 0;
putenv(envCXX);
2002-09-06 21:06:23 +04:00
}
2002-09-13 18:42:50 +04:00
std::string cmd = root;
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");
}
cmd += "/Templates/cxxconfigure";
cmSystemTools::RunCommand(cmd.c_str(), output,
cmSystemTools::ConvertToOutputPath(
mf->GetHomeOutputDirectory()).c_str());
2002-09-13 18:42:50 +04:00
std::string fpath = mf->GetHomeOutputDirectory();
fpath += "/CXXCMakeSystemConfig.cmake";
mf->ReadListFile(0,fpath.c_str());
this->SetLanguageEnabled("CXX");
if (!m_CMakeInstance->GetIsInTryCompile())
2002-09-06 21:06:23 +04:00
{
// for old versions of CMake ListFiles
2002-09-13 18:42:50 +04:00
const char* versionValue
= mf->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
if (!versionValue || atof(versionValue) <= 1.4)
{
fpath = root + "/Modules/CMakeBackwardCompatibilityCXX.cmake";
mf->ReadListFile(0,fpath.c_str());
2002-09-13 18:42:50 +04:00
}
2002-09-06 21:06:23 +04:00
}
2002-08-31 00:01:48 +04:00
}
2002-09-06 21:06:23 +04:00
// if we are from the top, always define this
mf->AddDefinition("RUN_CONFIGURE", true);
}
2002-08-31 00:01:48 +04:00
}
///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *cmGlobalUnixMakefileGenerator::CreateLocalGenerator()
{
cmLocalGenerator *lg = new cmLocalUnixMakefileGenerator;
lg->SetGlobalGenerator(this);
return lg;
}
2002-09-13 18:42:50 +04:00
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;
}