summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCalum Robinson <calum.robinson@sias.com>2024-09-11 11:25:08 (GMT)
committerCalum Robinson <calum.robinson@sias.com>2024-09-11 11:25:08 (GMT)
commit66bd326e28ca1cb6837956f62f1db1d286ba7dd4 (patch)
tree5df413ea74494446b722b470087a29c0d60fea07
parentbc5f3ed586d5f7050e9d203626cb1f92dd130dde (diff)
downloadCMake-66bd326e28ca1cb6837956f62f1db1d286ba7dd4.zip
CMake-66bd326e28ca1cb6837956f62f1db1d286ba7dd4.tar.gz
CMake-66bd326e28ca1cb6837956f62f1db1d286ba7dd4.tar.bz2
VS: Use OUTPUT_NAME in DOTNET_SDK projects
Fixes: #26285
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx23
-rw-r--r--Source/cmVisualStudio10TargetGenerator.h1
-rw-r--r--Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/VsDotnetSdk/VsDotnetSdkAssemblyName-check.cmake22
-rw-r--r--Tests/RunCMake/VsDotnetSdk/VsDotnetSdkAssemblyName.cmake9
5 files changed, 49 insertions, 7 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 72c1d7e..79df9a4 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -1004,6 +1004,8 @@ void cmVisualStudio10TargetGenerator::WriteSdkStyleProjectFile(
ConvertToWindowsSlash(outDir);
e1.Element("OutputPath", outDir);
+ e1.Element("AssemblyName", GetAssemblyName(config));
+
Options& o = *(this->ClOptions[config]);
OptionsHelper oh(o, e1);
oh.OutputFlagMap();
@@ -1609,13 +1611,7 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged(
this->WriteMSToolConfigurationValuesCommon(e1, config);
- std::string postfixName =
- cmStrCat(cmSystemTools::UpperCase(config), "_POSTFIX");
- std::string assemblyName = this->GeneratorTarget->GetOutputName(
- config, cmStateEnums::RuntimeBinaryArtifact);
- if (cmValue postfix = this->GeneratorTarget->GetProperty(postfixName)) {
- assemblyName += *postfix;
- }
+ std::string assemblyName = GetAssemblyName(config);
e1.Element("AssemblyName", assemblyName);
if (cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType()) {
@@ -3274,6 +3270,19 @@ std::string cmVisualStudio10TargetGenerator::GetTargetOutputName() const
return cmStrCat(nameComponents.prefix, nameComponents.base);
}
+std::string cmVisualStudio10TargetGenerator::GetAssemblyName(
+ std::string const& config) const
+{
+ std::string postfixName =
+ cmStrCat(cmSystemTools::UpperCase(config), "_POSTFIX");
+ std::string assemblyName = this->GeneratorTarget->GetOutputName(
+ config, cmStateEnums::RuntimeBinaryArtifact);
+ if (cmValue postfix = this->GeneratorTarget->GetProperty(postfixName)) {
+ assemblyName += *postfix;
+ }
+ return assemblyName;
+}
+
bool cmVisualStudio10TargetGenerator::ComputeClOptions()
{
return std::all_of(
diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h
index 9aae2d3..aae9ca3 100644
--- a/Source/cmVisualStudio10TargetGenerator.h
+++ b/Source/cmVisualStudio10TargetGenerator.h
@@ -122,6 +122,7 @@ private:
std::vector<std::string> GetIncludes(std::string const& config,
std::string const& lang) const;
std::string GetTargetOutputName() const;
+ std::string GetAssemblyName(std::string const& config) const;
bool ComputeClOptions();
bool ComputeClOptions(std::string const& configName);
diff --git a/Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake b/Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake
index 0be77ae..0b2525c 100644
--- a/Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake
+++ b/Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake
@@ -6,6 +6,7 @@ run_cmake(VsDotnetSdkStartupObject)
run_cmake(VsDotnetSdkDefines)
run_cmake(DotnetSdkVariables)
run_cmake(VsDotnetSdkXamlFiles)
+run_cmake(VsDotnetSdkAssemblyName)
function(run_VsDotnetSdk)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/VsDotnetSdk-build)
diff --git a/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkAssemblyName-check.cmake b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkAssemblyName-check.cmake
new file mode 100644
index 0000000..3d865b8
--- /dev/null
+++ b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkAssemblyName-check.cmake
@@ -0,0 +1,22 @@
+set(csProjectFile ${RunCMake_TEST_BINARY_DIR}/foo.csproj)
+
+if(NOT EXISTS "${csProjectFile}")
+ set(RunCMake_TEST_FAILED "Project file ${csProjectFile} does not exist.")
+ return()
+endif()
+
+set(hasAssemblyName FALSE)
+
+file(STRINGS "${csProjectFile}" lines)
+
+foreach(line IN LISTS lines)
+ if(NOT inLib1)
+ if(line MATCHES "<AssemblyName>longer name</AssemblyName>")
+ set(hasAssemblyName TRUE)
+ endif()
+ endif()
+endforeach()
+
+if(NOT hasAssemblyName)
+ set(RunCMake_TEST_FAILED "<AssemblyName> not found in ${csProjectFile}.")
+endif()
diff --git a/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkAssemblyName.cmake b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkAssemblyName.cmake
new file mode 100644
index 0000000..b057b72
--- /dev/null
+++ b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkAssemblyName.cmake
@@ -0,0 +1,9 @@
+enable_language(CSharp)
+
+if(NOT CMAKE_CSharp_COMPILER)
+ return()
+endif()
+
+set(CMAKE_DOTNET_SDK "Microsoft.NET.Sdk")
+add_library(foo SHARED lib1.cs)
+set_target_properties(foo PROPERTIES OUTPUT_NAME "longer name")