support for custom targets on exe and lib
This commit is contained in:
parent
123f9b50ea
commit
722283804b
|
@ -194,9 +194,6 @@ void cmDSPWriter::WriteDSPFile(std::ostream& fout,
|
|||
const char *libName,
|
||||
cmTarget &target)
|
||||
{
|
||||
// Write the DSP file's header.
|
||||
this->WriteDSPHeader(fout, libName, target);
|
||||
|
||||
// We may be modifying the source groups temporarily, so make a copy.
|
||||
std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
|
||||
|
||||
|
@ -228,6 +225,9 @@ void cmDSPWriter::WriteDSPFile(std::ostream& fout,
|
|||
sourceGroup.AddCustomCommand(cc);
|
||||
}
|
||||
|
||||
// Write the DSP file's header.
|
||||
this->WriteDSPHeader(fout, libName, target, sourceGroups);
|
||||
|
||||
// Find the group in which the CMakeLists.txt source belongs, and add
|
||||
// the rule to generate this DSP file.
|
||||
for(std::vector<cmSourceGroup>::reverse_iterator sg = sourceGroups.rbegin();
|
||||
|
@ -263,49 +263,25 @@ void cmDSPWriter::WriteDSPFile(std::ostream& fout,
|
|||
std::string source = cc->first;
|
||||
const cmSourceGroup::Commands& commands = cc->second;
|
||||
|
||||
fout << "# Begin Source File\n\n";\
|
||||
|
||||
// Tell MS-Dev what the source is. If the compiler knows how to
|
||||
// build it, then it will.
|
||||
fout << "SOURCE=" << cmSystemTools::EscapeSpaces(source.c_str()) << "\n\n";
|
||||
if (!commands.empty())
|
||||
if (source != libName)
|
||||
{
|
||||
// Loop through every custom command generating code from the
|
||||
// current source.
|
||||
// build up the depends and outputs and commands
|
||||
cmSourceGroup::CommandFiles totalCommand;
|
||||
std::string totalCommandStr;
|
||||
std::string temp;
|
||||
for(cmSourceGroup::Commands::const_iterator c = commands.begin();
|
||||
c != commands.end(); ++c)
|
||||
fout << "# Begin Source File\n\n";
|
||||
|
||||
// Tell MS-Dev what the source is. If the compiler knows how to
|
||||
// build it, then it will.
|
||||
fout << "SOURCE=" << cmSystemTools::EscapeSpaces(source.c_str()) << "\n\n";
|
||||
if (!commands.empty())
|
||||
{
|
||||
totalCommandStr += "\n\t";
|
||||
temp= c->second.m_Command;
|
||||
cmSystemTools::ConvertToWindowsSlashes(temp);
|
||||
temp = cmSystemTools::EscapeSpaces(temp.c_str());
|
||||
totalCommandStr += temp;
|
||||
totalCommandStr += " ";
|
||||
totalCommandStr += c->second.m_Arguments;
|
||||
totalCommand.Merge(c->second);
|
||||
}
|
||||
// Create a dummy file with the name of the source if it does
|
||||
// not exist
|
||||
if(totalCommand.m_Outputs.empty())
|
||||
{
|
||||
std::string dummyFile = m_Makefile->GetStartOutputDirectory();
|
||||
dummyFile += "/";
|
||||
dummyFile += source;
|
||||
if(!cmSystemTools::FileExists(dummyFile.c_str()))
|
||||
{
|
||||
std::ofstream fout(dummyFile.c_str());
|
||||
fout << "Dummy file created by cmake as unused source for utility command.\n";
|
||||
}
|
||||
cmSourceGroup::CommandFiles totalCommand;
|
||||
std::string totalCommandStr;
|
||||
totalCommandStr = this->CombineCommands(commands, totalCommand,
|
||||
source.c_str());
|
||||
this->WriteCustomRule(fout, source.c_str(), totalCommandStr.c_str(),
|
||||
totalCommand.m_Depends,
|
||||
totalCommand.m_Outputs);
|
||||
}
|
||||
this->WriteCustomRule(fout, source.c_str(), totalCommandStr.c_str(),
|
||||
totalCommand.m_Depends,
|
||||
totalCommand.m_Outputs);
|
||||
fout << "# End Source File\n";
|
||||
}
|
||||
fout << "# End Source File\n";
|
||||
}
|
||||
|
||||
// If the group has a name, write the footer.
|
||||
|
@ -462,9 +438,93 @@ void cmDSPWriter::SetBuildType(BuildType b, const char *libName)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
cmDSPWriter::CombineCommands(const cmSourceGroup::Commands &commands,
|
||||
cmSourceGroup::CommandFiles &totalCommand,
|
||||
const char *source)
|
||||
|
||||
{
|
||||
// Loop through every custom command generating code from the
|
||||
// current source.
|
||||
// build up the depends and outputs and commands
|
||||
std::string totalCommandStr = "";
|
||||
std::string temp;
|
||||
for(cmSourceGroup::Commands::const_iterator c = commands.begin();
|
||||
c != commands.end(); ++c)
|
||||
{
|
||||
totalCommandStr += "\n\t";
|
||||
temp= c->second.m_Command;
|
||||
cmSystemTools::ConvertToWindowsSlashes(temp);
|
||||
temp = cmSystemTools::EscapeSpaces(temp.c_str());
|
||||
totalCommandStr += temp;
|
||||
totalCommandStr += " ";
|
||||
totalCommandStr += c->second.m_Arguments;
|
||||
totalCommand.Merge(c->second);
|
||||
}
|
||||
// Create a dummy file with the name of the source if it does
|
||||
// not exist
|
||||
if(totalCommand.m_Outputs.empty())
|
||||
{
|
||||
std::string dummyFile = m_Makefile->GetStartOutputDirectory();
|
||||
dummyFile += "/";
|
||||
dummyFile += source;
|
||||
if(!cmSystemTools::FileExists(dummyFile.c_str()))
|
||||
{
|
||||
std::ofstream fout(dummyFile.c_str());
|
||||
fout << "Dummy file created by cmake as unused source for utility command.\n";
|
||||
}
|
||||
}
|
||||
return totalCommandStr;
|
||||
}
|
||||
|
||||
|
||||
// look for custom rules on a target and collect them together
|
||||
std::string
|
||||
cmDSPWriter::CreateTargetRules(const cmTarget &target,
|
||||
const char *libName)
|
||||
{
|
||||
std::string customRuleCode = "";
|
||||
|
||||
if (target.GetType() >= cmTarget::UTILITY)
|
||||
{
|
||||
return customRuleCode;
|
||||
}
|
||||
|
||||
// Find the group in which the lix exe custom rules belong
|
||||
bool init = false;
|
||||
for (std::vector<cmCustomCommand>::const_iterator cr =
|
||||
target.GetCustomCommands().begin();
|
||||
cr != target.GetCustomCommands().end(); ++cr)
|
||||
{
|
||||
cmCustomCommand cc(*cr);
|
||||
cc.ExpandVariables(*m_Makefile);
|
||||
if (cc.GetSourceName() == libName)
|
||||
{
|
||||
if (!init)
|
||||
{
|
||||
// header stuff
|
||||
customRuleCode = "# Begin Special Build Tool\nPostBuild_Cmds=";
|
||||
init = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
customRuleCode += "\t";
|
||||
}
|
||||
customRuleCode += cc.GetCommand() + " " + cc.GetArguments();
|
||||
}
|
||||
}
|
||||
|
||||
if (init)
|
||||
{
|
||||
customRuleCode += "\n# End Special Build Tool\n";
|
||||
}
|
||||
return customRuleCode;
|
||||
}
|
||||
|
||||
void cmDSPWriter::WriteDSPHeader(std::ostream& fout, const char *libName,
|
||||
const cmTarget &target)
|
||||
const cmTarget &target,
|
||||
std::vector<cmSourceGroup> &sourceGroups)
|
||||
{
|
||||
// determine the link directories
|
||||
std::string libOptions;
|
||||
|
@ -595,6 +655,10 @@ void cmDSPWriter::WriteDSPHeader(std::ostream& fout, const char *libName,
|
|||
libOptions += " /STACK:10000000 ";
|
||||
libMultiLineOptions += "# ADD LINK32 /STACK:10000000 \n";
|
||||
|
||||
// are there any custom rules on the target itself
|
||||
// only if the target is a lib or exe
|
||||
std::string customRuleCode = this->CreateTargetRules(target, libName);
|
||||
|
||||
std::ifstream fin(m_DSPHeaderTemplate.c_str());
|
||||
if(!fin)
|
||||
{
|
||||
|
@ -611,6 +675,8 @@ void cmDSPWriter::WriteDSPHeader(std::ostream& fout, const char *libName,
|
|||
{
|
||||
mfcFlag = "0";
|
||||
}
|
||||
cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE",
|
||||
customRuleCode.c_str());
|
||||
cmSystemTools::ReplaceString(line, "CMAKE_MFC_FLAG",
|
||||
mfcFlag);
|
||||
cmSystemTools::ReplaceString(line, "CM_LIBRARIES",
|
||||
|
|
|
@ -95,7 +95,7 @@ private:
|
|||
void WriteDSPEndGroup(std::ostream& fout);
|
||||
|
||||
void WriteDSPHeader(std::ostream& fout, const char *libName,
|
||||
const cmTarget &tgt);
|
||||
const cmTarget &tgt, std::vector<cmSourceGroup> &sgs);
|
||||
|
||||
void WriteDSPFooter(std::ostream& fout);
|
||||
void AddDSPBuildRule(cmSourceGroup&);
|
||||
|
@ -105,6 +105,13 @@ private:
|
|||
const std::set<std::string>& depends,
|
||||
const std::set<std::string>& outputs);
|
||||
|
||||
std::string CreateTargetRules(const cmTarget &target,
|
||||
const char *libName);
|
||||
std::string CombineCommands(const cmSourceGroup::Commands &commands,
|
||||
cmSourceGroup::CommandFiles &totalCommand,
|
||||
const char *source);
|
||||
|
||||
|
||||
std::string m_IncludeOptions;
|
||||
cmMakefile* m_Makefile;
|
||||
std::vector<std::string> m_Configurations;
|
||||
|
|
|
@ -73,6 +73,8 @@ LINK32=link.exe
|
|||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 CM_OPTIMIZED_LIBRARIES CM_LIBRARIES kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC CMAKE_MFC_FLAG
|
||||
|
@ -102,6 +104,8 @@ LINK32=link.exe
|
|||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 CM_DEBUG_LIBRARIES CM_LIBRARIES kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 MinSizeRel"
|
||||
|
||||
# PROP BASE Use_MFC CMAKE_MFC_FLAG
|
||||
|
@ -133,6 +137,8 @@ LINK32=link.exe
|
|||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /stack:0x989680 /dll /machine:I386
|
||||
# ADD LINK32 CM_OPTIMIZED_LIBRARIES CM_LIBRARIES kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /stack:0x989680 /dll /machine:I386
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
|
||||
|
||||
# PROP BASE Use_MFC CMAKE_MFC_FLAG
|
||||
|
@ -162,6 +168,7 @@ LINK32=link.exe
|
|||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 CM_OPTIMIZED_LIBRARIES CM_LIBRARIES kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ENDIF
|
||||
|
||||
|
|
|
@ -72,6 +72,8 @@ LINK32=link.exe
|
|||
CM_MULTILINE_OPTIMIZED_LIBRARIES
|
||||
CM_MULTILINE_LIBRARIES
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC CMAKE_MFC_FLAG
|
||||
|
@ -102,6 +104,8 @@ LINK32=link.exe
|
|||
CM_MULTILINE_DEBUG_LIBRARIES
|
||||
CM_MULTILINE_LIBRARIES
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 MinSizeRel"
|
||||
# PROP BASE Use_MFC CMAKE_MFC_FLAG
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
|
@ -129,6 +133,8 @@ LINK32=link.exe
|
|||
CM_MULTILINE_OPTIMIZED_LIBRARIES
|
||||
CM_MULTILINE_LIBRARIES
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
|
||||
|
||||
# PROP BASE Use_MFC CMAKE_MFC_FLAG
|
||||
|
@ -157,6 +163,8 @@ LINK32=link.exe
|
|||
CM_MULTILINE_OPTIMIZED_LIBRARIES
|
||||
CM_MULTILINE_LIBRARIES
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
|
|
@ -74,6 +74,8 @@ LINK32=link.exe
|
|||
CM_MULTILINE_OPTIMIZED_LIBRARIES
|
||||
CM_MULTILINE_LIBRARIES
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC CMAKE_MFC_FLAG
|
||||
|
@ -105,6 +107,8 @@ CM_MULTILINE_DEBUG_LIBRARIES
|
|||
CM_MULTILINE_LIBRARIES
|
||||
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 MinSizeRel"
|
||||
# PROP BASE Use_MFC CMAKE_MFC_FLAG
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
|
@ -132,6 +136,8 @@ LINK32=link.exe
|
|||
CM_MULTILINE_OPTIMIZED_LIBRARIES
|
||||
CM_MULTILINE_LIBRARIES
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
|
||||
|
||||
# PROP BASE Use_MFC CMAKE_MFC_FLAG
|
||||
|
@ -162,6 +168,8 @@ LINK32=link.exe
|
|||
CM_MULTILINE_OPTIMIZED_LIBRARIES
|
||||
CM_MULTILINE_LIBRARIES
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
|
|
@ -67,6 +67,8 @@ LIB32=link.exe -lib
|
|||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC CMAKE_MFC_FLAG
|
||||
|
@ -91,6 +93,9 @@ BSC32=bscmake.exe
|
|||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 MinSizeRel"
|
||||
|
||||
# PROP BASE Use_MFC CMAKE_MFC_FLAG
|
||||
|
@ -118,6 +123,8 @@ LIB32=link.exe -lib
|
|||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ELSEIF "$(CFG)" == "OUTPUT_LIBNAME - Win32 RelWithDebInfo"
|
||||
|
||||
# PROP BASE Use_MFC CMAKE_MFC_FLAG
|
||||
|
@ -144,6 +151,8 @@ LIB32=link.exe -lib
|
|||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
CMAKE_CUSTOM_RULE_CODE
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
|
Loading…
Reference in New Issue