mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 13:20:47 -06:00
VS: Enable DOTNET_TARGET_FRAMEWORK properties all target types
This makes them compatible with `VS_PACKAGE_REFERENCES` and, in particular, fixes nuget package references in combination with install targets. Fixes: #20764
This commit is contained in:
@@ -533,7 +533,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
|
|||||||
initProp("JOB_POOL_PRECOMPILE_HEADER");
|
initProp("JOB_POOL_PRECOMPILE_HEADER");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (impl->TargetType <= cmStateEnums::UTILITY) {
|
if (impl->TargetType <= cmStateEnums::GLOBAL_TARGET) {
|
||||||
initProp("DOTNET_TARGET_FRAMEWORK");
|
initProp("DOTNET_TARGET_FRAMEWORK");
|
||||||
initProp("DOTNET_TARGET_FRAMEWORK_VERSION");
|
initProp("DOTNET_TARGET_FRAMEWORK_VERSION");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,12 @@ if(NOT EXISTS "${vcProjectFile}")
|
|||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(installProjectFile "${RunCMake_TEST_BINARY_DIR}/INSTALL.vcxproj")
|
||||||
|
if(NOT EXISTS "${installProjectFile}")
|
||||||
|
set(RunCMake_TEST_FAILED "Install file INSTALL.vcxproj does not exist.")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
set(test1Library "boost")
|
set(test1Library "boost")
|
||||||
set(test1Version "1.7.0")
|
set(test1Version "1.7.0")
|
||||||
@@ -37,3 +43,19 @@ if(NOT Library1Found OR NOT Library2Found)
|
|||||||
set(RunCMake_TEST_FAILED "Failed to find package references")
|
set(RunCMake_TEST_FAILED "Failed to find package references")
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(DOT_NET_FRAMEWORK_VERSION_FOUND FALSE)
|
||||||
|
|
||||||
|
file(STRINGS "${installProjectFile}" installlines)
|
||||||
|
foreach(line IN LISTS lines)
|
||||||
|
if(line MATCHES "^ *<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>$")
|
||||||
|
set(DOT_NET_FRAMEWORK_VERSION_FOUND TRUE)
|
||||||
|
message(STATUS "The install target contains the correct TargetFrameworkVersion.")
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
if(NOT DOT_NET_FRAMEWORK_VERSION_FOUND)
|
||||||
|
set(RunCMake_TEST_FAILED "Failed to find TargetFrameworkVersion in the install target")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -1,4 +1,13 @@
|
|||||||
enable_language(CXX)
|
enable_language(CXX)
|
||||||
|
set(CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION "v4.7.2")
|
||||||
|
|
||||||
add_library(foo foo.cpp)
|
add_library(foo foo.cpp)
|
||||||
|
|
||||||
set_property(TARGET foo PROPERTY VS_PACKAGE_REFERENCES "boost_1.7.0;SFML_2.2.0")
|
set_property(TARGET foo PROPERTY VS_PACKAGE_REFERENCES "boost_1.7.0;SFML_2.2.0")
|
||||||
|
|
||||||
|
# install and export the targets to test the correct behavior
|
||||||
|
# nuget restore will only work with an install target when the correct
|
||||||
|
# target framework version is set
|
||||||
|
set(INSTALL_CMAKE_DIR CMake)
|
||||||
|
install(TARGETS foo EXPORT foo_Export_Target)
|
||||||
|
install(EXPORT foo_Export_Target DESTINATION ${INSTALL_CMAKE_DIR} FILE fooConfig.cmake)
|
||||||
|
|||||||
Reference in New Issue
Block a user