diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 6df088a2bf..3fbbdda716 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -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); diff --git a/Tests/RunCMake/AutoExportDll/sub/CMakeLists.txt b/Tests/RunCMake/AutoExportDll/sub/CMakeLists.txt index 8b70e7dfad..484659d114 100644 --- a/Tests/RunCMake/AutoExportDll/sub/CMakeLists.txt +++ b/Tests/RunCMake/AutoExportDll/sub/CMakeLists.txt @@ -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)