Ninja: Fix WINDOWS_EXPORT_ALL_SYMBOLS with PRE_LINK build event

Previously the `__create_def` command could fail in cases where a
`PRE_LINK` custom command changes the working directory.

Fixes: #26973
This commit is contained in:
Vince Dupuis
2025-05-29 14:16:23 -04:00
committed by Brad King
parent c3b2e5b444
commit 2ec61ed01d
2 changed files with 9 additions and 7 deletions

View File

@@ -1450,6 +1450,14 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
}
}
// If we have any PRE_LINK commands, we need to go back to CMAKE_BINARY_DIR
// for the link commands.
if (!preLinkCmdLines.empty()) {
std::string const homeOutDir = localGen.ConvertToOutputFormat(
localGen.GetBinaryDirectory(), cmOutputConverter::SHELL);
preLinkCmdLines.push_back("cd " + homeOutDir);
}
// maybe create .def file from list of objects
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
gt->GetModuleDefinitionInfo(config);
@@ -1490,13 +1498,6 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
fout << src->GetFullPath() << "\n";
}
}
// If we have any PRE_LINK commands, we need to go back to CMAKE_BINARY_DIR
// for the link commands.
if (!preLinkCmdLines.empty()) {
std::string const homeOutDir = localGen.ConvertToOutputFormat(
localGen.GetBinaryDirectory(), cmOutputConverter::SHELL);
preLinkCmdLines.push_back("cd " + homeOutDir);
}
vars["PRE_LINK"] = localGen.BuildCommandLine(
preLinkCmdLines, config, fileConfig, "pre-link", this->GeneratorTarget);

View File

@@ -3,3 +3,4 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Try msvc "big" object format.
target_compile_options(autoexport2 PRIVATE /bigobj)
endif()
add_custom_command(TARGET autoexport2 PRE_LINK COMMAND ${CMAKE_COMMAND} -E true)