Commit 134e795f authored by Brad King's avatar Brad King
Browse files

VS: Add workaround for CUDA compiler PDB location

The CUDA Toolkit Visual Studio Integration does not honor the
`ClCompile.ProgramDataBaseFileName` field when telling `nvcc` how to
invoke `cl`.  Work around this problem by passing `-Xcompiler=-Fd...`
ourselves through `AdditionalOptions`.

Fixes: #17647
parent 77705a2c
......@@ -2690,6 +2690,20 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
cudaOptions.AppendFlagString("AdditionalOptions", "-x cu");
}
// Specify the compiler program database file if configured.
std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName);
if (!pdb.empty()) {
// CUDA does not have a field for this and does not honor the
// ProgramDataBaseFileName field in ClCompile. Work around this
// limitation by creating the directory and passing the flag ourselves.
std::string const pdbDir = cmSystemTools::GetFilenamePath(pdb);
cmSystemTools::MakeDirectory(pdbDir);
pdb = this->ConvertPath(pdb, true);
ConvertToWindowsSlash(pdb);
std::string const clFd = "-Xcompiler=\"-Fd\\\"" + pdb + "\\\"\"";
cudaOptions.AppendFlagString("AdditionalOptions", clFd);
}
// CUDA automatically passes the proper '--machine' flag to nvcc
// for the current architecture, but does not reflect this default
// in the user-visible IDE settings. Set it explicitly.
......
......@@ -6,3 +6,7 @@ ADD_TEST_MACRO(CudaOnly.LinkSystemDeviceLibraries CudaOnlyLinkSystemDeviceLibrar
ADD_TEST_MACRO(CudaOnly.ResolveDeviceSymbols CudaOnlyResolveDeviceSymbols)
ADD_TEST_MACRO(CudaOnly.SeparateCompilation CudaOnlySeparateCompilation)
ADD_TEST_MACRO(CudaOnly.WithDefs CudaOnlyWithDefs)
if(MSVC)
ADD_TEST_MACRO(CudaOnly.PDB CudaOnlyPDB)
endif()
cmake_minimum_required(VERSION 3.11)
project (CudaOnlyPDB CUDA)
add_executable(CudaOnlyPDB main.cu)
set_target_properties(CudaOnlyPDB PROPERTIES
PDB_NAME LinkPDBName
PDB_OUTPUT_DIRECTORY LinkPDBDir
COMPILE_PDB_NAME CompPDBName
COMPILE_PDB_OUTPUT_DIRECTORY CompPDBDir
)
set(pdbs
${CMAKE_CURRENT_BINARY_DIR}/CompPDBDir/${CMAKE_CFG_INTDIR}/CompPDBName.pdb
${CMAKE_CURRENT_BINARY_DIR}/LinkPDBDir/${CMAKE_CFG_INTDIR}/LinkPDBName.pdb
)
add_custom_command(TARGET CudaOnlyPDB POST_BUILD
COMMAND ${CMAKE_COMMAND} -Dconfig=$<CONFIG> "-Dpdbs=${pdbs}"
-P ${CMAKE_CURRENT_SOURCE_DIR}/check_pdbs.cmake
)
if(NOT "${config}" MATCHES "[Dd][Ee][Bb]")
return()
endif()
foreach(pdb ${pdbs})
if(EXISTS "${pdb}")
message(STATUS "PDB Exists: ${pdb}")
else()
message(SEND_ERROR "PDB MISSING:\n ${pdb}")
endif()
endforeach()
int main()
{
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment