mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-04 04:40:56 -06:00
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
This commit is contained in:
@@ -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()
|
||||
|
||||
19
Tests/CudaOnly/PDB/CMakeLists.txt
Normal file
19
Tests/CudaOnly/PDB/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
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
|
||||
)
|
||||
10
Tests/CudaOnly/PDB/check_pdbs.cmake
Normal file
10
Tests/CudaOnly/PDB/check_pdbs.cmake
Normal file
@@ -0,0 +1,10 @@
|
||||
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()
|
||||
4
Tests/CudaOnly/PDB/main.cu
Normal file
4
Tests/CudaOnly/PDB/main.cu
Normal file
@@ -0,0 +1,4 @@
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user