diff options
author | Brad King <brad.king@kitware.com> | 2017-03-13 15:54:30 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-03-21 14:02:34 (GMT) |
commit | 075f6454092ae058add228eda8220a3680b2f9e4 (patch) | |
tree | c0bff4ce5eaf25b8e38d904f3cfb64ebfc13265b /Source/cmGlobalVisualStudioGenerator.cxx | |
parent | 21c4ec4ffe1c40382f6b435ff49eade31e1137f2 (diff) | |
download | CMake-075f6454092ae058add228eda8220a3680b2f9e4.zip CMake-075f6454092ae058add228eda8220a3680b2f9e4.tar.gz CMake-075f6454092ae058add228eda8220a3680b2f9e4.tar.bz2 |
Support WINDOWS_EXPORT_ALL_SYMBOLS with `.def` files
The `WINDOWS_EXPORT_ALL_SYMBOLS` target property exports all symbols
found in object files explicitly given to the linker. However, the
linker may also find additional symbols in dependencies and copy them
into the linked binary (e.g. from `msvcrt.lib`). Provide a way to
export an explicit list of such symbols by adding a `.def` file as a
source file.
Fixes: #16473
Diffstat (limited to 'Source/cmGlobalVisualStudioGenerator.cxx')
-rw-r--r-- | Source/cmGlobalVisualStudioGenerator.cxx | 68 |
1 files changed, 39 insertions, 29 deletions
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 4e7d92a..d052f03 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -816,7 +816,7 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand( { cmGeneratorTarget::ModuleDefinitionInfo const* mdi = gt->GetModuleDefinitionInfo(configName); - if (!mdi || !mdi->WindowsExportAllSymbols) { + if (!mdi || !mdi->DefFileGenerated) { return; } @@ -851,37 +851,47 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand( cmSystemTools::Error("could not open ", objs_file.c_str()); return; } - std::vector<std::string> objs; - for (std::vector<cmSourceFile const*>::const_iterator it = - objectSources.begin(); - it != objectSources.end(); ++it) { - // Find the object file name corresponding to this source file. - std::map<cmSourceFile const*, std::string>::const_iterator map_it = - mapping.find(*it); - // It must exist because we populated the mapping just above. - assert(!map_it->second.empty()); - std::string objFile = obj_dir + map_it->second; - objs.push_back(objFile); - } - std::vector<cmSourceFile const*> externalObjectSources; - gt->GetExternalObjects(externalObjectSources, configName); - for (std::vector<cmSourceFile const*>::const_iterator it = - externalObjectSources.begin(); - it != externalObjectSources.end(); ++it) { - objs.push_back((*it)->GetFullPath()); - } - gt->UseObjectLibraries(objs, configName); - for (std::vector<std::string>::iterator it = objs.begin(); it != objs.end(); - ++it) { - std::string objFile = *it; - // replace $(ConfigurationName) in the object names - cmSystemTools::ReplaceString(objFile, this->GetCMakeCFGIntDir(), - configName.c_str()); - if (cmHasLiteralSuffix(objFile, ".obj")) { - fout << objFile << "\n"; + if (mdi->WindowsExportAllSymbols) { + std::vector<std::string> objs; + for (std::vector<cmSourceFile const*>::const_iterator it = + objectSources.begin(); + it != objectSources.end(); ++it) { + // Find the object file name corresponding to this source file. + std::map<cmSourceFile const*, std::string>::const_iterator map_it = + mapping.find(*it); + // It must exist because we populated the mapping just above. + assert(!map_it->second.empty()); + std::string objFile = obj_dir + map_it->second; + objs.push_back(objFile); + } + std::vector<cmSourceFile const*> externalObjectSources; + gt->GetExternalObjects(externalObjectSources, configName); + for (std::vector<cmSourceFile const*>::const_iterator it = + externalObjectSources.begin(); + it != externalObjectSources.end(); ++it) { + objs.push_back((*it)->GetFullPath()); + } + + gt->UseObjectLibraries(objs, configName); + for (std::vector<std::string>::iterator it = objs.begin(); + it != objs.end(); ++it) { + std::string objFile = *it; + // replace $(ConfigurationName) in the object names + cmSystemTools::ReplaceString(objFile, this->GetCMakeCFGIntDir(), + configName.c_str()); + if (cmHasLiteralSuffix(objFile, ".obj")) { + fout << objFile << "\n"; + } } } + + for (std::vector<cmSourceFile const*>::const_iterator i = + mdi->Sources.begin(); + i != mdi->Sources.end(); ++i) { + fout << (*i)->GetFullPath() << "\n"; + } + cmCustomCommandLines commandLines; commandLines.push_back(cmdl); cmCustomCommand command(gt->Target->GetMakefile(), outputs, empty, empty, |