VS: Fix WINDOWS_EXPORT_ALL_SYMBOLS for object libraries

Teach Visual Studio generators to include object files from object
libraries in the list of objects whose symbols are to be exported.
The Makefile and Ninja generators already did this.  Update the
test to cover this case.

Reported-by: Bertrand Bellenot <Bertrand.Bellenot@cern.ch>
This commit is contained in:
Brad King 2016-07-20 11:26:55 -04:00
parent df14a98e9c
commit 13a6ff31be
4 changed files with 16 additions and 1 deletions

View File

@ -827,6 +827,7 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand(
cmSystemTools::Error("could not open ", objs_file.c_str()); cmSystemTools::Error("could not open ", objs_file.c_str());
return; return;
} }
std::vector<std::string> objs;
for (std::vector<cmSourceFile const*>::const_iterator it = for (std::vector<cmSourceFile const*>::const_iterator it =
objectSources.begin(); objectSources.begin();
it != objectSources.end(); ++it) { it != objectSources.end(); ++it) {
@ -836,6 +837,12 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand(
// It must exist because we populated the mapping just above. // It must exist because we populated the mapping just above.
assert(!map_it->second.empty()); assert(!map_it->second.empty());
std::string objFile = obj_dir + map_it->second; std::string objFile = obj_dir + map_it->second;
objs.push_back(objFile);
}
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 // replace $(ConfigurationName) in the object names
cmSystemTools::ReplaceString(objFile, this->GetCMakeCFGIntDir(), cmSystemTools::ReplaceString(objFile, this->GetCMakeCFGIntDir(),
configName.c_str()); configName.c_str());

View File

@ -2,7 +2,9 @@ project(autoexport)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${autoexport_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${autoexport_BINARY_DIR}/bin)
add_subdirectory(sub) add_subdirectory(sub)
add_library(autoexport SHARED hello.cxx world.cxx foo.c) add_library(objlib OBJECT objlib.c)
set_property(TARGET objlib PROPERTY POSITION_INDEPENDENT_CODE 1)
add_library(autoexport SHARED hello.cxx world.cxx foo.c $<TARGET_OBJECTS:objlib>)
add_executable(say say.cxx) add_executable(say say.cxx)
if(MSVC) if(MSVC)

View File

@ -0,0 +1,4 @@
int objlib()
{
return 7;
}

View File

@ -11,6 +11,7 @@ extern "C" {
int WINAPI foo(); int WINAPI foo();
// test regular C // test regular C
int bar(); int bar();
int objlib();
} }
// test c++ functions // test c++ functions
@ -39,6 +40,7 @@ int main()
foo(); foo();
printf("\n"); printf("\n");
bar(); bar();
objlib();
printf("\n"); printf("\n");
return 0; return 0;
} }