Merge topic 'csharp-source_group-bugfix'

8d87cfdbf3 VS: Fix regression in C# source links

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5314
This commit is contained in:
Brad King
2020-10-06 10:47:10 +00:00
committed by Kitware Robot
4 changed files with 20 additions and 6 deletions
+8 -1
View File
@@ -4996,6 +4996,7 @@ std::string cmVisualStudio10TargetGenerator::GetCSharpSourceLink(
// for this file exists, otherwise we check if the path relative to current
// source- or binary-dir is used within the link and return that
std::string link;
std::string sourceGroupedFile;
std::string const& fullFileName = source->GetFullPath();
std::string const& srcDir = this->Makefile->GetCurrentSourceDirectory();
std::string const& binDir = this->Makefile->GetCurrentBinaryDirectory();
@@ -5005,8 +5006,14 @@ std::string cmVisualStudio10TargetGenerator::GetCSharpSourceLink(
cmSourceGroup* sourceGroup =
this->Makefile->FindSourceGroup(fullFileName, sourceGroups);
if (sourceGroup && !sourceGroup->GetFullName().empty()) {
link = sourceGroup->GetFullName() + "/" +
sourceGroupedFile = sourceGroup->GetFullName() + "/" +
cmsys::SystemTools::GetFilenameName(fullFileName);
cmsys::SystemTools::ConvertToUnixSlashes(sourceGroupedFile);
}
if (!sourceGroupedFile.empty() &&
cmHasSuffix(fullFileName, sourceGroupedFile)) {
link = sourceGroupedFile;
} else if (cmHasPrefix(fullFileName, srcDir)) {
link = fullFileName.substr(srcDir.length() + 1);
} else if (cmHasPrefix(fullFileName, binDir)) {
@@ -9,12 +9,13 @@ file(STRINGS "${csProjFile}" lines)
include(${RunCMake_TEST_SOURCE_DIR}/VsCsharpSourceGroupHelpers.cmake)
set(SOURCE_GROUPS_TO_FIND
"CSharpSourceGroup"
"CSharpSourceGroup/nested"
"Images"
"CSharpSourceGroup\\\\foo\\.cs"
"CSharpSourceGroup\\\\nested\\\\baz\\.cs"
"CSharpSourceGroup\\\\images\\\\empty\\.bmp"
"VsCsharpSourceGroup\\.png"
)
foreach(GROUP_NAME IN LISTS ${SOURCE_GROUPS_TO_FIND})
foreach(GROUP_NAME IN LISTS SOURCE_GROUPS_TO_FIND)
find_source_group("${lines}" ${GROUP_NAME})
if(NOT ${SOURCE_GROUP_FOUND})
return()
@@ -9,8 +9,14 @@ set(SRC_FILES
set(IMAGE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/CSharpSourceGroup/Images/empty.bmp
)
# We explicitly don't set a source group for a source in the root level
# because of https://gitlab.kitware.com/cmake/cmake/-/issues/21221
set(RESOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/VsCsharpSourceGroup.png
)
add_library(VsCsharpSourceGroup SHARED ${SRC_FILES} ${IMAGE_FILES})
add_library(VsCsharpSourceGroup SHARED ${SRC_FILES} ${IMAGE_FILES} ${RESOURCE_FILES})
source_group("CSharpSourceGroup" FILES ${CMAKE_CURRENT_SOURCE_DIR}/CSharpSourceGroup/foo.cs)
source_group("CSharpSourceGroup/nested" FILES ${CMAKE_CURRENT_SOURCE_DIR}/CSharpSourceGroup/nested/baz.cs)
source_group("Images" FILES ${IMAGE_FILES})