VS: Add COMMON_LANGUAGE_RUNTIME support for "netcore"
Generate `CLRSupport` for Visual Studio projects. Fixes: #22054
This commit is contained in:
parent
0815329dbc
commit
eef13a4b33
@ -17,6 +17,13 @@ Not Set (default)
|
||||
|
||||
Mixed unmanaged/managed C++ using .NET Framework.
|
||||
|
||||
``netcore``
|
||||
.. versionadded:: 3.26
|
||||
|
||||
Mixed unmanaged/managed C++ using .NET Core.
|
||||
|
||||
This required VS 2019's v142 toolset or higher.
|
||||
|
||||
``pure``
|
||||
|
||||
Managed C++.
|
||||
|
@ -8515,9 +8515,14 @@ cmGeneratorTarget::ManagedType cmGeneratorTarget::CheckManagedType(
|
||||
// lib
|
||||
// 2. empty propval: add /clr as flag, mixed unmanaged/managed
|
||||
// target, has import lib
|
||||
// 3. any value (safe,pure): add /clr:[propval] as flag, target with
|
||||
// 3. netcore propval: add /clr:netcore as flag, mixed
|
||||
// unmanaged/managed target, has import lib.
|
||||
// 4. any value (safe,pure): add /clr:[propval] as flag, target with
|
||||
// managed code only, no import lib
|
||||
return propval.empty() ? ManagedType::Mixed : ManagedType::Managed;
|
||||
if (propval.empty() || propval == "netcore") {
|
||||
return ManagedType::Mixed;
|
||||
}
|
||||
return ManagedType::Managed;
|
||||
}
|
||||
|
||||
cmGeneratorTarget::ManagedType cmGeneratorTarget::GetManagedType(
|
||||
|
@ -3316,9 +3316,12 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
|
||||
}
|
||||
}
|
||||
|
||||
if (this->ProjectType != VsProjectType::csproj && clOptions.IsManaged()) {
|
||||
if (this->ProjectType != VsProjectType::csproj &&
|
||||
(clOptions.IsManaged() || clOptions.HasFlag("CLRSupport"))) {
|
||||
this->Managed = true;
|
||||
std::string managedType = clOptions.GetFlag("CompileAsManaged");
|
||||
std::string managedType = clOptions.HasFlag("CompileAsManaged")
|
||||
? clOptions.GetFlag("CompileAsManaged")
|
||||
: "Mixed";
|
||||
if (managedType == "Safe" || managedType == "Pure") {
|
||||
// force empty calling convention if safe clr is used
|
||||
clOptions.AddFlag("CallingConvention", "");
|
||||
|
@ -55,6 +55,13 @@
|
||||
"value": "Safe",
|
||||
"flags": []
|
||||
},
|
||||
{
|
||||
"name": "CLRSupport",
|
||||
"switch": "clr:netcore",
|
||||
"comment": ".NET Core Runtime Support",
|
||||
"value": "NetCore",
|
||||
"flags": []
|
||||
},
|
||||
{
|
||||
"name": "WarningLevel",
|
||||
"switch": "W0",
|
||||
|
@ -55,6 +55,13 @@
|
||||
"value": "Safe",
|
||||
"flags": []
|
||||
},
|
||||
{
|
||||
"name": "CLRSupport",
|
||||
"switch": "clr:netcore",
|
||||
"comment": ".NET Core Runtime Support",
|
||||
"value": "NetCore",
|
||||
"flags": []
|
||||
},
|
||||
{
|
||||
"name": "WarningLevel",
|
||||
"switch": "W0",
|
||||
|
@ -89,3 +89,10 @@ run_cmake(VsDotnetTargetFramework)
|
||||
run_cmake(VsDotnetTargetFrameworkVersion)
|
||||
run_cmake(VsNoCompileBatching)
|
||||
run_cmake(DebugInformationFormat)
|
||||
run_cmake(VsCLREmpty)
|
||||
run_cmake(VsCLRPure)
|
||||
run_cmake(VsCLRSafe)
|
||||
|
||||
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.20)
|
||||
run_cmake(VsCLRNetcore)
|
||||
endif()
|
||||
|
24
Tests/RunCMake/VS10Project/VsCLREmpty-check.cmake
Normal file
24
Tests/RunCMake/VS10Project/VsCLREmpty-check.cmake
Normal file
@ -0,0 +1,24 @@
|
||||
set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")
|
||||
if(NOT EXISTS "${vcProjectFile}")
|
||||
set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(propertyFound FALSE)
|
||||
file(STRINGS "${vcProjectFile}" lines)
|
||||
foreach(line IN LISTS lines)
|
||||
if(line MATCHES "^ *<CompileAsManaged>(.*)</CompileAsManaged>$")
|
||||
set(propertyFound TRUE)
|
||||
set(expectedValue "true")
|
||||
set(actualValue ${CMAKE_MATCH_1})
|
||||
if(NOT (${actualValue} STREQUAL ${expectedValue}))
|
||||
set(RunCMake_TEST_FAILED "CompileAsManaged \"${actualValue}\" differs from expected value \"${expectedValue}\".")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT propertyFound)
|
||||
set(RunCMake_TEST_FAILED "Property CompileAsManaged not found in project file.")
|
||||
return()
|
||||
endif()
|
6
Tests/RunCMake/VS10Project/VsCLREmpty.cmake
Normal file
6
Tests/RunCMake/VS10Project/VsCLREmpty.cmake
Normal file
@ -0,0 +1,6 @@
|
||||
enable_language(CXX)
|
||||
|
||||
add_library(foo foo.cpp)
|
||||
|
||||
set_target_properties(foo PROPERTIES
|
||||
COMMON_LANGUAGE_RUNTIME "")
|
24
Tests/RunCMake/VS10Project/VsCLRNetcore-check.cmake
Normal file
24
Tests/RunCMake/VS10Project/VsCLRNetcore-check.cmake
Normal file
@ -0,0 +1,24 @@
|
||||
set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")
|
||||
if(NOT EXISTS "${vcProjectFile}")
|
||||
set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(propertyFound FALSE)
|
||||
file(STRINGS "${vcProjectFile}" lines)
|
||||
foreach(line IN LISTS lines)
|
||||
if(line MATCHES "^ *<CLRSupport>(.*)</CLRSupport>$")
|
||||
set(propertyFound TRUE)
|
||||
set(expectedValue "NetCore")
|
||||
set(actualValue ${CMAKE_MATCH_1})
|
||||
if(NOT (${actualValue} STREQUAL ${expectedValue}))
|
||||
set(RunCMake_TEST_FAILED "CLRSupport \"${actualValue}\" differs from expected value \"${expectedValue}\".")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT propertyFound)
|
||||
set(RunCMake_TEST_FAILED "Property CLRSupport not found in project file.")
|
||||
return()
|
||||
endif()
|
6
Tests/RunCMake/VS10Project/VsCLRNetcore.cmake
Normal file
6
Tests/RunCMake/VS10Project/VsCLRNetcore.cmake
Normal file
@ -0,0 +1,6 @@
|
||||
enable_language(CXX)
|
||||
|
||||
add_library(foo foo.cpp)
|
||||
|
||||
set_target_properties(foo PROPERTIES
|
||||
COMMON_LANGUAGE_RUNTIME "netcore")
|
24
Tests/RunCMake/VS10Project/VsCLRPure-check.cmake
Normal file
24
Tests/RunCMake/VS10Project/VsCLRPure-check.cmake
Normal file
@ -0,0 +1,24 @@
|
||||
set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")
|
||||
if(NOT EXISTS "${vcProjectFile}")
|
||||
set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(propertyFound FALSE)
|
||||
file(STRINGS "${vcProjectFile}" lines)
|
||||
foreach(line IN LISTS lines)
|
||||
if(line MATCHES "^ *<CompileAsManaged>(.*)</CompileAsManaged>$")
|
||||
set(propertyFound TRUE)
|
||||
set(expectedValue "Pure")
|
||||
set(actualValue ${CMAKE_MATCH_1})
|
||||
if(NOT (${actualValue} STREQUAL ${expectedValue}))
|
||||
set(RunCMake_TEST_FAILED "CompileAsManaged \"${actualValue}\" differs from expected value \"${expectedValue}\".")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT propertyFound)
|
||||
set(RunCMake_TEST_FAILED "Property CompileAsManaged not found in project file.")
|
||||
return()
|
||||
endif()
|
6
Tests/RunCMake/VS10Project/VsCLRPure.cmake
Normal file
6
Tests/RunCMake/VS10Project/VsCLRPure.cmake
Normal file
@ -0,0 +1,6 @@
|
||||
enable_language(CXX)
|
||||
|
||||
add_library(foo foo.cpp)
|
||||
|
||||
set_target_properties(foo PROPERTIES
|
||||
COMMON_LANGUAGE_RUNTIME "pure")
|
24
Tests/RunCMake/VS10Project/VsCLRSafe-check.cmake
Normal file
24
Tests/RunCMake/VS10Project/VsCLRSafe-check.cmake
Normal file
@ -0,0 +1,24 @@
|
||||
set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")
|
||||
if(NOT EXISTS "${vcProjectFile}")
|
||||
set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(propertyFound FALSE)
|
||||
file(STRINGS "${vcProjectFile}" lines)
|
||||
foreach(line IN LISTS lines)
|
||||
if(line MATCHES "^ *<CompileAsManaged>(.*)</CompileAsManaged>$")
|
||||
set(propertyFound TRUE)
|
||||
set(expectedValue "Safe")
|
||||
set(actualValue ${CMAKE_MATCH_1})
|
||||
if(NOT (${actualValue} STREQUAL ${expectedValue}))
|
||||
set(RunCMake_TEST_FAILED "CompileAsManaged \"${actualValue}\" differs from expected value \"${expectedValue}\".")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT propertyFound)
|
||||
set(RunCMake_TEST_FAILED "Property CompileAsManaged not found in project file.")
|
||||
return()
|
||||
endif()
|
6
Tests/RunCMake/VS10Project/VsCLRSafe.cmake
Normal file
6
Tests/RunCMake/VS10Project/VsCLRSafe.cmake
Normal file
@ -0,0 +1,6 @@
|
||||
enable_language(CXX)
|
||||
|
||||
add_library(foo foo.cpp)
|
||||
|
||||
set_target_properties(foo PROPERTIES
|
||||
COMMON_LANGUAGE_RUNTIME "safe")
|
Loading…
Reference in New Issue
Block a user