From 764ac9803d8f7c33fed29ef43563d894161797fa Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 16 Jun 2009 11:44:07 -0400 Subject: ENH: Generalize exe implib dir creation for VS In VS 7,8,9 executable targets we generate a build event to create the output directory for the import library in case the executable marks symbols with dllexport (VS forgets to create this directory). This generalizes computation of the custom command line to support future use with other VS versions. --- Source/cmLocalVisualStudio7Generator.cxx | 34 ++++++-------------------------- Source/cmLocalVisualStudio7Generator.h | 2 -- Source/cmLocalVisualStudioGenerator.cxx | 30 ++++++++++++++++++++++++++++ Source/cmLocalVisualStudioGenerator.h | 6 ++++++ 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 31fcb1d..ddeeb83 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1674,33 +1674,6 @@ void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout) fout << "\t\t\n"; } -void cmLocalVisualStudio7Generator::MaybeCreateImplibDir(cmTarget& target, - const char* config, - EventWriter& event) -{ - // If an executable exports symbols then VS wants to create an - // import library but forgets to create the output directory. - if(target.GetType() != cmTarget::EXECUTABLE) { return; } - std::string outDir = target.GetDirectory(config, false); - std::string impDir = target.GetDirectory(config, true); - if(impDir == outDir) { return; } - - // Add a pre-build event to create the directory. - cmCustomCommandLine command; - command.push_back(this->Makefile->GetRequiredDefinition("CMAKE_COMMAND")); - command.push_back("-E"); - command.push_back("make_directory"); - command.push_back(impDir); - std::vector no_output; - std::vector no_depends; - cmCustomCommandLines commands; - commands.push_back(command); - cmCustomCommand cc(no_output, no_depends, commands, 0, 0); - cc.SetEscapeOldStyle(false); - cc.SetEscapeAllowMakeVars(true); - event.Write(cc); -} - // look for custom rules on a target and collect them together void cmLocalVisualStudio7Generator @@ -1720,7 +1693,12 @@ void cmLocalVisualStudio7Generator this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool"; event.Start(tool); event.Write(target.GetPreBuildCommands()); - this->MaybeCreateImplibDir(target, configName, event); + cmsys::auto_ptr pcc( + this->MaybeCreateImplibDir(target, configName)); + if(pcc.get()) + { + event.Write(*pcc); + } event.Finish(); // Add pre-link event. diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h index 0a62f23..8796130 100644 --- a/Source/cmLocalVisualStudio7Generator.h +++ b/Source/cmLocalVisualStudio7Generator.h @@ -125,8 +125,6 @@ private: class EventWriter; friend class EventWriter; - void MaybeCreateImplibDir(cmTarget& target, const char* config, - EventWriter& event); cmVS7FlagTable const* ExtraFlagTable; std::string ModuleDefinitionFile; diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index 66be038..4706a96 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -34,6 +34,36 @@ cmLocalVisualStudioGenerator::~cmLocalVisualStudioGenerator() } //---------------------------------------------------------------------------- +cmsys::auto_ptr +cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmTarget& target, + const char* config) +{ + cmsys::auto_ptr pcc; + + // If an executable exports symbols then VS wants to create an + // import library but forgets to create the output directory. + if(target.GetType() != cmTarget::EXECUTABLE) { return pcc; } + std::string outDir = target.GetDirectory(config, false); + std::string impDir = target.GetDirectory(config, true); + if(impDir == outDir) { return pcc; } + + // Add a pre-build event to create the directory. + cmCustomCommandLine command; + command.push_back(this->Makefile->GetRequiredDefinition("CMAKE_COMMAND")); + command.push_back("-E"); + command.push_back("make_directory"); + command.push_back(impDir); + std::vector no_output; + std::vector no_depends; + cmCustomCommandLines commands; + commands.push_back(command); + pcc.reset(new cmCustomCommand(no_output, no_depends, commands, 0, 0)); + pcc->SetEscapeOldStyle(false); + pcc->SetEscapeAllowMakeVars(true); + return pcc; +} + +//---------------------------------------------------------------------------- bool cmLocalVisualStudioGenerator::SourceFileCompiles(const cmSourceFile* sf) { // Identify the language of the source file. diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h index 64ce01d..bddf898 100644 --- a/Source/cmLocalVisualStudioGenerator.h +++ b/Source/cmLocalVisualStudioGenerator.h @@ -19,6 +19,8 @@ #include "cmLocalGenerator.h" +#include + class cmSourceFile; class cmSourceGroup; @@ -35,6 +37,10 @@ public: virtual ~cmLocalVisualStudioGenerator(); protected: + /** Construct a custom command to make exe import lib dir. */ + cmsys::auto_ptr + MaybeCreateImplibDir(cmTarget& target, const char* config); + /** Construct a script from the given list of command lines. */ std::string ConstructScript(const cmCustomCommandLines& commandLines, const char* workingDirectory, -- cgit v0.12