From 4747b64fff648b0f1fb944d9ad538beac553e15b Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 29 Sep 2025 16:26:31 -0400 Subject: [PATCH] VS: Restore include_external_msproject type detection Refactoring in commit 3882718872 (VS: Decouple solution generation from `.sln` file format, 2025-09-15) accidentally left out automatic detection of the external project type id from its file extension. --- Source/cmGlobalVisualStudio7Generator.cxx | 28 ---------- Source/cmGlobalVisualStudio7Generator.h | 2 - Source/cmGlobalVisualStudioGenerator.cxx | 34 ++++++++++++- Source/cmGlobalVisualStudioGenerator.h | 2 + Source/cmVSSolution.cxx | 17 ++++++- Source/cmVSSolution.h | 8 ++- .../AutoType-check-sln.cmake | 8 +++ .../AutoType-check-slnx.cmake | 51 +++++++++++++++++++ .../AutoType-check.cmake | 1 + .../include_external_msproject/AutoType.cmake | 8 +++ .../RunCMakeTest.cmake | 1 + 11 files changed, 126 insertions(+), 34 deletions(-) create mode 100644 Tests/RunCMake/include_external_msproject/AutoType-check-sln.cmake create mode 100644 Tests/RunCMake/include_external_msproject/AutoType-check-slnx.cmake create mode 100644 Tests/RunCMake/include_external_msproject/AutoType-check.cmake create mode 100644 Tests/RunCMake/include_external_msproject/AutoType.cmake diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 4ffd6528b2..4fb5f8c3f0 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -175,34 +175,6 @@ std::string cmGlobalVisualStudio7Generator::FindDevEnvCommand() return vscmd; } -char const* cmGlobalVisualStudio7Generator::ExternalProjectType( - std::string const& location) -{ - std::string extension = cmSystemTools::GetFilenameLastExtension(location); - if (extension == ".vbproj"_s) { - return "F184B08F-C81C-45F6-A57F-5ABD9991F28F"; - } - if (extension == ".csproj"_s) { - return "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC"; - } - if (extension == ".fsproj"_s) { - return "F2A71F9B-5D33-465A-A702-920D77279786"; - } - if (extension == ".vdproj"_s) { - return "54435603-DBB4-11D2-8724-00A0C9A8B90C"; - } - if (extension == ".dbproj"_s) { - return "C8D11400-126E-41CD-887F-60BD40844F9E"; - } - if (extension == ".wixproj"_s) { - return "930C7802-8A8C-48F9-8165-68863BCCD9DD"; - } - if (extension == ".pyproj"_s) { - return "888888A0-9F3D-457C-B088-3A5042F75D52"; - } - return "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942"; -} - std::vector cmGlobalVisualStudio7Generator::GenerateBuildCommand( std::string const& makeProgram, std::string const& projectName, diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 7cd1ab3ac3..1b4efd63d7 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -121,8 +121,6 @@ protected: std::string const& GetDevEnvCommand(); virtual std::string FindDevEnvCommand(); - static char const* ExternalProjectType(std::string const& location); - bool MarmasmEnabled; bool MasmEnabled; bool NasmEnabled; diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index a4e25d8919..281478abbb 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -774,6 +774,38 @@ bool cmGlobalVisualStudioGenerator::Open(std::string const& bindir, return std::async(std::launch::async, OpenSolution, sln).get(); } +cm::string_view cmGlobalVisualStudioGenerator::ExternalProjectTypeId( + std::string const& path) +{ + using namespace cm::VS; + std::string const extension = cmSystemTools::GetFilenameLastExtension(path); + if (extension == ".vfproj"_s) { + return Solution::Project::TypeIdFortran; + } + if (extension == ".vbproj"_s) { + return Solution::Project::TypeIdVisualBasic; + } + if (extension == ".csproj"_s) { + return Solution::Project::TypeIdCSharp; + } + if (extension == ".fsproj"_s) { + return Solution::Project::TypeIdFSharp; + } + if (extension == ".vdproj"_s) { + return Solution::Project::TypeIdVDProj; + } + if (extension == ".dbproj"_s) { + return Solution::Project::TypeIdDatabase; + } + if (extension == ".wixproj"_s) { + return Solution::Project::TypeIdWiX; + } + if (extension == ".pyproj"_s) { + return Solution::Project::TypeIdPython; + } + return Solution::Project::TypeIdDefault; +} + bool cmGlobalVisualStudioGenerator::IsDependedOn( TargetDependSet const& projectTargets, cmGeneratorTarget const* gtIn) const { @@ -936,7 +968,7 @@ cm::VS::Solution cmGlobalVisualStudioGenerator::CreateSolution( if (!projectType.IsEmpty()) { project->TypeId = *projectType; } else { - project->TypeId = Solution::Project::TypeIdDefault; + project->TypeId = this->ExternalProjectTypeId(project->Path); } for (std::string const& config : solution.Configs) { cmList mapConfig{ gt->GetProperty(cmStrCat( diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h index f739a2375c..163fb16794 100644 --- a/Source/cmGlobalVisualStudioGenerator.h +++ b/Source/cmGlobalVisualStudioGenerator.h @@ -183,6 +183,8 @@ protected: /** Returns true if the target system support debugging deployment. */ virtual bool TargetSystemSupportsDeployment() const = 0; + static cm::string_view ExternalProjectTypeId(std::string const& path); + std::set IsPartOfDefaultBuild( std::vector const& configs, TargetDependSet const& projectTargets, diff --git a/Source/cmVSSolution.cxx b/Source/cmVSSolution.cxx index ae973e3824..2fc6fca630 100644 --- a/Source/cmVSSolution.cxx +++ b/Source/cmVSSolution.cxx @@ -17,12 +17,25 @@ namespace cm { namespace VS { -cm::string_view const Solution::Project::TypeIdDefault = - "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942"_s; cm::string_view const Solution::Project::TypeIdCSharp = "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC"_s; +cm::string_view const Solution::Project::TypeIdDatabase = + "C8D11400-126E-41CD-887F-60BD40844F9E"_s; +cm::string_view const Solution::Project::TypeIdDefault = + "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942"_s; +cm::string_view const Solution::Project::TypeIdFSharp = + "F2A71F9B-5D33-465A-A702-920D77279786"_s; cm::string_view const Solution::Project::TypeIdFortran = "6989167D-11E4-40FE-8C1A-2192A86A7E90"_s; +cm::string_view const Solution::Project::TypeIdPython = + "888888A0-9F3D-457C-B088-3A5042F75D52"_s; +cm::string_view const Solution::Project::TypeIdVDProj = + "54435603-DBB4-11D2-8724-00A0C9A8B90C"_s; +cm::string_view const Solution::Project::TypeIdVisualBasic = + "F184B08F-C81C-45F6-A57F-5ABD9991F28F"_s; +cm::string_view const Solution::Project::TypeIdWiX = + "930C7802-8A8C-48F9-8165-68863BCCD9DD"_s; + cm::string_view const Solution::Folder::TypeId = "2150E333-8FDC-42A3-9474-1A3956D46DE8"_s; diff --git a/Source/cmVSSolution.h b/Source/cmVSSolution.h index e2cf5a147a..1678bdca0a 100644 --- a/Source/cmVSSolution.h +++ b/Source/cmVSSolution.h @@ -70,9 +70,15 @@ struct Solution final std::vector BuildDependencies; // Project type GUIDs used during creation. - static cm::string_view const TypeIdDefault; static cm::string_view const TypeIdCSharp; + static cm::string_view const TypeIdDatabase; + static cm::string_view const TypeIdDefault; + static cm::string_view const TypeIdFSharp; static cm::string_view const TypeIdFortran; + static cm::string_view const TypeIdPython; + static cm::string_view const TypeIdVDProj; + static cm::string_view const TypeIdVisualBasic; + static cm::string_view const TypeIdWiX; }; /** Represent one folder in a Solution. */ diff --git a/Tests/RunCMake/include_external_msproject/AutoType-check-sln.cmake b/Tests/RunCMake/include_external_msproject/AutoType-check-sln.cmake new file mode 100644 index 0000000000..b0c163ba3e --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/AutoType-check-sln.cmake @@ -0,0 +1,8 @@ +check_project(AutoType externalCS "" "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC" "" "") +check_project(AutoType externalDB "" "C8D11400-126E-41CD-887F-60BD40844F9E" "" "") +check_project(AutoType externalFS "" "F2A71F9B-5D33-465A-A702-920D77279786" "" "") +check_project(AutoType externalPy "" "888888A0-9F3D-457C-B088-3A5042F75D52" "" "") +check_project(AutoType externalVB "" "F184B08F-C81C-45F6-A57F-5ABD9991F28F" "" "") +check_project(AutoType externalVD "" "54435603-DBB4-11D2-8724-00A0C9A8B90C" "" "") +check_project(AutoType externalVF "" "6989167D-11E4-40FE-8C1A-2192A86A7E90" "" "") +check_project(AutoType externalWiX "" "930C7802-8A8C-48F9-8165-68863BCCD9DD" "" "") diff --git a/Tests/RunCMake/include_external_msproject/AutoType-check-slnx.cmake b/Tests/RunCMake/include_external_msproject/AutoType-check-slnx.cmake new file mode 100644 index 0000000000..4a4a1cb1b2 --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/AutoType-check-slnx.cmake @@ -0,0 +1,51 @@ +RunCMake_check_slnx("${RunCMake_TEST_BINARY_DIR}/AutoType.slnx" [[ +^<\?xml version="1\.0" encoding="UTF-8"\?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +$]]) diff --git a/Tests/RunCMake/include_external_msproject/AutoType-check.cmake b/Tests/RunCMake/include_external_msproject/AutoType-check.cmake new file mode 100644 index 0000000000..b88a40cfc4 --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/AutoType-check.cmake @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_LIST_DIR}/AutoType-check-${sln_ext}.cmake) diff --git a/Tests/RunCMake/include_external_msproject/AutoType.cmake b/Tests/RunCMake/include_external_msproject/AutoType.cmake new file mode 100644 index 0000000000..c812f4389a --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/AutoType.cmake @@ -0,0 +1,8 @@ +include_external_msproject(externalCS external.csproj) +include_external_msproject(externalDB external.dbproj) +include_external_msproject(externalFS external.fsproj) +include_external_msproject(externalPy external.pyproj) +include_external_msproject(externalVB external.vbproj) +include_external_msproject(externalVD external.vdproj) +include_external_msproject(externalVF external.vfproj) +include_external_msproject(externalWiX external.wixproj) diff --git a/Tests/RunCMake/include_external_msproject/RunCMakeTest.cmake b/Tests/RunCMake/include_external_msproject/RunCMakeTest.cmake index 3526e0f34c..1a869be4c1 100644 --- a/Tests/RunCMake/include_external_msproject/RunCMakeTest.cmake +++ b/Tests/RunCMake/include_external_msproject/RunCMakeTest.cmake @@ -8,6 +8,7 @@ else() set(sln_ext "slnx") endif() +run_cmake(AutoType) run_cmake(CustomGuid) run_cmake(CustomTypePlatform) run_cmake(CustomGuidTypePlatform)