[Cmake-commits] [cmake-commits] king committed CMakeLists.txt 1.411 1.412 cmInstallGenerator.cxx 1.16 1.17 cmInstallGenerator.h 1.13 1.14 cmInstallTargetGenerator.cxx 1.67 1.68 cmInstallTargetGenerator.h 1.28 1.29 cmScriptGenerator.cxx NONE 1.1 cmScriptGenerator.h NONE 1.1
cmake-commits at cmake.org
cmake-commits at cmake.org
Mon Mar 16 10:39:58 EDT 2009
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv28300/Source
Modified Files:
CMakeLists.txt cmInstallGenerator.cxx cmInstallGenerator.h
cmInstallTargetGenerator.cxx cmInstallTargetGenerator.h
Added Files:
cmScriptGenerator.cxx cmScriptGenerator.h
Log Message:
ENH: Refactor cmInstallGenerator for re-use
A new cmScriptGenerator base class factors out the non-install-specific
part of cmInstallGenerator. This will be useful for other generators
that want per-configuration functionality.
Index: cmInstallGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmInstallGenerator.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C 2 -d -r1.13 -r1.14
*** cmInstallGenerator.h 28 Jan 2008 13:38:35 -0000 1.13
--- cmInstallGenerator.h 16 Mar 2009 14:39:49 -0000 1.14
***************
*** 18,56 ****
#define cmInstallGenerator_h
! #include "cmStandardIncludes.h"
class cmLocalGenerator;
- class cmInstallGeneratorIndent
- {
- public:
- cmInstallGeneratorIndent(): Level(0) {}
- cmInstallGeneratorIndent(int level): Level(level) {}
- void Write(std::ostream& os) const
- {
- for(int i=0; i < this->Level; ++i)
- {
- os << " ";
- }
- }
- cmInstallGeneratorIndent Next(int step = 2) const
- {
- return cmInstallGeneratorIndent(this->Level + step);
- }
- private:
- int Level;
- };
- inline std::ostream& operator<<(std::ostream& os,
- cmInstallGeneratorIndent const& indent)
- {
- indent.Write(os);
- return os;
- }
-
/** \class cmInstallGenerator
* \brief Support class for generating install scripts.
*
*/
! class cmInstallGenerator
{
public:
--- 18,30 ----
#define cmInstallGenerator_h
! #include "cmScriptGenerator.h"
class cmLocalGenerator;
/** \class cmInstallGenerator
* \brief Support class for generating install scripts.
*
*/
! class cmInstallGenerator: public cmScriptGenerator
{
public:
***************
*** 60,66 ****
virtual ~cmInstallGenerator();
- void Generate(std::ostream& os, const char* config,
- std::vector<std::string> const& configurationTypes);
-
void AddInstallRule(
std::ostream& os, int type,
--- 34,37 ----
***************
*** 72,82 ****
const char* rename = 0,
const char* literal_args = 0,
! cmInstallGeneratorIndent const& indent = cmInstallGeneratorIndent()
);
const char* GetDestination() const
{ return this->Destination.c_str(); }
- const std::vector<std::string>& GetConfigurations() const
- { return this->Configurations; }
/** Get the install destination as it should appear in the
--- 43,51 ----
const char* rename = 0,
const char* literal_args = 0,
! Indent const& indent = Indent()
);
const char* GetDestination() const
{ return this->Destination.c_str(); }
/** Get the install destination as it should appear in the
***************
*** 88,108 ****
protected:
- typedef cmInstallGeneratorIndent Indent;
virtual void GenerateScript(std::ostream& os);
- virtual void GenerateScriptConfigs(std::ostream& os, Indent const& indent);
- virtual void GenerateScriptActions(std::ostream& os, Indent const& indent);
- std::string CreateConfigTest(const char* config);
- std::string CreateConfigTest(std::vector<std::string> const& configs);
std::string CreateComponentTest(const char* component);
// Information shared by most generator types.
std::string Destination;
- std::vector<std::string> const Configurations;
std::string Component;
-
- // Information used during generation.
- const char* ConfigurationName;
- std::vector<std::string> const* ConfigurationTypes;
};
--- 57,67 ----
Index: cmInstallGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmInstallGenerator.cxx,v
retrieving revision 1.16
retrieving revision 1.17
diff -C 2 -d -r1.16 -r1.17
*** cmInstallGenerator.cxx 16 Dec 2008 14:20:51 -0000 1.16
--- cmInstallGenerator.cxx 16 Mar 2009 14:39:48 -0000 1.17
***************
*** 25,33 ****
std::vector<std::string> const& configurations,
const char* component):
Destination(destination? destination:""),
! Configurations(configurations),
! Component(component? component:""),
! ConfigurationName(0),
! ConfigurationTypes(0)
{
}
--- 25,31 ----
std::vector<std::string> const& configurations,
const char* component):
+ cmScriptGenerator("CMAKE_INSTALL_CONFIG_NAME", configurations),
Destination(destination? destination:""),
! Component(component? component:"")
{
}
***************
*** 40,56 ****
//----------------------------------------------------------------------------
- void
- cmInstallGenerator
- ::Generate(std::ostream& os, const char* config,
- std::vector<std::string> const& configurationTypes)
- {
- this->ConfigurationName = config;
- this->ConfigurationTypes = &configurationTypes;
- this->GenerateScript(os);
- this->ConfigurationName = 0;
- this->ConfigurationTypes = 0;
- }
-
- //----------------------------------------------------------------------------
void cmInstallGenerator
::AddInstallRule(
--- 38,41 ----
***************
*** 64,68 ****
const char* rename /* = 0 */,
const char* literal_args /* = 0 */,
! cmInstallGeneratorIndent const& indent
)
{
--- 49,53 ----
const char* rename /* = 0 */,
const char* literal_args /* = 0 */,
! Indent const& indent
)
{
***************
*** 129,189 ****
//----------------------------------------------------------------------------
- static void cmInstallGeneratorEncodeConfig(const char* config,
- std::string& result)
- {
- for(const char* c = config; *c; ++c)
- {
- if(*c >= 'a' && *c <= 'z')
- {
- result += "[";
- result += *c + ('A' - 'a');
- result += *c;
- result += "]";
- }
- else if(*c >= 'A' && *c <= 'Z')
- {
- result += "[";
- result += *c;
- result += *c + ('a' - 'A');
- result += "]";
- }
- else
- {
- result += *c;
- }
- }
- }
-
- //----------------------------------------------------------------------------
- std::string
- cmInstallGenerator::CreateConfigTest(const char* config)
- {
- std::string result = "\"${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^(";
- if(config && *config)
- {
- cmInstallGeneratorEncodeConfig(config, result);
- }
- result += ")$\"";
- return result;
- }
-
- //----------------------------------------------------------------------------
- std::string
- cmInstallGenerator::CreateConfigTest(std::vector<std::string> const& configs)
- {
- std::string result = "\"${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^(";
- const char* sep = "";
- for(std::vector<std::string>::const_iterator ci = configs.begin();
- ci != configs.end(); ++ci)
- {
- result += sep;
- sep = "|";
- cmInstallGeneratorEncodeConfig(ci->c_str(), result);
- }
- result += ")$\"";
- return result;
- }
-
- //----------------------------------------------------------------------------
std::string
cmInstallGenerator::CreateComponentTest(const char* component)
--- 114,117 ----
***************
*** 215,265 ****
//----------------------------------------------------------------------------
- void
- cmInstallGenerator::GenerateScriptConfigs(std::ostream& os,
- Indent const& indent)
- {
- if(this->Configurations.empty())
- {
- // This rule is for all configurations.
- this->GenerateScriptActions(os, indent);
- }
- else
- {
- // Generate a per-configuration block.
- std::string config_test = this->CreateConfigTest(this->Configurations);
- os << indent << "IF(" << config_test << ")\n";
- this->GenerateScriptActions(os, indent.Next());
- os << indent << "ENDIF(" << config_test << ")\n";
- }
- }
-
- //----------------------------------------------------------------------------
- void cmInstallGenerator::GenerateScriptActions(std::ostream&, Indent const&)
- {
- // No actions for this generator.
- }
-
- //----------------------------------------------------------------------------
bool cmInstallGenerator::InstallsForConfig(const char* config)
{
! // If this is not a configuration-specific rule then we install.
! if(this->Configurations.empty())
! {
! return true;
! }
!
! // This is a configuration-specific rule. Check if the config
! // matches this rule.
! std::string config_upper = cmSystemTools::UpperCase(config?config:"");
! for(std::vector<std::string>::const_iterator i =
! this->Configurations.begin();
! i != this->Configurations.end(); ++i)
! {
! if(cmSystemTools::UpperCase(*i) == config_upper)
! {
! return true;
! }
! }
! return false;
}
--- 143,149 ----
//----------------------------------------------------------------------------
bool cmInstallGenerator::InstallsForConfig(const char* config)
{
! return this->GeneratesForConfig(config);
}
Index: cmInstallTargetGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmInstallTargetGenerator.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -C 2 -d -r1.28 -r1.29
*** cmInstallTargetGenerator.h 18 Dec 2008 15:06:09 -0000 1.28
--- cmInstallTargetGenerator.h 16 Mar 2009 14:39:50 -0000 1.29
***************
*** 66,74 ****
protected:
virtual void GenerateScript(std::ostream& os);
! virtual void GenerateScriptConfigs(std::ostream& os, Indent const& indent);
! virtual void GenerateScriptActions(std::ostream& os, Indent const& indent);
! void GenerateScriptForConfig(std::ostream& os,
! const char* config,
! Indent const& indent);
void AddInstallNamePatchRule(std::ostream& os, Indent const& indent,
const char* config,
--- 66,72 ----
protected:
virtual void GenerateScript(std::ostream& os);
! virtual void GenerateScriptForConfig(std::ostream& os,
! const char* config,
! Indent const& indent);
void AddInstallNamePatchRule(std::ostream& os, Indent const& indent,
const char* config,
--- NEW FILE: cmScriptGenerator.cxx ---
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile: cmScriptGenerator.cxx,v $
Language: C++
Date: $Date: 2009-03-16 14:39:51 $
Version: $Revision: 1.1 $
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 "cmScriptGenerator.h"
#include "cmSystemTools.h"
//----------------------------------------------------------------------------
cmScriptGenerator
::cmScriptGenerator(const char* config_var,
std::vector<std::string> const& configurations):
RuntimeConfigVariable(config_var),
Configurations(configurations),
ConfigurationName(0),
ConfigurationTypes(0),
ActionsPerConfig(false)
{
}
//----------------------------------------------------------------------------
cmScriptGenerator
::~cmScriptGenerator()
{
}
//----------------------------------------------------------------------------
void
cmScriptGenerator
::Generate(std::ostream& os, const char* config,
std::vector<std::string> const& configurationTypes)
{
this->ConfigurationName = config;
this->ConfigurationTypes = &configurationTypes;
this->GenerateScript(os);
this->ConfigurationName = 0;
this->ConfigurationTypes = 0;
}
//----------------------------------------------------------------------------
static void cmScriptGeneratorEncodeConfig(const char* config,
std::string& result)
{
for(const char* c = config; *c; ++c)
{
if(*c >= 'a' && *c <= 'z')
{
result += "[";
result += *c + ('A' - 'a');
result += *c;
result += "]";
}
else if(*c >= 'A' && *c <= 'Z')
{
result += "[";
result += *c;
result += *c + ('a' - 'A');
result += "]";
}
else
{
result += *c;
}
}
}
//----------------------------------------------------------------------------
std::string
cmScriptGenerator::CreateConfigTest(const char* config)
{
std::string result = "\"${";
result += this->RuntimeConfigVariable;
result += "}\" MATCHES \"^(";
if(config && *config)
{
cmScriptGeneratorEncodeConfig(config, result);
}
result += ")$\"";
return result;
}
//----------------------------------------------------------------------------
std::string
cmScriptGenerator::CreateConfigTest(std::vector<std::string> const& configs)
{
std::string result = "\"${";
result += this->RuntimeConfigVariable;
result += "}\" MATCHES \"^(";
const char* sep = "";
for(std::vector<std::string>::const_iterator ci = configs.begin();
ci != configs.end(); ++ci)
{
result += sep;
sep = "|";
cmScriptGeneratorEncodeConfig(ci->c_str(), result);
}
result += ")$\"";
return result;
}
//----------------------------------------------------------------------------
void cmScriptGenerator::GenerateScript(std::ostream& os)
{
// Track indentation.
Indent indent;
// Generate the script possibly with per-configuration code.
this->GenerateScriptConfigs(os, indent);
}
//----------------------------------------------------------------------------
void cmScriptGenerator::GenerateScriptConfigs(std::ostream& os,
Indent const& indent)
{
if(this->ActionsPerConfig)
{
this->GenerateScriptActionsPerConfig(os, indent);
}
else
{
this->GenerateScriptActionsOnce(os, indent);
}
}
//----------------------------------------------------------------------------
void cmScriptGenerator::GenerateScriptActions(std::ostream& os,
Indent const& indent)
{
if(this->ActionsPerConfig)
{
// This is reached for single-configuration build generators in a
// per-config script generator.
this->GenerateScriptForConfig(os, this->ConfigurationName, indent);
}
}
//----------------------------------------------------------------------------
void cmScriptGenerator::GenerateScriptForConfig(std::ostream&, const char*,
Indent const&)
{
// No actions for this generator.
}
//----------------------------------------------------------------------------
bool cmScriptGenerator::GeneratesForConfig(const char* config)
{
// If this is not a configuration-specific rule then we install.
if(this->Configurations.empty())
{
return true;
}
// This is a configuration-specific rule. Check if the config
// matches this rule.
std::string config_upper = cmSystemTools::UpperCase(config?config:"");
for(std::vector<std::string>::const_iterator i =
this->Configurations.begin();
i != this->Configurations.end(); ++i)
{
if(cmSystemTools::UpperCase(*i) == config_upper)
{
return true;
}
}
return false;
}
//----------------------------------------------------------------------------
void cmScriptGenerator::GenerateScriptActionsOnce(std::ostream& os,
Indent const& indent)
{
if(this->Configurations.empty())
{
// This rule is for all configurations.
this->GenerateScriptActions(os, indent);
}
else
{
// Generate a per-configuration block.
std::string config_test = this->CreateConfigTest(this->Configurations);
os << indent << "IF(" << config_test << ")\n";
this->GenerateScriptActions(os, indent.Next());
os << indent << "ENDIF(" << config_test << ")\n";
}
}
//----------------------------------------------------------------------------
void cmScriptGenerator::GenerateScriptActionsPerConfig(std::ostream& os,
Indent const& indent)
{
if(this->ConfigurationTypes->empty())
{
// In a single-configuration generator there is only one action
// and it applies if the runtime-requested configuration is among
// the rule's allowed configurations. The configuration built in
// the tree does not matter for this decision but will be used to
// generate proper target file names into the code.
this->GenerateScriptActionsOnce(os, indent);
}
else
{
// In a multi-configuration generator we produce a separate rule
// in a block for each configuration that is built. We restrict
// the list of configurations to those to which this rule applies.
for(std::vector<std::string>::const_iterator i =
this->ConfigurationTypes->begin();
i != this->ConfigurationTypes->end(); ++i)
{
const char* config = i->c_str();
if(this->GeneratesForConfig(config))
{
// Generate a per-configuration block.
std::string config_test = this->CreateConfigTest(config);
os << indent << "IF(" << config_test << ")\n";
this->GenerateScriptForConfig(os, config, indent.Next());
os << indent << "ENDIF(" << config_test << ")\n";
}
}
}
}
Index: cmInstallTargetGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmInstallTargetGenerator.cxx,v
retrieving revision 1.67
retrieving revision 1.68
diff -C 2 -d -r1.67 -r1.68
*** cmInstallTargetGenerator.cxx 25 Nov 2008 21:50:48 -0000 1.67
--- cmInstallTargetGenerator.cxx 16 Mar 2009 14:39:49 -0000 1.68
***************
*** 34,37 ****
--- 34,38 ----
ImportLibrary(implib), FilePermissions(file_permissions), Optional(optional)
{
+ this->ActionsPerConfig = true;
this->NamelinkMode = NamelinkModeNone;
this->Target->SetHaveInstallRule(true);
***************
*** 77,122 ****
//----------------------------------------------------------------------------
- void cmInstallTargetGenerator::GenerateScriptConfigs(std::ostream& os,
- Indent const& indent)
- {
- if(this->ConfigurationTypes->empty())
- {
- // In a single-configuration generator, only the install rule's
- // configuration test is important. If that passes, the target is
- // installed regardless of for what configuration it was built.
- this->cmInstallGenerator::GenerateScriptConfigs(os, indent);
- }
- else
- {
- // In a multi-configuration generator, a separate rule is produced
- // in a block for each configuration that is built. However, the
- // list of configurations is restricted to those for which this
- // install rule applies.
- for(std::vector<std::string>::const_iterator i =
- this->ConfigurationTypes->begin();
- i != this->ConfigurationTypes->end(); ++i)
- {
- const char* config = i->c_str();
- if(this->InstallsForConfig(config))
- {
- // Generate a per-configuration block.
- std::string config_test = this->CreateConfigTest(config);
- os << indent << "IF(" << config_test << ")\n";
- this->GenerateScriptForConfig(os, config, indent.Next());
- os << indent << "ENDIF(" << config_test << ")\n";
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------
- void cmInstallTargetGenerator::GenerateScriptActions(std::ostream& os,
- Indent const& indent)
- {
- // This is reached for single-configuration generators only.
- this->GenerateScriptForConfig(os, this->ConfigurationName, indent);
- }
-
- //----------------------------------------------------------------------------
void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
const char* config,
--- 78,81 ----
--- NEW FILE: cmScriptGenerator.h ---
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile: cmScriptGenerator.h,v $
Language: C++
Date: $Date: 2009-03-16 14:39:53 $
Version: $Revision: 1.1 $
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.
=========================================================================*/
#ifndef cmScriptGenerator_h
#define cmScriptGenerator_h
#include "cmStandardIncludes.h"
class cmScriptGeneratorIndent
{
public:
cmScriptGeneratorIndent(): Level(0) {}
cmScriptGeneratorIndent(int level): Level(level) {}
void Write(std::ostream& os) const
{
for(int i=0; i < this->Level; ++i)
{
os << " ";
}
}
cmScriptGeneratorIndent Next(int step = 2) const
{
return cmScriptGeneratorIndent(this->Level + step);
}
private:
int Level;
};
inline std::ostream& operator<<(std::ostream& os,
cmScriptGeneratorIndent const& indent)
{
indent.Write(os);
return os;
}
/** \class cmScriptGenerator
* \brief Support class for generating install and test scripts.
*
*/
class cmScriptGenerator
{
public:
cmScriptGenerator(const char* config_var,
std::vector<std::string> const& configurations);
virtual ~cmScriptGenerator();
void Generate(std::ostream& os, const char* config,
std::vector<std::string> const& configurationTypes);
const std::vector<std::string>& GetConfigurations() const
{ return this->Configurations; }
protected:
typedef cmScriptGeneratorIndent Indent;
virtual void GenerateScript(std::ostream& os);
virtual void GenerateScriptConfigs(std::ostream& os, Indent const& indent);
virtual void GenerateScriptActions(std::ostream& os, Indent const& indent);
virtual void GenerateScriptForConfig(std::ostream& os,
const char* config,
Indent const& indent);
// Test if this generator does something for a given configuration.
bool GeneratesForConfig(const char*);
std::string CreateConfigTest(const char* config);
std::string CreateConfigTest(std::vector<std::string> const& configs);
std::string CreateComponentTest(const char* component);
// Information shared by most generator types.
std::string RuntimeConfigVariable;
std::vector<std::string> const Configurations;
// Information used during generation.
const char* ConfigurationName;
std::vector<std::string> const* ConfigurationTypes;
// True if the subclass needs to generate an explicit rule for each
// configuration. False if the subclass only generates one rule for
// all enabled configurations.
bool ActionsPerConfig;
private:
void GenerateScriptActionsOnce(std::ostream& os, Indent const& indent);
void GenerateScriptActionsPerConfig(std::ostream& os, Indent const& indent);
};
#endif
Index: CMakeLists.txt
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CMakeLists.txt,v
retrieving revision 1.411
retrieving revision 1.412
diff -C 2 -d -r1.411 -r1.412
*** CMakeLists.txt 5 Mar 2009 20:17:06 -0000 1.411
--- CMakeLists.txt 16 Mar 2009 14:39:46 -0000 1.412
***************
*** 202,205 ****
--- 202,207 ----
cmPropertyMap.cxx
cmPropertyMap.h
+ cmScriptGenerator.h
+ cmScriptGenerator.cxx
cmSourceFile.cxx
cmSourceFile.h
More information about the Cmake-commits
mailing list