ENH: call configure from cmake

This commit is contained in:
Bill Hoffman 2001-05-07 18:11:16 -04:00
parent 5066defc23
commit 885e37da22
16 changed files with 409 additions and 141 deletions

View File

@ -3,8 +3,6 @@
# in, which need not be the source directory # in, which need not be the source directory
# #
SET (WORDS_BIGENDIAN @CMAKE_WORDS_BIGENDIAN@) SET (WORDS_BIGENDIAN @CMAKE_WORDS_BIGENDIAN@)
SET (HAVE_LIMITS_H @HAVE_LIMITS_H@)
SET (HAVE_UNISTD_H @HAVE_UNISTD_H@)
SET (CMAKE_USE_SPROC @CMAKE_USE_SPROC@) SET (CMAKE_USE_SPROC @CMAKE_USE_SPROC@)
SET (CMAKE_USE_PTHREADS @CMAKE_USE_PTHREADS@) SET (CMAKE_USE_PTHREADS @CMAKE_USE_PTHREADS@)
SET (CMAKE_HP_PTHREADS @CMAKE_HP_PTHREADS@) SET (CMAKE_HP_PTHREADS @CMAKE_HP_PTHREADS@)

View File

@ -104,14 +104,23 @@ int main(int ac, char** av)
std::string path = arg.substr(2); std::string path = arg.substr(2);
mf.SetHomeOutputDirectory(path.c_str()); mf.SetHomeOutputDirectory(path.c_str());
} }
if(arg.find("-D",0) == 0)
{
std::string value = arg.substr(2);
mf.AddDefinition(value.c_str(), true);
}
} }
} }
// Only generate makefiles if not trying to make the cache // Only generate makefiles if not trying to make the cache
if(!makeCache) cmUnixMakefileGenerator* gen = new cmUnixMakefileGenerator;
mf.SetMakefileGenerator(gen);
if(makeCache)
{ {
mf.SetMakefileGenerator(new cmUnixMakefileGenerator); // generate only enough for the cache
gen->SetCacheOnlyOn();
// generate for this makefile and all below it
gen->SetRecurseOn();
} }
// Read and parse the input makefile // Read and parse the input makefile
mf.MakeStartDirectoriesCurrent(); mf.MakeStartDirectoriesCurrent();
@ -137,14 +146,7 @@ int main(int ac, char** av)
Usage(av[0]); Usage(av[0]);
return -1; return -1;
} }
if(makeCache) mf.GenerateMakefile();
{
mf.GenerateCacheOnly();
}
else
{
mf.GenerateMakefile();
}
cmCacheManager::GetInstance()->SaveCache(&mf); cmCacheManager::GetInstance()->SaveCache(&mf);
if(makeCache) if(makeCache)
{ {

View File

@ -40,7 +40,7 @@ cmSourceFile.o : $(DEPENDS)
cmDirectory.o : $(DEPENDS) cmDirectory.o : $(DEPENDS)
cmCustomCommand.o : $(DEPENDS) cmCustomCommand.o : $(DEPENDS)
cmUnixMakefileGenerator.o : $(DEPENDS) cmUnixMakefileGenerator.o : $(DEPENDS)
cmCommands.o : $(DEPENDS) $(srcdir)/*.cxx cmCommands.o : $(DEPENDS) $(srcdir)/*Command*.cxx
cmTarget.o : $(DEPENDS) cmTarget.o : $(DEPENDS)
cmCacheManager.o : $(DEPENDS) cmCacheManager.o : $(DEPENDS)
cmSourceGroup.o : $(DEPENDS) cmSourceGroup.o : $(DEPENDS)

View File

@ -182,16 +182,33 @@ bool cmCacheManager::SaveCache(const char* path) const
<< "# TYPE is a hint to GUI's for the type of VALUE, DO NOT EDIT TYPE!.\n" << "# TYPE is a hint to GUI's for the type of VALUE, DO NOT EDIT TYPE!.\n"
<< "# VALUE is the current value for the KEY.\n\n"; << "# VALUE is the current value for the KEY.\n\n";
for( std::map<std::string, CacheEntry>::const_iterator i = m_Cache.begin();
i != m_Cache.end(); ++i)
{
const CacheEntry& ce = (*i).second;
CacheEntryType t = ce.m_Type;
if(t != INTERNAL)
{
// Format is key:type=value
cmCacheManager::OutputHelpString(fout, ce.m_HelpString);
fout << (*i).first.c_str() << ":"
<< cmCacheManagerTypes[t] << "="
<< ce.m_Value << "\n";
}
}
for( std::map<std::string, CacheEntry>::const_iterator i = m_Cache.begin(); for( std::map<std::string, CacheEntry>::const_iterator i = m_Cache.begin();
i != m_Cache.end(); ++i) i != m_Cache.end(); ++i)
{ {
const CacheEntry& ce = (*i).second; const CacheEntry& ce = (*i).second;
CacheEntryType t = ce.m_Type; CacheEntryType t = ce.m_Type;
// Format is key:type=value if(t == INTERNAL)
cmCacheManager::OutputHelpString(fout, ce.m_HelpString); {
fout << (*i).first.c_str() << ":" // Format is key:type=value
<< cmCacheManagerTypes[t] << "=" cmCacheManager::OutputHelpString(fout, ce.m_HelpString);
<< ce.m_Value << "\n"; fout << (*i).first.c_str() << ":"
<< cmCacheManagerTypes[t] << "="
<< ce.m_Value << "\n";
}
} }
fout << "\n"; fout << "\n";
fout.close(); fout.close();
@ -279,7 +296,10 @@ void cmCacheManager::PrintCache(std::ostream& out) const
for(std::map<std::string, CacheEntry>::const_iterator i = m_Cache.begin(); for(std::map<std::string, CacheEntry>::const_iterator i = m_Cache.begin();
i != m_Cache.end(); ++i) i != m_Cache.end(); ++i)
{ {
out << (*i).first.c_str() << " = " << (*i).second.m_Value.c_str() << std::endl; if((*i).second.m_Type != INTERNAL)
{
out << (*i).first.c_str() << " = " << (*i).second.m_Value.c_str() << std::endl;
}
} }
out << "\n\n"; out << "\n\n";
out << "To change values in the CMakeCache, \nedit CMakeCache.txt in your output directory.\n"; out << "To change values in the CMakeCache, \nedit CMakeCache.txt in your output directory.\n";

View File

@ -23,11 +23,11 @@
#include "cmCablePackageEntryCommand.cxx" #include "cmCablePackageEntryCommand.cxx"
#include "cmCableSourceFilesCommand.cxx" #include "cmCableSourceFilesCommand.cxx"
#include "cmCableWrapCommand.cxx" #include "cmCableWrapCommand.cxx"
#include "cmConfigureFile.cxx" #include "cmConfigureFileCommand.cxx"
#include "cmConfigureFileNoAutoconf.cxx" #include "cmConfigureFileNoAutoconf.cxx"
#include "cmElseCommand.cxx" #include "cmElseCommand.cxx"
#include "cmEndIfCommand.cxx" #include "cmEndIfCommand.cxx"
#include "cmExecProgram.cxx" #include "cmExecProgramCommand.cxx"
#include "cmFindFileCommand.cxx" #include "cmFindFileCommand.cxx"
#include "cmFindIncludeCommand.cxx" #include "cmFindIncludeCommand.cxx"
#include "cmFindLibraryCommand.cxx" #include "cmFindLibraryCommand.cxx"
@ -39,6 +39,7 @@
#include "cmIncludeRegularExpressionCommand.cxx" #include "cmIncludeRegularExpressionCommand.cxx"
#include "cmLinkDirectoriesCommand.cxx" #include "cmLinkDirectoriesCommand.cxx"
#include "cmLinkLibrariesCommand.cxx" #include "cmLinkLibrariesCommand.cxx"
#include "cmMakeDirectoryCommand.cxx"
#include "cmOptionCommand.cxx" #include "cmOptionCommand.cxx"
#include "cmProjectCommand.cxx" #include "cmProjectCommand.cxx"
#include "cmSetCommand.cxx" #include "cmSetCommand.cxx"
@ -74,11 +75,11 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands)
commands.push_back(new cmCablePackageCommand); commands.push_back(new cmCablePackageCommand);
commands.push_back(new cmCableSourceFilesCommand); commands.push_back(new cmCableSourceFilesCommand);
commands.push_back(new cmCableWrapCommand); commands.push_back(new cmCableWrapCommand);
commands.push_back(new cmConfigureFile); commands.push_back(new cmConfigureFileCommand);
commands.push_back(new cmConfigureFileNoAutoconf); commands.push_back(new cmConfigureFileNoAutoconf);
commands.push_back(new cmElseCommand); commands.push_back(new cmElseCommand);
commands.push_back(new cmEndIfCommand); commands.push_back(new cmEndIfCommand);
commands.push_back(new cmExecProgram); commands.push_back(new cmExecProgramCommand);
commands.push_back(new cmFindFileCommand); commands.push_back(new cmFindFileCommand);
commands.push_back(new cmFindIncludeCommand); commands.push_back(new cmFindIncludeCommand);
commands.push_back(new cmFindLibraryCommand); commands.push_back(new cmFindLibraryCommand);
@ -90,6 +91,7 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands)
commands.push_back(new cmIncludeRegularExpressionCommand); commands.push_back(new cmIncludeRegularExpressionCommand);
commands.push_back(new cmLinkDirectoriesCommand); commands.push_back(new cmLinkDirectoriesCommand);
commands.push_back(new cmLinkLibrariesCommand); commands.push_back(new cmLinkLibrariesCommand);
commands.push_back(new cmMakeDirectoryCommand);
commands.push_back(new cmOptionCommand); commands.push_back(new cmOptionCommand);
commands.push_back(new cmProjectCommand); commands.push_back(new cmProjectCommand);
commands.push_back(new cmSetCommand); commands.push_back(new cmSetCommand);

View File

@ -38,22 +38,28 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/ =========================================================================*/
#include "cmConfigureFile.h" #include "cmConfigureFileCommand.h"
// cmConfigureFile // cmConfigureFileCommand
bool cmConfigureFile::Invoke(std::vector<std::string>& args) bool cmConfigureFileCommand::Invoke(std::vector<std::string>& args)
{ {
if(args.size() != 2 ) if(args.size() < 2 )
{ {
this->SetError("called with incorrect number of arguments, expected 2"); this->SetError("called with incorrect number of arguments, expected 2");
return false; return false;
} }
m_InputFile = args[0]; m_InputFile = args[0];
m_OuputFile = args[1]; m_OuputFile = args[1];
m_CopyOnly = false;
if(args[2] == "COPYONLY")
{
m_CopyOnly = true;
}
return true; return true;
} }
void cmConfigureFile::FinalPass() void cmConfigureFileCommand::FinalPass()
{ {
m_Makefile->ExpandVariablesInString(m_InputFile); m_Makefile->ExpandVariablesInString(m_InputFile);
m_Makefile->ExpandVariablesInString(m_OuputFile); m_Makefile->ExpandVariablesInString(m_OuputFile);
@ -92,24 +98,25 @@ void cmConfigureFile::FinalPass()
if(fin) if(fin)
{ {
inLine = buffer; inLine = buffer;
m_Makefile->ExpandVariablesInString(inLine); if(!m_CopyOnly)
// This call will remove all tcl variable substitutions of the form ${Foo}
// m_Makefile->RemoveVariablesInString(inLine);
// look for special cmakedefine symbol and handle it
// is the symbol defined
if (cmdefine.find(inLine))
{ {
const char *def = m_Makefile->GetDefinition(cmdefine.match(1).c_str()); m_Makefile->ExpandVariablesInString(inLine);
if(!cmSystemTools::IsOff(def)) m_Makefile->RemoveVariablesInString(inLine);
// look for special cmakedefine symbol and handle it
// is the symbol defined
if (cmdefine.find(inLine))
{ {
cmSystemTools::ReplaceString(inLine, const char *def = m_Makefile->GetDefinition(cmdefine.match(1).c_str());
"#cmakedefine", "#define"); if(!cmSystemTools::IsOff(def))
} {
else cmSystemTools::ReplaceString(inLine,
{ "#cmakedefine", "#define");
cmSystemTools::ReplaceString(inLine, }
"#cmakedefine", "#undef"); else
{
cmSystemTools::ReplaceString(inLine,
"#cmakedefine", "#undef");
}
} }
} }
fout << inLine << "\n"; fout << inLine << "\n";

View File

@ -38,18 +38,18 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/ =========================================================================*/
#ifndef cmConfigureFile_h #ifndef cmConfigureFileCommand_h
#define cmConfigureFile_h #define cmConfigureFileCommand_h
#include "cmStandardIncludes.h" #include "cmStandardIncludes.h"
#include "cmCommand.h" #include "cmCommand.h"
class cmConfigureFile : public cmCommand class cmConfigureFileCommand : public cmCommand
{ {
public: public:
virtual cmCommand* Clone() virtual cmCommand* Clone()
{ {
return new cmConfigureFile; return new cmConfigureFileCommand;
} }
/** /**
@ -77,12 +77,13 @@ public:
virtual const char* GetFullDocumentation() virtual const char* GetFullDocumentation()
{ {
return return
"CONFIGURE_FILE(InputFile OutputFile)\n" "CONFIGURE_FILE(InputFile OutputFile [COPYONLY])\n"
"The Input and Ouput files have to have full paths.\n" "The Input and Ouput files have to have full paths.\n"
"They can also use variables like CMAKE_BINARY_DIR,CMAKE_SOURCE_DIR.\n" "They can also use variables like CMAKE_BINARY_DIR,CMAKE_SOURCE_DIR.\n"
"This command replaces any variables in the input file with their\n" "This command replaces any variables in the input file with their\n"
"values as determined by CMake. If a variables in not defined, it\n" "values as determined by CMake. If a variables in not defined, it\n"
"will be replaced with nothing."; "will be replaced with nothing. If COPYONLY is passed in, then\n"
"then no varible expansion will take place.\n";
} }
/** /**
@ -93,6 +94,7 @@ public:
private: private:
std::string m_InputFile; std::string m_InputFile;
std::string m_OuputFile; std::string m_OuputFile;
bool m_CopyOnly;
}; };

View File

@ -0,0 +1,71 @@
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2001 Insight Consortium
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* The name of the Insight Consortium, nor the names of any consortium members,
nor of any contributors, may be used to endorse or promote products derived
from this software without specific prior written permission.
* Modified source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#include "cmExecProgramCommand.h"
#include "cmSystemTools.h"
// cmExecProgramCommand
bool cmExecProgramCommand::Invoke(std::vector<std::string>& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
std::string output;
m_Makefile->ExpandVariablesInString(args[0]);
m_Makefile->ExpandVariablesInString(args[1]);
if(args.size() == 2)
{
cmSystemTools::MakeDirectory(args[1].c_str());
std::string command;
command = "cd ";
command += args[1].c_str();
command += "; ";
command += args[0].c_str();
cmSystemTools::RunCommand(command.c_str(), output);
}
else
{
cmSystemTools::RunCommand(args[0].c_str(), output);
}
return true;
}

View File

@ -38,20 +38,20 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/ =========================================================================*/
#ifndef cmExecProgram_h #ifndef cmExecProgramCommand_h
#define cmExecProgram_h #define cmExecProgramCommand_h
#include "cmStandardIncludes.h" #include "cmStandardIncludes.h"
#include "cmCommand.h" #include "cmCommand.h"
/** \class cmExecProgram /** \class cmExecProgramCommand
* \brief Command that adds a target to the build system. * \brief Command that adds a target to the build system.
* *
* cmExecProgram adds an extra target to the build system. * cmExecProgramCommand adds an extra target to the build system.
* This is useful when you would like to add special * This is useful when you would like to add special
* targets like "install,", "clean," and so on. * targets like "install,", "clean," and so on.
*/ */
class cmExecProgram : public cmCommand class cmExecProgramCommand : public cmCommand
{ {
public: public:
/** /**
@ -59,7 +59,7 @@ public:
*/ */
virtual cmCommand* Clone() virtual cmCommand* Clone()
{ {
return new cmExecProgram; return new cmExecProgramCommand;
} }
/** /**
@ -91,7 +91,7 @@ public:
"EXEC_PROGRAM(Executble )"; "EXEC_PROGRAM(Executble )";
} }
cmTypeMacro(cmExecProgram, cmCommand); cmTypeMacro(cmExecProgramCommand, cmCommand);
}; };
#endif #endif

View File

@ -38,19 +38,19 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/ =========================================================================*/
#include "cmExecProgram.h" #include "cmMakeDirectoryCommand.h"
#include "cmSystemTools.h" #include "cmDirectory.h"
// cmExecProgram // cmMakeDirectoryCommand
bool cmExecProgram::Invoke(std::vector<std::string>& args) bool cmMakeDirectoryCommand::Invoke(std::vector<std::string>& args)
{ {
if(args.size() < 1 ) if(args.size() < 1 )
{ {
this->SetError("called with incorrect number of arguments"); this->SetError("called with incorrect number of arguments");
return false; return false;
} }
std::string output; m_Makefile->ExpandVariablesInString(args[0]);
cmSystemTools::RunCommand(args[0].c_str(), output); cmSystemTools::MakeDirectory(args[0].c_str());
return true; return true;
} }

View File

@ -0,0 +1,101 @@
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2001 Insight Consortium
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* The name of the Insight Consortium, nor the names of any consortium members,
nor of any contributors, may be used to endorse or promote products derived
from this software without specific prior written permission.
* Modified source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#ifndef cmMakeDirectoryCommand_h
#define cmMakeDirectoryCommand_h
#include "cmStandardIncludes.h"
#include "cmCommand.h"
/** \class cmMakeDirectoryCommand
* \brief Specify auxiliary source code directories.
*
* cmMakeDirectoryCommand specifies source code directories
* that must be built as part of this build process. This directories
* are not recursively processed like the SUBDIR command (cmSubdirCommand).
* A side effect of this command is to create a subdirectory in the build
* directory structure.
*/
class cmMakeDirectoryCommand : public cmCommand
{
public:
/**
* This is a virtual constructor for the command.
*/
virtual cmCommand* Clone()
{
return new cmMakeDirectoryCommand;
}
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
virtual bool Invoke(std::vector<std::string>& args);
/**
* The name of the command as specified in CMakeList.txt.
*/
virtual const char* GetName() { return "MAKE_DIRECTORY";}
/**
* Succinct documentation.
*/
virtual const char* GetTerseDocumentation()
{
return "Create a directory in the build tree if it does not exist.\n"
"Parent directories will be created if the do not exist..";
}
/**
* More documentation.
*/
virtual const char* GetFullDocumentation()
{
return
"MAKE_DIRECTORY(directory)";
}
cmTypeMacro(cmMakeDirectoryCommand, cmCommand);
};
#endif

View File

@ -75,7 +75,7 @@ void cmMakefile::AddDefaultCommands()
{ {
this->AddCommand(*i); this->AddCommand(*i);
} }
#ifdef _WIN32 #if defined(_WIN32) || defined(__CYGWIN__)
this->AddDefinition("WIN32", "1"); this->AddDefinition("WIN32", "1");
#else #else
this->AddDefinition("UNIX", "1"); this->AddDefinition("UNIX", "1");
@ -729,66 +729,6 @@ cmMakefile::FindSubDirectoryCMakeListsFiles(std::vector<cmMakefile*>&
} }
} }
void cmMakefile::GenerateCacheOnly()
{
std::vector<cmMakefile*> makefiles;
this->FindSubDirectoryCMakeListsFiles(makefiles);
for(std::vector<cmMakefile*>::iterator i = makefiles.begin();
i != makefiles.end(); ++i)
{
cmMakefile* mf = *i;
std::string source = mf->GetHomeDirectory();
source += "/CMake/CMakeMakefileTemplate.in";
cmSystemTools::MakeDirectory(mf->GetStartOutputDirectory());
std::string dest = mf->GetStartOutputDirectory();
dest += "/Makefile";
std::ofstream fout(dest.c_str());
std::cout << "cmake: creating : " << dest.c_str() << "\n";
if(!fout)
{
cmSystemTools::Error("Failed to open file for write " , dest.c_str());
}
else
{
if(strcmp(mf->GetHomeDirectory(),
mf->GetHomeOutputDirectory()) == 0)
{
fout << "srcdir = .\n\n";
}
else
{
fout << "srcdir = " << mf->GetStartDirectory() << "\n";
fout << "VPATH = " << mf->GetStartDirectory() << "\n";
}
}
fout << "include "
<< mf->GetHomeOutputDirectory() << "/CMake/CMakeMaster.make\n";
dest = mf->GetStartOutputDirectory();
dest += "/CMakeTargets.make";
// make sure there is a CMakeTargets.make file as some
// makes require it to exist
if(!cmSystemTools::FileExists(dest.c_str()))
{
std::cout << "cmake: creating : " << dest.c_str() << "\n";
std::ofstream fout(dest.c_str());
if(!fout)
{
cmSystemTools::Error("Failed to open file for write " , dest.c_str());
}
fout << "#Initial CMakeTargets.make file created only to keep \n";
fout << "#certain makes happy that don't like to include makefiles\n";
fout << "#that do not exist\n";
}
}
// CLEAN up the makefiles created
for(unsigned int i =0; i < makefiles.size(); ++i)
{
delete makefiles[i];
}
}
/** /**
* Add the default definitions to the makefile. These values must not * Add the default definitions to the makefile. These values must not

View File

@ -466,13 +466,6 @@ public:
*/ */
void FindSubDirectoryCMakeListsFiles(std::vector<cmMakefile*>& makefiles); void FindSubDirectoryCMakeListsFiles(std::vector<cmMakefile*>& makefiles);
/** Generate the cache file only. This is done
* by calling FindSubDirectoryCMakeListsFiles which
* will cause all the rules to fire, and the cache to
* be filled.
*/
void GenerateCacheOnly();
/** /**
* find what source group this source is in * find what source group this source is in
*/ */

View File

@ -563,6 +563,10 @@ bool cmSystemTools::IsOff(const char* val)
bool cmSystemTools::RunCommand(const char* command, bool cmSystemTools::RunCommand(const char* command,
std::string& output) std::string& output)
{ {
const int BUFFER_SIZE = 4096;
char buffer[BUFFER_SIZE];
#if defined(WIN32) && !defined(__CYGWIN__)
std::string commandToFile = command; std::string commandToFile = command;
commandToFile += " > "; commandToFile += " > ";
std::string tempFile; std::string tempFile;
@ -576,8 +580,6 @@ bool cmSystemTools::RunCommand(const char* command,
tempFile.c_str()); tempFile.c_str());
return false; return false;
} }
const int BUFFER_SIZE = 4096;
char buffer[BUFFER_SIZE];
while(fin) while(fin)
{ {
fin.getline(buffer, BUFFER_SIZE); fin.getline(buffer, BUFFER_SIZE);
@ -585,6 +587,22 @@ bool cmSystemTools::RunCommand(const char* command,
} }
cmSystemTools::RemoveFile(tempFile.c_str()); cmSystemTools::RemoveFile(tempFile.c_str());
return true; return true;
#else
std::cout << "runing " << command << std::endl;
FILE* cpipe = popen(command, "r");
if(!cpipe)
{
return false;
}
fgets(buffer, BUFFER_SIZE, cpipe);
while(!feof(cpipe))
{
std::cout << buffer;
output += buffer;
fgets(buffer, BUFFER_SIZE, cpipe);
}
fclose(cpipe);
#endif
} }
#ifdef _MSC_VER #ifdef _MSC_VER

View File

@ -46,14 +46,34 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "cmMakeDepend.h" #include "cmMakeDepend.h"
#include "cmCacheManager.h" #include "cmCacheManager.h"
cmUnixMakefileGenerator::cmUnixMakefileGenerator()
{
m_CacheOnly = false;
m_Recurse = false;
}
void cmUnixMakefileGenerator::GenerateMakefile() void cmUnixMakefileGenerator::GenerateMakefile()
{ {
// Generate depends if(m_CacheOnly)
cmMakeDepend md; {
md.SetMakefile(m_Makefile); // Generate the cache only stuff
md.DoDepends(); this->GenerateCacheOnly();
// output the makefile fragment // if recurse then generate for all sub- makefiles
this->OutputMakefile("CMakeTargets.make"); if(m_Recurse)
{
this->RecursiveGenerateCacheOnly();
}
}
// normal makefile output
else
{
// Generate depends
cmMakeDepend md;
md.SetMakefile(m_Makefile);
md.DoDepends();
// output the makefile fragment
this->OutputMakefile("CMakeTargets.make");
}
} }
@ -539,3 +559,76 @@ void cmUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
} }
} }
} }
void cmUnixMakefileGenerator::GenerateCacheOnly()
{
std::string source = m_Makefile->GetHomeDirectory();
source += "/CMake/CMakeMakefileTemplate.in";
cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory());
std::string dest = m_Makefile->GetStartOutputDirectory();
dest += "/Makefile";
std::ofstream fout(dest.c_str());
std::cout << "cmake: creating : " << dest.c_str() << "\n";
if(!fout)
{
cmSystemTools::Error("Failed to open file for write " , dest.c_str());
}
else
{
if(strcmp(m_Makefile->GetHomeDirectory(),
m_Makefile->GetHomeOutputDirectory()) == 0)
{
fout << "srcdir = .\n\n";
}
else
{
fout << "srcdir = " << m_Makefile->GetStartDirectory() << "\n";
fout << "VPATH = " << m_Makefile->GetStartDirectory() << "\n";
}
}
fout << "include "
<< m_Makefile->GetHomeOutputDirectory() << "/CMake/CMakeMaster.make\n";
dest = m_Makefile->GetStartOutputDirectory();
dest += "/CMakeTargets.make";
// make sure there is a CMakeTargets.make file as some
// makes require it to exist
if(!cmSystemTools::FileExists(dest.c_str()))
{
std::cout << "cmake: creating : " << dest.c_str() << "\n";
std::ofstream fout(dest.c_str());
if(!fout)
{
cmSystemTools::Error("Failed to open file for write " , dest.c_str());
}
fout << "#Initial CMakeTargets.make file created only to keep \n";
fout << "#certain makes happy that don't like to include makefiles\n";
fout << "#that do not exist\n";
}
}
void cmUnixMakefileGenerator::RecursiveGenerateCacheOnly()
{
std::vector<cmMakefile*> makefiles;
m_Makefile->FindSubDirectoryCMakeListsFiles(makefiles);
for(std::vector<cmMakefile*>::iterator i = makefiles.begin();
i != makefiles.end(); ++i)
{
cmMakefile* mf = *i;
if(m_Makefile->GetDefinition("RUN_CONFIGURE"))
{
mf->AddDefinition("RUN_CONFIGURE", true);
}
cmUnixMakefileGenerator* gen = new cmUnixMakefileGenerator;
gen->SetCacheOnlyOn();
gen->SetRecurseOff();
mf->SetMakefileGenerator(gen);
mf->GenerateMakefile();
}
// CLEAN up the makefiles created
for(unsigned int i =0; i < makefiles.size(); ++i)
{
delete makefiles[i];
}
}

View File

@ -53,6 +53,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class cmUnixMakefileGenerator : public cmMakefileGenerator class cmUnixMakefileGenerator : public cmMakefileGenerator
{ {
public: public:
///! Set cache only and recurse to false by default.
cmUnixMakefileGenerator();
/**
* If cache only is on.
* and only stub makefiles are generated, and no depends, for speed.
* The default is OFF.
**/
void SetCacheOnlyOn() {m_CacheOnly = true;}
void SetCacheOnlyOff() {m_CacheOnly = false;}
/**
* If recurse is on, then all the makefiles below this one are parsed as well.
*/
void SetRecurseOn() {m_Recurse = true;}
void SetRecurseOff() {m_Recurse = false;}
/** /**
* Produce the makefile (in this case a Unix makefile). * Produce the makefile (in this case a Unix makefile).
*/ */
@ -65,7 +81,9 @@ public:
*/ */
void OutputObjectDepends(std::ostream&); void OutputObjectDepends(std::ostream&);
protected: private:
void RecursiveGenerateCacheOnly();
void GenerateCacheOnly();
void OutputMakefile(const char* file); void OutputMakefile(const char* file);
void OutputMakeFlags(std::ostream&); void OutputMakeFlags(std::ostream&);
void OutputVerbatim(std::ostream&); void OutputVerbatim(std::ostream&);
@ -76,6 +94,9 @@ protected:
void OutputDependInformation(std::ostream&); void OutputDependInformation(std::ostream&);
void OutputDependencies(std::ostream&); void OutputDependencies(std::ostream&);
void OutputCustomRules(std::ostream&); void OutputCustomRules(std::ostream&);
private:
bool m_CacheOnly;
bool m_Recurse;
}; };
#endif #endif