1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-19 02:17:27 +08:00

VS: switch to new folder structure while keeping the old one working

Fixes: #21170
This commit is contained in:
Marcel Ritzschke
2021-03-14 18:14:19 +01:00
parent 7483843816
commit c73b847b03
10 changed files with 81 additions and 20 deletions

View File

@@ -9,10 +9,9 @@ The :ref:`Visual Studio Generators` for VS 2010 and above support using
a standalone (non-installed) NVIDIA CUDA toolkit. The path a standalone (non-installed) NVIDIA CUDA toolkit. The path
may be specified by a field in :variable:`CMAKE_GENERATOR_TOOLSET` of may be specified by a field in :variable:`CMAKE_GENERATOR_TOOLSET` of
the form ``cuda=C:\path\to\cuda``. The given directory must at least the form ``cuda=C:\path\to\cuda``. The given directory must at least
contain a folder ``.\nvcc`` and must provide Visual Studio integration contain the nvcc compiler in path ``.\bin`` and must provide Visual Studio
files in path ``.\CUDAVisualStudioIntegration\extras\ integration files in path ``.\extras\visual_studio_integration\
visual_studio_integration\MSBuildExtensions\``. One can create a standalone MSBuildExtensions\``. One can create a standalone CUDA toolkit directory by
CUDA toolkit directory by either opening a installer with 7zip or either opening a installer with 7zip or copying the files that are extracted
copying the files that are extracted by the running installer. by the running installer. The value may be empty if no path to a standalone
The value may be empty if no path to a standalone CUDA Toolkit was CUDA Toolkit was specified.
specified.

View File

@@ -452,9 +452,19 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
set(id_ItemDefinitionGroup_entry "<CudaCompile>${cuda_target}<AdditionalOptions>%(AdditionalOptions)-v</AdditionalOptions><CodeGeneration>${cuda_codegen}</CodeGeneration></CudaCompile>") set(id_ItemDefinitionGroup_entry "<CudaCompile>${cuda_target}<AdditionalOptions>%(AdditionalOptions)-v</AdditionalOptions><CodeGeneration>${cuda_codegen}</CodeGeneration></CudaCompile>")
set(id_PostBuildEvent_Command [[echo CMAKE_CUDA_COMPILER=$(CudaToolkitBinDir)\nvcc.exe]]) set(id_PostBuildEvent_Command [[echo CMAKE_CUDA_COMPILER=$(CudaToolkitBinDir)\nvcc.exe]])
if(CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR) if(CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR)
set(id_CudaToolkitCustomDir "<CudaToolkitCustomDir>${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}nvcc</CudaToolkitCustomDir>") # check for legacy cuda custom toolkit folder structure
string(CONCAT id_Import_props "<Import Project=\"${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}\\CUDAVisualStudioIntegration\\extras\\visual_studio_integration\\MSBuildExtensions\\${cuda_tools}.props\" />") if(EXISTS ${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}nvcc)
string(CONCAT id_Import_targets "<Import Project=\"${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}\\CUDAVisualStudioIntegration\\extras\\visual_studio_integration\\MSBuildExtensions\\${cuda_tools}.targets\" />") set(id_CudaToolkitCustomDir "<CudaToolkitCustomDir>${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}nvcc</CudaToolkitCustomDir>")
else()
set(id_CudaToolkitCustomDir "<CudaToolkitCustomDir>${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}</CudaToolkitCustomDir>")
endif()
if(EXISTS ${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}CUDAVisualStudioIntegration)
string(CONCAT id_Import_props "<Import Project=\"${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}CUDAVisualStudioIntegration\\extras\\visual_studio_integration\\MSBuildExtensions\\${cuda_tools}.props\" />")
string(CONCAT id_Import_targets "<Import Project=\"${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}CUDAVisualStudioIntegration\\extras\\visual_studio_integration\\MSBuildExtensions\\${cuda_tools}.targets\" />")
else()
string(CONCAT id_Import_props "<Import Project=\"${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}\\extras\\visual_studio_integration\\MSBuildExtensions\\${cuda_tools}.props\" />")
string(CONCAT id_Import_targets "<Import Project=\"${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}\\extras\\visual_studio_integration\\MSBuildExtensions\\${cuda_tools}.targets\" />")
endif()
else() else()
string(CONCAT id_Import_props [[<Import Project="$(VCTargetsPath)\BuildCustomizations\]] "${cuda_tools}" [[.props" />]]) string(CONCAT id_Import_props [[<Import Project="$(VCTargetsPath)\BuildCustomizations\]] "${cuda_tools}" [[.props" />]])
string(CONCAT id_Import_targets [[<Import Project="$(VCTargetsPath)\BuildCustomizations\]] "${cuda_tools}" [[.targets" />]]) string(CONCAT id_Import_targets [[<Import Project="$(VCTargetsPath)\BuildCustomizations\]] "${cuda_tools}" [[.targets" />]])

View File

@@ -263,8 +263,8 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
bcDir = this->VCTargetsPath + "/BuildCustomizations"; bcDir = this->VCTargetsPath + "/BuildCustomizations";
} else { } else {
bcDir = this->GetPlatformToolsetCudaCustomDirString() + bcDir = this->GetPlatformToolsetCudaCustomDirString() +
"CUDAVisualStudioIntegration\\extras\\" this->GetPlatformToolsetCudaVSIntegrationSubdirString() +
"visual_studio_integration\\MSBuildExtensions"; "extras\\visual_studio_integration\\MSBuildExtensions";
cmSystemTools::ConvertToUnixSlashes(bcDir); cmSystemTools::ConvertToUnixSlashes(bcDir);
} }
cmsys::Glob gl; cmsys::Glob gl;
@@ -470,6 +470,17 @@ bool cmGlobalVisualStudio10Generator::ProcessGeneratorToolsetField(
if (this->GeneratorToolsetCudaCustomDir.back() != '\\') { if (this->GeneratorToolsetCudaCustomDir.back() != '\\') {
this->GeneratorToolsetCudaCustomDir.push_back('\\'); this->GeneratorToolsetCudaCustomDir.push_back('\\');
} }
/* check for legacy toolkit folder structure */
if (cmsys::SystemTools::FileIsDirectory(
cmStrCat(this->GeneratorToolsetCudaCustomDir, "nvcc"))) {
this->GeneratorToolsetCudaNvccSubdir = "nvcc\\";
}
if (cmsys::SystemTools::FileIsDirectory(
cmStrCat(this->GeneratorToolsetCudaCustomDir,
"CUDAVisualStudioIntegration"))) {
this->GeneratorToolsetCudaVSIntegrationSubdir =
"CUDAVisualStudioIntegration\\";
}
} else { } else {
this->GeneratorToolsetCuda = value; this->GeneratorToolsetCuda = value;
} }
@@ -787,6 +798,18 @@ cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDirString() const
return this->GeneratorToolsetCudaCustomDir; return this->GeneratorToolsetCudaCustomDir;
} }
std::string const&
cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaNvccSubdirString() const
{
return this->GeneratorToolsetCudaNvccSubdir;
}
std::string const& cmGlobalVisualStudio10Generator::
GetPlatformToolsetCudaVSIntegrationSubdirString() const
{
return this->GeneratorToolsetCudaVSIntegrationSubdir;
}
cmGlobalVisualStudio10Generator::AuxToolset cmGlobalVisualStudio10Generator::AuxToolset
cmGlobalVisualStudio10Generator::FindAuxToolset(std::string&, cmGlobalVisualStudio10Generator::FindAuxToolset(std::string&,
std::string&) const std::string&) const

View File

@@ -78,6 +78,13 @@ public:
const char* GetPlatformToolsetCudaCustomDir() const; const char* GetPlatformToolsetCudaCustomDir() const;
std::string const& GetPlatformToolsetCudaCustomDirString() const; std::string const& GetPlatformToolsetCudaCustomDirString() const;
/** The nvcc subdirectory of a custom cuda install directory */
std::string const& GetPlatformToolsetCudaNvccSubdirString() const;
/** The visual studio integration subdirectory of a custom cuda install
* directory */
std::string const& GetPlatformToolsetCudaVSIntegrationSubdirString() const;
/** Return whether we need to use No/Debug instead of false/true /** Return whether we need to use No/Debug instead of false/true
for GenerateDebugInformation. */ for GenerateDebugInformation. */
bool GetPlatformToolsetNeedsDebugEnum() const bool GetPlatformToolsetNeedsDebugEnum() const
@@ -188,6 +195,8 @@ protected:
std::string GeneratorToolsetCustomVCTargetsDir; std::string GeneratorToolsetCustomVCTargetsDir;
std::string GeneratorToolsetCuda; std::string GeneratorToolsetCuda;
std::string GeneratorToolsetCudaCustomDir; std::string GeneratorToolsetCudaCustomDir;
std::string GeneratorToolsetCudaNvccSubdir;
std::string GeneratorToolsetCudaVSIntegrationSubdir;
std::string DefaultPlatformToolset; std::string DefaultPlatformToolset;
std::string DefaultPlatformToolsetHostArchitecture; std::string DefaultPlatformToolsetHostArchitecture;
std::string DefaultAndroidToolset; std::string DefaultAndroidToolset;

View File

@@ -545,7 +545,7 @@ void cmVisualStudio10TargetGenerator::Generate()
e1.Element( e1.Element(
"CudaToolkitCustomDir", "CudaToolkitCustomDir",
this->GlobalGenerator->GetPlatformToolsetCudaCustomDirString() + this->GlobalGenerator->GetPlatformToolsetCudaCustomDirString() +
"nvcc"); this->GlobalGenerator->GetPlatformToolsetCudaNvccSubdirString());
} }
} }
@@ -654,8 +654,9 @@ void cmVisualStudio10TargetGenerator::Generate()
std::string cudaPath = customDir.empty() std::string cudaPath = customDir.empty()
? "$(VCTargetsPath)\\BuildCustomizations\\" ? "$(VCTargetsPath)\\BuildCustomizations\\"
: customDir + : customDir +
"CUDAVisualStudioIntegration\\extras\\" this->GlobalGenerator
"visual_studio_integration\\MSBuildExtensions\\"; ->GetPlatformToolsetCudaVSIntegrationSubdirString() +
"extras\\visual_studio_integration\\MSBuildExtensions\\";
Elem(e1, "Import") Elem(e1, "Import")
.Attribute("Project", .Attribute("Project",
std::move(cudaPath) + "CUDA " + std::move(cudaPath) + "CUDA " +
@@ -747,8 +748,9 @@ void cmVisualStudio10TargetGenerator::Generate()
std::string cudaPath = customDir.empty() std::string cudaPath = customDir.empty()
? "$(VCTargetsPath)\\BuildCustomizations\\" ? "$(VCTargetsPath)\\BuildCustomizations\\"
: customDir + : customDir +
"CUDAVisualStudioIntegration\\extras\\" this->GlobalGenerator
"visual_studio_integration\\MSBuildExtensions\\"; ->GetPlatformToolsetCudaVSIntegrationSubdirString() +
"extras\\visual_studio_integration\\MSBuildExtensions\\";
Elem(e1, "Import") Elem(e1, "Import")
.Attribute("Project", .Attribute("Project",
std::move(cudaPath) + "CUDA " + std::move(cudaPath) + "CUDA " +

View File

@@ -12,8 +12,12 @@ if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[012456]")
run_cmake(TestToolsetCudaVersionOnly) run_cmake(TestToolsetCudaVersionOnly)
set(RunCMake_GENERATOR_TOOLSET "cuda=0.0") set(RunCMake_GENERATOR_TOOLSET "cuda=0.0")
run_cmake(TestToolsetCudaVersionOnly) run_cmake(TestToolsetCudaVersionOnly)
set(RunCMake_GENERATOR_TOOLSET "cuda=C:\\dummy\\cuda") set(RunCMake_GENERATOR_TOOLSET "cuda=${CMAKE_CURRENT_BINARY_DIR}/CudaStandaloneToolset")
run_cmake(TestToolsetCudaPathOnly) run_cmake(TestToolsetCudaPathOnly)
set(RunCMake_GENERATOR_TOOLSET "cuda=${CMAKE_CURRENT_BINARY_DIR}/CudaStandaloneToolset")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/CudaStandaloneToolset/CUDAVisualStudioIntegration")
run_cmake(TestToolsetCudaPathOnlyOldLayout)
file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/CudaStandaloneToolset")
if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[2456]") if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[2456]")
set(RunCMake_GENERATOR_TOOLSET "Test Toolset,host=x64") set(RunCMake_GENERATOR_TOOLSET "Test Toolset,host=x64")
run_cmake(TestToolsetHostArchBoth) run_cmake(TestToolsetHostArchBoth)

View File

@@ -5,8 +5,8 @@ CMake Error at CMakeLists.txt:[0-9]+ \(project\):
given toolset given toolset
cuda=C:\\dummy\\cuda\\ cuda=.*/Tests/RunCMake/CudaStandaloneToolset\\
cannot detect Visual Studio integration files in path cannot detect Visual Studio integration files in path
C:/dummy/cuda/CUDAVisualStudioIntegration/extras/visual_studio_integration/MSBuildExtensions .*/Tests/RunCMake/CudaStandaloneToolset/extras/visual_studio_integration/MSBuildExtensions

View File

@@ -0,0 +1,12 @@
CMake Error at CMakeLists.txt:[0-9]+ \(project\):
Generator
Visual Studio .*
given toolset
cuda=.*/Tests/RunCMake/CudaStandaloneToolset\\
cannot detect Visual Studio integration files in path
.*/Tests/RunCMake/CudaStandaloneToolset/CUDAVisualStudioIntegration/extras/visual_studio_integration/MSBuildExtensions

View File

@@ -0,0 +1 @@
message(FATAL_ERROR "This should not be reached!")