diff options
author | Brad King <brad.king@kitware.com> | 2009-06-15 14:55:21 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-06-15 14:55:21 (GMT) |
commit | f4b3bdc6bef35e10791e6dd013edd58f70d0b33a (patch) | |
tree | 772e1d9d0f30c0ff3eb657c7744d2b0fad177c7b | |
parent | d30923d6313856bf1b05cb093514947437f6e8b5 (diff) | |
download | CMake-f4b3bdc6bef35e10791e6dd013edd58f70d0b33a.zip CMake-f4b3bdc6bef35e10791e6dd013edd58f70d0b33a.tar.gz CMake-f4b3bdc6bef35e10791e6dd013edd58f70d0b33a.tar.bz2 |
BUG: Create an exe's implib output dir for VS
If an executable marks symbols with __declspec(dllexport) then VS
creates an import library for it. However, it forgets to create the
directory that will contain the import library if it is different from
the location of the executable. We work around this VS bug by creating
a pre-build event on the executable target to make the directory.
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 28 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.h | 2 | ||||
-rw-r--r-- | Tests/Plugin/CMakeLists.txt | 2 |
3 files changed, 32 insertions, 0 deletions
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 72ae0e6..31fcb1d 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1674,6 +1674,33 @@ void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout) fout << "\t\t</Filter>\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<std::string> no_output; + std::vector<std::string> 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 @@ -1693,6 +1720,7 @@ void cmLocalVisualStudio7Generator this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool"; event.Start(tool); event.Write(target.GetPreBuildCommands()); + this->MaybeCreateImplibDir(target, configName, event); event.Finish(); // Add pre-link event. diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h index 8796130..0a62f23 100644 --- a/Source/cmLocalVisualStudio7Generator.h +++ b/Source/cmLocalVisualStudio7Generator.h @@ -125,6 +125,8 @@ private: class EventWriter; friend class EventWriter; + void MaybeCreateImplibDir(cmTarget& target, const char* config, + EventWriter& event); cmVS7FlagTable const* ExtraFlagTable; std::string ModuleDefinitionFile; diff --git a/Tests/Plugin/CMakeLists.txt b/Tests/Plugin/CMakeLists.txt index 2245a8a..38347a97 100644 --- a/Tests/Plugin/CMakeLists.txt +++ b/Tests/Plugin/CMakeLists.txt @@ -34,6 +34,8 @@ ADD_EXECUTABLE(example_exe src/example_exe.cxx) SET_TARGET_PROPERTIES(example_exe PROPERTIES ENABLE_EXPORTS 1 OUTPUT_NAME example + # Test placing exe import library in unique directory. + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/exe ) TARGET_LINK_LIBRARIES(example_exe kwsys) |